1 package org.openecomp.sdcrests.conflict.rest.mapping;
3 import org.openecomp.conflicts.types.Conflict;
4 import org.openecomp.core.utilities.json.JsonUtil;
5 import org.openecomp.sdc.datatypes.model.ElementType;
6 import org.openecomp.sdcrests.conflict.types.ConflictDto;
7 import org.openecomp.sdcrests.mapping.EchoMapMapping;
8 import org.openecomp.sdcrests.mapping.MappingBase;
9 import org.openecomp.sdcrests.vendorlicense.rest.mapping.*;
10 import org.openecomp.sdcrests.vendorlicense.types.*;
11 import org.openecomp.sdcrests.vendorsoftwareproducts.types.*;
12 import org.openecomp.sdcrests.vsp.rest.mapping.*;
14 import java.util.AbstractMap;
15 import java.util.HashMap;
18 public class MapConflictToDto extends MappingBase<Conflict, ConflictDto> {
21 public void doMapping(Conflict source, ConflictDto target) {
22 target.setId(source.getId());
23 target.setType(source.getType());
24 target.setName(source.getName());
26 Map.Entry<MappingBase, Class> mapperToTargetClass = getMapper(source.getType());
27 target.setTheirs(map(mapperToTargetClass, source.getTheirs()));
28 target.setYours(map(mapperToTargetClass, source.getYours()));
31 private Map map(Map.Entry<MappingBase, Class> mapperToTargetClass, Object object) {
33 .json2Object(JsonUtil.object2Json(
34 mapperToTargetClass.getKey().applyMapping(object, mapperToTargetClass.getValue())),
38 private Map.Entry<MappingBase, Class> getMapper(ElementType type) {
40 case VendorLicenseModel:
41 return new AbstractMap.SimpleEntry<>(new MapVendorLicenseModelEntityToDto(),
42 VendorLicenseModelEntityDto.class);
43 case LicenseAgreement:
44 return new AbstractMap.SimpleEntry<>(
45 new MapLicenseAgreementEntityToLicenseAgreementDescriptorDto(),
46 LicenseAgreementDescriptorDto.class);
48 return new AbstractMap.SimpleEntry<>(new MapFeatureGroupEntityToFeatureGroupDescriptorDto(),
49 FeatureGroupDescriptorDto.class);
51 return new AbstractMap.SimpleEntry<>(
52 new MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto(), LicenseKeyGroupEntityDto
55 return new AbstractMap.SimpleEntry<>(
56 new MapEntitlementPoolEntityToEntitlementPoolEntityDto(), EntitlementPoolEntityDto
59 return new AbstractMap.SimpleEntry<>(new MapLimitEntityToLimitDto(), LimitEntityDto.class);
60 case VendorSoftwareProduct:
61 return new AbstractMap.SimpleEntry<>(new MapVspDetailsToDto(), VspDetailsDto.class);
63 return new AbstractMap.SimpleEntry<>(new MapNetworkEntityToNetworkDto(), NetworkDto.class);
65 return new AbstractMap.SimpleEntry<>(new MapComponentEntityToComponentDto(),
67 case ComponentDependencies:
68 return new AbstractMap.SimpleEntry<>(new MapComponentDependencyModelEntityToDto(),
69 ComponentDependencyModel.class);
71 return new AbstractMap.SimpleEntry<>(new MapNicEntityToNicDto(), NicDto.class);
73 return new AbstractMap.SimpleEntry<>(new MapProcessEntityToProcessEntityDto(),
74 ProcessEntityDto.class);
75 case DeploymentFlavor:
76 return new AbstractMap.SimpleEntry<>(new MapDeploymentFlavorEntityToDeploymentFlavorDto(),
77 DeploymentFlavorDto.class);
79 return new AbstractMap.SimpleEntry<>(new MapComputeEntityToVspComputeDto(),
82 return new AbstractMap.SimpleEntry<>(new MapImageEntityToImageDto(), ImageDto.class);
83 case VSPQuestionnaire:
84 case NicQuestionnaire:
85 case ComponentQuestionnaire:
86 case ImageQuestionnaire:
87 case ComputeQuestionnaire:
88 return new AbstractMap.SimpleEntry<>(new MapQuestionnaireToQuestionnaireDto(),
89 QuestionnaireDto.class);
93 case OrchestrationTemplateCandidate:
94 return new AbstractMap.SimpleEntry<>(new MapFilesDataStructureToDto(),
95 FileDataStructureDto.class);
98 return new AbstractMap.SimpleEntry<>(new EchoMapMapping(), HashMap.class);
100 return new AbstractMap.SimpleEntry<>(new EchoMapMapping(), HashMap.class);
102 throw new RuntimeException("Get conflict does not support element type: " + type.name());