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 lombok.EqualsAndHashCode;
27 import lombok.ToString;
28 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
29 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
31 import java.util.ArrayList;
32 import java.util.List;
35 * Represents the requirement of the component or component instance
39 public class RequirementDataDefinition extends ToscaDataDefinition {
41 public static final String MIN_OCCURRENCES = "0";
42 public static final String MAX_OCCURRENCES = "UNBOUNDED";
43 public static final String MAX_DEFAULT_OCCURRENCES = "1";
47 public boolean external = false;
50 * The default constructor initializing limits of the occurrences
52 public RequirementDataDefinition() {
53 this.setMinOccurrences(MIN_OCCURRENCES);
54 this.setMaxOccurrences(MAX_OCCURRENCES);
55 this.setLeftOccurrences(MAX_OCCURRENCES);
59 * Deep copy constructor
63 public RequirementDataDefinition(RequirementDataDefinition other) {
64 this.setUniqueId(other.getUniqueId());
65 this.setName(other.getName());
66 this.setParentName(other.getParentName());
67 this.setPreviousName(other.getPreviousName());
68 this.setCapability(other.getCapability());
69 this.setNode(other.getNode());
70 this.setRelationship(other.getRelationship());
71 this.setOwnerId(other.getOwnerId());
72 this.setOwnerName(other.getOwnerName());
73 this.setMinOccurrences(other.getMinOccurrences());
74 this.setMaxOccurrences(other.getMaxOccurrences());
75 this.setLeftOccurrences(other.getLeftOccurrences());
76 if (other.getPath() == null) {
77 this.setPath(Lists.newArrayList());
79 this.setPath(Lists.newArrayList(other.getPath()));
81 this.setSource(other.getSource());
82 this.setExternal(other.isExternal());
86 * Unique id of the requirement
88 public String getUniqueId() {
89 return (String) getToscaPresentationValue(JsonPresentationFields.UNIQUE_ID);
92 public void setUniqueId(String uniqueId) {
93 setToscaPresentationValue(JsonPresentationFields.UNIQUE_ID, uniqueId);
96 public String getName() {
97 return (String) getToscaPresentationValue(JsonPresentationFields.NAME);
100 public void setName(String name) {
101 setToscaPresentationValue(JsonPresentationFields.NAME, name);
104 public String getParentName() {
105 return (String) getToscaPresentationValue(JsonPresentationFields.PARENT_NAME);
108 public void setParentName(String parentName) {
109 setToscaPresentationValue(JsonPresentationFields.PARENT_NAME, parentName);
112 public String getPreviousName() {
113 return (String) getToscaPresentationValue(JsonPresentationFields.PREVIOUS_NAME);
116 public void setPreviousName(String previousName) {
117 setToscaPresentationValue(JsonPresentationFields.PREVIOUS_NAME, previousName);
121 * specify the capability type
124 public String getCapability() {
125 return (String) getToscaPresentationValue(JsonPresentationFields.CAPABILITY);
128 public void setCapability(String capability) {
129 setToscaPresentationValue(JsonPresentationFields.CAPABILITY, capability);
133 * specify the node type(Optional by tosca)
135 public String getNode() {
136 return (String) getToscaPresentationValue(JsonPresentationFields.NODE);
139 public void setNode(String node) {
140 setToscaPresentationValue(JsonPresentationFields.NODE, node);
144 * specify the relationship type(Optional by tosca)
146 public String getRelationship() {
147 return (String) getToscaPresentationValue(JsonPresentationFields.RELATIONSHIP);
150 public void setRelationship(String relationship) {
151 setToscaPresentationValue(JsonPresentationFields.RELATIONSHIP, relationship);
155 * specifies the resource instance holding this requirement
158 public String getOwnerId() {
159 return (String) getToscaPresentationValue(JsonPresentationFields.OWNER_ID);
163 public void setOwnerId(String ownerId) {
164 setToscaPresentationValue(JsonPresentationFields.OWNER_ID, ownerId);
167 public String getOwnerName() {
168 return (String) getToscaPresentationValue(JsonPresentationFields.OWNER_NAME);
171 public void setOwnerName(String ownerName) {
172 setToscaPresentationValue(JsonPresentationFields.OWNER_NAME, ownerName);
175 public String getMinOccurrences() {
176 return (String) getToscaPresentationValue(JsonPresentationFields.MIN_OCCURRENCES);
179 public void setMinOccurrences(String minOccurrences) {
180 setToscaPresentationValue(JsonPresentationFields.MIN_OCCURRENCES, minOccurrences);
183 public String getLeftOccurrences() {
184 return (String) getToscaPresentationValue(JsonPresentationFields.LEFT_OCCURRENCES);
187 public void setLeftOccurrences(String leftOccurrences) {
188 setToscaPresentationValue(JsonPresentationFields.LEFT_OCCURRENCES, leftOccurrences);
191 public String getMaxOccurrences() {
192 return (String) getToscaPresentationValue(JsonPresentationFields.MAX_OCCURRENCES);
195 public void setMaxOccurrences(String maxOccurrences) {
196 setToscaPresentationValue(JsonPresentationFields.MAX_OCCURRENCES, maxOccurrences);
199 public void setPath(List<String> path) {
200 setToscaPresentationValue(JsonPresentationFields.PATH, path);
203 @SuppressWarnings({"unchecked"})
204 public List<String> getPath() {
205 return (List<String>) getToscaPresentationValue(JsonPresentationFields.PATH);
208 public void setSource(String source) {
209 setToscaPresentationValue(JsonPresentationFields.SOURCE, source);
212 public String getSource() {
213 return (String) getToscaPresentationValue(JsonPresentationFields.SOURCE);
217 * Adds the element to the path avoiding duplication
219 * @param elementInPath
221 public void addToPath(String elementInPath) {
222 List<String> path = getPath();
224 path = new ArrayList<>();
226 if (!path.contains(elementInPath)) {
227 path.add(elementInPath);