Merge "Add test for CreateSliceService flow"
[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 org.modelmapper.ModelMapper;
26 import org.modelmapper.convention.MatchingStrategies;
27 import org.onap.so.bpmn.servicedecomposition.bbobjects.AggregateRoute;
28 import org.onap.so.bpmn.servicedecomposition.bbobjects.AllottedResource;
29 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
30 import org.onap.so.bpmn.servicedecomposition.bbobjects.Collection;
31 import org.onap.so.bpmn.servicedecomposition.bbobjects.Configuration;
32 import org.onap.so.bpmn.servicedecomposition.bbobjects.CtagAssignment;
33 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
34 import org.onap.so.bpmn.servicedecomposition.bbobjects.Entitlement;
35 import org.onap.so.bpmn.servicedecomposition.bbobjects.Evc;
36 import org.onap.so.bpmn.servicedecomposition.bbobjects.ForwarderEvc;
37 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
38 import org.onap.so.bpmn.servicedecomposition.bbobjects.HostRoute;
39 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
40 import org.onap.so.bpmn.servicedecomposition.bbobjects.LagInterface;
41 import org.onap.so.bpmn.servicedecomposition.bbobjects.LineOfBusiness;
42 import org.onap.so.bpmn.servicedecomposition.bbobjects.NetworkPolicy;
43 import org.onap.so.bpmn.servicedecomposition.bbobjects.OwningEntity;
44 import org.onap.so.bpmn.servicedecomposition.bbobjects.Platform;
45 import org.onap.so.bpmn.servicedecomposition.bbobjects.Project;
46 import org.onap.so.bpmn.servicedecomposition.bbobjects.RouteTableReference;
47 import org.onap.so.bpmn.servicedecomposition.bbobjects.RouteTarget;
48 import org.onap.so.bpmn.servicedecomposition.bbobjects.SegmentationAssignment;
49 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
50 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceSubscription;
51 import org.onap.so.bpmn.servicedecomposition.bbobjects.Subnet;
52 import org.onap.so.bpmn.servicedecomposition.bbobjects.Tenant;
53 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
54 import org.onap.so.bpmn.servicedecomposition.bbobjects.Vnfc;
55 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
56 import org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBinding;
57 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
58 import org.onap.so.bpmn.servicedecomposition.generalobjects.License;
59 import org.onap.so.bpmn.servicedecomposition.generalobjects.OrchestrationContext;
60 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestContext;
61 import org.onap.so.bpmn.servicedecomposition.generalobjects.RequestParameters;
62 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoCollection;
63 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoConfiguration;
64 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoGenericVnf;
65 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoInstanceGroup;
66 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoNetwork;
67 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance;
68 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceProxy;
69 import org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoVfModule;
70 import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
71 import org.onap.so.db.catalog.beans.CollectionResource;
72 import org.onap.so.db.catalog.beans.CollectionResourceCustomization;
73 import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization;
74 import org.onap.so.db.catalog.beans.ConfigurationResourceCustomization;
75 import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization;
76 import org.onap.so.db.catalog.beans.InstanceGroup;
77 import org.onap.so.db.catalog.beans.InstanceGroupType;
78 import org.onap.so.db.catalog.beans.NetworkResourceCustomization;
79 import org.onap.so.db.catalog.beans.OrchestrationStatus;
80 import org.onap.so.db.catalog.beans.Service;
81 import org.onap.so.db.catalog.beans.ServiceProxyResourceCustomization;
82 import org.onap.so.db.catalog.beans.VfModuleCustomization;
83 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
84 import org.onap.so.serviceinstancebeans.CloudConfiguration;
85 import org.onap.so.serviceinstancebeans.RequestDetails;
86 import org.slf4j.Logger;
87 import org.slf4j.LoggerFactory;
88 import org.springframework.stereotype.Component;
89 import java.util.ArrayList;
90 import java.util.Arrays;
91 import java.util.HashMap;
92 import java.util.List;
93 import java.util.Map;
94 import java.util.Optional;
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         ModelInfoVfModule modelInfo = new ModelInfoVfModule();
190         modelInfo.setModelCustomizationUUID(aaiVolumeGroup.getModelCustomizationId());
191         volumeGroup.setModelInfoVfModule(modelInfo);
192         volumeGroup.setOrchestrationStatus(this.mapOrchestrationStatusFromAAI(aaiVolumeGroup.getOrchestrationStatus()));
193         return volumeGroup;
194     }
195
196     protected void setPlatformAndLOBIntoServiceInstance(Platform platformMSO, LineOfBusiness lineOfBusinessMSO,
197             ServiceInstance serviceInstance, Map<ResourceKey, String> resourcesToBeOrchestrated) {
198         String vnfId = resourcesToBeOrchestrated.get(ResourceKey.GENERIC_VNF_ID);
199         if (vnfId != null && !serviceInstance.getVnfs().isEmpty()) {
200             for (GenericVnf vnf : serviceInstance.getVnfs()) {
201                 if (vnf.getVnfId().equalsIgnoreCase(vnfId)) {
202                     vnf.setPlatform(platformMSO);
203                     vnf.setLineOfBusiness(lineOfBusinessMSO);
204                     break;
205                 }
206             }
207         }
208     }
209
210     public ModelInfoServiceInstance mapCatalogServiceIntoServiceInstance(Service service) {
211         return modelMapper.map(service, ModelInfoServiceInstance.class);
212     }
213
214     protected ModelInfoInstanceGroup mapCatalogInstanceGroupToInstanceGroup(
215             CollectionResourceCustomization collectionCust, InstanceGroup instanceGroup) {
216         ModelInfoInstanceGroup modelInfoInstanceGroup = modelMapper.map(instanceGroup, ModelInfoInstanceGroup.class);
217         if (instanceGroup.getType() != null && instanceGroup.getType().equals(InstanceGroupType.L3_NETWORK))
218             modelInfoInstanceGroup.setType(ModelInfoInstanceGroup.TYPE_L3_NETWORK);
219         else
220             modelInfoInstanceGroup.setType(ModelInfoInstanceGroup.TYPE_VNFC);
221         if (collectionCust != null) {
222             List<CollectionResourceInstanceGroupCustomization> instanceGroupCustList =
223                     instanceGroup.getCollectionInstanceGroupCustomizations();
224             for (CollectionResourceInstanceGroupCustomization collectionInsatnceGroupCust : instanceGroupCustList) {
225                 if (collectionInsatnceGroupCust.getModelCustomizationUUID()
226                         .equalsIgnoreCase(collectionCust.getModelCustomizationUUID())) {
227                     modelInfoInstanceGroup.setFunction(collectionInsatnceGroupCust.getFunction());
228                     modelInfoInstanceGroup.setDescription(collectionInsatnceGroupCust.getDescription());
229                     break;
230                 }
231             }
232         }
233         return modelInfoInstanceGroup;
234     }
235
236     protected ModelInfoCollection mapCatalogCollectionToCollection(CollectionResourceCustomization collectionCust,
237             CollectionResource collectionResource) {
238         ModelInfoCollection modelInfoCollection = new ModelInfoCollection();
239         modelInfoCollection.setCollectionFunction(collectionCust.getFunction());
240         modelInfoCollection.setCollectionRole(collectionCust.getRole());
241         modelInfoCollection.setCollectionType(collectionCust.getType());
242         modelInfoCollection.setDescription(collectionResource.getDescription());
243         modelInfoCollection.setModelInvariantUUID(collectionResource.getModelInvariantUUID());
244         modelInfoCollection.setModelVersionId(collectionResource.getModelUUID());
245         modelInfoCollection.setModelCustomizationUUID(collectionCust.getModelCustomizationUUID());
246         return modelInfoCollection;
247     }
248
249     public ServiceInstance mapAAIServiceInstanceIntoServiceInstance(
250             org.onap.aai.domain.yang.ServiceInstance aaiServiceInstance) {
251         ServiceInstance serviceInstance = modelMapper.map(aaiServiceInstance, ServiceInstance.class);
252         if (aaiServiceInstance.getAllottedResources() != null) {
253             for (org.onap.aai.domain.yang.AllottedResource allottedResource : aaiServiceInstance.getAllottedResources()
254                     .getAllottedResource()) {
255                 serviceInstance.getAllottedResources().add(mapAAIAllottedResource(allottedResource));
256             }
257         }
258         serviceInstance.setOrchestrationStatus(
259                 this.mapOrchestrationStatusFromAAI(aaiServiceInstance.getOrchestrationStatus()));
260         return serviceInstance;
261     }
262
263     protected AllottedResource mapAAIAllottedResource(org.onap.aai.domain.yang.AllottedResource aaiAllottedResource) {
264         AllottedResource allottedResource = modelMapper.map(aaiAllottedResource, AllottedResource.class);
265         return allottedResource;
266     }
267
268     protected L3Network mapAAIL3Network(org.onap.aai.domain.yang.L3Network aaiL3Network) {
269         L3Network network = modelMapper.map(aaiL3Network, L3Network.class);
270         mapAllSubnetsIntoL3Network(aaiL3Network, network);
271         mapAllCtagAssignmentsIntoL3Network(aaiL3Network, network);
272         mapAllSegmentationAssignmentsIntoL3Network(aaiL3Network, network);
273         mapAllAggregateRoutesIntoL3Network(aaiL3Network, network);
274         network.setOrchestrationStatus(this.mapOrchestrationStatusFromAAI(aaiL3Network.getOrchestrationStatus()));
275         return network;
276     }
277
278     protected void mapAllAggregateRoutesIntoL3Network(org.onap.aai.domain.yang.L3Network aaiL3Network,
279             L3Network network) {
280         if (aaiL3Network.getAggregateRoutes() != null) {
281             for (org.onap.aai.domain.yang.AggregateRoute aaiAggregateRoute : aaiL3Network.getAggregateRoutes()
282                     .getAggregateRoute()) {
283                 network.getAggregateRoutes().add(mapAAIAggregateRoute(aaiAggregateRoute));
284             }
285         }
286     }
287
288     protected void mapAllSegmentationAssignmentsIntoL3Network(org.onap.aai.domain.yang.L3Network aaiL3Network,
289             L3Network network) {
290         if (aaiL3Network.getSegmentationAssignments() != null) {
291             for (org.onap.aai.domain.yang.SegmentationAssignment aaiSegmentationAssignment : aaiL3Network
292                     .getSegmentationAssignments().getSegmentationAssignment()) {
293                 network.getSegmentationAssignments().add(mapAAISegmentationAssignment(aaiSegmentationAssignment));
294             }
295         }
296     }
297
298     protected void mapAllCtagAssignmentsIntoL3Network(org.onap.aai.domain.yang.L3Network aaiL3Network,
299             L3Network network) {
300         if (aaiL3Network.getCtagAssignments() != null) {
301             for (org.onap.aai.domain.yang.CtagAssignment aaiCtagAssignment : aaiL3Network.getCtagAssignments()
302                     .getCtagAssignment()) {
303                 network.getCtagAssignments().add(mapAAICtagAssignment(aaiCtagAssignment));
304             }
305         }
306     }
307
308     protected void mapAllSubnetsIntoL3Network(org.onap.aai.domain.yang.L3Network aaiL3Network, L3Network network) {
309         if (aaiL3Network.getSubnets() != null) {
310             for (org.onap.aai.domain.yang.Subnet aaiSubnet : aaiL3Network.getSubnets().getSubnet()) {
311                 network.getSubnets().add(mapAAISubnet(aaiSubnet));
312             }
313         }
314     }
315
316     protected GenericVnf mapAAIGenericVnfIntoGenericVnf(org.onap.aai.domain.yang.GenericVnf aaiGenericVnf) {
317         GenericVnf genericVnf = modelMapper.map(aaiGenericVnf, GenericVnf.class);
318         mapAllVfModulesIntoGenericVnf(aaiGenericVnf, genericVnf);
319         mapAllLagInterfacesIntoGenericVnf(aaiGenericVnf, genericVnf);
320         mapAllEntitlementsIntoGenericVnf(aaiGenericVnf, genericVnf);
321         mapAllLicensesIntoGenericVnf(aaiGenericVnf, genericVnf);
322         genericVnf.setOrchestrationStatus(this.mapOrchestrationStatusFromAAI(aaiGenericVnf.getOrchestrationStatus()));
323         return genericVnf;
324     }
325
326     protected void mapAllLicensesIntoGenericVnf(org.onap.aai.domain.yang.GenericVnf aaiGenericVnf,
327             GenericVnf genericVnf) {
328         if (aaiGenericVnf.getLicenses() != null) {
329             for (org.onap.aai.domain.yang.License aaiLicense : aaiGenericVnf.getLicenses().getLicense()) {
330                 genericVnf.setLicense(mapAAILicense(aaiLicense));
331             }
332         }
333     }
334
335     protected void mapAllEntitlementsIntoGenericVnf(org.onap.aai.domain.yang.GenericVnf aaiGenericVnf,
336             GenericVnf genericVnf) {
337         if (aaiGenericVnf.getEntitlements() != null) {
338             for (org.onap.aai.domain.yang.Entitlement aaiEntitlement : aaiGenericVnf.getEntitlements()
339                     .getEntitlement()) {
340                 genericVnf.getEntitlements().add(mapAAIEntitlement(aaiEntitlement));
341             }
342         }
343     }
344
345     protected void mapAllLagInterfacesIntoGenericVnf(org.onap.aai.domain.yang.GenericVnf aaiGenericVnf,
346             GenericVnf genericVnf) {
347         if (aaiGenericVnf.getLagInterfaces() != null) {
348             for (org.onap.aai.domain.yang.LagInterface aaiLagInterface : aaiGenericVnf.getLagInterfaces()
349                     .getLagInterface()) {
350                 genericVnf.getLagInterfaces().add(mapAAILagInterface(aaiLagInterface));
351             }
352         }
353     }
354
355     protected void mapAllVfModulesIntoGenericVnf(org.onap.aai.domain.yang.GenericVnf aaiGenericVnf,
356             GenericVnf genericVnf) {
357         if (aaiGenericVnf.getVfModules() != null) {
358             for (org.onap.aai.domain.yang.VfModule aaiVfModule : aaiGenericVnf.getVfModules().getVfModule()) {
359                 VfModule vfModule = mapAAIVfModule(aaiVfModule);
360                 genericVnf.getVfModules().add(vfModule);
361             }
362         }
363     }
364
365     public OrchestrationStatus mapOrchestrationStatusFromAAI(String orchestrationStatus) {
366
367         Optional<OrchestrationStatus> result = Arrays.asList(OrchestrationStatus.values()).stream()
368                 .filter(item -> item.fuzzyMap(orchestrationStatus)).findFirst();
369
370         return result.orElse(null);
371
372     }
373
374     public RequestContext mapRequestContext(RequestDetails requestDetails) {
375         RequestContext context = new RequestContext();
376         if (null != requestDetails.getRequestInfo()) {
377             modelMapper.map(requestDetails.getRequestInfo(), context);
378         }
379         org.onap.so.serviceinstancebeans.RequestParameters requestParameters = requestDetails.getRequestParameters();
380         if (null != requestParameters) {
381             context.setSubscriptionServiceType(requestParameters.getSubscriptionServiceType());
382             context.setRequestParameters(this.mapRequestParameters(requestDetails.getRequestParameters()));
383             context.setUserParams(this.mapNameValueUserParams(requestDetails.getRequestParameters()));
384         }
385         if (requestDetails.getConfigurationParameters() != null) {
386             context.setConfigurationParameters(requestDetails.getConfigurationParameters());
387         }
388         return context;
389     }
390
391     protected RequestParameters mapRequestParameters(
392             org.onap.so.serviceinstancebeans.RequestParameters requestParameters) {
393         RequestParameters requestParams = new RequestParameters();
394         requestParams.setaLaCarte(requestParameters.getALaCarte());
395         requestParams.setUsePreload(requestParameters.getUsePreload());
396         requestParams.setSubscriptionServiceType(requestParameters.getSubscriptionServiceType());
397         requestParams.setUserParams(requestParameters.getUserParams());
398         requestParams.setPayload(requestParameters.getPayload());
399         return requestParams;
400     }
401
402     protected Map<String, Object> mapNameValueUserParams(
403             org.onap.so.serviceinstancebeans.RequestParameters requestParameters) {
404         Map<String, Object> userParamsResult = new HashMap<String, Object>();
405         if (requestParameters.getUserParams() != null) {
406             List<Map<String, Object>> userParams = requestParameters.getUserParams();
407             for (Map<String, Object> userParamsMap : userParams) {
408                 if (userParamsMap.containsKey(USER_PARAM_NAME_KEY)
409                         && (userParamsMap.get(USER_PARAM_NAME_KEY) instanceof String)
410                         && userParamsMap.containsKey(USER_PARAM_VALUE_KEY)) {
411                     userParamsResult.put((String) userParamsMap.get(USER_PARAM_NAME_KEY),
412                             userParamsMap.get(USER_PARAM_VALUE_KEY));
413                 }
414             }
415         }
416         return userParamsResult;
417     }
418
419     protected OrchestrationContext mapOrchestrationContext(RequestDetails requestDetails) {
420         OrchestrationContext context = new OrchestrationContext();
421         if (requestDetails.getRequestInfo() != null) {
422             context.setIsRollbackEnabled(!(requestDetails.getRequestInfo().getSuppressRollback()));
423         } else {
424             context.setIsRollbackEnabled(false);
425         }
426         return context;
427     }
428
429     protected CloudRegion mapCloudRegion(CloudConfiguration cloudConfiguration,
430             org.onap.aai.domain.yang.CloudRegion aaiCloudRegion) {
431         CloudRegion cloudRegion = new CloudRegion();
432         if (cloudConfiguration != null)
433             cloudRegion = modelMapper.map(cloudConfiguration, CloudRegion.class);
434         if (aaiCloudRegion != null)
435             modelMapper.map(aaiCloudRegion, cloudRegion);
436         return cloudRegion;
437     }
438
439     protected Tenant mapTenant(org.onap.aai.domain.yang.Tenant aaiTenant) {
440         Tenant tenant = new Tenant();
441         if (aaiTenant != null) {
442             modelMapper.map(aaiTenant, tenant);
443         }
444         return tenant;
445     }
446
447     protected Collection mapAAICollectionIntoCollection(org.onap.aai.domain.yang.Collection aaiCollection) {
448         Collection collection = new Collection();
449         collection.setId(aaiCollection.getCollectionId());
450         collection.setOrchestrationStatus(this.mapOrchestrationStatusFromAAI(aaiCollection.getOrchestrationStatus()));
451         return collection;
452     }
453
454     protected org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup mapAAIInstanceGroupIntoInstanceGroup(
455             org.onap.aai.domain.yang.InstanceGroup aaiInstanceGroup) {
456         return modelMapper.map(aaiInstanceGroup, org.onap.so.bpmn.servicedecomposition.bbobjects.InstanceGroup.class);
457     }
458
459     public RouteTableReference mapAAIRouteTableReferenceIntoRouteTableReference(
460             org.onap.aai.domain.yang.RouteTableReference aaiRouteTableReference) {
461         return modelMapper.map(aaiRouteTableReference, RouteTableReference.class);
462     }
463
464     protected ModelInfoNetwork mapCatalogNetworkToNetwork(NetworkResourceCustomization networkResourceCustomization) {
465         modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
466         ModelInfoNetwork modelInfoNetwork = modelMapper.map(networkResourceCustomization, ModelInfoNetwork.class);
467         modelMapper.map(networkResourceCustomization.getNetworkResource(), modelInfoNetwork);
468         modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STANDARD);
469         return modelInfoNetwork;
470     }
471
472     protected ModelInfoGenericVnf mapCatalogVnfToVnf(VnfResourceCustomization vnfResourceCustomization) {
473         ModelInfoGenericVnf modelInfoVnf = modelMapper.map(vnfResourceCustomization, ModelInfoGenericVnf.class);
474         modelMapper.map(vnfResourceCustomization.getVnfResources(), modelInfoVnf);
475         return modelInfoVnf;
476     }
477
478     protected ModelInfoVfModule mapCatalogVfModuleToVfModule(VfModuleCustomization vfResourceCustomization) {
479         ModelInfoVfModule modelInfoVfModule = modelMapper.map(vfResourceCustomization, ModelInfoVfModule.class);
480         modelMapper.map(vfResourceCustomization.getVfModule(), modelInfoVfModule);
481         return modelInfoVfModule;
482     }
483
484     protected Platform mapRequestPlatform(org.onap.so.serviceinstancebeans.Platform platform) {
485         return modelMapper.map(platform, Platform.class);
486     }
487
488     protected LineOfBusiness mapRequestLineOfBusiness(org.onap.so.serviceinstancebeans.LineOfBusiness lineOfBusiness) {
489         return modelMapper.map(lineOfBusiness, LineOfBusiness.class);
490     }
491
492     public Configuration mapAAIConfiguration(org.onap.aai.domain.yang.Configuration configurationAAI) {
493         modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STRICT);
494         Configuration configuration = modelMapper.map(configurationAAI, Configuration.class);
495         modelMapper.getConfiguration().setMatchingStrategy(MatchingStrategies.STANDARD);
496         configuration.getForwarderEvcs().addAll(mapAllForwarderEvcs(configurationAAI));
497         configuration.getEvcs().addAll(mapAllEvcs(configurationAAI));
498         configuration
499                 .setOrchestrationStatus(this.mapOrchestrationStatusFromAAI(configurationAAI.getOrchestrationStatus()));
500         return configuration;
501     }
502
503     protected List<Evc> mapAllEvcs(org.onap.aai.domain.yang.Configuration configurationAAI) {
504         List<Evc> listOfEvcs = new ArrayList<>();
505         if (configurationAAI.getEvcs() != null) {
506             for (org.onap.aai.domain.yang.Evc aaiEvc : configurationAAI.getEvcs().getEvc()) {
507                 listOfEvcs.add(mapEvc(aaiEvc));
508             }
509         }
510         return listOfEvcs;
511     }
512
513     protected Evc mapEvc(org.onap.aai.domain.yang.Evc aaiEvc) {
514         return modelMapper.map(aaiEvc, Evc.class);
515     }
516
517     protected List<ForwarderEvc> mapAllForwarderEvcs(org.onap.aai.domain.yang.Configuration configurationAAI) {
518         List<ForwarderEvc> listOfForwarderEvcs = new ArrayList<>();
519         if (configurationAAI.getForwarderEvcs() != null) {
520             for (org.onap.aai.domain.yang.ForwarderEvc aaiForwarderEvc : configurationAAI.getForwarderEvcs()
521                     .getForwarderEvc()) {
522                 listOfForwarderEvcs.add(mapForwarderEvc(aaiForwarderEvc));
523             }
524         }
525         return listOfForwarderEvcs;
526     }
527
528     protected ForwarderEvc mapForwarderEvc(org.onap.aai.domain.yang.ForwarderEvc aaiForwarderEvc) {
529         return modelMapper.map(aaiForwarderEvc, ForwarderEvc.class);
530     }
531
532     protected OwningEntity mapRequestOwningEntity(org.onap.so.serviceinstancebeans.OwningEntity owningEntity) {
533         return modelMapper.map(owningEntity, OwningEntity.class);
534     }
535
536     protected Project mapRequestProject(org.onap.so.serviceinstancebeans.Project project) {
537         return modelMapper.map(project, Project.class);
538     }
539
540     protected ModelInfoConfiguration mapCatalogConfigurationToConfiguration(
541             ConfigurationResourceCustomization configurationResourceCustomization,
542             CvnfcConfigurationCustomization cvnfcConfigurationCustomization) {
543
544         ModelInfoConfiguration modelInfoConfiguration = new ModelInfoConfiguration();
545         modelInfoConfiguration
546                 .setModelVersionId(configurationResourceCustomization.getConfigurationResource().getModelUUID());
547         modelInfoConfiguration.setModelCustomizationId(configurationResourceCustomization.getModelCustomizationUUID());
548         modelInfoConfiguration.setModelInvariantId(
549                 configurationResourceCustomization.getConfigurationResource().getModelInvariantUUID());
550         modelInfoConfiguration.setConfigurationRole(configurationResourceCustomization.getRole());
551         modelInfoConfiguration.setConfigurationType(configurationResourceCustomization.getType());
552         if (cvnfcConfigurationCustomization != null) {
553             modelInfoConfiguration.setPolicyName(cvnfcConfigurationCustomization.getPolicyName());
554         }
555         return modelInfoConfiguration;
556     }
557
558     protected ModelInfoConfiguration mapCatalogConfigurationToConfiguration(
559             CvnfcConfigurationCustomization cvnfcConfigurationCustomization) {
560         ModelInfoConfiguration modelInfoConfiguration = new ModelInfoConfiguration();
561         modelInfoConfiguration
562                 .setModelVersionId(cvnfcConfigurationCustomization.getConfigurationResource().getModelUUID());
563         modelInfoConfiguration.setModelCustomizationId(cvnfcConfigurationCustomization.getModelCustomizationUUID());
564         modelInfoConfiguration.setModelInvariantId(
565                 cvnfcConfigurationCustomization.getConfigurationResource().getModelInvariantUUID());
566         modelInfoConfiguration.setPolicyName(cvnfcConfigurationCustomization.getPolicyName());
567         modelInfoConfiguration.setConfigurationType(cvnfcConfigurationCustomization.getConfigurationType());
568         modelInfoConfiguration.setConfigurationRole(cvnfcConfigurationCustomization.getConfigurationRole());
569         return modelInfoConfiguration;
570     }
571
572     public NetworkResourceCustomization mapCollectionNetworkResourceCustToNetworkResourceCust(
573             CollectionNetworkResourceCustomization collectionNetworkResourceCust) {
574         return modelMapper.map(collectionNetworkResourceCust, NetworkResourceCustomization.class);
575     }
576
577     public Vnfc mapAAIVnfc(org.onap.aai.domain.yang.Vnfc vnfcAAI) {
578         return modelMapper.map(vnfcAAI, Vnfc.class);
579     }
580
581     public VpnBinding mapAAIVpnBinding(org.onap.aai.domain.yang.VpnBinding aaiVpnBinding) {
582         VpnBinding vpnBinding = modelMapper.map(aaiVpnBinding, VpnBinding.class);
583         mapAllRouteTargetsToAAIVpnBinding(aaiVpnBinding, vpnBinding);
584         return vpnBinding;
585     }
586
587     protected void mapAllRouteTargetsToAAIVpnBinding(org.onap.aai.domain.yang.VpnBinding aaiVpnBinding,
588             VpnBinding vpnBinding) {
589         if (aaiVpnBinding.getRouteTargets() != null) {
590             for (org.onap.aai.domain.yang.RouteTarget aaiRouteTarget : aaiVpnBinding.getRouteTargets()
591                     .getRouteTarget()) {
592                 vpnBinding.getRouteTargets().add(mapAAIRouteTarget(aaiRouteTarget));
593             }
594         }
595     }
596
597     public RouteTarget mapAAIRouteTarget(org.onap.aai.domain.yang.RouteTarget aaiRouteTarget) {
598         return modelMapper.map(aaiRouteTarget, RouteTarget.class);
599     }
600
601     protected ModelInfoServiceProxy mapServiceProxyCustomizationToServiceProxy(
602             ServiceProxyResourceCustomization serviceProxyCustomization) {
603         ModelInfoServiceProxy modelInfoServiceProxy =
604                 modelMapper.map(serviceProxyCustomization.getSourceService(), ModelInfoServiceProxy.class);
605         modelInfoServiceProxy.setModelInstanceName(serviceProxyCustomization.getModelInstanceName());
606         return modelInfoServiceProxy;
607     }
608 }