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.MapEntitlementPoolEntityToEntitlementPoolEntityDto;
10 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapFeatureGroupEntityToFeatureGroupDescriptorDto;
11 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapLicenseAgreementEntityToLicenseAgreementDescriptorDto;
12 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto;
13 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapLimitEntityToLimitDto;
14 import org.openecomp.sdcrests.vendorlicense.rest.mapping.MapVendorLicenseModelEntityToDto;
15 import org.openecomp.sdcrests.vendorlicense.types.EntitlementPoolEntityDto;
16 import org.openecomp.sdcrests.vendorlicense.types.FeatureGroupDescriptorDto;
17 import org.openecomp.sdcrests.vendorlicense.types.LicenseAgreementDescriptorDto;
18 import org.openecomp.sdcrests.vendorlicense.types.LicenseKeyGroupEntityDto;
19 import org.openecomp.sdcrests.vendorlicense.types.LimitEntityDto;
20 import org.openecomp.sdcrests.vendorlicense.types.VendorLicenseModelEntityDto;
21 import org.openecomp.sdcrests.vendorsoftwareproducts.types.ComponentDependencyModel;
22 import org.openecomp.sdcrests.vendorsoftwareproducts.types.ComponentDto;
23 import org.openecomp.sdcrests.vendorsoftwareproducts.types.DeploymentFlavorDto;
24 import org.openecomp.sdcrests.vendorsoftwareproducts.types.FileDataStructureDto;
25 import org.openecomp.sdcrests.vendorsoftwareproducts.types.ImageDto;
26 import org.openecomp.sdcrests.vendorsoftwareproducts.types.NetworkDto;
27 import org.openecomp.sdcrests.vendorsoftwareproducts.types.NicDto;
28 import org.openecomp.sdcrests.vendorsoftwareproducts.types.ProcessEntityDto;
29 import org.openecomp.sdcrests.vendorsoftwareproducts.types.QuestionnaireDto;
30 import org.openecomp.sdcrests.vendorsoftwareproducts.types.VspComputeDto;
31 import org.openecomp.sdcrests.vendorsoftwareproducts.types.VspDetailsDto;
32 import org.openecomp.sdcrests.vsp.rest.mapping.MapComponentDependencyModelEntityToDto;
33 import org.openecomp.sdcrests.vsp.rest.mapping.MapComponentEntityToComponentDto;
34 import org.openecomp.sdcrests.vsp.rest.mapping.MapComputeEntityToVspComputeDto;
35 import org.openecomp.sdcrests.vsp.rest.mapping.MapDeploymentFlavorEntityToDeploymentFlavorDto;
36 import org.openecomp.sdcrests.vsp.rest.mapping.MapFilesDataStructureToDto;
37 import org.openecomp.sdcrests.vsp.rest.mapping.MapImageEntityToImageDto;
38 import org.openecomp.sdcrests.vsp.rest.mapping.MapNetworkEntityToNetworkDto;
39 import org.openecomp.sdcrests.vsp.rest.mapping.MapNicEntityToNicDto;
40 import org.openecomp.sdcrests.vsp.rest.mapping.MapProcessEntityToProcessEntityDto;
41 import org.openecomp.sdcrests.vsp.rest.mapping.MapQuestionnaireToQuestionnaireDto;
42 import org.openecomp.sdcrests.vsp.rest.mapping.MapVspDetailsToDto;
44 import java.util.AbstractMap;
45 import java.util.HashMap;
48 public class MapConflictToDto extends MappingBase<Conflict, ConflictDto> {
51 public void doMapping(Conflict source, ConflictDto target) {
52 target.setId(source.getId());
53 target.setType(source.getType());
54 target.setName(source.getName());
56 Map.Entry<MappingBase, Class> mapperToTargetClass = getMapper(source.getType());
57 target.setTheirs(map(mapperToTargetClass, source.getTheirs()));
58 target.setYours(map(mapperToTargetClass, source.getYours()));
61 private Map map(Map.Entry<MappingBase, Class> mapperToTargetClass, Object object) {
63 .json2Object(JsonUtil.object2Json(
64 mapperToTargetClass.getKey().applyMapping(object, mapperToTargetClass.getValue())),
68 private Map.Entry<MappingBase, Class> getMapper(ElementType type) {
70 case VendorLicenseModel:
71 return new AbstractMap.SimpleEntry<>(new MapVendorLicenseModelEntityToDto(),
72 VendorLicenseModelEntityDto.class);
73 case LicenseAgreement:
74 return new AbstractMap.SimpleEntry<>(
75 new MapLicenseAgreementEntityToLicenseAgreementDescriptorDto(),
76 LicenseAgreementDescriptorDto.class);
78 return new AbstractMap.SimpleEntry<>(new MapFeatureGroupEntityToFeatureGroupDescriptorDto(),
79 FeatureGroupDescriptorDto.class);
81 return new AbstractMap.SimpleEntry<>(
82 new MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto(), LicenseKeyGroupEntityDto
85 return new AbstractMap.SimpleEntry<>(
86 new MapEntitlementPoolEntityToEntitlementPoolEntityDto(), EntitlementPoolEntityDto
89 return new AbstractMap.SimpleEntry<>(new MapLimitEntityToLimitDto(), LimitEntityDto.class);
90 case VendorSoftwareProduct:
91 return new AbstractMap.SimpleEntry<>(new MapVspDetailsToDto(), VspDetailsDto.class);
93 return new AbstractMap.SimpleEntry<>(new MapNetworkEntityToNetworkDto(), NetworkDto.class);
95 return new AbstractMap.SimpleEntry<>(new MapComponentEntityToComponentDto(),
97 case ComponentDependencies:
98 return new AbstractMap.SimpleEntry<>(new MapComponentDependencyModelEntityToDto(),
99 ComponentDependencyModel.class);
101 return new AbstractMap.SimpleEntry<>(new MapNicEntityToNicDto(), NicDto.class);
103 return new AbstractMap.SimpleEntry<>(new MapProcessEntityToProcessEntityDto(),
104 ProcessEntityDto.class);
105 case DeploymentFlavor:
106 return new AbstractMap.SimpleEntry<>(new MapDeploymentFlavorEntityToDeploymentFlavorDto(),
107 DeploymentFlavorDto.class);
109 return new AbstractMap.SimpleEntry<>(new MapComputeEntityToVspComputeDto(),
110 VspComputeDto.class);
112 return new AbstractMap.SimpleEntry<>(new MapImageEntityToImageDto(), ImageDto.class);
113 case VSPQuestionnaire:
114 case NicQuestionnaire:
115 case ComponentQuestionnaire:
116 case ImageQuestionnaire:
117 case ComputeQuestionnaire:
118 return new AbstractMap.SimpleEntry<>(new MapQuestionnaireToQuestionnaireDto(),
119 QuestionnaireDto.class);
123 case OrchestrationTemplateCandidate:
124 return new AbstractMap.SimpleEntry<>(new MapFilesDataStructureToDto(),
125 FileDataStructureDto.class);
128 return new AbstractMap.SimpleEntry<>(new EchoMapMapping(), HashMap.class);
130 return new AbstractMap.SimpleEntry<>(new EchoMapMapping(), HashMap.class);
132 throw new RuntimeException("Get conflict does not support element type: " + type.name());