2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.so.bpmn.infrastructure.scripts;
22 import static org.apache.commons.lang3.StringUtils.*;
24 import org.onap.so.bpmn.core.domain.ServiceDecomposition
25 import org.onap.so.bpmn.core.domain.Resource
26 import org.onap.so.bpmn.core.json.JsonUtils
27 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
28 import org.onap.so.bpmn.common.scripts.ExceptionUtil
30 import org.camunda.bpm.engine.delegate.DelegateExecution
33 * This groovy class supports the <class>DoCompareModelVersions.bpmn</class> process.
36 * @param - model-invariant-id-target
37 * @param - model-version-id-target
38 * @param - model-invariant-id-original
39 * @param - model-version-id-original
42 * @param - addResourceList
43 * @param - delResourceList
46 public class DoCompareModelVersions extends AbstractServiceTaskProcessor {
48 String Prefix="DCMPMDV_"
49 ExceptionUtil exceptionUtil = new ExceptionUtil()
50 JsonUtils jsonUtil = new JsonUtils()
52 public void preProcessRequest (DelegateExecution execution) {
53 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
55 utils.log("INFO"," ***** preProcessRequest *****", isDebugEnabled)
58 execution.setVariable("prefix", Prefix)
61 String modelInvariantUuid_target = execution.getVariable("model-invariant-id-target")
62 if (isBlank(modelInvariantUuid_target)) {
63 msg = "Input model-invariant-id-target is null"
64 utils.log("INFO", msg, isDebugEnabled)
65 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
68 String modelUuid_target = execution.getVariable("model-version-id-target")
69 if (isBlank(modelUuid_target)) {
70 msg = "Input model-version-id-target is null"
71 utils.log("INFO", msg, isDebugEnabled)
72 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
75 String modelInvariantUuid_original = execution.getVariable("model-invariant-id-original")
76 if (isBlank(modelInvariantUuid_original)) {
77 msg = "Input model-invariant-id-original is null"
78 utils.log("INFO", msg, isDebugEnabled)
79 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
82 String modelUuid_original = execution.getVariable("model-version-id-original")
83 if (isBlank(modelUuid_original)) {
84 msg = "Input model-version-id-original is null"
85 utils.log("INFO", msg, isDebugEnabled)
86 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
89 // Target and original modelInvariantUuid must to be the same
90 if(modelInvariantUuid_target != modelInvariantUuid_original){
91 msg = "Input model-invariant-id-target and model-invariant-id-original must to be the same"
92 utils.log("INFO", msg, isDebugEnabled)
93 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
96 // Target and original modelUuid must not to be the same
97 if(modelUuid_target == modelUuid_original){
98 msg = "Input model-version-id-target and model-version-id-original must not to be the same"
99 utils.log("INFO", msg, isDebugEnabled)
100 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
103 } catch (Exception ex){
104 msg = "Exception in preProcessRequest " + ex.getMessage()
105 utils.log("INFO", msg, isDebugEnabled)
106 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
108 utils.log("INFO"," ***** Exit preProcessRequest *****", isDebugEnabled)
111 public void prepareDecomposeService_Target(DelegateExecution execution) {
112 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
115 utils.log("DEBUG", " ***** Inside prepareDecomposeService_Target of update generic e2e service ***** ", isDebugEnabled)
116 String modelInvariantUuid = execution.getVariable("model-invariant-id-target")
117 String modelUuid = execution.getVariable("model-version-id-target")
118 //here modelVersion is not set, we use modelUuid to decompose the service.
119 String serviceModelInfo = """{
120 "modelInvariantUuid":"${modelInvariantUuid}",
121 "modelUuid":"${modelUuid}",
125 execution.setVariable("serviceModelInfo_Target", serviceModelInfo)
127 utils.log("DEBUG", " ***** Completed prepareDecomposeService_Target of update generic e2e service ***** ", isDebugEnabled)
128 } catch (Exception ex) {
129 // try error in method block
130 String exceptionMessage = "Bpmn error encountered in update generic e2e service flow. Unexpected Error from method prepareDecomposeService_Target() - " + ex.getMessage()
131 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
135 public void processDecomposition_Target(DelegateExecution execution) {
136 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
138 utils.log("DEBUG", " ***** Inside processDecomposition_Target() of update generic e2e service flow ***** ", isDebugEnabled)
140 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
141 execution.setVariable("serviceDecomposition_Target", serviceDecomposition)
142 } catch (Exception ex) {
143 String exceptionMessage = "Bpmn error encountered in update generic e2e service flow. Unexpected Error from method processDecomposition_Target() - " + ex.getMessage()
144 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
145 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
149 public void prepareDecomposeService_Original(DelegateExecution execution) {
150 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
153 utils.log("DEBUG", " ***** Inside prepareDecomposeService_Original of update generic e2e service ***** ", isDebugEnabled)
154 String modelInvariantUuid = execution.getVariable("model-invariant-id-original")
155 String modelUuid = execution.getVariable("model-version-id-original")
156 //here modelVersion is not set, we use modelUuid to decompose the service.
157 String serviceModelInfo = """{
158 "modelInvariantUuid":"${modelInvariantUuid}",
159 "modelUuid":"${modelUuid}",
163 execution.setVariable("serviceModelInfo_Original", serviceModelInfo)
165 utils.log("DEBUG", " ***** Completed prepareDecomposeService_Original of update generic e2e service ***** ", isDebugEnabled)
166 } catch (Exception ex) {
167 // try error in method block
168 String exceptionMessage = "Bpmn error encountered in update generic e2e service flow. Unexpected Error from method prepareDecomposeService_Original() - " + ex.getMessage()
169 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
173 public void processDecomposition_Original(DelegateExecution execution) {
174 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
176 utils.log("DEBUG", " ***** Inside processDecomposition_Original() of update generic e2e service flow ***** ", isDebugEnabled)
178 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
179 execution.setVariable("serviceDecomposition_Original", serviceDecomposition)
180 } catch (Exception ex) {
181 String exceptionMessage = "Bpmn error encountered in update generic e2e service flow. processDecomposition_Original() - " + ex.getMessage()
182 utils.log("DEBUG", exceptionMessage, isDebugEnabled)
183 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
187 public void doCompareModelVersions(DelegateExecution execution){
188 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
189 utils.log("INFO", "======== Start doCompareModelVersions Process ======== ", isDebugEnabled)
191 ServiceDecomposition serviceDecomposition_Target = execution.getVariable("serviceDecomposition_Target")
192 ServiceDecomposition serviceDecomposition_Original = execution.getVariable("serviceDecomposition_Original")
194 List<Resource> allSR_target = serviceDecomposition_Target.getServiceResources();
195 List<Resource> allSR_original = serviceDecomposition_Original.getServiceResources();
197 List<Resource> addResourceList = new ArrayList<String>()
198 List<Resource> delResourceList = new ArrayList<String>()
200 addResourceList.addAll(allSR_target)
201 delResourceList.addAll(allSR_original)
204 for (Resource rc_t : allSR_target){
205 String muuid = rc_t.getModelInfo().getModelUuid()
206 String mIuuid = rc_t.getModelInfo().getModelInvariantUuid()
207 String mCuuid = rc_t.getModelInfo().getModelCustomizationUuid()
208 for (Resource rc_o : allSR_original){
209 if(rc_o.getModelInfo().getModelUuid() == muuid
210 && rc_o.getModelInfo().getModelInvariantUuid() == mIuuid
211 && rc_o.getModelInfo().getModelCustomizationUuid() == mCuuid) {
212 addResourceList.remove(rc_t);
213 delResourceList.remove(rc_o);
218 execution.setVariable("addResourceList", addResourceList)
219 execution.setVariable("delResourceList", delResourceList)
220 utils.log("INFO", "addResourceList: " + addResourceList, isDebugEnabled)
221 utils.log("INFO", "delResourceList: " + delResourceList, isDebugEnabled)
223 utils.log("INFO", "======== COMPLETED doCompareModelVersions Process ======== ", isDebugEnabled)