TOSCA Consolidation Data handling - Refactoring
[sdc.git] / openecomp-be / lib / openecomp-sdc-translator-lib / openecomp-sdc-translator-core / src / main / java / org / openecomp / sdc / translator / datatypes / heattotosca / unifiedmodel / consolidation / EntityConsolidationData.java
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation;
18
19 import java.util.ArrayList;
20 import java.util.HashMap;
21 import java.util.List;
22 import java.util.Map;
23 import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
24
25 /**
26  * The type Entity consolidation data.
27  */
28 public class EntityConsolidationData {
29
30     private String nodeTemplateId;
31
32     //groups that point to this entity node template
33     private List<String> groupIds;
34
35     // key - node template id which has connection to this entity
36     // value - List of Requirement assignment data which connect to this entity
37     private Map<String, List<RequirementAssignmentData>> nodesConnectedIn;
38
39     // key - node template id which connected from this entity
40     // List of Requirement assignment data which connect to the key node template id
41     private Map<String, List<RequirementAssignmentData>> nodesConnectedOut;
42
43     //key - node template id which include get attribute function from this entity
44     //key - node template id which include get attribute function from this entity
45     //value - List of getAttr data
46     private Map<String, List<GetAttrFuncData>> nodesGetAttrIn;
47
48     //key - node template id which is pointed by this entity using get attribute function
49     //value - List of getAttr data
50     private Map<String, List<GetAttrFuncData>> nodesGetAttrOut;
51
52     //List of getAttr data
53     private List<GetAttrFuncData> outputParametersGetAttrIn;
54
55     /**
56     * Gets node template id.
57     *
58     * @return the node template id
59     */
60     public String getNodeTemplateId() {
61         return nodeTemplateId;
62     }
63
64     /**
65     * Sets node template id.
66     *
67     * @param nodeTemplateId the node template id
68     */
69     public void setNodeTemplateId(String nodeTemplateId) {
70         this.nodeTemplateId = nodeTemplateId;
71     }
72
73     /**
74     * Gets group ids point to me.
75     *
76     * @return the group ids point to me
77     */
78     public List<String> getGroupIds() {
79         return groupIds;
80     }
81
82     /**
83     * Sets group ids point to me.
84     *
85     * @param groupIds the group ids point to me
86     */
87     public void setGroupIds(List<String> groupIds) {
88         this.groupIds = groupIds;
89     }
90
91
92     /**
93     * Sets node connected to me.
94     *
95     * @param nodesConnectedIn the node connected to me
96     */
97     public void setNodesConnectedIn(Map<String, List<RequirementAssignmentData>> nodesConnectedIn) {
98         this.nodesConnectedIn = nodesConnectedIn;
99     }
100
101     /**
102     * Add nodeConnectedIn.
103     *
104     * @param nodeTemplateId        the node template id which has connection to me
105     * @param requirementId         the requirement id
106     * @param requirementAssignment the requirement assignment
107     */
108     public void addNodesConnectedIn(String nodeTemplateId, String requirementId,
109                                   RequirementAssignment requirementAssignment) {
110
111         if (this.nodesConnectedIn == null) {
112             this.nodesConnectedIn = new HashMap<>();
113         }
114
115         this.nodesConnectedIn.computeIfAbsent(nodeTemplateId, k -> new ArrayList<>());
116         this.nodesConnectedIn.get(nodeTemplateId).add(
117                 new RequirementAssignmentData(requirementId, requirementAssignment));
118     }
119
120     /**
121     * Gets node connected to me.
122     *
123     * @return the node connected to me
124     */
125     public Map<String, List<RequirementAssignmentData>> getNodesConnectedIn() {
126         return nodesConnectedIn;
127     }
128
129
130     /**
131     * Gets node connected from me.
132     *
133     * @return the node connected from me
134     */
135     public Map<String, List<RequirementAssignmentData>> getNodesConnectedOut() {
136         return nodesConnectedOut;
137     }
138
139     /**
140     * Sets node connected from me.
141     *
142     * @param nodesConnectedOut the node connected from me
143     */
144     public void setNodesConnectedOut(Map<String, List<RequirementAssignmentData>> nodesConnectedOut) {
145         this.nodesConnectedOut = nodesConnectedOut;
146     }
147
148     /**
149     * Add nodeConnectedOut.
150     *
151     * @param nodeTemplateId        the node template id which is connected from me
152     * @param requirementId         the requirement id
153     * @param requirementAssignment the requirement assignment
154     */
155     public void addNodesConnectedOut(String nodeTemplateId, String requirementId,
156                                    RequirementAssignment requirementAssignment) {
157
158         if (this.nodesConnectedOut == null) {
159             this.nodesConnectedOut = new HashMap<>();
160         }
161
162         this.nodesConnectedOut.computeIfAbsent(nodeTemplateId, k -> new ArrayList<>());
163         this.nodesConnectedOut.get(nodeTemplateId).add(
164                 new RequirementAssignmentData(requirementId, requirementAssignment));
165     }
166
167     /**
168     * Gets nodes get attr in.
169     *
170     * @return the get attr in
171     */
172     public Map<String, List<GetAttrFuncData>> getNodesGetAttrIn() {
173         return nodesGetAttrIn;
174     }
175
176     /**
177     * Sets nodes get attr in.
178     *
179     * @param nodesGetAttrIn the get attr in
180     */
181     public void setNodesGetAttrIn(Map<String, List<GetAttrFuncData>> nodesGetAttrIn) {
182         this.nodesGetAttrIn = nodesGetAttrIn;
183     }
184
185     /**
186     * Add nodes get attr in data.
187     *
188     * @param nodeTemplateId  the node template id
189     * @param getAttrFuncData get attr data
190     */
191     public void addNodesGetAttrIn(String nodeTemplateId, GetAttrFuncData getAttrFuncData) {
192
193         if (nodesGetAttrIn == null) {
194             nodesGetAttrIn = new HashMap<>();
195         }
196
197         this.nodesGetAttrIn.putIfAbsent(nodeTemplateId, new ArrayList<>());
198         this.nodesGetAttrIn.get(nodeTemplateId).add(getAttrFuncData);
199     }
200
201     /**
202     * Gets output parameters get attr from me.
203     *
204     * @return the get attr from me
205     */
206     public List<GetAttrFuncData> getOutputParametersGetAttrIn() {
207         return outputParametersGetAttrIn;
208     }
209
210     /**
211     * Sets output parameters get attr from me.
212     *
213     * @param outputParametersGetAttrIn the output parameters get attr from me
214     */
215     public void setOutputParametersGetAttrIn(List<GetAttrFuncData> outputParametersGetAttrIn) {
216         this.outputParametersGetAttrIn = outputParametersGetAttrIn;
217     }
218
219     /**
220     * Add output parameters get attr data.
221     *
222     * @param getAttrFuncData get attr data
223     */
224     public void addOutputParamGetAttrIn(GetAttrFuncData getAttrFuncData) {
225
226         if (outputParametersGetAttrIn == null) {
227             outputParametersGetAttrIn = new ArrayList<>();
228         }
229
230         this.outputParametersGetAttrIn.add(getAttrFuncData);
231     }
232
233     /**
234     * Gets nodes get attr out.
235     *
236     * @return the get attr out
237     */
238     public Map<String, List<GetAttrFuncData>> getNodesGetAttrOut() {
239         return nodesGetAttrOut;
240     }
241
242     /**
243     * Sets nodes get attr out.
244     *
245     * @param nodesGetAttrOut the get attr out
246     */
247     public void setNodesGetAttrOut(Map<String, List<GetAttrFuncData>> nodesGetAttrOut) {
248         this.nodesGetAttrOut = nodesGetAttrOut;
249     }
250
251     /**
252     * Add nodes get attr out data.
253     *
254     * @param nodeTemplateId  the node template id
255     * @param getAttrFuncData get attr data
256     */
257     public void addNodesGetAttrOut(String nodeTemplateId, GetAttrFuncData getAttrFuncData) {
258
259         if (nodesGetAttrOut == null) {
260             nodesGetAttrOut = new HashMap<>();
261         }
262
263         this.nodesGetAttrOut.putIfAbsent(nodeTemplateId, new ArrayList<>());
264         this.nodesGetAttrOut.get(nodeTemplateId).add(getAttrFuncData);
265     }
266
267     public void removeParamNameFromAttrFuncList(String paramName) {
268
269         if (outputParametersGetAttrIn == null) {
270             return;
271         }
272
273         outputParametersGetAttrIn.removeIf(outputParameters -> paramName.equals(outputParameters.getFieldName()));
274     }
275 }