2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 # Copyright (c) 2020, Wipro Limited.
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=========================================================
21 package org.onap.so.bpmn.infrastructure.scripts
23 import org.camunda.bpm.engine.delegate.BpmnError
24 import org.camunda.bpm.engine.delegate.DelegateExecution
25 import org.onap.so.bpmn.common.scripts.AbstractServiceTaskProcessor
26 import org.onap.so.bpmn.common.scripts.ExceptionUtil
27 import org.onap.so.bpmn.common.scripts.RequestDBUtil
28 import org.onap.so.bpmn.core.json.JsonUtils
29 import org.onap.so.db.request.beans.ResourceOperationStatus
30 import org.slf4j.Logger
31 import org.slf4j.LoggerFactory
33 import static org.apache.commons.lang3.StringUtils.isBlank
35 class ModifyServiceIntentInstance extends AbstractServiceTaskProcessor {
37 ExceptionUtil exceptionUtil = new ExceptionUtil()
38 JsonUtils jsonUtil = new JsonUtils()
39 RequestDBUtil requestDBUtil = new RequestDBUtil()
40 ServiceIntentUtils serviceIntentUtils = new ServiceIntentUtils()
42 private static final Logger logger = LoggerFactory.getLogger(ModifyServiceIntentInstance.class)
45 void preProcessRequest(DelegateExecution execution) {
46 logger.debug(Prefix + "preProcessRequest Start")
47 execution.setVariable("prefix", Prefix)
48 execution.setVariable("startTime", System.currentTimeMillis())
52 String subnetInstanceReq = execution.getVariable("bpmnRequest")
53 logger.debug(subnetInstanceReq)
55 serviceIntentUtils.setCommonExecutionVars(execution)
57 String serviceInstanceID = jsonUtil.getJsonValue(subnetInstanceReq, "serviceInstanceID")
58 if (isBlank(serviceInstanceID)) {
59 msg = "Input serviceInstanceID is null"
61 exceptionUtil.buildAndThrowWorkflowException(execution, 500, msg)
64 execution.setVariable("serviceInstanceID", serviceInstanceID)
67 String jobId = UUID.randomUUID().toString()
68 execution.setVariable("jobId", jobId)
70 } catch(BpmnError e) {
72 } catch(Exception ex) {
73 msg = "Exception in ModifyServiceIntentInstance.preProcessRequest " + ex.getMessage()
75 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
77 logger.debug(Prefix + "preProcessRequest Exit")
82 * create operation status in request db
84 * Init the Operation Status
86 def prepareInitOperationStatus = { DelegateExecution execution ->
87 logger.debug(Prefix + "prepareInitOperationStatus Start")
89 String siId = execution.getVariable("serviceInstanceID")
90 String jobId = execution.getVariable("jobId")
92 String modelUuid = serviceIntentUtils.getModelUuidFromServiceInstance(siId)
93 logger.debug("Generated new job for Service Instance serviceId:" + nsiId + "jobId:" + jobId)
95 ResourceOperationStatus initStatus = new ResourceOperationStatus()
96 initStatus.setServiceId(nsiId)
97 initStatus.setOperationId(jobId)
98 initStatus.setResourceTemplateUUID(modelUuid)
99 initStatus.setOperType("Modify")
100 requestDBUtil.prepareInitResourceOperationStatus(execution, initStatus)
102 logger.debug(Prefix + "prepareInitOperationStatus Exit")
108 * return sync response
110 def sendSyncResponse = { DelegateExecution execution ->
111 logger.debug(Prefix + "sendSyncResponse Start")
113 String jobId = execution.getVariable("jobId")
114 String modifySyncResponse = """{"jobId": "${jobId}","status": "processing"}"""
115 .trim().replaceAll(" ", "")
116 logger.debug("sendSyncResponse to APIH:" + "\n" + modifySyncResponse)
117 sendWorkflowResponse(execution, 202, modifySyncResponse)
119 execution.setVariable("sentSyncResponse", true)
120 } catch (Exception ex) {
121 String msg = "Exception in sendSyncResponse:" + ex.getMessage()
123 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg)
125 logger.debug(Prefix + "sendSyncResponse Exit")