Added oparent to sdc main
[sdc.git] / openecomp-be / api / openecomp-sdc-rest-webapp / conflict-rest / conflict-rest-services / src / main / java / org / openecomp / sdcrests / conflict / rest / mapping / MapConflictToDto.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdcrests.conflict.rest.mapping;
22
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.*;
33
34 import java.util.AbstractMap;
35 import java.util.HashMap;
36 import java.util.Map;
37
38 public class MapConflictToDto extends MappingBase<Conflict, ConflictDto> {
39
40   @Override
41   public void doMapping(Conflict source, ConflictDto target) {
42     target.setId(source.getId());
43     target.setType(source.getType());
44     target.setName(source.getName());
45
46     Map.Entry<MappingBase, Class> mapperToTargetClass = getMapper(source.getType());
47     target.setTheirs(map(mapperToTargetClass, source.getTheirs()));
48     target.setYours(map(mapperToTargetClass, source.getYours()));
49   }
50
51   private Map map(Map.Entry<MappingBase, Class> mapperToTargetClass, Object object) {
52     return JsonUtil
53         .json2Object(JsonUtil.object2Json(
54             mapperToTargetClass.getKey().applyMapping(object, mapperToTargetClass.getValue())),
55             Map.class);
56   }
57
58   private Map.Entry<MappingBase, Class> getMapper(ElementType type) {
59     switch (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);
67       case FeatureGroup:
68         return new AbstractMap.SimpleEntry<>(new MapFeatureGroupEntityToFeatureGroupDescriptorDto(),
69             FeatureGroupDescriptorDto.class);
70       case LicenseKeyGroup:
71         return new AbstractMap.SimpleEntry<>(
72             new MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto(), LicenseKeyGroupEntityDto
73             .class);
74       case EntitlementPool:
75         return new AbstractMap.SimpleEntry<>(
76             new MapEntitlementPoolEntityToEntitlementPoolEntityDto(), EntitlementPoolEntityDto
77             .class);
78       case Limit:
79         return new AbstractMap.SimpleEntry<>(new MapLimitEntityToLimitDto(), LimitEntityDto.class);
80       case VendorSoftwareProduct:
81         return new AbstractMap.SimpleEntry<>(new MapVspDetailsToDto(), VspDetailsDto.class);
82       case Network:
83         return new AbstractMap.SimpleEntry<>(new MapNetworkEntityToNetworkDto(), NetworkDto.class);
84       case Component:
85         return new AbstractMap.SimpleEntry<>(new MapComponentEntityToComponentDto(),
86             ComponentDto.class);
87       case ComponentDependencies:
88         return new AbstractMap.SimpleEntry<>(new MapComponentDependencyModelEntityToDto(),
89             ComponentDependencyModel.class);
90       case Nic:
91         return new AbstractMap.SimpleEntry<>(new MapNicEntityToNicDto(), NicDto.class);
92       case Process:
93         return new AbstractMap.SimpleEntry<>(new MapProcessEntityToProcessEntityDto(),
94             ProcessEntityDto.class);
95       case DeploymentFlavor:
96         return new AbstractMap.SimpleEntry<>(new MapDeploymentFlavorEntityToDeploymentFlavorDto(),
97             DeploymentFlavorDto.class);
98       case Compute:
99         return new AbstractMap.SimpleEntry<>(new MapComputeEntityToVspComputeDto(),
100             VspComputeDto.class);
101       case Image:
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);
110       case SNMP_POLL:
111       case SNMP_TRAP:
112       case VES_EVENTS:
113       case OrchestrationTemplateCandidate:
114         return new AbstractMap.SimpleEntry<>(new MapFilesDataStructureToDto(),
115             FileDataStructureDto.class);
116       case ServiceModel:
117       case NetworkPackage:
118         return new AbstractMap.SimpleEntry<>(new EchoMapMapping(), HashMap.class);
119       case itemVersion:
120         return new AbstractMap.SimpleEntry<>(new EchoMapMapping(), HashMap.class);
121     }
122     throw new RuntimeException("Get conflict does not support element type: " + type.name());
123   }
124 }