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.onap.sdc.tosca.datatypes.model;
23 import java.util.HashMap;
24 import java.util.List;
26 import java.util.Optional;
27 import lombok.EqualsAndHashCode;
30 import org.apache.commons.collections4.MapUtils;
31 import org.onap.sdc.tosca.error.ToscaRuntimeException;
32 import org.onap.sdc.tosca.services.YamlUtil;
38 public class NodeTemplate implements Template, Cloneable {
41 private String description;
42 private Map<String, String> metadata;
43 private List<String> directives;
44 private Map<String, Object> properties;
45 private Map<String, Object> attributes;
46 private List<Map<String, RequirementAssignment>> requirements;
47 private Map<String, CapabilityAssignment> capabilities;
48 private Map<String, Object> interfaces;
49 private Map<String, ArtifactDefinition> artifacts;
50 private NodeFilter node_filter;
54 public Map<String, InterfaceDefinitionTemplate> getNormalizeInterfaces() {
55 if (MapUtils.isEmpty(interfaces)) {
56 return new HashMap<>();
58 Map<String, InterfaceDefinitionTemplate> normativeInterfaceDefinition = new HashMap<>();
59 for (Map.Entry<String, Object> interfaceEntry : interfaces.entrySet()) {
60 InterfaceDefinitionTemplate interfaceDefinitionTemplate =
61 new InterfaceDefinitionTemplate(interfaceEntry.getValue());
62 normativeInterfaceDefinition.put(interfaceEntry.getKey(), interfaceDefinitionTemplate);
64 return normativeInterfaceDefinition;
67 public void addInterface(String interfaceKey, InterfaceDefinitionTemplate interfaceDefinitionTemplate) {
68 if (MapUtils.isEmpty(this.interfaces)) {
69 this.interfaces = new HashMap<>();
72 Optional<Object> toscaInterfaceObj = interfaceDefinitionTemplate.convertInterfaceDefTemplateToToscaObj();
73 if (!toscaInterfaceObj.isPresent()) {
74 throw new ToscaRuntimeException("Illegal Statement");
76 if (this.interfaces.containsKey(interfaceKey)) {
77 this.interfaces.remove(interfaceKey);
79 this.interfaces.put(interfaceKey, toscaInterfaceObj.get());
85 public NodeTemplate clone() {
86 YamlUtil yamlUtil = new YamlUtil();
87 return yamlUtil.yamlToObject(yamlUtil.objectToYaml(this), NodeTemplate.class);