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 String msoRequestId = UUID.randomUUID().toString();
61 if (requestContext != null && requestContext.getMsoRequestId() != null) {
62 msoRequestId = requestContext.getMsoRequestId();
64 GenericResourceApiSdncrequestheaderSdncRequestHeader sdncRequestHeader = generalTopologyObjectMapper.buildSdncRequestHeader(svcAction, sdncReqId);
65 GenericResourceApiRequestinformationRequestInformation requestInformation = generalTopologyObjectMapper.buildGenericResourceApiRequestinformationRequestInformation(msoRequestId, reqAction);
66 GenericResourceApiServiceinformationServiceInformation serviceInformation = generalTopologyObjectMapper.buildServiceInformation(serviceInstance, requestContext, customer, true);
67 GenericResourceApiNetworkinformationNetworkInformation networkInformation = generalTopologyObjectMapper.buildNetworkInformation(network);
68 GenericResourceApiNetworkrequestinputNetworkRequestInput networkRequestInput = buildNetworkRequestInput(network, serviceInstance, cloudRegion);
70 req.setRequestInformation(requestInformation);
71 req.setSdncRequestHeader(sdncRequestHeader);
72 req.setServiceInformation(serviceInformation);
73 req.setNetworkInformation(networkInformation);
75 if (requestContext != null && requestContext.getUserParams() != null) {
76 for (Map.Entry<String, Object> entry : requestContext.getUserParams().entrySet()) {
77 GenericResourceApiParam networkInputParameters = new GenericResourceApiParam();
78 GenericResourceApiParamParam paramItem = new GenericResourceApiParamParam();
79 paramItem.setName(entry.getKey());
80 paramItem.setValue(generalTopologyObjectMapper.mapUserParamValue(entry.getValue()));
81 networkInputParameters.addParamItem(paramItem);
82 networkRequestInput.setNetworkInputParameters(networkInputParameters);
86 req.setNetworkRequestInput(networkRequestInput);
90 * Private helper to build GenericResourceApiNetworkrequestinputNetworkRequestInput
92 private GenericResourceApiNetworkrequestinputNetworkRequestInput buildNetworkRequestInput(L3Network network, ServiceInstance serviceInstance, CloudRegion cloudRegion){
93 GenericResourceApiNetworkrequestinputNetworkRequestInput networkRequestInput = new GenericResourceApiNetworkrequestinputNetworkRequestInput();
94 networkRequestInput.setTenant(cloudRegion.getTenantId());
95 networkRequestInput.setCloudOwner(cloudRegion.getCloudOwner());
96 networkRequestInput.setAicCloudRegion(cloudRegion.getLcpCloudRegionId());
97 if (network.getNetworkName() != null && !network.getNetworkName().equals("")) {
98 networkRequestInput.setNetworkName(network.getNetworkName());
100 if (serviceInstance.getCollection() != null && serviceInstance.getCollection().getInstanceGroup() != null){
101 //set only for network created as part of the collection/instance since 1806
102 networkRequestInput.setNetworkInstanceGroupId(serviceInstance.getCollection().getInstanceGroup().getId());
104 return networkRequestInput;