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;
23 import java.util.List;
27 import org.onap.sdnc.northbound.client.model.GenericResourceApiConfigurationinformationConfigurationInformation;
28 import org.onap.sdnc.northbound.client.model.GenericResourceApiGcrequestinputGcRequestInput;
29 import org.onap.sdnc.northbound.client.model.GenericResourceApiNetworkinformationNetworkInformation;
30 import org.onap.sdnc.northbound.client.model.GenericResourceApiOnapmodelinformationOnapModelInformation;
31 import org.onap.sdnc.northbound.client.model.GenericResourceApiParam;
32 import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestActionEnumeration;
33 import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestinformationRequestInformation;
34 import org.onap.sdnc.northbound.client.model.GenericResourceApiSdncrequestheaderSdncRequestHeader;
35 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceinformationServiceInformation;
36 import org.onap.sdnc.northbound.client.model.GenericResourceApiVfmoduleinformationVfModuleInformation;
37 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfinformationVnfInformation;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
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.L3Network;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
44 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
45 import org.onap.so.client.exception.MapperException;
46 import org.onap.so.client.sdnc.beans.SDNCSvcAction;
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
49 import org.springframework.stereotype.Component;
51 import com.fasterxml.jackson.core.JsonProcessingException;
52 import com.fasterxml.jackson.databind.ObjectMapper;
55 public class GeneralTopologyObjectMapper {
57 private static final Logger logger = LoggerFactory.getLogger(GeneralTopologyObjectMapper.class);
58 private ObjectMapper mapper = new ObjectMapper();
61 * Build GenericResourceApiRequestinformationRequestInformation
63 public GenericResourceApiRequestinformationRequestInformation buildGenericResourceApiRequestinformationRequestInformation(String msoReqId, GenericResourceApiRequestActionEnumeration requestAction){
65 GenericResourceApiRequestinformationRequestInformation requestInformation = new GenericResourceApiRequestinformationRequestInformation();
66 requestInformation.setRequestId(msoReqId);
67 requestInformation.setRequestAction(requestAction);
68 requestInformation.setSource("MSO");
69 return requestInformation;
72 * Build GenericResourceApiServiceinformationServiceInformation
74 public GenericResourceApiServiceinformationServiceInformation buildServiceInformation(ServiceInstance serviceInstance, RequestContext requestContext, Customer customer, boolean includeModelInformation){
75 GenericResourceApiServiceinformationServiceInformation serviceInformation = new GenericResourceApiServiceinformationServiceInformation();
76 serviceInformation.serviceId(serviceInstance.getServiceInstanceId());
77 if (requestContext != null) {
78 serviceInformation.setSubscriptionServiceType(requestContext.getProductFamilyId());
80 if (includeModelInformation) {
81 GenericResourceApiOnapmodelinformationOnapModelInformation onapModelInformation = new GenericResourceApiOnapmodelinformationOnapModelInformation();
82 onapModelInformation.setModelInvariantUuid(serviceInstance.getModelInfoServiceInstance().getModelInvariantUuid());
83 onapModelInformation.setModelVersion(serviceInstance.getModelInfoServiceInstance().getModelVersion());
84 onapModelInformation.setModelName(serviceInstance.getModelInfoServiceInstance().getModelName());
85 onapModelInformation.setModelUuid(serviceInstance.getModelInfoServiceInstance().getModelUuid());
86 serviceInformation.setOnapModelInformation(onapModelInformation );
88 serviceInformation.setServiceInstanceId(serviceInstance.getServiceInstanceId());
90 if (customer != null) {
91 serviceInformation.setGlobalCustomerId(customer.getGlobalCustomerId());
92 if(customer.getServiceSubscription() != null){
93 serviceInformation.setSubscriptionServiceType(customer.getServiceSubscription().getServiceType());
97 return serviceInformation;
100 * Build GenericResourceApiNetworkinformationNetworkInformation
102 public GenericResourceApiNetworkinformationNetworkInformation buildNetworkInformation(L3Network network){
103 GenericResourceApiNetworkinformationNetworkInformation networkInformation = new GenericResourceApiNetworkinformationNetworkInformation();
104 GenericResourceApiOnapmodelinformationOnapModelInformation onapModelInformation = new GenericResourceApiOnapmodelinformationOnapModelInformation();
105 if (network.getModelInfoNetwork() != null) {
106 onapModelInformation.setModelInvariantUuid(network.getModelInfoNetwork().getModelInvariantUUID());
107 onapModelInformation.setModelName(network.getModelInfoNetwork().getModelName());
108 onapModelInformation.setModelVersion(network.getModelInfoNetwork().getModelVersion());
109 onapModelInformation.setModelUuid(network.getModelInfoNetwork().getModelUUID());
110 onapModelInformation.setModelCustomizationUuid(network.getModelInfoNetwork().getModelCustomizationUUID());
111 networkInformation.setOnapModelInformation(onapModelInformation);
114 networkInformation.setFromPreload(null);
115 networkInformation.setNetworkId(network.getNetworkId());
116 networkInformation.setNetworkType(network.getNetworkType());
117 networkInformation.setNetworkTechnology(network.getNetworkTechnology());
118 return networkInformation;
121 * Build GenericResourceApiVnfinformationVnfInformation
123 public GenericResourceApiVnfinformationVnfInformation buildVnfInformation(GenericVnf vnf, ServiceInstance serviceInstance, boolean includeModelInformation){
124 GenericResourceApiVnfinformationVnfInformation vnfInformation = new GenericResourceApiVnfinformationVnfInformation();
125 if (includeModelInformation && vnf.getModelInfoGenericVnf() != null) {
126 GenericResourceApiOnapmodelinformationOnapModelInformation onapModelInformation = new GenericResourceApiOnapmodelinformationOnapModelInformation();
127 onapModelInformation.setModelInvariantUuid(vnf.getModelInfoGenericVnf().getModelInvariantUuid());
128 onapModelInformation.setModelName(vnf.getModelInfoGenericVnf().getModelName());
129 onapModelInformation.setModelVersion(vnf.getModelInfoGenericVnf().getModelVersion());
130 onapModelInformation.setModelUuid(vnf.getModelInfoGenericVnf().getModelUuid());
131 onapModelInformation.setModelCustomizationUuid(vnf.getModelInfoGenericVnf().getModelCustomizationUuid());
132 vnfInformation.setOnapModelInformation(onapModelInformation);
134 vnfInformation.setVnfId(vnf.getVnfId());
135 vnfInformation.setVnfType(vnf.getVnfType());
136 vnfInformation.setVnfName(vnf.getVnfName());
137 return vnfInformation;
140 * Build GenericResourceApiVfModuleinformationVfModuleInformation
142 public GenericResourceApiVfmoduleinformationVfModuleInformation buildVfModuleInformation(VfModule vfModule, GenericVnf vnf, ServiceInstance serviceInstance, RequestContext requestContext, boolean includeModelInformation) throws MapperException {
143 GenericResourceApiVfmoduleinformationVfModuleInformation vfModuleInformation = new GenericResourceApiVfmoduleinformationVfModuleInformation();
144 if (includeModelInformation) {
145 if (vfModule.getModelInfoVfModule() == null) {
146 throw new MapperException("VF Module model info is null for " + vfModule.getVfModuleId());
149 GenericResourceApiOnapmodelinformationOnapModelInformation onapModelInformation = new GenericResourceApiOnapmodelinformationOnapModelInformation();
150 onapModelInformation.setModelInvariantUuid(vfModule.getModelInfoVfModule().getModelInvariantUUID());
151 onapModelInformation.setModelName(vfModule.getModelInfoVfModule().getModelName());
152 onapModelInformation.setModelVersion(vfModule.getModelInfoVfModule().getModelVersion());
153 onapModelInformation.setModelUuid(vfModule.getModelInfoVfModule().getModelUUID());
154 onapModelInformation.setModelCustomizationUuid(vfModule.getModelInfoVfModule().getModelCustomizationUUID());
155 vfModuleInformation.setOnapModelInformation(onapModelInformation);
158 if (vfModule.getModelInfoVfModule() != null) {
159 vfModuleInformation.setVfModuleType(vfModule.getModelInfoVfModule().getModelName());
161 vfModuleInformation.setVfModuleId(vfModule.getVfModuleId());
162 if (requestContext != null && requestContext.getRequestParameters() != null) {
163 vfModuleInformation.setFromPreload(requestContext.getRequestParameters().getUsePreload());
166 vfModuleInformation.setFromPreload(true);
169 return vfModuleInformation;
173 public GenericResourceApiSdncrequestheaderSdncRequestHeader buildSdncRequestHeader(SDNCSvcAction svcAction, String sdncReqId){
174 return buildSdncRequestHeader(svcAction, sdncReqId, null);
177 public GenericResourceApiSdncrequestheaderSdncRequestHeader buildSdncRequestHeader(SDNCSvcAction svcAction, String sdncReqId, String callbackUrl){
178 GenericResourceApiSdncrequestheaderSdncRequestHeader sdncRequestHeader = new GenericResourceApiSdncrequestheaderSdncRequestHeader();
179 sdncRequestHeader.setSvcAction(svcAction.getSdncApiAction());
180 sdncRequestHeader.setSvcRequestId(sdncReqId);
181 sdncRequestHeader.setSvcNotificationUrl(callbackUrl);
182 return sdncRequestHeader;
186 * Build ConfigurationInformation
187 * @param configuration
188 * @param includeModelInformation
191 public GenericResourceApiConfigurationinformationConfigurationInformation buildConfigurationInformation(Configuration configuration, boolean includeModelInformation) {
192 GenericResourceApiConfigurationinformationConfigurationInformation configurationInformation = new GenericResourceApiConfigurationinformationConfigurationInformation();
193 configurationInformation.setConfigurationId(configuration.getConfigurationId());
194 configurationInformation.setConfigurationName(configuration.getConfigurationName());
195 configurationInformation.setConfigurationType(configuration.getConfigurationType());
196 if(includeModelInformation) {
197 GenericResourceApiOnapmodelinformationOnapModelInformation onapModelInformation = new GenericResourceApiOnapmodelinformationOnapModelInformation();
198 onapModelInformation.setModelInvariantUuid(configuration.getModelInfoConfiguration().getModelInvariantId());
199 onapModelInformation.setModelUuid(configuration.getModelInfoConfiguration().getModelVersionId());
200 onapModelInformation.setModelCustomizationUuid(configuration.getModelInfoConfiguration().getModelCustomizationId());
201 configurationInformation.setOnapModelInformation(onapModelInformation);
203 return configurationInformation;
208 * Build GcRequestInformation
210 * @param genericResourceApiParam
213 public GenericResourceApiGcrequestinputGcRequestInput buildGcRequestInformation(GenericVnf vnf,GenericResourceApiParam genericResourceApiParam) {
214 GenericResourceApiGcrequestinputGcRequestInput gcRequestInput = new GenericResourceApiGcrequestinputGcRequestInput();
215 gcRequestInput.setVnfId(vnf.getVnfId());
216 if(genericResourceApiParam != null) {
217 gcRequestInput.setInputParameters(genericResourceApiParam);
219 return gcRequestInput;
223 public String mapUserParamValue(Object value) {
227 if (value instanceof Map || value instanceof Set || value instanceof List) {
229 return mapper.writeValueAsString(value);
230 } catch (JsonProcessingException e) {
231 logger.error("could not map value to string", e);
232 throw new IllegalArgumentException(e);
235 return value.toString();