2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
22 package org.onap.so.bpmn.infrastructure.scripts;
24 import static org.apache.commons.lang3.StringUtils.*;
26 import org.onap.so.bpmn.core.domain.ServiceDecomposition
27 import org.onap.so.bpmn.core.domain.Resource
28 import org.onap.so.bpmn.core.json.JsonUtils
29 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
30 import org.onap.so.bpmn.common.scripts.ExceptionUtil
31 import org.slf4j.Logger
32 import org.slf4j.LoggerFactory
34 import org.camunda.bpm.engine.delegate.DelegateExecution
37 * This groovy class supports the <class>DoCompareModelVersions.bpmn</class> process.
40 * @param - model-invariant-id-target
41 * @param - model-version-id-target
42 * @param - model-invariant-id-original
43 * @param - model-version-id-original
46 * @param - addResourceList
47 * @param - delResourceList
50 public class DoCompareModelVersions extends AbstractServiceTaskProcessor {
52 String Prefix="DCMPMDV_"
53 ExceptionUtil exceptionUtil = new ExceptionUtil()
54 JsonUtils jsonUtil = new JsonUtils()
55 private static final Logger logger = LoggerFactory.getLogger( DoCompareModelVersions.class);
57 public void preProcessRequest (DelegateExecution execution) {
58 def isDebugEnabled = execution.getVariable("isDebugLogEnabled")
60 logger.info(" ***** preProcessRequest *****")
63 execution.setVariable("prefix", Prefix)
66 String modelInvariantUuid_target = execution.getVariable("model-invariant-id-target")
67 if (isBlank(modelInvariantUuid_target)) {
68 msg = "Input model-invariant-id-target is null"
70 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
73 String modelUuid_target = execution.getVariable("model-version-id-target")
74 if (isBlank(modelUuid_target)) {
75 msg = "Input model-version-id-target is null"
77 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
80 String modelInvariantUuid_original = execution.getVariable("model-invariant-id-original")
81 if (isBlank(modelInvariantUuid_original)) {
82 msg = "Input model-invariant-id-original is null"
84 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
87 String modelUuid_original = execution.getVariable("model-version-id-original")
88 if (isBlank(modelUuid_original)) {
89 msg = "Input model-version-id-original is null"
91 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
94 // Target and original modelInvariantUuid must to be the same
95 if(modelInvariantUuid_target != modelInvariantUuid_original){
96 msg = "Input model-invariant-id-target and model-invariant-id-original must to be the same"
98 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
101 // Target and original modelUuid must not to be the same
102 if(modelUuid_target == modelUuid_original){
103 msg = "Input model-version-id-target and model-version-id-original must not to be the same"
105 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
108 } catch (Exception ex){
109 msg = "Exception in preProcessRequest " + ex.getMessage()
111 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
113 logger.info(" ***** Exit preProcessRequest *****")
116 public void prepareDecomposeService_Target(DelegateExecution execution) {
117 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
120 logger.debug( " ***** Inside prepareDecomposeService_Target of update generic e2e service ***** ")
121 String modelInvariantUuid = execution.getVariable("model-invariant-id-target")
122 String modelUuid = execution.getVariable("model-version-id-target")
123 //here modelVersion is not set, we use modelUuid to decompose the service.
124 String serviceModelInfo = """{
125 "modelInvariantUuid":"${modelInvariantUuid}",
126 "modelUuid":"${modelUuid}",
130 execution.setVariable("serviceModelInfo_Target", serviceModelInfo)
132 logger.debug( " ***** Completed prepareDecomposeService_Target of update generic e2e service ***** ")
133 } catch (Exception ex) {
134 // try error in method block
135 String exceptionMessage = "Bpmn error encountered in update generic e2e service flow. Unexpected Error from method prepareDecomposeService_Target() - " + ex.getMessage()
136 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
140 public void processDecomposition_Target(DelegateExecution execution) {
141 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
143 logger.debug( " ***** Inside processDecomposition_Target() of update generic e2e service flow ***** ")
145 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
146 execution.setVariable("serviceDecomposition_Target", serviceDecomposition)
147 } catch (Exception ex) {
148 String exceptionMessage = "Bpmn error encountered in update generic e2e service flow. Unexpected Error from method processDecomposition_Target() - " + ex.getMessage()
149 logger.debug( exceptionMessage)
150 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
154 public void prepareDecomposeService_Original(DelegateExecution execution) {
155 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
158 logger.debug( " ***** Inside prepareDecomposeService_Original of update generic e2e service ***** ")
159 String modelInvariantUuid = execution.getVariable("model-invariant-id-original")
160 String modelUuid = execution.getVariable("model-version-id-original")
161 //here modelVersion is not set, we use modelUuid to decompose the service.
162 String serviceModelInfo = """{
163 "modelInvariantUuid":"${modelInvariantUuid}",
164 "modelUuid":"${modelUuid}",
168 execution.setVariable("serviceModelInfo_Original", serviceModelInfo)
170 logger.debug( " ***** Completed prepareDecomposeService_Original of update generic e2e service ***** ")
171 } catch (Exception ex) {
172 // try error in method block
173 String exceptionMessage = "Bpmn error encountered in update generic e2e service flow. Unexpected Error from method prepareDecomposeService_Original() - " + ex.getMessage()
174 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
178 public void processDecomposition_Original(DelegateExecution execution) {
179 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
181 logger.debug( " ***** Inside processDecomposition_Original() of update generic e2e service flow ***** ")
183 ServiceDecomposition serviceDecomposition = execution.getVariable("serviceDecomposition")
184 execution.setVariable("serviceDecomposition_Original", serviceDecomposition)
185 } catch (Exception ex) {
186 String exceptionMessage = "Bpmn error encountered in update generic e2e service flow. processDecomposition_Original() - " + ex.getMessage()
187 logger.debug( exceptionMessage)
188 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, exceptionMessage)
192 public void doCompareModelVersions(DelegateExecution execution){
193 def isDebugEnabled=execution.getVariable("isDebugLogEnabled")
194 logger.info( "======== Start doCompareModelVersions Process ======== ")
196 ServiceDecomposition serviceDecomposition_Target = execution.getVariable("serviceDecomposition_Target")
197 ServiceDecomposition serviceDecomposition_Original = execution.getVariable("serviceDecomposition_Original")
199 List<Resource> allSR_target = serviceDecomposition_Target.getServiceResources();
200 List<Resource> allSR_original = serviceDecomposition_Original.getServiceResources();
202 List<Resource> addResourceList = new ArrayList<String>()
203 List<Resource> delResourceList = new ArrayList<String>()
205 addResourceList.addAll(allSR_target)
206 delResourceList.addAll(allSR_original)
209 for (Resource rc_t : allSR_target){
210 String muuid = rc_t.getModelInfo().getModelUuid()
211 String mIuuid = rc_t.getModelInfo().getModelInvariantUuid()
212 String mCuuid = rc_t.getModelInfo().getModelCustomizationUuid()
213 for (Resource rc_o : allSR_original){
214 if(rc_o.getModelInfo().getModelUuid() == muuid
215 && rc_o.getModelInfo().getModelInvariantUuid() == mIuuid
216 && rc_o.getModelInfo().getModelCustomizationUuid() == mCuuid) {
217 addResourceList.remove(rc_t);
218 delResourceList.remove(rc_o);
223 execution.setVariable("addResourceList", addResourceList)
224 execution.setVariable("delResourceList", delResourceList)
225 logger.info( "addResourceList: " + addResourceList)
226 logger.info( "delResourceList: " + delResourceList)
228 logger.info( "======== COMPLETED doCompareModelVersions Process ======== ")