AT&T 1712 and 1802 release code
[so.git] / bpmn / MSOInfrastructureBPMN / src / main / groovy / org / openecomp / mso / bpmn / infrastructure / scripts / DoCreateServiceInstanceV2.groovy
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * ONAP - SO\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  *\r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  *\r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END=========================================================\r
19  */\r
20 package org.openecomp.mso.bpmn.infrastructure.scripts;\r
21 \r
22 import static org.apache.commons.lang3.StringUtils.*;\r
23 \r
24 import org.apache.commons.lang3.*\r
25 import org.camunda.bpm.engine.delegate.BpmnError\r
26 import org.camunda.bpm.engine.delegate.DelegateExecution\r
27 import org.openecomp.mso.bpmn.common.scripts.AbstractServiceTaskProcessor\r
28 import org.openecomp.mso.bpmn.core.domain.ServiceDecomposition\r
29 import org.openecomp.mso.client.orchestration.AAIOrchestrator\r
30 import org.openecomp.mso.client.orchestration.SDNCOrchestrator\r
31 \r
32 import groovy.json.*\r
33 \r
34 /**\r
35  * This groovy class supports the <class>DoCreateServiceInstanceV2.bpmn</class> process.\r
36  *\r
37 */\r
38 \r
39 public class DoCreateServiceInstanceV2 extends AbstractServiceTaskProcessor {\r
40 \r
41         AAIOrchestrator aaiO = new AAIOrchestrator()\r
42         SDNCOrchestrator sdncO = new SDNCOrchestrator()\r
43         \r
44         @Override\r
45         public void preProcessRequest(DelegateExecution execution) {\r
46         }\r
47 \r
48         public void createServiceInstance(DelegateExecution execution) { \r
49                 execution.setVariable("callSDNC",true)\r
50                 if(execution.getVariable("serviceType").equalsIgnoreCase("PORT-MIRROR")== false){\r
51                                 if(execution.getVariable("sdncVersion").equals("1610")){\r
52                                         execution.setVariable("callSDNC",false);                                \r
53                                 }\r
54                 }\r
55                 ServiceDecomposition serviceDecomp = (ServiceDecomposition) execution.getVariable("serviceDecomposition")\r
56                 try{\r
57                         aaiO.createServiceInstance(serviceDecomp)\r
58                 } catch (BpmnError e) {\r
59                         throw e\r
60                 }\r
61         }\r
62         \r
63         public void createProject(DelegateExecution execution) {\r
64                 ServiceDecomposition serviceDecomp = (ServiceDecomposition) execution.getVariable("serviceDecomposition")\r
65                 if (serviceDecomp.getServiceInstance() != null && serviceDecomp.getProject() != null) { \r
66                         try{\r
67                                 aaiO.createProjectandConnectServiceInstance(serviceDecomp)\r
68                         } catch (BpmnError e) {\r
69                                 throw e\r
70                         }\r
71                 }\r
72         }\r
73         \r
74         public void createOwningEntity(DelegateExecution execution) {\r
75                 ServiceDecomposition serviceDecomp = (ServiceDecomposition) execution.getVariable("serviceDecomposition")\r
76                 if (serviceDecomp.getServiceInstance() != null && serviceDecomp.getOwningEntity() != null) {\r
77                         try{\r
78                                 aaiO.createOwningEntityandConnectServiceInstance(serviceDecomp)\r
79                         } catch (BpmnError e) {\r
80                                 throw e\r
81                         }       \r
82                 }                       \r
83         }\r
84         \r
85         public void sdncAssignRequest(DelegateExecution execution) {\r
86                 ServiceDecomposition serviceDecomp = (ServiceDecomposition) execution.getVariable("serviceDecomposition")\r
87                 if (serviceDecomp != null) {\r
88                         try {\r
89                                 sdncO.sendSyncResponse(serviceDecomp)\r
90                         } catch (BpmnError e) {\r
91                                 throw e\r
92                         }\r
93                 }\r
94 \r
95         }\r
96         \r
97         public void rollback(DelegateExecution execution) {\r
98                 //TODO\r
99         }\r
100         \r
101 }\r