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.translator.services.heattotosca.globaltypes;
23 import org.openecomp.sdc.tosca.datatypes.ToscaDataType;
24 import org.openecomp.sdc.tosca.datatypes.ToscaNodeType;
25 import org.openecomp.sdc.tosca.datatypes.model.Constraint;
26 import org.openecomp.sdc.tosca.datatypes.model.DataType;
27 import org.openecomp.sdc.tosca.datatypes.model.NodeType;
28 import org.openecomp.sdc.tosca.datatypes.model.PropertyDefinition;
29 import org.openecomp.sdc.tosca.datatypes.model.PropertyType;
30 import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate;
31 import org.openecomp.sdc.tosca.services.DataModelUtil;
32 import org.openecomp.sdc.tosca.services.ToscaConstants;
33 import org.openecomp.sdc.translator.services.heattotosca.Constants;
35 import java.util.ArrayList;
36 import java.util.HashMap;
37 import java.util.List;
41 public class AbstractSubstituteGlobalType {
43 private AbstractSubstituteGlobalType() {
47 * Create service template service template.
49 * @return the service template
51 public static ServiceTemplate createServiceTemplate() {
52 ServiceTemplate serviceTemplate = new ServiceTemplate();
53 serviceTemplate.setTosca_definitions_version(ToscaConstants.TOSCA_DEFINITIONS_VERSION);
54 serviceTemplate.setMetadata(
55 DataModelUtil.createMetadata(Constants.ABSTRACT_SUBSTITUTE_TEMPLATE_NAME, "1.0.0", null));
56 serviceTemplate.setImports(GlobalTypesUtil.createCommonImportList());
57 serviceTemplate.setDescription("Abstract Substitute Global Types");
58 serviceTemplate.setData_types(createGlobalDataTypes());
59 serviceTemplate.setNode_types(createGlobalNodeTypes());
60 return serviceTemplate;
63 private static Map<String, NodeType> createGlobalNodeTypes() {
64 Map<String, NodeType> globalNodeTypes = new HashMap<>();
65 globalNodeTypes.put(ToscaNodeType.ABSTRACT_SUBSTITUTE.getDisplayName(),
66 createAbstractSubstituteNodeType());
67 return globalNodeTypes;
70 private static NodeType createAbstractSubstituteNodeType() {
71 NodeType nodeType = new NodeType();
72 nodeType.setDerived_from(ToscaNodeType.ROOT.getDisplayName());
73 nodeType.setProperties(createAbstractSubstituteProperties());
77 private static Map<String, PropertyDefinition> createAbstractSubstituteProperties() {
78 Map<String, PropertyDefinition> props = new HashMap<>();
79 props.put(ToscaConstants.SERVICE_TEMPLATE_FILTER_PROPERTY_NAME, DataModelUtil
80 .createPropertyDefinition(ToscaDataType.SUBSTITUTION_FILTERING.getDisplayName(),
81 "Substitution Filter", true, null, null, null, null));
87 private static Map<String, DataType> createGlobalDataTypes() {
88 Map<String, DataType> globalDataTypes = new HashMap<>();
89 globalDataTypes.put(ToscaDataType.SUBSTITUTION_FILTER.getDisplayName(),
90 createSubstitutionFilterDataType());
91 globalDataTypes.put(ToscaDataType.SUBSTITUTION_FILTERING.getDisplayName(),
92 createSubstitutionFilteringDataType());
93 return globalDataTypes;
96 private static DataType createSubstitutionFilterDataType() {
97 DataType dataType = new DataType();
98 dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
99 dataType.setDescription("Substitution Filter");
100 Map<String, PropertyDefinition> properties = new HashMap<>();
101 properties.put(ToscaConstants.COUNT_PROPERTY_NAME, DataModelUtil
102 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Count", false, null, null,
104 properties.put(ToscaConstants.SCALING_ENABLED_PROPERTY_NAME, DataModelUtil
105 .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
106 "Indicates whether service scaling is enabled", false, null, null, null, true));
107 properties.put(ToscaConstants.SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME, DataModelUtil
108 .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
109 "Substitute Service Template", true, null, null, null, null));
110 properties.put("mandatory", DataModelUtil
111 .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(), "Mandatory", false, null,
113 properties.put("index_variable", DataModelUtil
114 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Index variable", false,
115 createMinLengthConstraint(), null, null, "%index%"));
117 dataType.setProperties(properties);
121 private static List<Constraint> createMinLengthConstraint() {
122 List<Constraint> constraints;
123 constraints = new ArrayList<>();
124 Constraint constraint = new Constraint();
125 constraint.setMin_length(3);
126 constraints.add(constraint);
130 private static DataType createSubstitutionFilteringDataType() {
131 DataType dataType = new DataType();
132 dataType.setDerived_from(ToscaDataType.ROOT.getDisplayName());
133 dataType.setDescription("Substitution Filter");
134 Map<String, PropertyDefinition> properties = new HashMap<>();
135 properties.put(ToscaConstants.COUNT_PROPERTY_NAME, DataModelUtil
136 .createPropertyDefinition(PropertyType.STRING.getDisplayName(), "Count", false, null, null,
138 properties.put(ToscaConstants.INDEX_VALUE_PROPERTY_NAME, DataModelUtil
139 .createPropertyDefinition(PropertyType.INTEGER.getDisplayName(),
140 "Index value of the substitution service template runtime instance", false,
141 createIndexValueConstraint(), null, null, 0));
142 properties.put(ToscaConstants.SCALING_ENABLED_PROPERTY_NAME, DataModelUtil
143 .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(),
144 "Indicates whether service scaling is enabled", false, null, null, null, true));
145 properties.put(ToscaConstants.SUBSTITUTE_SERVICE_TEMPLATE_PROPERTY_NAME, DataModelUtil
146 .createPropertyDefinition(PropertyType.STRING.getDisplayName(),
147 "Substitute Service Template", true, null, null, null, null));
148 properties.put("mandatory", DataModelUtil
149 .createPropertyDefinition(PropertyType.BOOLEAN.getDisplayName(), "Mandatory", false, null,
153 dataType.setProperties(properties);
157 private static List<Constraint> createIndexValueConstraint() {
158 List<Constraint> constraints;
159 constraints = new ArrayList<>();
160 Constraint constraint = new Constraint();
161 constraint.setGreater_or_equal(0);
162 constraints.add(constraint);