Upgrade SDC from Titan to Janus Graph
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / tosca / ToscaUtils.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 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.sdc.be.tosca;
22
23 import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
24 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
25 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
26 import org.openecomp.sdc.be.model.Component;
27
28 import java.lang.reflect.Field;
29 import java.util.*;
30 public class ToscaUtils {
31
32     private ToscaUtils() {}
33
34     public static boolean isNotComplexVfc(Component component) {
35         if (ComponentTypeEnum.RESOURCE == component.getComponentType()) {
36             ResourceTypeEnum resourceType = ((ResourceMetadataDataDefinition) component.getComponentMetadataDefinition().getMetadataDataDefinition()).getResourceType();
37             if (ResourceTypeEnum.CVFC == resourceType) {
38                 return false;
39             }
40         }
41         return true;
42     }
43
44     public static Map<String, Object> objectToMap(Object objectToConvert, Class<?> clazz) throws IllegalAccessException {
45         Map<String, Object> map = new HashMap<>();
46         List<Field> fields = new ArrayList<>();
47
48         fields = getAllFields(fields, clazz);
49
50         for (Field field : fields) {
51             field.setAccessible(true);
52             map.put(field.getName(), field.get(objectToConvert));
53         }
54         return map;
55     }
56
57     private static List<Field> getAllFields(List<Field> fields, Class<?> type) {
58         fields.addAll(Arrays.asList(type.getDeclaredFields()));
59         if (type.getSuperclass() != null) {
60             return getAllFields(fields, type.getSuperclass());
61         }
62         return fields;
63     }
64
65     public static class SubstitutionEntry {
66
67         private String fullName = "";
68         private String sourceName = "";
69         private String owner = "";
70
71         SubstitutionEntry(String fullName, String sourceName, String owner) {
72             if(fullName != null) {
73                 this.fullName = fullName;
74             }
75             if(sourceName != null) {
76                 this.sourceName = sourceName;
77             }
78             if(owner != null) {
79                 this.owner = owner;
80             }
81         }
82
83         public String getFullName() {
84             return fullName;
85         }
86
87         public void setFullName(String fullName) {
88             this.fullName = fullName;
89         }
90
91         public String getSourceName() {
92             return sourceName;
93         }
94
95         public void setSourceName(String sourceName) {
96             this.sourceName = sourceName;
97         }
98
99         public String getOwner() {
100             return owner;
101         }
102
103         public void setOwner(String owner) {
104             this.owner = owner;
105         }
106     }
107
108 }