Fix interface types creation
[sdc.git] / common-be / src / main / java / org / openecomp / sdc / be / utils / TypeUtils.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 package org.openecomp.sdc.be.utils;
21
22 import java.util.Map;
23 import java.util.function.Consumer;
24
25 public class TypeUtils {
26
27
28     private static final String FIRST_CERTIFIED_VERSION_VERSION = "1.0";
29
30     public static <FieldType> void setField(Map<String, Object> toscaJson, ToscaTagNamesEnum tagName, Consumer<FieldType> setter) {
31         String fieldName = tagName.getElementName();
32         if (toscaJson.containsKey(fieldName)) {
33             FieldType fieldValue = (FieldType) toscaJson.get(fieldName);
34             setter.accept(fieldValue);
35         }
36     }
37
38     public static String getFirstCertifiedVersionVersion() {
39         return FIRST_CERTIFIED_VERSION_VERSION;
40     }
41
42     public enum ToscaTagNamesEnum {
43         DERIVED_FROM("derived_from"), IS_PASSWORD("is_password"),
44         // Properties
45         PROPERTIES("properties"), TYPE("type"), STATUS("status"), ENTRY_SCHEMA("entry_schema"), REQUIRED("required"), DESCRIPTION("description"), DEFAULT_VALUE("default"), VALUE("value"), CONSTRAINTS("constraints"),
46         // Group Types
47         MEMBERS("members"), METADATA("metadata"),
48         // Policy Types
49         POLICIES("policies"), TARGETS("targets"),
50         // Capabilities
51         CAPABILITIES("capabilities"), VALID_SOURCE_TYPES("valid_source_types"),
52         // Requirements
53         REQUIREMENTS("requirements"), NODE("node"), RELATIONSHIP("relationship"), CAPABILITY("capability"), INTERFACES("interfaces"),
54         NODE_FILTER("node_filter"), TOSCA_ID("tosca_id"),
55         // Artifacts
56         ARTIFACTS("artifacts"), FILE("file"),
57         // Heat env Validation
58         PARAMETERS("parameters"),
59         // Import Validations
60         TOSCA_VERSION("tosca_definitions_version"), TOPOLOGY_TEMPLATE("topology_template"), NODE_TYPES("node_types"), OCCURRENCES("occurrences"), NODE_TEMPLATES("node_templates"), GROUPS("groups"), INPUTS("inputs"),
61         SUBSTITUTION_MAPPINGS("substitution_mappings"), NODE_TYPE("node_type"), DIRECTIVES("directives"),
62         // Attributes
63         ATTRIBUTES("attributes"), LABEL("label"), HIDDEN("hidden"), IMMUTABLE("immutable"), ANNOTATIONS("annotations"),
64         VERSION("version"), OPERATIONS("operations"), NOTIFICATIONS("notifications"),
65         //functions
66         GET_INPUT("get_input");
67
68         private final String elementName;
69
70         ToscaTagNamesEnum(final String elementName) {
71             this.elementName = elementName;
72         }
73
74         public String getElementName() {
75             return elementName;
76         }
77     }
78 }