summaryrefslogtreecommitdiffstats
path: root/openecomp-be/api/openecomp-sdc-rest-webapp/conflict-rest/conflict-rest-services/src/main/java/org/openecomp/sdcrests/conflict/rest/mapping/MapConflictToDto.java
blob: 1a1f3296faf462a8014327a251fa31eb6adcb2cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*-
 * ============LICENSE_START=======================================================
 * SDC
 * ================================================================================
 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.sdcrests.conflict.rest.mapping;

import org.openecomp.conflicts.types.Conflict;
import org.openecomp.core.utilities.json.JsonUtil;
import org.openecomp.sdc.datatypes.model.ElementType;
import org.openecomp.sdcrests.conflict.types.ConflictDto;
import org.openecomp.sdcrests.mapping.EchoMapMapping;
import org.openecomp.sdcrests.mapping.MappingBase;
import org.openecomp.sdcrests.vendorlicense.rest.mapping.*;
import org.openecomp.sdcrests.vendorlicense.types.*;
import org.openecomp.sdcrests.vendorsoftwareproducts.types.*;
import org.openecomp.sdcrests.vsp.rest.mapping.*;

import java.util.AbstractMap;
import java.util.HashMap;
import java.util.Map;

public class MapConflictToDto extends MappingBase<Conflict, ConflictDto> {

  @Override
  public void doMapping(Conflict source, ConflictDto target) {
    target.setId(source.getId());
    target.setType(source.getType());
    target.setName(source.getName());

    Map.Entry<MappingBase, Class> mapperToTargetClass = getMapper(source.getType());
    target.setTheirs(map(mapperToTargetClass, source.getTheirs()));
    target.setYours(map(mapperToTargetClass, source.getYours()));
  }

  private Map map(Map.Entry<MappingBase, Class> mapperToTargetClass, Object object) {
    return JsonUtil
        .json2Object(JsonUtil.object2Json(
            mapperToTargetClass.getKey().applyMapping(object, mapperToTargetClass.getValue())),
            Map.class);
  }

  private Map.Entry<MappingBase, Class> getMapper(ElementType type) {
    switch (type) {
      case VendorLicenseModel:
        return new AbstractMap.SimpleEntry<>(new MapVendorLicenseModelEntityToDto(),
            VendorLicenseModelEntityDto.class);
      case LicenseAgreement:
        return new AbstractMap.SimpleEntry<>(
            new MapLicenseAgreementEntityToLicenseAgreementDescriptorDto(),
            LicenseAgreementDescriptorDto.class);
      case FeatureGroup:
        return new AbstractMap.SimpleEntry<>(new MapFeatureGroupEntityToFeatureGroupDescriptorDto(),
            FeatureGroupDescriptorDto.class);
      case LicenseKeyGroup:
        return new AbstractMap.SimpleEntry<>(
            new MapLicenseKeyGroupEntityToLicenseKeyGroupEntityDto(), LicenseKeyGroupEntityDto
            .class);
      case EntitlementPool:
        return new AbstractMap.SimpleEntry<>(
            new MapEntitlementPoolEntityToEntitlementPoolEntityDto(), EntitlementPoolEntityDto
            .class);
      case Limit:
        return new AbstractMap.SimpleEntry<>(new MapLimitEntityToLimitDto(), LimitEntityDto.class);
      case VendorSoftwareProduct:
        return new AbstractMap.SimpleEntry<>(new MapVspDetailsToDto(), VspDetailsDto.class);
      case Network:
        return new AbstractMap.SimpleEntry<>(new MapNetworkEntityToNetworkDto(), NetworkDto.class);
      case Component:
        return new AbstractMap.SimpleEntry<>(new MapComponentEntityToComponentDto(),
            ComponentDto.class);
      case ComponentDependencies:
        return new AbstractMap.SimpleEntry<>(new MapComponentDependencyModelEntityToDto(),
            ComponentDependencyModel.class);
      case Nic:
        return new AbstractMap.SimpleEntry<>(new MapNicEntityToNicDto(), NicDto.class);
      case Process:
        return new AbstractMap.SimpleEntry<>(new MapProcessEntityToProcessEntityDto(),
            ProcessEntityDto.class);
      case DeploymentFlavor:
        return new AbstractMap.SimpleEntry<>(new MapDeploymentFlavorEntityToDeploymentFlavorDto(),
            DeploymentFlavorDto.class);
      case Compute:
        return new AbstractMap.SimpleEntry<>(new MapComputeEntityToVspComputeDto(),
            VspComputeDto.class);
      case Image:
        return new AbstractMap.SimpleEntry<>(new MapImageEntityToImageDto(), ImageDto.class);
      case VSPQuestionnaire:
      case NicQuestionnaire:
      case ComponentQuestionnaire:
      case ImageQuestionnaire:
      case ComputeQuestionnaire:
        return new AbstractMap.SimpleEntry<>(new MapQuestionnaireToQuestionnaireDto(),
            QuestionnaireDto.class);
      case SNMP_POLL:
      case SNMP_TRAP:
      case VES_EVENTS:
      case OrchestrationTemplateCandidate:
        return new AbstractMap.SimpleEntry<>(new MapFilesDataStructureToDto(),
            FileDataStructureDto.class);
      case ServiceModel:
      case NetworkPackage:
        return new AbstractMap.SimpleEntry<>(new EchoMapMapping(), HashMap.class);
      case itemVersion:
        return new AbstractMap.SimpleEntry<>(new EchoMapMapping(), HashMap.class);
    }
    throw new RuntimeException("Get conflict does not support element type: " + type.name());
  }
}