2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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=========================================================
20 package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.composition;
22 import java.util.Collection;
23 import java.util.HashMap;
24 import java.util.HashSet;
26 import java.util.Objects;
27 import java.util.Optional;
30 import org.apache.commons.collections4.MapUtils;
31 import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
33 public class UnifiedSubstitutionData {
35 //Key - node template id, Value - related abstract node template id
36 private Map<String, String> nodesRelatedAbstractNode = new HashMap<>();
37 //Key - node template id, Value - related node template id in the substitution service template
38 private Map<String, String> nodesRelatedSubstitutionServiceTemplateNode = new HashMap<>();
39 private Map<String, NodeTemplateInformation> cleanedNodeTemplates = new HashMap<>();
40 //Key - nested node template id, Value - related unified nested node template id
41 private Map<String, String> nestedNodeTemplateRelatedUnifiedTranslatedId = new HashMap<>();
42 //Key - nested node type id, Value - related unified nested node template id
43 private Map<String, String> nestedNodeTypeRelatedUnifiedTranslatedId = new HashMap<>();
44 //Key - handled compute type, Value - number of times it was handled
45 private Map<String, Integer> handledComputeTypesInNestedSubstitutionTemplate =
47 //Key - nested compute type, Value - list of nested files that the compute type is present
48 private Map<String, Integer> handledNestedComputeTypesNestedFiles = new HashMap<>();
49 //Key - new property id, Value - orig property value
50 private Map<String, Object> newParameterIdsToPropertiesFromOrigNodeTemplate = new HashMap<>();
51 //handled nested files
52 private Set<String> handledNestedFiles = new HashSet<>();
53 //handled nested nodes
54 private Set<String> handledNestedNodes = new HashSet<>();
56 public Map<String, String> getNodesRelatedAbstractNode() {
57 return nodesRelatedAbstractNode;
60 public void setNodesRelatedAbstractNode(
61 Map<String, String> nodesRelatedAbstractNode) {
62 this.nodesRelatedAbstractNode = nodesRelatedAbstractNode;
65 public void addHandledNestedNodes(String handledNestedNodeId) {
66 this.handledNestedNodes.add(handledNestedNodeId);
69 public Map<String, String> getNodesRelatedSubstitutionServiceTemplateNode() {
70 return nodesRelatedSubstitutionServiceTemplateNode;
73 public void setNodesRelatedSubstitutionServiceTemplateNode(
74 Map<String, String> nodesRelatedSubstitutionServiceTemplateNode) {
75 this.nodesRelatedSubstitutionServiceTemplateNode = nodesRelatedSubstitutionServiceTemplateNode;
78 public String getNodeRelatedAbstractNode(String origNodeId) {
79 return this.nodesRelatedAbstractNode.get(origNodeId);
82 public Collection<String> getAllRelatedAbstractNodeIds() {
83 return this.nodesRelatedAbstractNode.values();
86 public Collection<String> getAllUnifiedNestedNodeTemplateIds() {
87 return this.nestedNodeTemplateRelatedUnifiedTranslatedId.values();
91 * Add cleaned node template.
93 * @param nodeTemplateId the node template id
94 * @param unifiedCompositionEntity the unified composition entity
95 * @param nodeTemplate the node template
97 public void addCleanedNodeTemplate(String nodeTemplateId,
98 UnifiedCompositionEntity unifiedCompositionEntity,
99 NodeTemplate nodeTemplate) {
100 NodeTemplateInformation nodeTemplateInformation = new NodeTemplateInformation(
101 unifiedCompositionEntity, nodeTemplate);
102 this.cleanedNodeTemplates.putIfAbsent(nodeTemplateId, nodeTemplateInformation);
105 public NodeTemplate getCleanedNodeTemplate(String nodeTemplateId) {
106 return this.cleanedNodeTemplates.get(nodeTemplateId).getNodeTemplate().clone();
109 public UnifiedCompositionEntity getCleanedNodeTemplateCompositionEntity(String nodeTemplateId) {
110 return this.cleanedNodeTemplates.get(nodeTemplateId).getUnifiedCompositionEntity();
113 public void addUnifiedNestedNodeTemplateId(String nestedNodeTemplateId,
114 String unifiedNestedNodeRelatedId) {
115 this.nestedNodeTemplateRelatedUnifiedTranslatedId
116 .put(nestedNodeTemplateId, unifiedNestedNodeRelatedId);
119 public Optional<String> getUnifiedNestedNodeTemplateId(String nestedNodeTemplateId) {
120 return this.nestedNodeTemplateRelatedUnifiedTranslatedId.get(nestedNodeTemplateId) == null
122 : Optional.of(this.nestedNodeTemplateRelatedUnifiedTranslatedId.get(nestedNodeTemplateId));
125 public void addUnifiedNestedNodeTypeId(String nestedNodeTypeId,
126 String unifiedNestedNodeRelatedId) {
127 this.nestedNodeTypeRelatedUnifiedTranslatedId.put(nestedNodeTypeId, unifiedNestedNodeRelatedId);
130 public Optional<String> getUnifiedNestedNodeTypeId(String nestedNodeTypeId) {
131 return this.nestedNodeTypeRelatedUnifiedTranslatedId.get(nestedNodeTypeId) == null ? Optional
133 : Optional.of(this.nestedNodeTypeRelatedUnifiedTranslatedId.get(nestedNodeTypeId));
136 public Set<String> getAllRelatedNestedNodeTypeIds(){
137 if(MapUtils.isEmpty(nestedNodeTypeRelatedUnifiedTranslatedId)){
138 return new HashSet<>();
140 return new HashSet<>(this.nestedNodeTypeRelatedUnifiedTranslatedId.values());
143 public void addHandledComputeType(String handledComputeType) {
145 if (this.handledComputeTypesInNestedSubstitutionTemplate.containsKey(handledComputeType)) {
146 Integer timesHandled =
147 this.handledComputeTypesInNestedSubstitutionTemplate.get(handledComputeType);
148 this.handledComputeTypesInNestedSubstitutionTemplate
149 .put(handledComputeType, timesHandled + 1);
151 //this.handledNestedFiles.add(nestedServiceTemplateFileName);
152 handledComputeTypesInNestedSubstitutionTemplate.put(handledComputeType, 0);
156 public boolean isComputeTypeHandledInServiceTemplate(String computeType) {
157 return this.handledComputeTypesInNestedSubstitutionTemplate.containsKey(computeType);
160 public int getHandledNestedComputeNodeTemplateIndex(String computeType) {
161 return this.handledComputeTypesInNestedSubstitutionTemplate.containsKey(computeType) ?
162 this.handledComputeTypesInNestedSubstitutionTemplate.get(computeType) : 0;
165 public void addHandlesNestedServiceTemplate(String nestedServiceTemplateFileName){
166 this.handledNestedFiles.add(nestedServiceTemplateFileName);
169 public boolean isNestedServiceTemplateWasHandled(String nestedServiceTemplateFileName) {
170 return this.handledNestedFiles.contains(nestedServiceTemplateFileName);
173 public void updateUsedTimesForNestedComputeNodeType(String computeType) {
174 this.handledNestedComputeTypesNestedFiles.putIfAbsent(computeType, 0);
176 Integer usedNumber = this.handledNestedComputeTypesNestedFiles.get(computeType);
177 this.handledNestedComputeTypesNestedFiles.put(computeType, usedNumber + 1);
181 public int getGlobalNodeTypeIndex(String computeType) {
182 return Objects.isNull(this.handledNestedComputeTypesNestedFiles.get(computeType))
183 || this.handledNestedComputeTypesNestedFiles.get(computeType)== 0 ? 0
184 : this.handledNestedComputeTypesNestedFiles.get(computeType);
187 public boolean isNestedNodeWasHandled(String nestedNodeId) {
188 return this.handledNestedNodes.contains(nestedNodeId);
192 public Map<String, Object> getAllNewPropertyInputParamIds(){
193 return this.newParameterIdsToPropertiesFromOrigNodeTemplate;
196 public void addNewPropertyIdToNodeTemplate(String newPropertyId,
197 Object origPropertyValue){
198 if(!newParameterIdsToPropertiesFromOrigNodeTemplate.containsKey(newPropertyId)) {
199 newParameterIdsToPropertiesFromOrigNodeTemplate.put(newPropertyId, origPropertyValue);
203 public Optional<Object> getNewPropertyInputParam(String newPropertyId){
204 if(!newParameterIdsToPropertiesFromOrigNodeTemplate.containsKey(newPropertyId)){
205 return Optional.empty();
208 return Optional.of(newParameterIdsToPropertiesFromOrigNodeTemplate.get(newPropertyId));