91b95df1b282175d4830b02d04e10ebf8d95723c
[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.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.request.information.RequestInformation;
26 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.sdnc.request.header.SdncRequestHeader;
27 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.SdncUnderlayVpnPreprocessTask;
28 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.entity.OnapModelInformationEntity;
29 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.entity.ParamEntity;
30 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.entity.RequestInformationEntity;
31 import org.openecomp.mso.bpmn.infrastructure.workflow.serviceTask.client.entity.ServiceInformationEntity;
32 import org.openecomp.mso.requestsdb.RequestsDbConstant;
33
34 import java.util.ArrayList;
35 import java.util.List;
36 import java.util.Map;
37 import java.util.UUID;
38
39 /**
40  * Created by 10112215 on 2017/9/20.
41  */
42 public abstract class AbstractBuilder<IN, OUT> {
43      protected String requestId = null;
44
45      abstract OUT build(DelegateExecution execution, IN input) throws Exception;
46
47      protected String getRequestActoin(DelegateExecution execution) {
48           String action = RequestInformation.RequestAction.CreateNetworkInstance.name();
49           String operType = getOperType(execution);
50           if (!StringUtils.isBlank(operType)) {
51                if (RequestsDbConstant.OperationType.DELETE.equals(operType)) {
52                     action = RequestInformation.RequestAction.DeleteNetworkInstance.name();
53                } else if (RequestsDbConstant.OperationType.CREATE.equals(operType)) {
54                     action = RequestInformation.RequestAction.CreateNetworkInstance.name();
55                }
56           }
57           return action;
58      }
59
60      protected String getOperationType(DelegateExecution execution) {
61           String action = SdncRequestHeader.SvcAction.Create.name();
62           String operType = getOperType(execution);
63           if (!StringUtils.isBlank(operType)) {
64                if (RequestsDbConstant.OperationType.DELETE.equals(operType)) {
65                     action = SdncRequestHeader.SvcAction.Delete.name();
66                } else if (RequestsDbConstant.OperationType.CREATE.equals(operType)) {
67                     action = SdncRequestHeader.SvcAction.Create.name();
68                }
69           }
70           return action;
71      }
72
73      protected synchronized String getRequestId(DelegateExecution execution) {
74           if (StringUtils.isBlank(requestId)) {
75                requestId = (String) execution.getVariable("msoRequestId");
76                if (StringUtils.isBlank(requestId)) {
77                     requestId = UUID.randomUUID().toString();
78                }
79           }
80           return requestId;
81      }
82
83      protected String getOperType(DelegateExecution execution) {
84           return (String) execution.getVariable(SdncUnderlayVpnPreprocessTask.RESOURCE_OPER_TYPE);
85      }
86
87      protected OnapModelInformationEntity getOnapModelInformationEntity(DelegateExecution execution) {
88           OnapModelInformationEntity onapModelInformationEntity = new OnapModelInformationEntity();
89           {
90                String modelInvariantUuid = (String) execution.getVariable("modelInvariantUuid");
91                String modelVersion = (String) execution.getVariable("modelVersion");
92                String modelUuid = (String) execution.getVariable("modelUuid");
93                String modelName = (String) execution.getVariable("modelName");
94                onapModelInformationEntity.setModelInvariantUuid(modelInvariantUuid);
95                onapModelInformationEntity.setModelVersion(modelVersion);
96                onapModelInformationEntity.setModelUuid(modelUuid);
97                onapModelInformationEntity.setModelName(modelName);
98           }
99           return onapModelInformationEntity;
100      }
101
102      protected List<ParamEntity> getParamEntities(Map<String, String> inputs) {
103           List<ParamEntity> paramEntityList = new ArrayList<>();
104           if (inputs != null && !inputs.isEmpty()) {
105                inputs.keySet().forEach(key -> {
106                     ParamEntity paramEntity = new ParamEntity();
107                     paramEntity.setName(key);
108                     paramEntity.setValue(inputs.get(key));
109                     paramEntityList.add(paramEntity);
110                });
111           }
112           return paramEntityList;
113      }
114
115      protected RequestInformationEntity getRequestInformationEntity(DelegateExecution execution) {
116           RequestInformationEntity requestInformationEntity = new RequestInformationEntity();
117           {
118                requestInformationEntity.setRequestId(getRequestId(execution));
119                requestInformationEntity.setRequestAction(getRequestActoin(execution));
120           }
121           return requestInformationEntity;
122      }
123
124      protected ServiceInformationEntity getServiceInformationEntity(DelegateExecution execution) {
125           ServiceInformationEntity serviceInformationEntity = new ServiceInformationEntity();
126           serviceInformationEntity.setServiceId((String) execution.getVariable("productFamilyId"));
127           serviceInformationEntity.setSubscriptionServiceType((String) execution.getVariable("subscriptionServiceType"));
128           serviceInformationEntity.setOnapModelInformation(getOnapModelInformationEntity(execution));
129           serviceInformationEntity.setServiceInstanceId((String) execution.getVariable("serviceInstanceId"));
130           serviceInformationEntity.setGlobalCustomerId((String) execution.getVariable("globalSubscriberId"));
131           return serviceInformationEntity;
132      }
133
134      protected String getServiceInstanceName(DelegateExecution execution) {
135           return (String) execution.getVariable("serviceInstanceName");
136      }
137 }