Replaced all tabs with spaces in java and pom.xml
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / client / sdnc / mapper / VnfTopologyOperationRequestMapper.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.onap.so.client.sdnc.mapper;
22
23 import java.util.ArrayList;
24 import java.util.List;
25 import java.util.Map;
26 import java.util.UUID;
27 import org.apache.commons.lang.StringUtils;
28 import org.onap.sdnc.northbound.client.model.GenericResourceApiParam;
29 import org.onap.sdnc.northbound.client.model.GenericResourceApiParamParam;
30 import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration;
31 import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestinformationRequestInformation;
32 import org.onap.sdnc.northbound.client.model.GenericResourceApiSdncrequestheaderSdncRequestHeader;
33 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceinformationServiceInformation;
34 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfOperationInformation;
35 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfinformationVnfInformation;
36 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfrequestinputVnfRequestInput;
37 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfrequestinputVnfrequestinputVnfNetworkInstanceGroupIds;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
43 import org.onap.so.bpmn.servicedecomposition.generalobjects.License;
44 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
45 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoInstanceGroup;
46 import org.onap.so.client.sdnc.beans.SDNCSvcAction;
47 import org.onap.so.client.sdnc.beans.SDNCSvcOperation;
48 import org.springframework.beans.factory.annotation.Autowired;
49 import org.springframework.stereotype.Component;
50
51 @Component
52 public class VnfTopologyOperationRequestMapper {
53
54     @Autowired
55     private GeneralTopologyObjectMapper generalTopologyObjectMapper;
56
57     public GenericResourceApiVnfOperationInformation reqMapper(SDNCSvcOperation svcOperation, SDNCSvcAction svcAction,
58             GenericResourceApiRequestActionEnumeration requestAction, GenericVnf vnf, ServiceInstance serviceInstance,
59             Customer customer, CloudRegion cloudRegion, RequestContext requestContext, boolean homing) {
60         String sdncReqId = UUID.randomUUID().toString();
61         String msoRequestId = UUID.randomUUID().toString();
62         if (requestContext != null && requestContext.getMsoRequestId() != null) {
63             msoRequestId = requestContext.getMsoRequestId();
64         }
65         GenericResourceApiVnfOperationInformation req = new GenericResourceApiVnfOperationInformation();
66         GenericResourceApiSdncrequestheaderSdncRequestHeader sdncRequestHeader =
67                 generalTopologyObjectMapper.buildSdncRequestHeader(svcAction, sdncReqId);
68         GenericResourceApiRequestinformationRequestInformation requestInformation = generalTopologyObjectMapper
69                 .buildGenericResourceApiRequestinformationRequestInformation(msoRequestId, requestAction);
70         GenericResourceApiServiceinformationServiceInformation serviceInformation =
71                 generalTopologyObjectMapper.buildServiceInformation(serviceInstance, requestContext, customer, true);
72         GenericResourceApiVnfinformationVnfInformation vnfInformation =
73                 generalTopologyObjectMapper.buildVnfInformation(vnf, serviceInstance, true);
74         GenericResourceApiVnfrequestinputVnfRequestInput vnfRequestInput =
75                 new GenericResourceApiVnfrequestinputVnfRequestInput();
76
77         vnfRequestInput.setTenant(cloudRegion.getTenantId());
78         vnfRequestInput.setAicCloudRegion(cloudRegion.getLcpCloudRegionId());
79         vnfRequestInput.setCloudOwner(cloudRegion.getCloudOwner());
80
81         if (StringUtils.isNotBlank(vnf.getVnfName())) {
82             vnfRequestInput.setVnfName(vnf.getVnfName());
83         }
84
85         req.setRequestInformation(requestInformation);
86         req.setSdncRequestHeader(sdncRequestHeader);
87         req.setServiceInformation(serviceInformation);
88         req.setVnfInformation(vnfInformation);
89
90         GenericResourceApiParam vnfInputParameters = new GenericResourceApiParam();
91         if (requestContext != null && requestContext.getUserParams() != null) {
92             for (Map.Entry<String, Object> entry : requestContext.getUserParams().entrySet()) {
93                 GenericResourceApiParamParam paramItem = new GenericResourceApiParamParam();
94                 paramItem.setName(entry.getKey());
95                 paramItem.setValue(generalTopologyObjectMapper.mapUserParamValue(entry.getValue()));
96                 vnfInputParameters.addParamItem(paramItem);
97                 vnfRequestInput.setVnfInputParameters(vnfInputParameters);
98             }
99         }
100         if (vnf.getCloudParams() != null) {
101             for (Map.Entry<String, String> entry : vnf.getCloudParams().entrySet()) {
102                 GenericResourceApiParamParam paramItem = new GenericResourceApiParamParam();
103                 paramItem.setName(entry.getKey());
104                 paramItem.setValue(entry.getValue());
105                 vnfInputParameters.addParamItem(paramItem);
106             }
107         }
108         if (homing) {
109             License license = vnf.getLicense();
110             if (license != null) {
111                 if (license.getEntitlementPoolUuids() != null && !license.getEntitlementPoolUuids().isEmpty()) {
112                     String entitlementPoolUuid = license.getEntitlementPoolUuids().get(0);
113                     GenericResourceApiParamParam paramItem = new GenericResourceApiParamParam();
114                     paramItem.setName("entitlement_assignment_group_uuid");
115                     paramItem.setValue(entitlementPoolUuid);
116                     vnfInputParameters.addParamItem(paramItem);
117                 }
118                 if (license.getLicenseKeyGroupUuids() != null && !license.getLicenseKeyGroupUuids().isEmpty()) {
119                     String licenseKeyGroupUuid = license.getLicenseKeyGroupUuids().get(0);
120                     GenericResourceApiParamParam paramItem2 = new GenericResourceApiParamParam();
121                     paramItem2.setName("license_assignment_group_uuid");
122                     paramItem2.setValue(licenseKeyGroupUuid);
123                     vnfInputParameters.addParamItem(paramItem2);
124                 }
125             }
126         }
127         List<InstanceGroup> instanceGroups = vnf.getInstanceGroups();
128         List<GenericResourceApiVnfrequestinputVnfrequestinputVnfNetworkInstanceGroupIds> networkInstanceGroupIdList =
129                 new ArrayList<GenericResourceApiVnfrequestinputVnfrequestinputVnfNetworkInstanceGroupIds>();
130
131         for (InstanceGroup instanceGroup : instanceGroups) {
132             if (ModelInfoInstanceGroup.TYPE_L3_NETWORK
133                     .equalsIgnoreCase(instanceGroup.getModelInfoInstanceGroup().getType())) {
134                 GenericResourceApiVnfrequestinputVnfrequestinputVnfNetworkInstanceGroupIds instanceGroupId =
135                         new GenericResourceApiVnfrequestinputVnfrequestinputVnfNetworkInstanceGroupIds();
136                 instanceGroupId.setVnfNetworkInstanceGroupId(instanceGroup.getId());
137                 networkInstanceGroupIdList.add(instanceGroupId);
138             }
139         }
140
141         vnfRequestInput.setVnfNetworkInstanceGroupIds(networkInstanceGroupIdList);
142         vnfRequestInput.setVnfInputParameters(vnfInputParameters);
143         req.setVnfRequestInput(vnfRequestInput);
144         return req;
145     }
146 }