Merge "Reorder modifiers"
[so.git] / bpmn / MSOInfrastructureBPMN / src / main / java / org / openecomp / mso / bpmn / infrastructure / DoCreateServiceInstance / SetupServiceDecomp.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. 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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.openecomp.mso.bpmn.infrastructure.DoCreateServiceInstance;\r
22 \r
23 import java.util.logging.Logger;\r
24 \r
25 import org.camunda.bpm.engine.delegate.DelegateExecution;\r
26 import org.camunda.bpm.engine.delegate.JavaDelegate;\r
27 import org.json.JSONObject;\r
28 import org.openecomp.mso.bpmn.common.scripts.ExceptionUtil;\r
29 import org.openecomp.mso.bpmn.core.domain.Customer;\r
30 import org.openecomp.mso.bpmn.core.domain.ModelInfo;\r
31 import org.openecomp.mso.bpmn.core.domain.OwningEntity;\r
32 import org.openecomp.mso.bpmn.core.domain.Project;\r
33 import org.openecomp.mso.bpmn.core.domain.Request;\r
34 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition;\r
35 import org.openecomp.mso.bpmn.core.domain.ServiceInstance;\r
36 \r
37 public class SetupServiceDecomp implements JavaDelegate {\r
38 \r
39         ExceptionUtil exceptionUtil = new ExceptionUtil();\r
40         private static Logger LOGGER = Logger.getLogger("SetupServiceDecomp");\r
41 \r
42         public void execute(DelegateExecution execution) throws Exception {\r
43                 LOGGER.info("Starting SetupServiceDecomp");\r
44                 try {\r
45                         String json = (String) execution.getVariable("bpmnRequest");\r
46                         JSONObject jsonObj = new JSONObject(json);\r
47                         JSONObject jsonReq = jsonObj.getJSONObject("requestDetails");\r
48                         JSONObject jsonServ = jsonReq.getJSONObject("serviceInstance");\r
49                         String serviceInstanceId = jsonServ.getString("serviceInstanceId");\r
50                         System.out.println("servInstId: "+serviceInstanceId);\r
51                         String serviceInstanceName = jsonServ.getString("serviceInstanceName");\r
52                         String serviceType = jsonServ.getString("serviceType");\r
53                         String serviceRole = jsonServ.getString("serviceRole");\r
54                         String modelInvariantUuid = jsonServ.getString("modelInvariantUuid");\r
55                         String modelUuid = jsonServ.getString("modelUuid");\r
56                         String modelVersion = jsonServ.getString("modelVersion");\r
57                         String modelName = jsonServ.getString("modelName");\r
58                         String environmentContext = jsonServ.getString("environmentContext");\r
59                         String workloadContext = jsonServ.getString("workloadContext");\r
60                         JSONObject jsonProject = jsonReq.getJSONObject("project");\r
61                         String projectName = jsonProject.getString("projectName");\r
62                         JSONObject jsonOwningEntity = jsonReq.getJSONObject("owningEntity");\r
63                         String owningEntityId = jsonOwningEntity.getString("owningEntityId");\r
64                         String owningEntityName = jsonOwningEntity.getString("owningEntityName");\r
65                         JSONObject jsonCustomer = jsonReq.getJSONObject("customer");\r
66                         String subscriptionServiceType = jsonCustomer.getString("subscriptionServiceType");\r
67                         String globalSubscriberId = jsonCustomer.getString("globalSubscriberId");\r
68                         JSONObject jsonRequest = jsonReq.getJSONObject("request");\r
69                         String sdncRequestId = jsonRequest.getString("sdncRequestId");\r
70                         String callbackURL = jsonRequest.getString("callbackURL");\r
71                         String requestId = jsonRequest.getString("requestId");\r
72                         String productFamilyId = jsonRequest.getString("productFamilyId");\r
73                         ServiceDecomposition serviceDecomp = new ServiceDecomposition("{}");\r
74                         serviceDecomp.setCallbackURN(callbackURL);\r
75                         serviceDecomp.setServiceRole(serviceRole);\r
76                         ModelInfo modelInfo = new ModelInfo();\r
77                         modelInfo.setModelInvariantUuid(modelInvariantUuid);\r
78                         modelInfo.setModelName(modelName);\r
79                         modelInfo.setModelVersion(modelVersion);\r
80                         modelInfo.setModelUuid(modelUuid);\r
81                         ServiceInstance serviceInstance = new ServiceInstance();\r
82                         serviceInstance.setInstanceId(serviceInstanceId);\r
83                         serviceInstance.setInstanceName(serviceInstanceName);\r
84                         serviceInstance.setServiceType(serviceType);\r
85                         serviceInstance.setModelInfo(modelInfo);\r
86                         serviceInstance.setEnvironmentContext(environmentContext);\r
87                         serviceInstance.setWorkloadContext(workloadContext);\r
88                         Project project = new Project();\r
89                         project.setProjectName(projectName);\r
90                         OwningEntity owningEntity = new OwningEntity();\r
91                         owningEntity.setOwningEntityId(owningEntityId);\r
92                         owningEntity.setOwningEntityName(owningEntityName);\r
93                         Customer customer = new Customer();\r
94                         customer.setGlobalSubscriberId(globalSubscriberId);\r
95                         customer.setSubscriptionServiceType(subscriptionServiceType);\r
96                         Request request = new Request();\r
97                         request.setRequestId(requestId);\r
98                         request.setSdncRequestId(sdncRequestId);\r
99                         request.setProductFamilyId(productFamilyId);\r
100                         serviceDecomp.setCustomer(customer);\r
101                         serviceDecomp.setServiceInstance(serviceInstance);\r
102                         serviceDecomp.setRequest(request);\r
103                         serviceDecomp.setProject(project);\r
104                         serviceDecomp.setOwningEntity(owningEntity);\r
105                         execution.setVariable("ServiceDecomposition", serviceDecomp);\r
106                 } catch (Exception ex) {\r
107                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "ERROR IN SET UP SERVICE DECOMP");\r
108                 }\r
109                 LOGGER.info("Finished SetupServiceDecomp");\r
110         }\r
111 \r
112 }\r