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.be.datatypes.elements;
23 import com.google.common.collect.Lists;
24 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
25 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
27 import java.util.ArrayList;
28 import java.util.List;
30 * Represents the requirement of the component or component instance
32 public class RequirementDataDefinition extends ToscaDataDefinition {
34 public static final String MIN_OCCURRENCES = "1";
35 public static final String MAX_OCCURRENCES = "UNBOUNDED";
36 public static final String MAX_DEFAULT_OCCURRENCES = "1";
39 * The default constructor initializing limits of the occurrences
41 public RequirementDataDefinition() {
42 this.setMinOccurrences( MIN_OCCURRENCES );
43 this.setMaxOccurrences( MAX_OCCURRENCES);
44 this.setLeftOccurrences( MAX_OCCURRENCES);
47 * Deep copy constructor
50 public RequirementDataDefinition(RequirementDataDefinition other) {
51 this.setUniqueId(other.getUniqueId());
52 this.setName(other.getName());
53 this.setParentName(other.getParentName());
54 this.setPreviousName(other.getPreviousName());
55 this.setCapability(other.getCapability());
56 this.setNode(other.getNode());
57 this.setRelationship(other.getRelationship());
58 this.setOwnerId(other.getOwnerId());
59 this.setOwnerName(other.getOwnerName());
60 this.setMinOccurrences(other.getMinOccurrences());
61 this.setMaxOccurrences(other.getMaxOccurrences());
62 this.setLeftOccurrences(other.getLeftOccurrences());
63 if(other.getPath() == null)
64 this.setPath(Lists.newArrayList());
66 this.setPath(Lists.newArrayList(other.getPath()));
67 this.setSource(other.getSource());
71 * Unique id of the requirement
73 public String getUniqueId() {
74 return (String) getToscaPresentationValue(JsonPresentationFields.UNIQUE_ID);
77 public void setUniqueId(String uniqueId) {
78 setToscaPresentationValue(JsonPresentationFields.UNIQUE_ID, uniqueId);
81 public String getName() {
82 return (String) getToscaPresentationValue(JsonPresentationFields.NAME);
85 public void setName(String name) {
86 setToscaPresentationValue(JsonPresentationFields.NAME, name);
89 public String getParentName() {
90 return (String) getToscaPresentationValue(JsonPresentationFields.PARENT_NAME);
93 public void setParentName(String parentName) {
94 setToscaPresentationValue(JsonPresentationFields.PARENT_NAME, parentName);
97 public String getPreviousName() {
98 return (String) getToscaPresentationValue(JsonPresentationFields.PREVIOUS_NAME);
101 public void setPreviousName(String previousName) {
102 setToscaPresentationValue(JsonPresentationFields.PREVIOUS_NAME, previousName);
106 * specify the capability type
109 public String getCapability() {
110 return (String) getToscaPresentationValue(JsonPresentationFields.CAPAPILITY);
113 public void setCapability(String capability) {
114 setToscaPresentationValue(JsonPresentationFields.CAPAPILITY, capability);
118 * specify the node type(Optional by tosca)
120 public String getNode() {
121 return (String) getToscaPresentationValue(JsonPresentationFields.NODE);
124 public void setNode(String node) {
125 setToscaPresentationValue(JsonPresentationFields.NODE, node);
129 * specify the relationship type(Optional by tosca)
131 public String getRelationship() {
132 return (String) getToscaPresentationValue(JsonPresentationFields.RELATIONSHIP);
135 public void setRelationship(String relationship) {
136 setToscaPresentationValue(JsonPresentationFields.RELATIONSHIP, relationship);
140 * specifies the resource instance holding this requirement
143 public String getOwnerId() {
144 return (String) getToscaPresentationValue(JsonPresentationFields.OWNER_ID);
148 public void setOwnerId(String ownerId) {
149 setToscaPresentationValue(JsonPresentationFields.OWNER_ID, ownerId);
152 public String getOwnerName() {
153 return (String) getToscaPresentationValue(JsonPresentationFields.OWNER_NAME);
156 public void setOwnerName(String ownerName) {
157 setToscaPresentationValue(JsonPresentationFields.OWNER_NAME, ownerName);
160 public String getMinOccurrences() {
161 return (String) getToscaPresentationValue(JsonPresentationFields.MIN_OCCURRENCES);
164 public void setMinOccurrences(String minOccurrences) {
165 setToscaPresentationValue(JsonPresentationFields.MIN_OCCURRENCES, minOccurrences);
168 public String getLeftOccurrences() {
169 return (String) getToscaPresentationValue(JsonPresentationFields.LEFT_OCCURRENCES);
172 public void setLeftOccurrences(String leftOccurrences) {
173 setToscaPresentationValue(JsonPresentationFields.LEFT_OCCURRENCES, leftOccurrences);
176 public String getMaxOccurrences() {
177 return (String) getToscaPresentationValue(JsonPresentationFields.MAX_OCCURRENCES);
180 public void setMaxOccurrences(String maxOccurrences) {
181 setToscaPresentationValue(JsonPresentationFields.MAX_OCCURRENCES, maxOccurrences);
184 public void setPath(List<String> path) {
185 setToscaPresentationValue(JsonPresentationFields.PATH, path);
188 @SuppressWarnings({ "unchecked" })
189 public List<String> getPath() {
190 return (List<String>) getToscaPresentationValue(JsonPresentationFields.PATH);
193 public void setSource(String source) {
194 setToscaPresentationValue(JsonPresentationFields.SOURCE, source);
197 public String getSource() {
198 return (String) getToscaPresentationValue(JsonPresentationFields.SOURCE);
202 * Adds the element to the path avoiding duplication
203 * @param elementInPath
205 public void addToPath(String elementInPath) {
206 List<String> path = getPath();
208 path = new ArrayList<>();
210 if(!path.contains(elementInPath)){
211 path.add(elementInPath);
217 public int hashCode() {
218 final int prime = 31;
220 String name = getName();
221 String uniqueId = getUniqueId();
222 String capability = getCapability();
223 String node = getNode();
224 String relationship = getRelationship();
225 String ownerId = getOwnerId();
226 String ownerName = getOwnerName();
227 String minOccurrences = getMinOccurrences();
228 String maxOccurrences = getMaxOccurrences();
229 String leftOccurrences = getLeftOccurrences();
231 List<String> path = this.getPath();
232 String source = getSource();
234 result = prime * result + ((capability == null) ? 0 : capability.hashCode());
235 result = prime * result + ((name == null) ? 0 : name.hashCode());
236 result = prime * result + ((node == null) ? 0 : node.hashCode());
237 result = prime * result + ((ownerId == null) ? 0 : ownerId.hashCode());
238 result = prime * result + ((ownerName == null) ? 0 : ownerName.hashCode());
239 result = prime * result + ((relationship == null) ? 0 : relationship.hashCode());
240 result = prime * result + ((uniqueId == null) ? 0 : uniqueId.hashCode());
241 result = prime * result + ((minOccurrences == null) ? 0 : minOccurrences.hashCode());
242 result = prime * result + ((maxOccurrences == null) ? 0 : maxOccurrences.hashCode());
243 result = prime * result + ((leftOccurrences == null) ? 0 : leftOccurrences.hashCode());
244 result = prime * result + ((path == null) ? 0 : path.hashCode());
245 result = prime * result + ((source == null) ? 0 : source.hashCode());
250 public boolean equals(Object obj) {
255 if (getClass() != obj.getClass())
257 RequirementDataDefinition other = (RequirementDataDefinition) obj;
259 String name = getName();
260 String uniqueId = getUniqueId();
261 String capability = getCapability();
262 String node = getNode();
263 String relationship = getRelationship();
264 String ownerId = getOwnerId();
265 String ownerName = getOwnerName();
266 String minOccurrences = getMinOccurrences();
267 String maxOccurrences = getMaxOccurrences();
268 String leftOccurrences = getLeftOccurrences();
269 List<String> path = this.getPath();
270 String source = getSource();
272 if (capability == null) {
273 if (other.getCapability() != null)
275 } else if (!capability.equals(other.getCapability()))
278 if (other.getName() != null)
280 } else if (!name.equals(other.getName()))
283 if (other.getNode() != null)
285 } else if (!node.equals(other.getNode()))
287 if (ownerId == null) {
288 if (other.getOwnerId() != null)
290 } else if (!ownerId.equals(other.getOwnerId()))
292 if (ownerName == null) {
293 if (other.getOwnerName() != null)
295 } else if (!ownerName.equals(other.getOwnerName()))
297 if (relationship == null) {
298 if (other.getRelationship() != null)
300 } else if (!relationship.equals(other.getRelationship()))
302 if (uniqueId == null) {
303 if (other.getUniqueId() != null)
305 } else if (!uniqueId.equals(other.getUniqueId()))
307 if (minOccurrences == null) {
308 if (other.getMinOccurrences() != null)
310 } else if (!minOccurrences.equals(other.getMinOccurrences()))
312 if (maxOccurrences == null) {
313 if (other.getMaxOccurrences() != null)
315 } else if (!maxOccurrences.equals(other.getMaxOccurrences()))
317 if (leftOccurrences == null) {
318 if (other.getLeftOccurrences() != null)
320 } else if (!leftOccurrences.equals(other.getLeftOccurrences()))
323 if (other.getPath() != null)
325 } else if (!path.equals(other.getPath()))
327 if (source == null) {
328 if (other.getSource() != null)
330 } else if (!source.equals(other.getSource()))
336 public String toString() {
337 String name = getName();
338 String uniqueId = getUniqueId();
339 String capability = getCapability();
340 String node = getNode();
341 String relationship = getRelationship();
342 String ownerId = getOwnerId();
343 String ownerName = getOwnerName();
344 String minOccurrences = getMinOccurrences();
345 String maxOccurrences = getMaxOccurrences();
346 String leftOccurrences = getLeftOccurrences();
347 List<String> path = this.getPath();
348 String source = getSource();
350 return "RequirementDefinition [uniqueId=" + uniqueId + ", name=" + name + ", capability=" + capability + ", node=" + node + ", relationship=" + relationship + ", ownerId=" + ownerId + ", ownerName=" + ownerName + ", minOccurrences="
351 + minOccurrences + ", maxOccurrences=" + maxOccurrences + ",leftOccurrences=" + leftOccurrences + ", path=" + path + ", source=" + source + "]";