2 * ============LICENSE_START=======================================================
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
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.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.builder;
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;
32 import java.util.ArrayList;
33 import java.util.List;
35 import java.util.UUID;
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;
41 * Created by 10112215 on 2017/9/20.
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");
64 private RequestAction(int value, String name) {
69 public String getName() {
73 public int getIntValue() {
78 public enum SvcAction {
79 Reserve(0, "reserve"),
81 Activate(2, "activate"),
83 Changeassign(4, "changeassign"),
84 Changedelete(5, "changedelete"),
85 Rollback(6, "rollback"),
86 Deactivate(7, "deactivate"),
87 Unassign(8, "unassign"),
93 private SvcAction(int value, String name) {
98 public String getName() {
102 public int getIntValue() {
107 protected String requestId = null;
109 abstract OUT build(DelegateExecution execution, IN input) throws Exception;
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();
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();
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();
147 protected String getOperType(DelegateExecution execution) {
148 return (String) execution.getVariable(SdncUnderlayVpnPreprocessTask.RESOURCE_OPER_TYPE);
151 protected OnapModelInformationEntity getOnapModelInformationEntity(DelegateExecution execution) {
152 OnapModelInformationEntity onapModelInformationEntity = new OnapModelInformationEntity();
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);
163 return onapModelInformationEntity;
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);
176 return paramEntityList;
179 protected RequestInformationEntity getRequestInformationEntity(DelegateExecution execution) {
180 RequestInformationEntity requestInformationEntity = new RequestInformationEntity();
182 requestInformationEntity.setRequestId(getRequestId(execution));
183 requestInformationEntity.setRequestAction(getRequestActoin(execution));
185 return requestInformationEntity;
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;
198 protected String getServiceInstanceName(DelegateExecution execution) {
199 return (String) execution.getVariable("serviceInstanceName");