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 java.io.Serializable;
24 import java.util.ArrayList;
25 import java.util.List;
27 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
28 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
30 import com.google.common.collect.Lists;
32 * Represents the requirement of the component or component instance
34 public class RequirementDataDefinition extends ToscaDataDefinition implements Serializable {
38 public static final String MIN_OCCURRENCES = "1";
39 public static final String MAX_OCCURRENCES = "UNBOUNDED";
40 public static final String MAX_DEFAULT_OCCURRENCES = "1";
42 private static final long serialVersionUID = -8840549489409274532L;
44 * The default constructor initializing limits of the occurrences
46 public RequirementDataDefinition() {
48 this.setMinOccurrences( MIN_OCCURRENCES );
49 this.setMaxOccurrences( MAX_OCCURRENCES);
50 this.setLeftOccurrences( MAX_OCCURRENCES);
53 * Deep copy constructor
56 public RequirementDataDefinition(RequirementDataDefinition other) {
57 this.setUniqueId(other.getUniqueId());
58 this.setName(other.getName());
59 this.setParentName(other.getParentName());
60 this.setCapability(other.getCapability());
61 this.setNode(other.getNode());
62 this.setRelationship(other.getRelationship());
63 this.setOwnerId(other.getOwnerId());
64 this.setOwnerName(other.getOwnerName());
65 this.setMinOccurrences(other.getMinOccurrences());
66 this.setMaxOccurrences(other.getMaxOccurrences());
67 this.setLeftOccurrences(other.getLeftOccurrences());
68 if(other.getPath() == null)
69 this.setPath(Lists.newArrayList());
71 this.setPath(Lists.newArrayList(other.getPath()));
72 this.setSource(other.getSource());
76 * Unique id of the requirement
78 public String getUniqueId() {
79 return (String) getToscaPresentationValue(JsonPresentationFields.UNIQUE_ID);
82 public void setUniqueId(String uniqueId) {
83 setToscaPresentationValue(JsonPresentationFields.UNIQUE_ID, uniqueId);
86 public String getName() {
87 return (String) getToscaPresentationValue(JsonPresentationFields.NAME);
90 public void setName(String name) {
91 setToscaPresentationValue(JsonPresentationFields.NAME, name);
94 public String getParentName() {
95 return (String) getToscaPresentationValue(JsonPresentationFields.PARENT_NAME);
98 public void setParentName(String parentName) {
99 setToscaPresentationValue(JsonPresentationFields.PARENT_NAME, parentName);
103 * specify the capability type
106 public String getCapability() {
107 return (String) getToscaPresentationValue(JsonPresentationFields.CAPAPILITY);
110 public void setCapability(String capability) {
111 setToscaPresentationValue(JsonPresentationFields.CAPAPILITY, capability);
115 * specify the node type(Optional by tosca)
117 public String getNode() {
118 return (String) getToscaPresentationValue(JsonPresentationFields.NODE);
121 public void setNode(String node) {
122 setToscaPresentationValue(JsonPresentationFields.NODE, node);
126 * specify the relationship type(Optional by tosca)
128 public String getRelationship() {
129 return (String) getToscaPresentationValue(JsonPresentationFields.RELATIONSHIP);
132 public void setRelationship(String relationship) {
133 setToscaPresentationValue(JsonPresentationFields.RELATIONSHIP, relationship);
137 * specifies the resource instance holding this requirement
140 public String getOwnerId() {
141 return (String) getToscaPresentationValue(JsonPresentationFields.OWNER_ID);
145 public void setOwnerId(String ownerId) {
146 setToscaPresentationValue(JsonPresentationFields.OWNER_ID, ownerId);
149 public String getOwnerName() {
150 return (String) getToscaPresentationValue(JsonPresentationFields.OWNER_NAME);
153 public void setOwnerName(String ownerName) {
154 setToscaPresentationValue(JsonPresentationFields.OWNER_NAME, ownerName);
157 public String getMinOccurrences() {
158 return (String) getToscaPresentationValue(JsonPresentationFields.MIN_OCCURRENCES);
161 public void setMinOccurrences(String minOccurrences) {
162 setToscaPresentationValue(JsonPresentationFields.MIN_OCCURRENCES, minOccurrences);
165 public String getLeftOccurrences() {
166 return (String) getToscaPresentationValue(JsonPresentationFields.LEFT_OCCURRENCES);
169 public void setLeftOccurrences(String leftOccurrences) {
170 setToscaPresentationValue(JsonPresentationFields.LEFT_OCCURRENCES, leftOccurrences);
173 public String getMaxOccurrences() {
174 return (String) getToscaPresentationValue(JsonPresentationFields.MAX_OCCURRENCES);
177 public void setMaxOccurrences(String maxOccurrences) {
178 setToscaPresentationValue(JsonPresentationFields.MAX_OCCURRENCES, maxOccurrences);
181 public void setPath(List<String> path) {
182 setToscaPresentationValue(JsonPresentationFields.PATH, path);
185 @SuppressWarnings({ "unchecked" })
186 public List<String> getPath() {
187 return (List<String>) getToscaPresentationValue(JsonPresentationFields.PATH);
190 public void setSource(String source) {
191 setToscaPresentationValue(JsonPresentationFields.SOURCE, source);
194 public String getSource() {
195 return (String) getToscaPresentationValue(JsonPresentationFields.SOURCE);
199 * Adds the element to the path avoiding duplication
200 * @param elementInPath
202 public void addToPath(String elementInPath) {
203 List<String> path = getPath();
205 path = new ArrayList<>();
207 if(!path.contains(elementInPath)){
208 path.add(elementInPath);
214 public int hashCode() {
215 final int prime = 31;
217 String name = getName();
218 String uniqueId = getUniqueId();
219 String capability = getCapability();
220 String node = getNode();
221 String relationship = getRelationship();
222 String ownerId = getOwnerId();
223 String ownerName = getOwnerName();
224 String minOccurrences = getMinOccurrences();
225 String maxOccurrences = getMaxOccurrences();
226 String leftOccurrences = getLeftOccurrences();
228 List<String> path = this.getPath();
229 String source = getSource();
231 result = prime * result + ((capability == null) ? 0 : capability.hashCode());
232 result = prime * result + ((name == null) ? 0 : name.hashCode());
233 result = prime * result + ((node == null) ? 0 : node.hashCode());
234 result = prime * result + ((ownerId == null) ? 0 : ownerId.hashCode());
235 result = prime * result + ((ownerName == null) ? 0 : ownerName.hashCode());
236 result = prime * result + ((relationship == null) ? 0 : relationship.hashCode());
237 result = prime * result + ((uniqueId == null) ? 0 : uniqueId.hashCode());
238 result = prime * result + ((minOccurrences == null) ? 0 : minOccurrences.hashCode());
239 result = prime * result + ((maxOccurrences == null) ? 0 : maxOccurrences.hashCode());
240 result = prime * result + ((leftOccurrences == null) ? 0 : leftOccurrences.hashCode());
241 result = prime * result + ((path == null) ? 0 : path.hashCode());
242 result = prime * result + ((source == null) ? 0 : source.hashCode());
247 public boolean equals(Object obj) {
252 if (getClass() != obj.getClass())
254 RequirementDataDefinition other = (RequirementDataDefinition) obj;
256 String name = getName();
257 String uniqueId = getUniqueId();
258 String capability = getCapability();
259 String node = getNode();
260 String relationship = getRelationship();
261 String ownerId = getOwnerId();
262 String ownerName = getOwnerName();
263 String minOccurrences = getMinOccurrences();
264 String maxOccurrences = getMaxOccurrences();
265 String leftOccurrences = getLeftOccurrences();
266 List<String> path = this.getPath();
267 String source = getSource();
269 if (capability == null) {
270 if (other.getCapability() != null)
272 } else if (!capability.equals(other.getCapability()))
275 if (other.getName() != null)
277 } else if (!name.equals(other.getName()))
280 if (other.getNode() != null)
282 } else if (!node.equals(other.getNode()))
284 if (ownerId == null) {
285 if (other.getOwnerId() != null)
287 } else if (!ownerId.equals(other.getOwnerId()))
289 if (ownerName == null) {
290 if (other.getOwnerName() != null)
292 } else if (!ownerName.equals(other.getOwnerName()))
294 if (relationship == null) {
295 if (other.getRelationship() != null)
297 } else if (!relationship.equals(other.getRelationship()))
299 if (uniqueId == null) {
300 if (other.getUniqueId() != null)
302 } else if (!uniqueId.equals(other.getUniqueId()))
304 if (minOccurrences == null) {
305 if (other.getMinOccurrences() != null)
307 } else if (!minOccurrences.equals(other.getMinOccurrences()))
309 if (maxOccurrences == null) {
310 if (other.getMaxOccurrences() != null)
312 } else if (!maxOccurrences.equals(other.getMaxOccurrences()))
314 if (leftOccurrences == null) {
315 if (other.getLeftOccurrences() != null)
317 } else if (!leftOccurrences.equals(other.getLeftOccurrences()))
320 if (other.getPath() != null)
322 } else if (!path.equals(other.getPath()))
324 if (source == null) {
325 if (other.getSource() != null)
327 } else if (!source.equals(other.getSource()))
333 public String toString() {
334 String name = getName();
335 String uniqueId = getUniqueId();
336 String capability = getCapability();
337 String node = getNode();
338 String relationship = getRelationship();
339 String ownerId = getOwnerId();
340 String ownerName = getOwnerName();
341 String minOccurrences = getMinOccurrences();
342 String maxOccurrences = getMaxOccurrences();
343 String leftOccurrences = getLeftOccurrences();
344 List<String> path = this.getPath();
345 String source = getSource();
347 return "RequirementDefinition [uniqueId=" + uniqueId + ", name=" + name + ", capability=" + capability + ", node=" + node + ", relationship=" + relationship + ", ownerId=" + ownerId + ", ownerName=" + ownerName + ", minOccurrences="
348 + minOccurrences + ", maxOccurrences=" + maxOccurrences + ",leftOccurrences=" + leftOccurrences + ", path=" + path + ", source=" + source + "]";