Merge "add junit coverage for SvnfmService"
[so.git] / bpmn / MSOCommonBPMN / src / main / java / org / onap / so / bpmn / servicedecomposition / tasks / BBInputSetupMapperLayer.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (c) 2019 Samsung
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.bpmn.servicedecomposition.tasks;
24
25 import java.util.ArrayList;
26 import java.util.Arrays;
27 import java.util.HashMap;
28 import java.util.List;
29 import java.util.Map;
30 import java.util.Optional;
31 import org.modelmapper.ModelMapper;
32 import org.modelmapper.convention.MatchingStrategies;
33 import org.onap.so.bpmn.servicedecomposition.bbobjects.AggregateRoute;
34 import org.onap.so.bpmn.servicedecomposition.bbobjects.AllottedResource;
35 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.CtagAssignment;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.Entitlement;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.Evc;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.ForwarderEvc;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
44 import org.onap.so.bpmn.servicedecomposition.bbobjects.HostRoute;
45 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
46 import org.onap.so.bpmn.servicedecomposition.bbobjects.LagInterface;
47 import org.onap.so.bpmn.servicedecomposition.bbobjects.LineOfBusiness;
48 import org.onap.so.bpmn.servicedecomposition.bbobjects.NetworkPolicy;
49 import org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity;
50 import org.onap.so.bpmn.servicedecomposition.bbobjects.Platform;
51 import org.onap.so.bpmn.servicedecomposition.bbobjects.Project;
52 import org.onap.so.bpmn.servicedecomposition.bbobjects.RouteTableReference;
53 import org.onap.so.bpmn.servicedecomposition.bbobjects.RouteTarget;
54 import org.onap.so.bpmn.servicedecomposition.bbobjects.SegmentationAssignment;
55 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
56 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription;
57 import org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet;
58 import org.onap.so.bpmn.servicedecomposition.bbobjects.Tenant;
59 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
60 import org.onap.so.bpmn.servicedecomposition.bbobjects.Vnfc;
61 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
62 import org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBinding;
63 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
64 import org.onap.so.bpmn.servicedecomposition.generalobjects.License;
65 import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext;
66 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
67 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters;
68 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoCollection;
69 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoConfiguration;
70 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf;
71 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoInstanceGroup;
72 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoNetwork;
73 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance;
74 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceProxy;
75 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule;
76 import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
77 import org.onap.so.db.catalog.beans.CollectionResource;
78 import org.onap.so.db.catalog.beans.CollectionResourceCustomization;
79 import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization;
80 import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization;
81 import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization;
82 import org.onap.so.db.catalog.beans.InstanceGroup;
83 import org.onap.so.db.catalog.beans.InstanceGroupType;
84 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
85 import org.onap.so.db.catalog.beans.OrchestrationStatus;
86 import org.onap.so.db.catalog.beans.Service;
87 import org.onap.so.db.catalog.beans.ServiceProxyResourceCustomization;
88 import org.onap.so.db.catalog.beans.VfModuleCustomization;
89 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
90 import org.onap.so.serviceinstancebeans.CloudConfiguration;
91 import org.onap.so.serviceinstancebeans.RequestDetails;
92 import org.slf4j.Logger;
93 import org.slf4j.LoggerFactory;
94 import org.springframework.stereotype.Component;
95
96 @Component("BBInputSetupMapperLayer")
97 public class BBInputSetupMapperLayer {
98     private static final String USER_PARAM_NAME_KEY = "name";
99     private static final String USER_PARAM_VALUE_KEY = "value";
100
101     private static final Logger logger = LoggerFactory.getLogger(BBInputSetupMapperLayer.class);
102
103     private ModelMapper modelMapper = new ModelMapper();
104
105     public Customer mapAAICustomer(org.onap.aai.domain.yang.Customer customerAAI) {
106         return modelMapper.map(customerAAI, Customer.class);
107     }
108
109     public ServiceSubscription mapAAIServiceSubscription(
110             org.onap.aai.domain.yang.ServiceSubscription serviceSubscriptionAAI) {
111         return modelMapper.map(serviceSubscriptionAAI, ServiceSubscription.class);
112     }
113
114     protected Project mapAAIProject(org.onap.aai.domain.yang.Project aaiProject) {
115         return modelMapper.map(aaiProject, Project.class);
116     }
117
118     protected OwningEntity mapAAIOwningEntity(org.onap.aai.domain.yang.OwningEntity aaiOwningEntity) {
119         return modelMapper.map(aaiOwningEntity, OwningEntity.class);
120     }
121
122     protected Platform mapAAIPlatform(org.onap.aai.domain.yang.Platform aaiPlatform) {
123         return modelMapper.map(aaiPlatform, Platform.class);
124     }
125
126     protected LineOfBusiness mapAAILineOfBusiness(org.onap.aai.domain.yang.LineOfBusiness aaiLineOfBusiness) {
127         return modelMapper.map(aaiLineOfBusiness, LineOfBusiness.class);
128     }
129
130     protected SegmentationAssignment mapAAISegmentationAssignment(
131             org.onap.aai.domain.yang.SegmentationAssignment aaiSegmentationAssignment) {
132         return modelMapper.map(aaiSegmentationAssignment, SegmentationAssignment.class);
133     }
134
135     protected AggregateRoute mapAAIAggregateRoute(org.onap.aai.domain.yang.AggregateRoute aaiAggregateRoute) {
136         return modelMapper.map(aaiAggregateRoute, AggregateRoute.class);
137     }
138
139     protected CtagAssignment mapAAICtagAssignment(org.onap.aai.domain.yang.CtagAssignment aaiCtagAssignment) {
140         return modelMapper.map(aaiCtagAssignment, CtagAssignment.class);
141     }
142
143     protected Subnet mapAAISubnet(org.onap.aai.domain.yang.Subnet aaiSubnet) {
144         Subnet subnet = modelMapper.map(aaiSubnet, Subnet.class);
145         mapAllHostRoutesIntoSubnet(aaiSubnet, subnet);
146         return subnet;
147     }
148
149     protected void mapAllHostRoutesIntoSubnet(org.onap.aai.domain.yang.Subnet aaiSubnet, Subnet subnet) {
150         if (aaiSubnet.getHostRoutes() != null) {
151             for (org.onap.aai.domain.yang.HostRoute aaiHostRoute : aaiSubnet.getHostRoutes().getHostRoute()) {
152                 subnet.getHostRoutes().add(mapAAIHostRoute(aaiHostRoute));
153             }
154         }
155     }
156
157     protected HostRoute mapAAIHostRoute(org.onap.aai.domain.yang.HostRoute aaiHostRoute) {
158         return modelMapper.map(aaiHostRoute, HostRoute.class);
159     }
160
161     protected License mapAAILicense(org.onap.aai.domain.yang.License aaiLicense) {
162         return modelMapper.map(aaiLicense, License.class);
163     }
164
165     protected Entitlement mapAAIEntitlement(org.onap.aai.domain.yang.Entitlement aaiEntitlement) {
166         return modelMapper.map(aaiEntitlement, Entitlement.class);
167     }
168
169     protected LagInterface mapAAILagInterface(org.onap.aai.domain.yang.LagInterface aaiLagInterface) {
170         return modelMapper.map(aaiLagInterface, LagInterface.class);
171     }
172
173     protected VfModule mapAAIVfModule(org.onap.aai.domain.yang.VfModule aaiVfModule) {
174         VfModule vfModule = modelMapper.map(aaiVfModule, VfModule.class);
175         vfModule.setOrchestrationStatus(this.mapOrchestrationStatusFromAAI(aaiVfModule.getOrchestrationStatus()));
176
177         ModelInfoVfModule modelInfoVfModule = new ModelInfoVfModule();
178         modelInfoVfModule.setIsBaseBoolean(aaiVfModule.isIsBaseVfModule());
179         vfModule.setModelInfoVfModule(modelInfoVfModule);
180         return vfModule;
181     }
182
183     public NetworkPolicy mapAAINetworkPolicy(org.onap.aai.domain.yang.NetworkPolicy aaiNetworkPolicy) {
184         return modelMapper.map(aaiNetworkPolicy, NetworkPolicy.class);
185     }
186
187     protected VolumeGroup mapAAIVolumeGroup(org.onap.aai.domain.yang.VolumeGroup aaiVolumeGroup) {
188         VolumeGroup volumeGroup = modelMapper.map(aaiVolumeGroup, VolumeGroup.class);
189         volumeGroup.setOrchestrationStatus(this.mapOrchestrationStatusFromAAI(aaiVolumeGroup.getOrchestrationStatus()));
190         return volumeGroup;
191     }
192
193     protected void setPlatformAndLOBIntoServiceInstance(Platform platformMSO, LineOfBusiness lineOfBusinessMSO,
194             ServiceInstance serviceInstance, Map<ResourceKey, String> resourcesToBeOrchestrated) {
195         String vnfId = resourcesToBeOrchestrated.get(ResourceKey.GENERIC_VNF_ID);
196         if (vnfId != null && !serviceInstance.getVnfs().isEmpty()) {
197             for (GenericVnf vnf : serviceInstance.getVnfs()) {
198                 if (vnf.getVnfId().equalsIgnoreCase(vnfId)) {
199                     vnf.setPlatform(platformMSO);
200                     vnf.setLineOfBusiness(lineOfBusinessMSO);
201                     break;
202                 }
203             }
204         }
205     }
206
207     public ModelInfoServiceInstance mapCatalogServiceIntoServiceInstance(Service service) {
208         return modelMapper.map(service, ModelInfoServiceInstance.class);
209     }
210
211     protected ModelInfoInstanceGroup mapCatalogInstanceGroupToInstanceGroup(
212             CollectionResourceCustomization collectionCust, InstanceGroup instanceGroup) {
213         ModelInfoInstanceGroup modelInfoInstanceGroup = modelMapper.map(instanceGroup, ModelInfoInstanceGroup.class);
214         if (instanceGroup.getType() != null && instanceGroup.getType().equals(InstanceGroupType.L3_NETWORK))
215             modelInfoInstanceGroup.setType(ModelInfoInstanceGroup.TYPE_L3_NETWORK);
216         else
217             modelInfoInstanceGroup.setType(ModelInfoInstanceGroup.TYPE_VNFC);
218         if (collectionCust != null) {
219             List<CollectionResourceInstanceGroupCustomization> instanceGroupCustList =
220                     instanceGroup.getCollectionInstanceGroupCustomizations();
221             for (CollectionResourceInstanceGroupCustomization collectionInsatnceGroupCust : instanceGroupCustList) {
222                 if (collectionInsatnceGroupCust.getModelCustomizationUUID()
223                         .equalsIgnoreCase(collectionCust.getModelCustomizationUUID())) {
224                     modelInfoInstanceGroup.setFunction(collectionInsatnceGroupCust.getFunction());
225                     modelInfoInstanceGroup.setDescription(collectionInsatnceGroupCust.getDescription());
226                     break;
227                 }
228             }
229         }
230         return modelInfoInstanceGroup;
231     }
232
233     protected ModelInfoCollection mapCatalogCollectionToCollection(CollectionResourceCustomization collectionCust,
234             CollectionResource collectionResource) {
235         ModelInfoCollection modelInfoCollection = new ModelInfoCollection();
236         modelInfoCollection.setCollectionFunction(collectionCust.getFunction());
237         modelInfoCollection.setCollectionRole(collectionCust.getRole());
238         modelInfoCollection.setCollectionType(collectionCust.getType());
239         modelInfoCollection.setDescription(collectionResource.getDescription());
240         modelInfoCollection.setModelInvariantUUID(collectionResource.getModelInvariantUUID());
241         modelInfoCollection.setModelVersionId(collectionResource.getModelUUID());
242         modelInfoCollection.setModelCustomizationUUID(collectionCust.getModelCustomizationUUID());
243         return modelInfoCollection;
244     }
245
246     public ServiceInstance mapAAIServiceInstanceIntoServiceInstance(
247             org.onap.aai.domain.yang.ServiceInstance aaiServiceInstance) {
248         ServiceInstance serviceInstance = modelMapper.map(aaiServiceInstance, ServiceInstance.class);
249         if (aaiServiceInstance.getAllottedResources() != null) {
250             for (org.onap.aai.domain.yang.AllottedResource allottedResource : aaiServiceInstance.getAllottedResources()
251                     .getAllottedResource()) {
252                 serviceInstance.getAllottedResources().add(mapAAIAllottedResource(allottedResource));
253             }
254         }
255         serviceInstance.setOrchestrationStatus(
256                 this.mapOrchestrationStatusFromAAI(aaiServiceInstance.getOrchestrationStatus()));
257         return serviceInstance;
258     }
259
260     protected AllottedResource mapAAIAllottedResource(org.onap.aai.domain.yang.AllottedResource aaiAllottedResource) {
261         AllottedResource allottedResource = modelMapper.map(aaiAllottedResource, AllottedResource.class);
262         return allottedResource;
263     }
264
265     protected L3Network mapAAIL3Network(org.onap.aai.domain.yang.L3Network aaiL3Network) {
266         L3Network network = modelMapper.map(aaiL3Network, L3Network.class);
267         mapAllSubnetsIntoL3Network(aaiL3Network, network);
268         mapAllCtagAssignmentsIntoL3Network(aaiL3Network, network);
269         mapAllSegmentationAssignmentsIntoL3Network(aaiL3Network, network);
270         mapAllAggregateRoutesIntoL3Network(aaiL3Network, network);
271         network.setOrchestrationStatus(this.mapOrchestrationStatusFromAAI(aaiL3Network.getOrchestrationStatus()));
272         return network;
273     }
274
275     protected void mapAllAggregateRoutesIntoL3Network(org.onap.aai.domain.yang.L3Network aaiL3Network,
276             L3Network network) {
277         if (aaiL3Network.getAggregateRoutes() != null) {
278             for (org.onap.aai.domain.yang.AggregateRoute aaiAggregateRoute : aaiL3Network.getAggregateRoutes()
279                     .getAggregateRoute()) {
280                 network.getAggregateRoutes().add(mapAAIAggregateRoute(aaiAggregateRoute));
281             }
282         }
283     }
284
285     protected void mapAllSegmentationAssignmentsIntoL3Network(org.onap.aai.domain.yang.L3Network aaiL3Network,
286             L3Network network) {
287         if (aaiL3Network.getSegmentationAssignments() != null) {
288             for (org.onap.aai.domain.yang.SegmentationAssignment aaiSegmentationAssignment : aaiL3Network
289                     .getSegmentationAssignments().getSegmentationAssignment()) {
290                 network.getSegmentationAssignments().add(mapAAISegmentationAssignment(aaiSegmentationAssignment));
291             }
292         }
293     }
294
295     protected void mapAllCtagAssignmentsIntoL3Network(org.onap.aai.domain.yang.L3Network aaiL3Network,
296             L3Network network) {
297         if (aaiL3Network.getCtagAssignments() != null) {
298             for (org.onap.aai.domain.yang.CtagAssignment aaiCtagAssignment : aaiL3Network.getCtagAssignments()
299                     .getCtagAssignment()) {
300                 network.getCtagAssignments().add(mapAAICtagAssignment(aaiCtagAssignment));
301             }
302         }
303     }
304
305     protected void mapAllSubnetsIntoL3Network(org.onap.aai.domain.yang.L3Network aaiL3Network, L3Network network) {
306         if (aaiL3Network.getSubnets() != null) {
307             for (org.onap.aai.domain.yang.Subnet aaiSubnet : aaiL3Network.getSubnets().getSubnet()) {
308                 network.getSubnets().add(mapAAISubnet(aaiSubnet));
309             }
310         }
311     }
312
313     protected GenericVnf mapAAIGenericVnfIntoGenericVnf(org.onap.aai.domain.yang.GenericVnf aaiGenericVnf) {
314         GenericVnf genericVnf = modelMapper.map(aaiGenericVnf, GenericVnf.class);
315         mapAllVfModulesIntoGenericVnf(aaiGenericVnf, genericVnf);
316         mapAllLagInterfacesIntoGenericVnf(aaiGenericVnf, genericVnf);
317         mapAllEntitlementsIntoGenericVnf(aaiGenericVnf, genericVnf);
318         mapAllLicensesIntoGenericVnf(aaiGenericVnf, genericVnf);
319         genericVnf.setOrchestrationStatus(this.mapOrchestrationStatusFromAAI(aaiGenericVnf.getOrchestrationStatus()));
320         return genericVnf;
321     }
322
323     protected void mapAllLicensesIntoGenericVnf(org.onap.aai.domain.yang.GenericVnf aaiGenericVnf,
324             GenericVnf genericVnf) {
325         if (aaiGenericVnf.getLicenses() != null) {
326             for (org.onap.aai.domain.yang.License aaiLicense : aaiGenericVnf.getLicenses().getLicense()) {
327                 genericVnf.setLicense(mapAAILicense(aaiLicense));
328             }
329         }
330     }
331
332     protected void mapAllEntitlementsIntoGenericVnf(org.onap.aai.domain.yang.GenericVnf aaiGenericVnf,
333             GenericVnf genericVnf) {
334         if (aaiGenericVnf.getEntitlements() != null) {
335             for (org.onap.aai.domain.yang.Entitlement aaiEntitlement : aaiGenericVnf.getEntitlements()
336                     .getEntitlement()) {
337                 genericVnf.getEntitlements().add(mapAAIEntitlement(aaiEntitlement));
338             }
339         }
340     }
341
342     protected void mapAllLagInterfacesIntoGenericVnf(org.onap.aai.domain.yang.GenericVnf aaiGenericVnf,
343             GenericVnf genericVnf) {
344         if (aaiGenericVnf.getLagInterfaces() != null) {
345             for (org.onap.aai.domain.yang.LagInterface aaiLagInterface : aaiGenericVnf.getLagInterfaces()
346                     .getLagInterface()) {
347                 genericVnf.getLagInterfaces().add(mapAAILagInterface(aaiLagInterface));
348             }
349         }
350     }
351
352     protected void mapAllVfModulesIntoGenericVnf(org.onap.aai.domain.yang.GenericVnf aaiGenericVnf,
353             GenericVnf genericVnf) {
354         if (aaiGenericVnf.getVfModules() != null) {
355             for (org.onap.aai.domain.yang.VfModule aaiVfModule : aaiGenericVnf.getVfModules().getVfModule()) {
356                 VfModule vfModule = mapAAIVfModule(aaiVfModule);
357                 genericVnf.getVfModules().add(vfModule);
358             }
359         }
360     }
361
362     public OrchestrationStatus mapOrchestrationStatusFromAAI(String orchestrationStatus) {
363
364         Optional<OrchestrationStatus> result = Arrays.asList(OrchestrationStatus.values()).stream()
365                 .filter(item -> item.fuzzyMap(orchestrationStatus)).findFirst();
366
367         return result.orElse(null);
368
369     }
370
371     public RequestContext mapRequestContext(RequestDetails requestDetails) {
372         RequestContext context = new RequestContext();
373         if (null != requestDetails.getRequestInfo()) {
374             modelMapper.map(requestDetails.getRequestInfo(), context);
375         }
376         org.onap.so.serviceinstancebeans.RequestParameters requestParameters = requestDetails.getRequestParameters();
377         if (null != requestParameters) {
378             context.setSubscriptionServiceType(requestParameters.getSubscriptionServiceType());
379             context.setRequestParameters(this.mapRequestParameters(requestDetails.getRequestParameters()));
380             context.setUserParams(this.mapNameValueUserParams(requestDetails.getRequestParameters()));
381         }
382         if (requestDetails.getConfigurationParameters() != null) {
383             context.setConfigurationParameters(requestDetails.getConfigurationParameters());
384         }
385         return context;
386     }
387
388     protected RequestParameters mapRequestParameters(
389             org.onap.so.serviceinstancebeans.RequestParameters requestParameters) {
390         RequestParameters requestParams = new RequestParameters();
391         requestParams.setaLaCarte(requestParameters.getALaCarte());
392         requestParams.setUsePreload(requestParameters.getUsePreload());
393         requestParams.setSubscriptionServiceType(requestParameters.getSubscriptionServiceType());
394         requestParams.setUserParams(requestParameters.getUserParams());
395         requestParams.setPayload(requestParameters.getPayload());
396         return requestParams;
397     }
398
399     protected Map<String, Object> mapNameValueUserParams(
400             org.onap.so.serviceinstancebeans.RequestParameters requestParameters) {
401         Map<String, Object> userParamsResult = new HashMap<String, Object>();
402         if (requestParameters.getUserParams() != null) {
403             List<Map<String, Object>> userParams = requestParameters.getUserParams();
404             for (Map<String, Object> userParamsMap : userParams) {
405                 if (userParamsMap.containsKey(USER_PARAM_NAME_KEY)
406                         && (userParamsMap.get(USER_PARAM_NAME_KEY) instanceof String)
407                         && userParamsMap.containsKey(USER_PARAM_VALUE_KEY)) {
408                     userParamsResult.put((String) userParamsMap.get(USER_PARAM_NAME_KEY),
409                             userParamsMap.get(USER_PARAM_VALUE_KEY));
410                 }
411             }
412         }
413         return userParamsResult;
414     }
415
416     protected OrchestrationContext mapOrchestrationContext(RequestDetails requestDetails) {
417         OrchestrationContext context = new OrchestrationContext();
418         if (requestDetails.getRequestInfo() != null) {
419             context.setIsRollbackEnabled(!(requestDetails.getRequestInfo().getSuppressRollback()));
420         } else {
421             context.setIsRollbackEnabled(false);
422         }
423         return context;
424     }
425
426     protected CloudRegion mapCloudRegion(CloudConfiguration cloudConfiguration,
427             org.onap.aai.domain.yang.CloudRegion aaiCloudRegion) {
428         CloudRegion cloudRegion = new CloudRegion();
429         if (cloudConfiguration != null)
430             cloudRegion = modelMapper.map(cloudConfiguration, CloudRegion.class);
431         if (aaiCloudRegion != null)
432             modelMapper.map(aaiCloudRegion, cloudRegion);
433         return cloudRegion;
434     }
435
436     protected Tenant mapTenant(org.onap.aai.domain.yang.Tenant aaiTenant) {
437         Tenant tenant = new Tenant();
438         if (aaiTenant != null) {
439             modelMapper.map(aaiTenant, tenant);
440         }
441         return tenant;
442     }
443
444     protected Collection mapAAICollectionIntoCollection(org.onap.aai.domain.yang.Collection aaiCollection) {
445         Collection collection = new Collection();
446         collection.setId(aaiCollection.getCollectionId());
447         collection.setOrchestrationStatus(this.mapOrchestrationStatusFromAAI(aaiCollection.getOrchestrationStatus()));
448         return collection;
449     }
450
451     protected org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup mapAAIInstanceGroupIntoInstanceGroup(
452             org.onap.aai.domain.yang.InstanceGroup aaiInstanceGroup) {
453         return modelMapper.map(aaiInstanceGroup, org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup.class);
454     }
455
456     public RouteTableReference mapAAIRouteTableReferenceIntoRouteTableReference(
457             org.onap.aai.domain.yang.RouteTableReference aaiRouteTableReference) {
458         return modelMapper.map(aaiRouteTableReference, RouteTableReference.class);
459     }
460
461     protected ModelInfoNetwork mapCatalogNetworkToNetwork(NetworkResourceCustomization networkResourceCustomization) {
462         modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
463         ModelInfoNetwork modelInfoNetwork = modelMapper.map(networkResourceCustomization, ModelInfoNetwork.class);
464         modelMapper.map(networkResourceCustomization.getNetworkResource(), modelInfoNetwork);
465         modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STANDARD);
466         return modelInfoNetwork;
467     }
468
469     protected ModelInfoGenericVnf mapCatalogVnfToVnf(VnfResourceCustomization vnfResourceCustomization) {
470         ModelInfoGenericVnf modelInfoVnf = modelMapper.map(vnfResourceCustomization, ModelInfoGenericVnf.class);
471         modelMapper.map(vnfResourceCustomization.getVnfResources(), modelInfoVnf);
472         return modelInfoVnf;
473     }
474
475     protected ModelInfoVfModule mapCatalogVfModuleToVfModule(VfModuleCustomization vfResourceCustomization) {
476         ModelInfoVfModule modelInfoVfModule = modelMapper.map(vfResourceCustomization, ModelInfoVfModule.class);
477         modelMapper.map(vfResourceCustomization.getVfModule(), modelInfoVfModule);
478         return modelInfoVfModule;
479     }
480
481     protected Platform mapRequestPlatform(org.onap.so.serviceinstancebeans.Platform platform) {
482         return modelMapper.map(platform, Platform.class);
483     }
484
485     protected LineOfBusiness mapRequestLineOfBusiness(org.onap.so.serviceinstancebeans.LineOfBusiness lineOfBusiness) {
486         return modelMapper.map(lineOfBusiness, LineOfBusiness.class);
487     }
488
489     public Configuration mapAAIConfiguration(org.onap.aai.domain.yang.Configuration configurationAAI) {
490         modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
491         Configuration configuration = modelMapper.map(configurationAAI, Configuration.class);
492         modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STANDARD);
493         configuration.getForwarderEvcs().addAll(mapAllForwarderEvcs(configurationAAI));
494         configuration.getEvcs().addAll(mapAllEvcs(configurationAAI));
495         configuration
496                 .setOrchestrationStatus(this.mapOrchestrationStatusFromAAI(configurationAAI.getOrchestrationStatus()));
497         return configuration;
498     }
499
500     protected List<Evc> mapAllEvcs(org.onap.aai.domain.yang.Configuration configurationAAI) {
501         List<Evc> listOfEvcs = new ArrayList<>();
502         if (configurationAAI.getEvcs() != null) {
503             for (org.onap.aai.domain.yang.Evc aaiEvc : configurationAAI.getEvcs().getEvc()) {
504                 listOfEvcs.add(mapEvc(aaiEvc));
505             }
506         }
507         return listOfEvcs;
508     }
509
510     protected Evc mapEvc(org.onap.aai.domain.yang.Evc aaiEvc) {
511         return modelMapper.map(aaiEvc, Evc.class);
512     }
513
514     protected List<ForwarderEvc> mapAllForwarderEvcs(org.onap.aai.domain.yang.Configuration configurationAAI) {
515         List<ForwarderEvc> listOfForwarderEvcs = new ArrayList<>();
516         if (configurationAAI.getForwarderEvcs() != null) {
517             for (org.onap.aai.domain.yang.ForwarderEvc aaiForwarderEvc : configurationAAI.getForwarderEvcs()
518                     .getForwarderEvc()) {
519                 listOfForwarderEvcs.add(mapForwarderEvc(aaiForwarderEvc));
520             }
521         }
522         return listOfForwarderEvcs;
523     }
524
525     protected ForwarderEvc mapForwarderEvc(org.onap.aai.domain.yang.ForwarderEvc aaiForwarderEvc) {
526         return modelMapper.map(aaiForwarderEvc, ForwarderEvc.class);
527     }
528
529     protected OwningEntity mapRequestOwningEntity(org.onap.so.serviceinstancebeans.OwningEntity owningEntity) {
530         return modelMapper.map(owningEntity, OwningEntity.class);
531     }
532
533     protected Project mapRequestProject(org.onap.so.serviceinstancebeans.Project project) {
534         return modelMapper.map(project, Project.class);
535     }
536
537     protected ModelInfoConfiguration mapCatalogConfigurationToConfiguration(
538             ConfigurationResourceCustomization configurationResourceCustomization,
539             CvnfcConfigurationCustomization cvnfcConfigurationCustomization) {
540
541         ModelInfoConfiguration modelInfoConfiguration = new ModelInfoConfiguration();
542         modelInfoConfiguration
543                 .setModelVersionId(configurationResourceCustomization.getConfigurationResource().getModelUUID());
544         modelInfoConfiguration.setModelCustomizationId(configurationResourceCustomization.getModelCustomizationUUID());
545         modelInfoConfiguration.setModelInvariantId(
546                 configurationResourceCustomization.getConfigurationResource().getModelInvariantUUID());
547         modelInfoConfiguration.setConfigurationRole(configurationResourceCustomization.getRole());
548         modelInfoConfiguration.setConfigurationType(configurationResourceCustomization.getType());
549         if (cvnfcConfigurationCustomization != null) {
550             modelInfoConfiguration.setPolicyName(cvnfcConfigurationCustomization.getPolicyName());
551         }
552         return modelInfoConfiguration;
553     }
554
555     protected ModelInfoConfiguration mapCatalogConfigurationToConfiguration(
556             CvnfcConfigurationCustomization cvnfcConfigurationCustomization) {
557         ModelInfoConfiguration modelInfoConfiguration = new ModelInfoConfiguration();
558         modelInfoConfiguration
559                 .setModelVersionId(cvnfcConfigurationCustomization.getConfigurationResource().getModelUUID());
560         modelInfoConfiguration.setModelCustomizationId(cvnfcConfigurationCustomization.getModelCustomizationUUID());
561         modelInfoConfiguration.setModelInvariantId(
562                 cvnfcConfigurationCustomization.getConfigurationResource().getModelInvariantUUID());
563         modelInfoConfiguration.setPolicyName(cvnfcConfigurationCustomization.getPolicyName());
564         modelInfoConfiguration.setConfigurationType(cvnfcConfigurationCustomization.getConfigurationType());
565         modelInfoConfiguration.setConfigurationRole(cvnfcConfigurationCustomization.getConfigurationRole());
566         return modelInfoConfiguration;
567     }
568
569     public NetworkResourceCustomization mapCollectionNetworkResourceCustToNetworkResourceCust(
570             CollectionNetworkResourceCustomization collectionNetworkResourceCust) {
571         return modelMapper.map(collectionNetworkResourceCust, NetworkResourceCustomization.class);
572     }
573
574     public Vnfc mapAAIVnfc(org.onap.aai.domain.yang.Vnfc vnfcAAI) {
575         return modelMapper.map(vnfcAAI, Vnfc.class);
576     }
577
578     public VpnBinding mapAAIVpnBinding(org.onap.aai.domain.yang.VpnBinding aaiVpnBinding) {
579         VpnBinding vpnBinding = modelMapper.map(aaiVpnBinding, VpnBinding.class);
580         mapAllRouteTargetsToAAIVpnBinding(aaiVpnBinding, vpnBinding);
581         return vpnBinding;
582     }
583
584     protected void mapAllRouteTargetsToAAIVpnBinding(org.onap.aai.domain.yang.VpnBinding aaiVpnBinding,
585             VpnBinding vpnBinding) {
586         if (aaiVpnBinding.getRouteTargets() != null) {
587             for (org.onap.aai.domain.yang.RouteTarget aaiRouteTarget : aaiVpnBinding.getRouteTargets()
588                     .getRouteTarget()) {
589                 vpnBinding.getRouteTargets().add(mapAAIRouteTarget(aaiRouteTarget));
590             }
591         }
592     }
593
594     public RouteTarget mapAAIRouteTarget(org.onap.aai.domain.yang.RouteTarget aaiRouteTarget) {
595         return modelMapper.map(aaiRouteTarget, RouteTarget.class);
596     }
597
598     protected ModelInfoServiceProxy mapServiceProxyCustomizationToServiceProxy(
599             ServiceProxyResourceCustomization serviceProxyCustomization) {
600         ModelInfoServiceProxy modelInfoServiceProxy =
601                 modelMapper.map(serviceProxyCustomization.getSourceService(), ModelInfoServiceProxy.class);
602         modelInfoServiceProxy.setModelInstanceName(serviceProxyCustomization.getModelInstanceName());
603         return modelInfoServiceProxy;
604     }
605 }