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;
26 import org.onap.sdnc.northbound.client.model.GenericResourceApiConfigurationinformationConfigurationInformation;
27 import org.onap.sdnc.northbound.client.model.GenericResourceApiGcrequestinputGcRequestInput;
28 import org.onap.sdnc.northbound.client.model.GenericResourceApiNetworkinformationNetworkInformation;
29 import org.onap.sdnc.northbound.client.model.GenericResourceApiOnapmodelinformationOnapModelInformation;
30 import org.onap.sdnc.northbound.client.model.GenericResourceApiParam;
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.sdnc.northbound.client.model.GenericResourceApiVfmoduleinformationVfModuleInformation;
36 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfinformationVnfInformation;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
43 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
44 import org.onap.so.client.exception.MapperException;
45 import org.onap.so.client.sdnc.beans.SDNCSvcAction;
46 import org.slf4j.Logger;
47 import org.slf4j.LoggerFactory;
48 import org.springframework.stereotype.Component;
49 import com.fasterxml.jackson.core.JsonProcessingException;
50 import com.fasterxml.jackson.databind.ObjectMapper;
53 public class GeneralTopologyObjectMapper {
55 private static final Logger logger = LoggerFactory.getLogger(GeneralTopologyObjectMapper.class);
56 private ObjectMapper mapper = new ObjectMapper();
59 * Build GenericResourceApiRequestinformationRequestInformation
61 public GenericResourceApiRequestinformationRequestInformation buildGenericResourceApiRequestinformationRequestInformation(
62 String msoReqId, GenericResourceApiRequestActionEnumeration requestAction) {
64 GenericResourceApiRequestinformationRequestInformation requestInformation =
65 new GenericResourceApiRequestinformationRequestInformation();
66 requestInformation.setRequestId(msoReqId);
67 requestInformation.setRequestAction(requestAction);
68 requestInformation.setSource("MSO");
69 return requestInformation;
73 * Build GenericResourceApiServiceinformationServiceInformation
75 public GenericResourceApiServiceinformationServiceInformation buildServiceInformation(
76 ServiceInstance serviceInstance, RequestContext requestContext, Customer customer,
77 boolean includeModelInformation) {
78 GenericResourceApiServiceinformationServiceInformation serviceInformation =
79 new GenericResourceApiServiceinformationServiceInformation();
80 serviceInformation.serviceId(serviceInstance.getServiceInstanceId());
81 if (requestContext != null) {
82 serviceInformation.setSubscriptionServiceType(requestContext.getProductFamilyId());
84 if (includeModelInformation) {
85 GenericResourceApiOnapmodelinformationOnapModelInformation onapModelInformation =
86 new GenericResourceApiOnapmodelinformationOnapModelInformation();
88 .setModelInvariantUuid(serviceInstance.getModelInfoServiceInstance().getModelInvariantUuid());
89 onapModelInformation.setModelVersion(serviceInstance.getModelInfoServiceInstance().getModelVersion());
90 onapModelInformation.setModelName(serviceInstance.getModelInfoServiceInstance().getModelName());
91 onapModelInformation.setModelUuid(serviceInstance.getModelInfoServiceInstance().getModelUuid());
92 serviceInformation.setOnapModelInformation(onapModelInformation);
94 serviceInformation.setServiceInstanceId(serviceInstance.getServiceInstanceId());
96 if (customer != null) {
97 serviceInformation.setGlobalCustomerId(customer.getGlobalCustomerId());
98 if (customer.getServiceSubscription() != null) {
99 serviceInformation.setSubscriptionServiceType(customer.getServiceSubscription().getServiceType());
103 return serviceInformation;
107 * Build GenericResourceApiNetworkinformationNetworkInformation
109 public GenericResourceApiNetworkinformationNetworkInformation buildNetworkInformation(L3Network network) {
110 GenericResourceApiNetworkinformationNetworkInformation networkInformation =
111 new GenericResourceApiNetworkinformationNetworkInformation();
112 GenericResourceApiOnapmodelinformationOnapModelInformation onapModelInformation =
113 new GenericResourceApiOnapmodelinformationOnapModelInformation();
114 if (network.getModelInfoNetwork() != null) {
115 onapModelInformation.setModelInvariantUuid(network.getModelInfoNetwork().getModelInvariantUUID());
116 onapModelInformation.setModelName(network.getModelInfoNetwork().getModelName());
117 onapModelInformation.setModelVersion(network.getModelInfoNetwork().getModelVersion());
118 onapModelInformation.setModelUuid(network.getModelInfoNetwork().getModelUUID());
119 onapModelInformation.setModelCustomizationUuid(network.getModelInfoNetwork().getModelCustomizationUUID());
120 networkInformation.setOnapModelInformation(onapModelInformation);
123 networkInformation.setFromPreload(null);
124 networkInformation.setNetworkId(network.getNetworkId());
125 networkInformation.setNetworkType(network.getNetworkType());
126 networkInformation.setNetworkTechnology(network.getNetworkTechnology());
127 return networkInformation;
131 * Build GenericResourceApiVnfinformationVnfInformation
133 public GenericResourceApiVnfinformationVnfInformation buildVnfInformation(GenericVnf vnf,
134 ServiceInstance serviceInstance, boolean includeModelInformation) {
135 GenericResourceApiVnfinformationVnfInformation vnfInformation =
136 new GenericResourceApiVnfinformationVnfInformation();
137 if (includeModelInformation && vnf.getModelInfoGenericVnf() != null) {
138 GenericResourceApiOnapmodelinformationOnapModelInformation onapModelInformation =
139 new GenericResourceApiOnapmodelinformationOnapModelInformation();
140 onapModelInformation.setModelInvariantUuid(vnf.getModelInfoGenericVnf().getModelInvariantUuid());
141 onapModelInformation.setModelName(vnf.getModelInfoGenericVnf().getModelName());
142 onapModelInformation.setModelVersion(vnf.getModelInfoGenericVnf().getModelVersion());
143 onapModelInformation.setModelUuid(vnf.getModelInfoGenericVnf().getModelUuid());
144 onapModelInformation.setModelCustomizationUuid(vnf.getModelInfoGenericVnf().getModelCustomizationUuid());
145 vnfInformation.setOnapModelInformation(onapModelInformation);
147 vnfInformation.setVnfId(vnf.getVnfId());
148 vnfInformation.setVnfType(vnf.getVnfType());
149 vnfInformation.setVnfName(vnf.getVnfName());
150 return vnfInformation;
154 * Build GenericResourceApiVfModuleinformationVfModuleInformation
156 public GenericResourceApiVfmoduleinformationVfModuleInformation buildVfModuleInformation(VfModule vfModule,
157 GenericVnf vnf, ServiceInstance serviceInstance, RequestContext requestContext,
158 boolean includeModelInformation) throws MapperException {
159 GenericResourceApiVfmoduleinformationVfModuleInformation vfModuleInformation =
160 new GenericResourceApiVfmoduleinformationVfModuleInformation();
161 if (includeModelInformation) {
162 if (vfModule.getModelInfoVfModule() == null) {
163 throw new MapperException("VF Module model info is null for " + vfModule.getVfModuleId());
165 GenericResourceApiOnapmodelinformationOnapModelInformation onapModelInformation =
166 new GenericResourceApiOnapmodelinformationOnapModelInformation();
167 onapModelInformation.setModelInvariantUuid(vfModule.getModelInfoVfModule().getModelInvariantUUID());
168 onapModelInformation.setModelName(vfModule.getModelInfoVfModule().getModelName());
169 onapModelInformation.setModelVersion(vfModule.getModelInfoVfModule().getModelVersion());
170 onapModelInformation.setModelUuid(vfModule.getModelInfoVfModule().getModelUUID());
172 .setModelCustomizationUuid(vfModule.getModelInfoVfModule().getModelCustomizationUUID());
173 vfModuleInformation.setOnapModelInformation(onapModelInformation);
176 if (vfModule.getModelInfoVfModule() != null) {
177 vfModuleInformation.setVfModuleType(vfModule.getModelInfoVfModule().getModelName());
179 vfModuleInformation.setVfModuleId(vfModule.getVfModuleId());
180 if (requestContext != null && requestContext.getRequestParameters() != null) {
181 vfModuleInformation.setFromPreload(requestContext.getRequestParameters().getUsePreload());
183 vfModuleInformation.setFromPreload(true);
186 return vfModuleInformation;
190 public GenericResourceApiSdncrequestheaderSdncRequestHeader buildSdncRequestHeader(SDNCSvcAction svcAction,
192 return buildSdncRequestHeader(svcAction, sdncReqId, null);
195 public GenericResourceApiSdncrequestheaderSdncRequestHeader buildSdncRequestHeader(SDNCSvcAction svcAction,
196 String sdncReqId, String callbackUrl) {
197 GenericResourceApiSdncrequestheaderSdncRequestHeader sdncRequestHeader =
198 new GenericResourceApiSdncrequestheaderSdncRequestHeader();
199 sdncRequestHeader.setSvcAction(svcAction.getSdncApiAction());
200 sdncRequestHeader.setSvcRequestId(sdncReqId);
201 sdncRequestHeader.setSvcNotificationUrl(callbackUrl);
202 return sdncRequestHeader;
206 * Build ConfigurationInformation
208 * @param configuration
209 * @param includeModelInformation
212 public GenericResourceApiConfigurationinformationConfigurationInformation buildConfigurationInformation(
213 Configuration configuration, boolean includeModelInformation) {
214 GenericResourceApiConfigurationinformationConfigurationInformation configurationInformation =
215 new GenericResourceApiConfigurationinformationConfigurationInformation();
216 configurationInformation.setConfigurationId(configuration.getConfigurationId());
217 configurationInformation.setConfigurationName(configuration.getConfigurationName());
218 configurationInformation.setConfigurationType(configuration.getConfigurationType());
219 if (includeModelInformation) {
220 GenericResourceApiOnapmodelinformationOnapModelInformation onapModelInformation =
221 new GenericResourceApiOnapmodelinformationOnapModelInformation();
222 onapModelInformation.setModelInvariantUuid(configuration.getModelInfoConfiguration().getModelInvariantId());
223 onapModelInformation.setModelUuid(configuration.getModelInfoConfiguration().getModelVersionId());
225 .setModelCustomizationUuid(configuration.getModelInfoConfiguration().getModelCustomizationId());
226 configurationInformation.setOnapModelInformation(onapModelInformation);
228 return configurationInformation;
233 * Build GcRequestInformation
236 * @param genericResourceApiParam
239 public GenericResourceApiGcrequestinputGcRequestInput buildGcRequestInformation(GenericVnf vnf,
240 GenericResourceApiParam genericResourceApiParam) {
241 GenericResourceApiGcrequestinputGcRequestInput gcRequestInput =
242 new GenericResourceApiGcrequestinputGcRequestInput();
243 gcRequestInput.setVnfId(vnf.getVnfId());
244 if (genericResourceApiParam != null) {
245 gcRequestInput.setInputParameters(genericResourceApiParam);
247 return gcRequestInput;
251 public String mapUserParamValue(Object value) {
255 if (value instanceof Map || value instanceof Set || value instanceof List) {
257 return mapper.writeValueAsString(value);
258 } catch (JsonProcessingException e) {
259 logger.error("could not map value to string", e);
260 throw new IllegalArgumentException(e);
263 return value.toString();