2 * Copyright © 2016-2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation;
19 import java.util.ArrayList;
20 import java.util.Collection;
21 import java.util.HashMap;
22 import java.util.HashSet;
23 import java.util.List;
26 import java.util.stream.Collectors;
28 import org.apache.commons.collections4.MapUtils;
29 import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
30 import org.openecomp.sdc.translator.services.heattotosca.ConsolidationDataUtil;
33 * The type Entity consolidation data.
35 public class EntityConsolidationData {
37 private String nodeTemplateId;
39 //groups that point to this entity node template
40 private List<String> groupIds;
42 // key - node template id which has connection to this entity
43 // value - List of Requirement assignment data which connect to this entity
44 private Map<String, List<RequirementAssignmentData>> nodesConnectedIn;
46 // key - node template id which connected from this entity
47 // List of Requirement assignment data which connect to the key node template id
48 private Map<String, List<RequirementAssignmentData>> nodesConnectedOut;
50 //key - node template id which include get attribute function from this entity
51 //value - List of getAttr data
52 private Map<String, List<GetAttrFuncData>> nodesGetAttrIn;
54 //key - node template id which is pointed by this entity using get attribute function
55 //value - List of getAttr data
56 private Map<String, List<GetAttrFuncData>> nodesGetAttrOut;
58 //List of getAttr data
59 private List<GetAttrFuncData> outputParametersGetAttrIn;
61 public String getNodeTemplateId() {
62 return nodeTemplateId;
65 public void setNodeTemplateId(String nodeTemplateId) {
66 this.nodeTemplateId = nodeTemplateId;
70 * Gets group ids point to me.
72 * @return the group ids point to me
74 public List<String> getGroupIds() {
79 * Sets group ids point to me.
81 * @param groupIds the group ids point to me
83 public void setGroupIds(List<String> groupIds) {
84 this.groupIds = groupIds;
89 * Sets node connected to me.
91 * @param nodesConnectedIn the node connected to me
93 public void setNodesConnectedIn(Map<String, List<RequirementAssignmentData>> nodesConnectedIn) {
94 this.nodesConnectedIn = nodesConnectedIn;
98 * Add nodeConnectedIn.
100 * @param nodeTemplateId the node template id which has connection to me
101 * @param requirementId the requirement id
102 * @param requirementAssignment the requirement assignment
104 public void addNodesConnectedIn(String nodeTemplateId, String requirementId,
105 RequirementAssignment requirementAssignment) {
107 if (this.nodesConnectedIn == null) {
108 this.nodesConnectedIn = new HashMap<>();
111 this.nodesConnectedIn.computeIfAbsent(nodeTemplateId, k -> new ArrayList<>());
112 this.nodesConnectedIn.get(nodeTemplateId).add(
113 new RequirementAssignmentData(requirementId, requirementAssignment));
117 * Gets node connected to me.
119 * @return the node connected to me
121 public Map<String, List<RequirementAssignmentData>> getNodesConnectedIn() {
122 return nodesConnectedIn;
127 * Gets node connected from me.
129 * @return the node connected from me
131 public Map<String, List<RequirementAssignmentData>> getNodesConnectedOut() {
132 return nodesConnectedOut;
136 * Sets node connected from me.
138 * @param nodesConnectedOut the node connected from me
140 public void setNodesConnectedOut(Map<String, List<RequirementAssignmentData>> nodesConnectedOut) {
141 this.nodesConnectedOut = nodesConnectedOut;
145 * Add nodeConnectedOut.
147 * @param nodeTemplateId the node template id which is connected from me
148 * @param requirementId the requirement id
149 * @param requirementAssignment the requirement assignment
151 public void addNodesConnectedOut(String nodeTemplateId, String requirementId,
152 RequirementAssignment requirementAssignment) {
154 if (this.nodesConnectedOut == null) {
155 this.nodesConnectedOut = new HashMap<>();
158 this.nodesConnectedOut.computeIfAbsent(nodeTemplateId, k -> new ArrayList<>());
159 this.nodesConnectedOut.get(nodeTemplateId).add(
160 new RequirementAssignmentData(requirementId, requirementAssignment));
164 * Gets nodes get attr in.
166 * @return the get attr in
168 public Map<String, List<GetAttrFuncData>> getNodesGetAttrIn() {
169 return nodesGetAttrIn;
173 * Sets nodes get attr in.
175 * @param nodesGetAttrIn the get attr in
177 public void setNodesGetAttrIn(Map<String, List<GetAttrFuncData>> nodesGetAttrIn) {
178 this.nodesGetAttrIn = nodesGetAttrIn;
182 * Add nodes get attr in data.
184 * @param nodeTemplateId the node template id
185 * @param getAttrFuncData get attr data
187 public void addNodesGetAttrIn(String nodeTemplateId, GetAttrFuncData getAttrFuncData) {
189 if (nodesGetAttrIn == null) {
190 nodesGetAttrIn = new HashMap<>();
193 this.nodesGetAttrIn.putIfAbsent(nodeTemplateId, new ArrayList<>());
194 this.nodesGetAttrIn.get(nodeTemplateId).add(getAttrFuncData);
198 * Gets output parameters get attr from me.
200 * @return the get attr from me
202 public List<GetAttrFuncData> getOutputParametersGetAttrIn() {
203 return outputParametersGetAttrIn;
207 * Sets output parameters get attr from me.
209 * @param outputParametersGetAttrIn the output parameters get attr from me
211 public void setOutputParametersGetAttrIn(List<GetAttrFuncData> outputParametersGetAttrIn) {
212 this.outputParametersGetAttrIn = outputParametersGetAttrIn;
216 * Add output parameters get attr data.
218 * @param getAttrFuncData get attr data
220 public void addOutputParamGetAttrIn(GetAttrFuncData getAttrFuncData) {
222 if (outputParametersGetAttrIn == null) {
223 outputParametersGetAttrIn = new ArrayList<>();
226 this.outputParametersGetAttrIn.add(getAttrFuncData);
230 * Gets nodes get attr out.
232 * @return the get attr out
234 public Map<String, List<GetAttrFuncData>> getNodesGetAttrOut() {
235 return nodesGetAttrOut;
239 * Sets nodes get attr out.
241 * @param nodesGetAttrOut the get attr out
243 public void setNodesGetAttrOut(Map<String, List<GetAttrFuncData>> nodesGetAttrOut) {
244 this.nodesGetAttrOut = nodesGetAttrOut;
248 * Add nodes get attr out data.
250 * @param nodeTemplateId the node template id
251 * @param getAttrFuncData get attr data
253 public void addNodesGetAttrOut(String nodeTemplateId, GetAttrFuncData getAttrFuncData) {
255 if (nodesGetAttrOut == null) {
256 nodesGetAttrOut = new HashMap<>();
259 this.nodesGetAttrOut.putIfAbsent(nodeTemplateId, new ArrayList<>());
260 this.nodesGetAttrOut.get(nodeTemplateId).add(getAttrFuncData);
263 public void removeParamNameFromAttrFuncList(String paramName) {
265 if (outputParametersGetAttrIn == null) {
269 outputParametersGetAttrIn.removeIf(outputParameters -> paramName.equals(outputParameters.getFieldName()));
273 * Per port type compare get attr of entity with given consolidation data list.
275 * @param entityConsolidationDataList consolidation data list
276 * @param portTypeToIds the port type to ids
277 * @return true in case get attr list same for all port types.
278 * otherwise return false
280 public boolean isGetAttrOutFromEntityLegal(
281 Collection<? extends EntityConsolidationData> entityConsolidationDataList,
282 Map<String, List<String>> portTypeToIds) {
284 for (String portType : portTypeToIds.keySet()) {
285 Set<GetAttrFuncData> startingGetAttrFunc =
286 getEntityGetAttrFuncAsSet(portType);
288 for (EntityConsolidationData entity : entityConsolidationDataList) {
289 Set<GetAttrFuncData> currentGetAttrFuncData =
290 entity.getEntityGetAttrFuncAsSet(portType);
291 if (!(startingGetAttrFunc.equals(currentGetAttrFuncData))) {
300 private Set<GetAttrFuncData> getEntityGetAttrFuncAsSet(String portType) {
301 if (MapUtils.isEmpty(nodesGetAttrOut)) {
302 return new HashSet<>();
305 return nodesGetAttrOut.entrySet().stream()
306 .filter(entry -> portType.equals(ConsolidationDataUtil.getPortType(entry.getKey())))
307 .flatMap(entry -> entry.getValue().stream())
308 .collect(Collectors.toSet());