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.io.Serializable;
28 import java.util.ArrayList;
29 import java.util.List;
31 * Represents the requirement of the component or component instance
33 public class RequirementDataDefinition extends ToscaDataDefinition implements Serializable {
37 public static final String MIN_OCCURRENCES = "1";
38 public static final String MAX_OCCURRENCES = "UNBOUNDED";
39 public static final String MAX_DEFAULT_OCCURRENCES = "1";
41 private static final long serialVersionUID = -8840549489409274532L;
43 * The default constructor initializing limits of the occurrences
45 public RequirementDataDefinition() {
47 this.setMinOccurrences( MIN_OCCURRENCES );
48 this.setMaxOccurrences( MAX_OCCURRENCES);
49 this.setLeftOccurrences( MAX_OCCURRENCES);
52 * Deep copy constructor
55 public RequirementDataDefinition(RequirementDataDefinition other) {
56 this.setUniqueId(other.getUniqueId());
57 this.setName(other.getName());
58 this.setParentName(other.getParentName());
59 this.setCapability(other.getCapability());
60 this.setNode(other.getNode());
61 this.setRelationship(other.getRelationship());
62 this.setOwnerId(other.getOwnerId());
63 this.setOwnerName(other.getOwnerName());
64 this.setMinOccurrences(other.getMinOccurrences());
65 this.setMaxOccurrences(other.getMaxOccurrences());
66 this.setLeftOccurrences(other.getLeftOccurrences());
67 if(other.getPath() == null)
68 this.setPath(Lists.newArrayList());
70 this.setPath(Lists.newArrayList(other.getPath()));
71 this.setSource(other.getSource());
75 * Unique id of the requirement
77 public String getUniqueId() {
78 return (String) getToscaPresentationValue(JsonPresentationFields.UNIQUE_ID);
81 public void setUniqueId(String uniqueId) {
82 setToscaPresentationValue(JsonPresentationFields.UNIQUE_ID, uniqueId);
85 public String getName() {
86 return (String) getToscaPresentationValue(JsonPresentationFields.NAME);
89 public void setName(String name) {
90 setToscaPresentationValue(JsonPresentationFields.NAME, name);
93 public String getParentName() {
94 return (String) getToscaPresentationValue(JsonPresentationFields.PARENT_NAME);
97 public void setParentName(String parentName) {
98 setToscaPresentationValue(JsonPresentationFields.PARENT_NAME, parentName);
102 * specify the capability type
105 public String getCapability() {
106 return (String) getToscaPresentationValue(JsonPresentationFields.CAPAPILITY);
109 public void setCapability(String capability) {
110 setToscaPresentationValue(JsonPresentationFields.CAPAPILITY, capability);
114 * specify the node type(Optional by tosca)
116 public String getNode() {
117 return (String) getToscaPresentationValue(JsonPresentationFields.NODE);
120 public void setNode(String node) {
121 setToscaPresentationValue(JsonPresentationFields.NODE, node);
125 * specify the relationship type(Optional by tosca)
127 public String getRelationship() {
128 return (String) getToscaPresentationValue(JsonPresentationFields.RELATIONSHIP);
131 public void setRelationship(String relationship) {
132 setToscaPresentationValue(JsonPresentationFields.RELATIONSHIP, relationship);
136 * specifies the resource instance holding this requirement
139 public String getOwnerId() {
140 return (String) getToscaPresentationValue(JsonPresentationFields.OWNER_ID);
144 public void setOwnerId(String ownerId) {
145 setToscaPresentationValue(JsonPresentationFields.OWNER_ID, ownerId);
148 public String getOwnerName() {
149 return (String) getToscaPresentationValue(JsonPresentationFields.OWNER_NAME);
152 public void setOwnerName(String ownerName) {
153 setToscaPresentationValue(JsonPresentationFields.OWNER_NAME, ownerName);
156 public String getMinOccurrences() {
157 return (String) getToscaPresentationValue(JsonPresentationFields.MIN_OCCURRENCES);
160 public void setMinOccurrences(String minOccurrences) {
161 setToscaPresentationValue(JsonPresentationFields.MIN_OCCURRENCES, minOccurrences);
164 public String getLeftOccurrences() {
165 return (String) getToscaPresentationValue(JsonPresentationFields.LEFT_OCCURRENCES);
168 public void setLeftOccurrences(String leftOccurrences) {
169 setToscaPresentationValue(JsonPresentationFields.LEFT_OCCURRENCES, leftOccurrences);
172 public String getMaxOccurrences() {
173 return (String) getToscaPresentationValue(JsonPresentationFields.MAX_OCCURRENCES);
176 public void setMaxOccurrences(String maxOccurrences) {
177 setToscaPresentationValue(JsonPresentationFields.MAX_OCCURRENCES, maxOccurrences);
180 public void setPath(List<String> path) {
181 setToscaPresentationValue(JsonPresentationFields.PATH, path);
184 @SuppressWarnings({ "unchecked" })
185 public List<String> getPath() {
186 return (List<String>) getToscaPresentationValue(JsonPresentationFields.PATH);
189 public void setSource(String source) {
190 setToscaPresentationValue(JsonPresentationFields.SOURCE, source);
193 public String getSource() {
194 return (String) getToscaPresentationValue(JsonPresentationFields.SOURCE);
198 * Adds the element to the path avoiding duplication
199 * @param elementInPath
201 public void addToPath(String elementInPath) {
202 List<String> path = getPath();
204 path = new ArrayList<>();
206 if(!path.contains(elementInPath)){
207 path.add(elementInPath);
213 public int hashCode() {
214 final int prime = 31;
216 String name = getName();
217 String uniqueId = getUniqueId();
218 String capability = getCapability();
219 String node = getNode();
220 String relationship = getRelationship();
221 String ownerId = getOwnerId();
222 String ownerName = getOwnerName();
223 String minOccurrences = getMinOccurrences();
224 String maxOccurrences = getMaxOccurrences();
225 String leftOccurrences = getLeftOccurrences();
227 List<String> path = this.getPath();
228 String source = getSource();
230 result = prime * result + ((capability == null) ? 0 : capability.hashCode());
231 result = prime * result + ((name == null) ? 0 : name.hashCode());
232 result = prime * result + ((node == null) ? 0 : node.hashCode());
233 result = prime * result + ((ownerId == null) ? 0 : ownerId.hashCode());
234 result = prime * result + ((ownerName == null) ? 0 : ownerName.hashCode());
235 result = prime * result + ((relationship == null) ? 0 : relationship.hashCode());
236 result = prime * result + ((uniqueId == null) ? 0 : uniqueId.hashCode());
237 result = prime * result + ((minOccurrences == null) ? 0 : minOccurrences.hashCode());
238 result = prime * result + ((maxOccurrences == null) ? 0 : maxOccurrences.hashCode());
239 result = prime * result + ((leftOccurrences == null) ? 0 : leftOccurrences.hashCode());
240 result = prime * result + ((path == null) ? 0 : path.hashCode());
241 result = prime * result + ((source == null) ? 0 : source.hashCode());
246 public boolean equals(Object obj) {
251 if (getClass() != obj.getClass())
253 RequirementDataDefinition other = (RequirementDataDefinition) obj;
255 String name = getName();
256 String uniqueId = getUniqueId();
257 String capability = getCapability();
258 String node = getNode();
259 String relationship = getRelationship();
260 String ownerId = getOwnerId();
261 String ownerName = getOwnerName();
262 String minOccurrences = getMinOccurrences();
263 String maxOccurrences = getMaxOccurrences();
264 String leftOccurrences = getLeftOccurrences();
265 List<String> path = this.getPath();
266 String source = getSource();
268 if (capability == null) {
269 if (other.getCapability() != null)
271 } else if (!capability.equals(other.getCapability()))
274 if (other.getName() != null)
276 } else if (!name.equals(other.getName()))
279 if (other.getNode() != null)
281 } else if (!node.equals(other.getNode()))
283 if (ownerId == null) {
284 if (other.getOwnerId() != null)
286 } else if (!ownerId.equals(other.getOwnerId()))
288 if (ownerName == null) {
289 if (other.getOwnerName() != null)
291 } else if (!ownerName.equals(other.getOwnerName()))
293 if (relationship == null) {
294 if (other.getRelationship() != null)
296 } else if (!relationship.equals(other.getRelationship()))
298 if (uniqueId == null) {
299 if (other.getUniqueId() != null)
301 } else if (!uniqueId.equals(other.getUniqueId()))
303 if (minOccurrences == null) {
304 if (other.getMinOccurrences() != null)
306 } else if (!minOccurrences.equals(other.getMinOccurrences()))
308 if (maxOccurrences == null) {
309 if (other.getMaxOccurrences() != null)
311 } else if (!maxOccurrences.equals(other.getMaxOccurrences()))
313 if (leftOccurrences == null) {
314 if (other.getLeftOccurrences() != null)
316 } else if (!leftOccurrences.equals(other.getLeftOccurrences()))
319 if (other.getPath() != null)
321 } else if (!path.equals(other.getPath()))
323 if (source == null) {
324 if (other.getSource() != null)
326 } else if (!source.equals(other.getSource()))
332 public String toString() {
333 String name = getName();
334 String uniqueId = getUniqueId();
335 String capability = getCapability();
336 String node = getNode();
337 String relationship = getRelationship();
338 String ownerId = getOwnerId();
339 String ownerName = getOwnerName();
340 String minOccurrences = getMinOccurrences();
341 String maxOccurrences = getMaxOccurrences();
342 String leftOccurrences = getLeftOccurrences();
343 List<String> path = this.getPath();
344 String source = getSource();
346 return "RequirementDefinition [uniqueId=" + uniqueId + ", name=" + name + ", capability=" + capability + ", node=" + node + ", relationship=" + relationship + ", ownerId=" + ownerId + ", ownerName=" + ownerName + ", minOccurrences="
347 + minOccurrences + ", maxOccurrences=" + maxOccurrences + ",leftOccurrences=" + leftOccurrences + ", path=" + path + ", source=" + source + "]";