2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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.openecomp.sdcrests.conflict.rest.mapping;
23 import org.openecomp.conflicts.types.Conflict;
24 import org.openecomp.core.utilities.json.JsonUtil;
25 import org.openecomp.sdc.datatypes.model.ElementType;
26 import org.openecomp.sdcrests.conflict.types.ConflictDto;
27 import org.openecomp.sdcrests.mapping.EchoMapMapping;
28 import org.openecomp.sdcrests.mapping.MappingBase;
29 import org.openecomp.sdcrests.vendorlicense.rest.mapping.*;
30 import org.openecomp.sdcrests.vendorlicense.types.*;
31 import org.openecomp.sdcrests.vendorsoftwareproducts.types.*;
32 import org.openecomp.sdcrests.vsp.rest.mapping.*;
34 import java.util.AbstractMap;
35 import java.util.HashMap;
38 public class MapConflictToDto extends MappingBase<Conflict, ConflictDto> {
41 public void doMapping(Conflict source, ConflictDto target) {
42 target.setId(source.getId());
43 target.setType(source.getType());
44 target.setName(source.getName());
46 Map.Entry<MappingBase, Class> mapperToTargetClass = getMapper(source.getType());
47 target.setTheirs(map(mapperToTargetClass, source.getTheirs()));
48 target.setYours(map(mapperToTargetClass, source.getYours()));
51 private Map map(Map.Entry<MappingBase, Class> mapperToTargetClass, Object object) {
53 .json2Object(JsonUtil.object2Json(
54 mapperToTargetClass.getKey().applyMapping(object, mapperToTargetClass.getValue())),
58 private Map.Entry<MappingBase, Class> getMapper(ElementType type) {
60 case VendorLicenseModel:
61 return new AbstractMap.SimpleEntry<>(new MapVendorLicenseModelEntityToDto(),
62 VendorLicenseModelEntityDto.class);
63 case LicenseAgreement:
64 return new AbstractMap.SimpleEntry<>(
65 new MapLicenseAgreementEntityToLicenseAgreementDescriptorDto(),
66 LicenseAgreementDescriptorDto.class);
68 return new AbstractMap.SimpleEntry<>(new MapFeatureGroupEntityToFeatureGroupDescriptorDto(),
69 FeatureGroupDescriptorDto.class);
71 return new AbstractMap.SimpleEntry<>(
72 new MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto(), LicenseKeyGroupEntityDto
75 return new AbstractMap.SimpleEntry<>(
76 new MapEntitlementPoolEntityToEntitlementPoolEntityDto(), EntitlementPoolEntityDto
79 return new AbstractMap.SimpleEntry<>(new MapLimitEntityToLimitDto(), LimitEntityDto.class);
80 case VendorSoftwareProduct:
81 return new AbstractMap.SimpleEntry<>(new MapVspDetailsToDto(), VspDetailsDto.class);
83 return new AbstractMap.SimpleEntry<>(new MapNetworkEntityToNetworkDto(), NetworkDto.class);
85 return new AbstractMap.SimpleEntry<>(new MapComponentEntityToComponentDto(),
87 case ComponentDependencies:
88 return new AbstractMap.SimpleEntry<>(new MapComponentDependencyModelEntityToDto(),
89 ComponentDependencyModel.class);
91 return new AbstractMap.SimpleEntry<>(new MapNicEntityToNicDto(), NicDto.class);
93 return new AbstractMap.SimpleEntry<>(new MapProcessEntityToProcessEntityDto(),
94 ProcessEntityDto.class);
95 case DeploymentFlavor:
96 return new AbstractMap.SimpleEntry<>(new MapDeploymentFlavorEntityToDeploymentFlavorDto(),
97 DeploymentFlavorDto.class);
99 return new AbstractMap.SimpleEntry<>(new MapComputeEntityToVspComputeDto(),
100 VspComputeDto.class);
102 return new AbstractMap.SimpleEntry<>(new MapImageEntityToImageDto(), ImageDto.class);
103 case VSPQuestionnaire:
104 case NicQuestionnaire:
105 case ComponentQuestionnaire:
106 case ImageQuestionnaire:
107 case ComputeQuestionnaire:
108 return new AbstractMap.SimpleEntry<>(new MapQuestionnaireToQuestionnaireDto(),
109 QuestionnaireDto.class);
113 case OrchestrationTemplateCandidate:
114 return new AbstractMap.SimpleEntry<>(new MapFilesDataStructureToDto(),
115 FileDataStructureDto.class);
118 return new AbstractMap.SimpleEntry<>(new EchoMapMapping(), HashMap.class);
120 return new AbstractMap.SimpleEntry<>(new EchoMapMapping(), HashMap.class);
122 throw new RuntimeException("Get conflict does not support element type: " + type.name());