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 public class RequirementDataDefinition extends ToscaDataDefinition implements Serializable {
34 public final static String MIN_OCCURRENCES = "1";
35 public final static String MAX_OCCURRENCES = "UNBOUNDED";
36 public final static String MAX_DEFAULT_OCCURRENCES = "1";
38 private static final long serialVersionUID = -8840549489409274532L;
40 public RequirementDataDefinition() {
42 this.setMinOccurrences( MIN_OCCURRENCES );
43 this.setMaxOccurrences( MAX_OCCURRENCES);
44 this.setLeftOccurrences( MAX_OCCURRENCES);
47 public RequirementDataDefinition(RequirementDataDefinition other) {
48 this.setUniqueId(other.getUniqueId());
49 this.setName(other.getName());
50 this.setCapability(other.getCapability());
51 this.setNode(other.getNode());
52 this.setRelationship(other.getRelationship());
53 this.setOwnerId(other.getOwnerId());
54 this.setOwnerName(other.getOwnerName());
55 this.setMinOccurrences(other.getMinOccurrences());
56 this.setMaxOccurrences(other.getMaxOccurrences());
57 this.setLeftOccurrences(other.getLeftOccurrences());
58 this.setPath(other.getPath());
59 this.setSource(other.getSource());
64 * Unique id of the requirement
66 public String getUniqueId() {
67 return (String) getToscaPresentationValue(JsonPresentationFields.UNIQUE_ID);
70 public void setUniqueId(String uniqueId) {
71 setToscaPresentationValue(JsonPresentationFields.UNIQUE_ID, uniqueId);
74 public String getName() {
75 return (String) getToscaPresentationValue(JsonPresentationFields.NAME);
78 public void setName(String name) {
79 setToscaPresentationValue(JsonPresentationFields.NAME, name);
83 * specify the capability type
86 public String getCapability() {
87 return (String) getToscaPresentationValue(JsonPresentationFields.CAPAPILITY);
90 public void setCapability(String capability) {
91 setToscaPresentationValue(JsonPresentationFields.CAPAPILITY, capability);
95 * specify the node type(Optional by tosca)
97 public String getNode() {
98 return (String) getToscaPresentationValue(JsonPresentationFields.NODE);
101 public void setNode(String node) {
102 setToscaPresentationValue(JsonPresentationFields.NODE, node);
106 * specify the relationship type(Optional by tosca)
108 public String getRelationship() {
109 return (String) getToscaPresentationValue(JsonPresentationFields.RELATIONSHIP);
112 public void setRelationship(String relationship) {
113 setToscaPresentationValue(JsonPresentationFields.RELATIONSHIP, relationship);
116 // public RequirementImplDef getRequirementImpl() {
117 // return requirementImpl;
120 // public void setRequirementImpl(RequirementImplDef requirementImpl) {
121 // this.requirementImpl = requirementImpl;
124 // specifies the resource instance holding this requirement
125 public String getOwnerId() {
126 return (String) getToscaPresentationValue(JsonPresentationFields.OWNER_ID);
129 public void setOwnerId(String ownerId) {
130 setToscaPresentationValue(JsonPresentationFields.OWNER_ID, ownerId);
133 public String getOwnerName() {
134 return (String) getToscaPresentationValue(JsonPresentationFields.OWNER_NAME);
137 public void setOwnerName(String ownerName) {
138 setToscaPresentationValue(JsonPresentationFields.OWNER_NAME, ownerName);
141 public String getMinOccurrences() {
142 return (String) getToscaPresentationValue(JsonPresentationFields.MIN_OCCURRENCES);
145 public void setMinOccurrences(String minOccurrences) {
146 setToscaPresentationValue(JsonPresentationFields.MIN_OCCURRENCES, minOccurrences);
149 public String getLeftOccurrences() {
150 return (String) getToscaPresentationValue(JsonPresentationFields.LEFT_OCCURRENCES);
153 public void setLeftOccurrences(String leftOccurrences) {
154 setToscaPresentationValue(JsonPresentationFields.LEFT_OCCURRENCES, leftOccurrences);
157 public String getMaxOccurrences() {
158 return (String) getToscaPresentationValue(JsonPresentationFields.MAX_OCCURRENCES);
161 public void setMaxOccurrences(String maxOccurrences) {
162 setToscaPresentationValue(JsonPresentationFields.MAX_OCCURRENCES, maxOccurrences);
165 public void setPath(List<String> path) {
166 setToscaPresentationValue(JsonPresentationFields.PATH, path);
169 public List<String> getPath() {
170 return (List<String>) getToscaPresentationValue(JsonPresentationFields.PATH);
173 public void setSource(String source) {
174 setToscaPresentationValue(JsonPresentationFields.SOURCE, source);
177 public String getSource() {
178 return (String) getToscaPresentationValue(JsonPresentationFields.SOURCE);
181 public void addToPath(String elementInPath) {
182 List<String> path = getPath();
184 path = new ArrayList<>();
186 path.add(elementInPath);
191 public int hashCode() {
192 final int prime = 31;
194 String name = getName();
195 String uniqueId = getUniqueId();
196 String capability = getCapability();
197 String node = getNode();
198 String relationship = getRelationship();
199 String ownerId = getOwnerId();
200 String ownerName = getOwnerName();
201 String minOccurrences = getMinOccurrences();
202 String maxOccurrences = getMaxOccurrences();
203 String leftOccurrences = getLeftOccurrences();
205 List<String> path = this.getPath();
206 String source = getSource();
208 result = prime * result + ((capability == null) ? 0 : capability.hashCode());
209 result = prime * result + ((name == null) ? 0 : name.hashCode());
210 result = prime * result + ((node == null) ? 0 : node.hashCode());
211 result = prime * result + ((ownerId == null) ? 0 : ownerId.hashCode());
212 result = prime * result + ((ownerName == null) ? 0 : ownerName.hashCode());
213 result = prime * result + ((relationship == null) ? 0 : relationship.hashCode());
214 result = prime * result + ((uniqueId == null) ? 0 : uniqueId.hashCode());
215 result = prime * result + ((minOccurrences == null) ? 0 : minOccurrences.hashCode());
216 result = prime * result + ((maxOccurrences == null) ? 0 : maxOccurrences.hashCode());
217 result = prime * result + ((leftOccurrences == null) ? 0 : leftOccurrences.hashCode());
218 result = prime * result + ((path == null) ? 0 : path.hashCode());
219 result = prime * result + ((source == null) ? 0 : source.hashCode());
224 public boolean equals(Object obj) {
229 if (getClass() != obj.getClass())
231 RequirementDataDefinition other = (RequirementDataDefinition) obj;
233 String name = getName();
234 String uniqueId = getUniqueId();
235 String capability = getCapability();
236 String node = getNode();
237 String relationship = getRelationship();
238 String ownerId = getOwnerId();
239 String ownerName = getOwnerName();
240 String minOccurrences = getMinOccurrences();
241 String maxOccurrences = getMaxOccurrences();
242 String leftOccurrences = getLeftOccurrences();
243 List<String> path = this.getPath();
244 String source = getSource();
246 if (capability == null) {
247 if (other.getCapability() != null)
249 } else if (!capability.equals(other.getCapability()))
252 if (other.getName() != null)
254 } else if (!name.equals(other.getName()))
257 if (other.getNode() != null)
259 } else if (!node.equals(other.getNode()))
261 if (ownerId == null) {
262 if (other.getOwnerId() != null)
264 } else if (!ownerId.equals(other.getOwnerId()))
266 if (ownerName == null) {
267 if (other.getOwnerName() != null)
269 } else if (!ownerName.equals(other.getOwnerName()))
271 if (relationship == null) {
272 if (other.getRelationship() != null)
274 } else if (!relationship.equals(other.getRelationship()))
276 if (uniqueId == null) {
277 if (other.getUniqueId() != null)
279 } else if (!uniqueId.equals(other.getUniqueId()))
281 if (minOccurrences == null) {
282 if (other.getMinOccurrences() != null)
284 } else if (!minOccurrences.equals(other.getMinOccurrences()))
286 if (maxOccurrences == null) {
287 if (other.getMaxOccurrences() != null)
289 } else if (!maxOccurrences.equals(other.getMaxOccurrences()))
291 if (leftOccurrences == null) {
292 if (other.getLeftOccurrences() != null)
294 } else if (!leftOccurrences.equals(other.getLeftOccurrences()))
297 if (other.getPath() != null)
299 } else if (!path.equals(other.getPath()))
301 if (source == null) {
302 if (other.getSource() != null)
304 } else if (!source.equals(other.getSource()))
310 public String toString() {
311 String name = getName();
312 String uniqueId = getUniqueId();
313 String capability = getCapability();
314 String node = getNode();
315 String relationship = getRelationship();
316 String ownerId = getOwnerId();
317 String ownerName = getOwnerName();
318 String minOccurrences = getMinOccurrences();
319 String maxOccurrences = getMaxOccurrences();
320 String leftOccurrences = getLeftOccurrences();
321 List<String> path = this.getPath();
322 String source = getSource();
324 return "RequirementDefinition [uniqueId=" + uniqueId + ", name=" + name + ", capability=" + capability + ", node=" + node + ", relationship=" + relationship + ", ownerId=" + ownerId + ", ownerName=" + ownerName + ", minOccurrences="
325 + minOccurrences + ", maxOccurrences=" + maxOccurrences + ",leftOccurrences=" + leftOccurrences + ", path=" + path + ", source=" + source + "]";