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