2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.be.tosca;
23 import java.lang.reflect.Field;
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.HashMap;
27 import java.util.List;
30 import org.openecomp.sdc.be.datatypes.components.ResourceMetadataDataDefinition;
31 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
32 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
33 import org.openecomp.sdc.be.model.Component;
35 public class ToscaUtils {
37 public static boolean isComplexVfc(Component component) {
38 if (ComponentTypeEnum.RESOURCE == component.getComponentType()) {
39 ResourceTypeEnum resourceType = ((ResourceMetadataDataDefinition) component.getComponentMetadataDefinition().getMetadataDataDefinition()).getResourceType();
40 if (ResourceTypeEnum.CVFC == resourceType) {
47 public static Map<String, Object> objectToMap(Object objectToConvert, Class<?> clazz) throws IllegalArgumentException, IllegalAccessException {
48 Map<String, Object> map = new HashMap<>();
49 List<Field> fields = new ArrayList<>();
51 fields = getAllFields(fields, clazz);
53 for (Field field : fields) {
54 field.setAccessible(true);
55 map.put(field.getName(), field.get(objectToConvert));
60 public static List<Field> getAllFields(List<Field> fields, Class<?> type) {
61 fields.addAll(Arrays.asList(type.getDeclaredFields()));
63 if (type.getSuperclass() != null) {
64 fields = getAllFields(fields, type.getSuperclass());
69 public static class SubstituitionEntry{
71 private String fullName = "";
72 private String sourceName = "";
73 private String owner = "";
75 public SubstituitionEntry() {}
77 public SubstituitionEntry(String fullName, String sourceName, String owner) {
79 this.fullName = fullName;
80 if(sourceName != null)
81 this.sourceName = sourceName;
86 public String getFullName() {
90 public void setFullName(String fullName) {
91 this.fullName = fullName;
94 public String getSourceName() {
98 public void setSourceName(String sourceName) {
99 this.sourceName = sourceName;
102 public String getOwner() {
106 public void setOwner(String owner) {