Containerization feature of SO
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / client / sdnc / mapper / NetworkTopologyOperationRequestMapper.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.Map;
24 import java.util.UUID;
25
26 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
27 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
28 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
29 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
30 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
31 import org.onap.so.client.sdnc.beans.SDNCSvcAction;
32 import org.onap.so.client.sdnc.beans.SDNCSvcOperation;
33 import org.springframework.stereotype.Component;
34
35 import org.onap.sdnc.apps.client.model.GenericResourceApiNetworkOperationInformation;
36 import org.onap.sdnc.apps.client.model.GenericResourceApiNetworkinformationNetworkInformation;
37 import org.onap.sdnc.apps.client.model.GenericResourceApiNetworkrequestinputNetworkRequestInput;
38 import org.onap.sdnc.apps.client.model.GenericResourceApiParam;
39 import org.onap.sdnc.apps.client.model.GenericResourceApiParamParam;
40 import org.onap.sdnc.apps.client.model.GenericResourceApiRequestActionEnumeration;
41 import org.onap.sdnc.apps.client.model.GenericResourceApiRequestinformationRequestInformation;
42 import org.onap.sdnc.apps.client.model.GenericResourceApiSdncrequestheaderSdncRequestHeader;
43 import org.onap.sdnc.apps.client.model.GenericResourceApiServiceinformationServiceInformation;
44
45 /**
46  * Mapper creating SDNC request
47  *
48  */
49 @Component
50 public class NetworkTopologyOperationRequestMapper {
51         
52         static GeneralTopologyObjectMapper generalTopologyObjectMapper = new GeneralTopologyObjectMapper();
53
54         public GenericResourceApiNetworkOperationInformation reqMapper(SDNCSvcOperation svcOperation,
55                         SDNCSvcAction svcAction, GenericResourceApiRequestActionEnumeration reqAction, L3Network network, ServiceInstance serviceInstance,
56                         Customer customer, RequestContext requestContext, CloudRegion cloudRegion) {
57                 GenericResourceApiNetworkOperationInformation req = new GenericResourceApiNetworkOperationInformation();
58                 String sdncReqId = UUID.randomUUID().toString();
59                 GenericResourceApiSdncrequestheaderSdncRequestHeader sdncRequestHeader = generalTopologyObjectMapper.buildSdncRequestHeader(svcAction, sdncReqId);
60                 GenericResourceApiRequestinformationRequestInformation requestInformation = generalTopologyObjectMapper.buildGenericResourceApiRequestinformationRequestInformation(sdncReqId, reqAction);
61                 GenericResourceApiServiceinformationServiceInformation serviceInformation = generalTopologyObjectMapper.buildServiceInformation(serviceInstance, requestContext, customer, true);
62                 GenericResourceApiNetworkinformationNetworkInformation networkInformation = generalTopologyObjectMapper.buildNetworkInformation(network);
63                 GenericResourceApiNetworkrequestinputNetworkRequestInput networkRequestInput = buildNetworkRequestInput(network, serviceInstance, cloudRegion);
64
65                 req.setRequestInformation(requestInformation);
66                 req.setSdncRequestHeader(sdncRequestHeader);
67                 req.setServiceInformation(serviceInformation);
68                 req.setNetworkInformation(networkInformation);
69
70                 if (requestContext.getUserParams() != null) {
71                         for (Map.Entry<String, String> entry : requestContext.getUserParams().entrySet()) {
72                                 GenericResourceApiParam networkInputParameters = new GenericResourceApiParam();
73                                 GenericResourceApiParamParam paramItem = new GenericResourceApiParamParam();
74                                 paramItem.setName(entry.getKey()); 
75                                 paramItem.setValue(entry.getValue()); 
76                                 networkInputParameters.addParamItem(paramItem);
77                                 networkRequestInput.setNetworkInputParameters(networkInputParameters);
78                         }
79                 }
80
81                 req.setNetworkRequestInput(networkRequestInput);
82                 return req;
83         }
84         /*
85          * Private helper to build GenericResourceApiNetworkrequestinputNetworkRequestInput
86          */
87         private GenericResourceApiNetworkrequestinputNetworkRequestInput buildNetworkRequestInput(L3Network network, ServiceInstance serviceInstance, CloudRegion cloudRegion){
88                 GenericResourceApiNetworkrequestinputNetworkRequestInput networkRequestInput = new GenericResourceApiNetworkrequestinputNetworkRequestInput();
89                 networkRequestInput.setTenant(cloudRegion.getTenantId());
90                 networkRequestInput.setAicCloudRegion(cloudRegion.getLcpCloudRegionId());
91                 if (network.getNetworkName() != null && !network.getNetworkName().equals("")) {
92                         networkRequestInput.setNetworkName(network.getNetworkName());
93                 }
94                 if (serviceInstance.getCollection() != null && serviceInstance.getCollection().getInstanceGroup() != null){
95                         //set only for network created as part of the collection/instance since 1806
96                         networkRequestInput.setNetworkInstanceGroupId(serviceInstance.getCollection().getInstanceGroup().getId());
97                 }
98                 return networkRequestInput;
99         }
100 }