41fa8f250afb6c3ab8e1a8374220762153e2c527
[so.git] /
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.workflow.serviceTask.client.builder;
22
23 import org.apache.commons.lang3.StringUtils;
24 import org.camunda.bpm.engine.delegate.DelegateExecution;
25 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.SdncUnderlayVpnPreprocessTask;
26 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.entity.OnapModelInformationEntity;
27 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.entity.ParamEntity;
28 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.entity.RequestInformationEntity;
29 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.entity.ServiceInformationEntity;
30 import org.openecomp.mso.requestsdb.RequestsDbConstant;
31
32 import java.util.ArrayList;
33 import java.util.List;
34 import java.util.Map;
35 import java.util.UUID;
36
37 //import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.request.information.RequestInformation;
38 //import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.sdnc.request.header.SdncRequestHeader;
39
40 /**
41  * Created by 10112215 on 2017/9/20.
42  */
43 public abstract class AbstractBuilder<IN, OUT> {
44      public static enum RequestAction {
45           CreateNetworkInstance(0, "CreateNetworkInstance"),
46           ActivateNetworkInstance(1, "ActivateNetworkInstance"),
47           CreateServiceInstance(2, "CreateServiceInstance"),
48           DeleteServiceInstance(3, "DeleteServiceInstance"),
49           DeleteNetworkInstance(4, "DeleteNetworkInstance"),
50           CreateVnfInstance(5, "CreateVnfInstance"),
51           ActivateVnfInstance(6, "ActivateVnfInstance"),
52           DeleteVnfInstance(7, "DeleteVnfInstance"),
53           CreateVfModuleInstance(8, "CreateVfModuleInstance"),
54           ActivateVfModuleInstance(9, "ActivateVfModuleInstance"),
55           DeleteVfModuleInstance(10, "DeleteVfModuleInstance"),
56           CreateContrailRouteInstance(11, "CreateContrailRouteInstance"),
57           DeleteContrailRouteInstance(12, "DeleteContrailRouteInstance"),
58           CreateSecurityZoneInstance(13, "CreateSecurityZoneInstance"),
59           DeleteSecurityZoneInstance(14, "DeleteSecurityZoneInstance");
60
61           String name;
62           int value;
63
64           private RequestAction(int value, String name) {
65                this.value = value;
66                this.name = name;
67           }
68
69           public String getName() {
70                return this.name;
71           }
72
73           public int getIntValue() {
74                return this.value;
75           }
76      }
77
78      public enum SvcAction {
79           Reserve(0, "reserve"),
80           Assign(1, "assign"),
81           Activate(2, "activate"),
82           Delete(3, "delete"),
83           Changeassign(4, "changeassign"),
84           Changedelete(5, "changedelete"),
85           Rollback(6, "rollback"),
86           Deactivate(7, "deactivate"),
87           Unassign(8, "unassign"),
88           Create(9, "create");
89
90           String name;
91           int value;
92
93           private SvcAction(int value, String name) {
94                this.value = value;
95                this.name = name;
96           }
97
98           public String getName() {
99                return this.name;
100           }
101
102           public int getIntValue() {
103                return this.value;
104           }
105      }
106
107      protected String requestId = null;
108
109      abstract OUT build(DelegateExecution execution, IN input) throws Exception;
110
111      protected String getRequestActoin(DelegateExecution execution) {
112           String action = /*RequestInformation.*/RequestAction.CreateNetworkInstance.name();
113           String operType = getOperType(execution);
114           if (!StringUtils.isBlank(operType)) {
115                if (RequestsDbConstant.OperationType.DELETE.equals(operType)) {
116                     action = /*RequestInformation.*/RequestAction.DeleteNetworkInstance.name();
117                } else if (RequestsDbConstant.OperationType.CREATE.equals(operType)) {
118                     action = /*RequestInformation.*/RequestAction.CreateNetworkInstance.name();
119                }
120           }
121           return action;
122      }
123
124      protected String getOperationType(DelegateExecution execution) {
125           String action = /*SdncRequestHeader.*/SvcAction.Create.name();
126           String operType = getOperType(execution);
127           if (!StringUtils.isBlank(operType)) {
128                if (RequestsDbConstant.OperationType.DELETE.equals(operType)) {
129                     action = /*SdncRequestHeader.*/SvcAction.Delete.name();
130                } else if (RequestsDbConstant.OperationType.CREATE.equals(operType)) {
131                     action = /*SdncRequestHeader.*/SvcAction.Create.name();
132                }
133           }
134           return action;
135      }
136
137      protected synchronized String getRequestId(DelegateExecution execution) {
138           if (StringUtils.isBlank(requestId)) {
139                requestId = (String) execution.getVariable("msoRequestId");
140                if (StringUtils.isBlank(requestId)) {
141                     requestId = UUID.randomUUID().toString();
142                }
143           }
144           return requestId;
145      }
146
147      protected String getOperType(DelegateExecution execution) {
148           return (String) execution.getVariable(SdncUnderlayVpnPreprocessTask.RESOURCE_OPER_TYPE);
149      }
150
151      protected OnapModelInformationEntity getOnapModelInformationEntity(DelegateExecution execution) {
152           OnapModelInformationEntity onapModelInformationEntity = new OnapModelInformationEntity();
153           {
154                String modelInvariantUuid = (String) execution.getVariable("modelInvariantUuid");
155                String modelVersion = (String) execution.getVariable("modelVersion");
156                String modelUuid = (String) execution.getVariable("modelUuid");
157                String modelName = (String) execution.getVariable("modelName");
158                onapModelInformationEntity.setModelInvariantUuid(modelInvariantUuid);
159                onapModelInformationEntity.setModelVersion(modelVersion);
160                onapModelInformationEntity.setModelUuid(modelUuid);
161                onapModelInformationEntity.setModelName(modelName);
162           }
163           return onapModelInformationEntity;
164      }
165
166      protected List<ParamEntity> getParamEntities(Map<String, String> inputs) {
167           List<ParamEntity> paramEntityList = new ArrayList<>();
168           if (inputs != null && !inputs.isEmpty()) {
169                inputs.keySet().forEach(key -> {
170                     ParamEntity paramEntity = new ParamEntity();
171                     paramEntity.setName(key);
172                     paramEntity.setValue(inputs.get(key));
173                     paramEntityList.add(paramEntity);
174                });
175           }
176           return paramEntityList;
177      }
178
179      protected RequestInformationEntity getRequestInformationEntity(DelegateExecution execution) {
180           RequestInformationEntity requestInformationEntity = new RequestInformationEntity();
181           {
182                requestInformationEntity.setRequestId(getRequestId(execution));
183                requestInformationEntity.setRequestAction(getRequestActoin(execution));
184           }
185           return requestInformationEntity;
186      }
187
188      protected ServiceInformationEntity getServiceInformationEntity(DelegateExecution execution) {
189           ServiceInformationEntity serviceInformationEntity = new ServiceInformationEntity();
190           serviceInformationEntity.setServiceId((String) execution.getVariable("productFamilyId"));
191           serviceInformationEntity.setSubscriptionServiceType((String) execution.getVariable("subscriptionServiceType"));
192           serviceInformationEntity.setOnapModelInformation(getOnapModelInformationEntity(execution));
193           serviceInformationEntity.setServiceInstanceId((String) execution.getVariable("serviceInstanceId"));
194           serviceInformationEntity.setGlobalCustomerId((String) execution.getVariable("globalSubscriberId"));
195           return serviceInformationEntity;
196      }
197
198      protected String getServiceInstanceName(DelegateExecution execution) {
199           return (String) execution.getVariable("serviceInstanceName");
200      }
201 }