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 private boolean external = false;
50 private String externalName;
53 * The default constructor initializing limits of the occurrences
55 public RequirementDataDefinition() {
56 this.setMinOccurrences(MIN_OCCURRENCES);
57 this.setMaxOccurrences(MAX_OCCURRENCES);
58 this.setLeftOccurrences(MAX_OCCURRENCES);
62 * Deep copy constructor
66 public RequirementDataDefinition(RequirementDataDefinition other) {
67 this.setUniqueId(other.getUniqueId());
68 this.setName(other.getName());
69 this.setParentName(other.getParentName());
70 this.setPreviousName(other.getPreviousName());
71 this.setCapability(other.getCapability());
72 this.setNode(other.getNode());
73 this.setRelationship(other.getRelationship());
74 this.setOwnerId(other.getOwnerId());
75 this.setOwnerName(other.getOwnerName());
76 this.setMinOccurrences(other.getMinOccurrences());
77 this.setMaxOccurrences(other.getMaxOccurrences());
78 this.setLeftOccurrences(other.getLeftOccurrences());
79 if (other.getPath() == null) {
80 this.setPath(Lists.newArrayList());
82 this.setPath(Lists.newArrayList(other.getPath()));
84 this.setSource(other.getSource());
85 this.setExternal(other.isExternal());
86 this.setExternalName(other.getExternalName());
90 * Unique id of the requirement
92 public String getUniqueId() {
93 return (String) getToscaPresentationValue(JsonPresentationFields.UNIQUE_ID);
96 public void setUniqueId(String uniqueId) {
97 setToscaPresentationValue(JsonPresentationFields.UNIQUE_ID, uniqueId);
100 public String getName() {
101 return (String) getToscaPresentationValue(JsonPresentationFields.NAME);
104 public void setName(String name) {
105 setToscaPresentationValue(JsonPresentationFields.NAME, name);
108 public String getParentName() {
109 return (String) getToscaPresentationValue(JsonPresentationFields.PARENT_NAME);
112 public void setParentName(String parentName) {
113 setToscaPresentationValue(JsonPresentationFields.PARENT_NAME, parentName);
116 public String getPreviousName() {
117 return (String) getToscaPresentationValue(JsonPresentationFields.PREVIOUS_NAME);
120 public void setPreviousName(String previousName) {
121 setToscaPresentationValue(JsonPresentationFields.PREVIOUS_NAME, previousName);
125 * specify the capability type
128 public String getCapability() {
129 return (String) getToscaPresentationValue(JsonPresentationFields.CAPABILITY);
132 public void setCapability(String capability) {
133 setToscaPresentationValue(JsonPresentationFields.CAPABILITY, capability);
137 * specify the node type(Optional by tosca)
139 public String getNode() {
140 return (String) getToscaPresentationValue(JsonPresentationFields.NODE);
143 public void setNode(String node) {
144 setToscaPresentationValue(JsonPresentationFields.NODE, node);
148 * specify the relationship type(Optional by tosca)
150 public String getRelationship() {
151 return (String) getToscaPresentationValue(JsonPresentationFields.RELATIONSHIP);
154 public void setRelationship(String relationship) {
155 setToscaPresentationValue(JsonPresentationFields.RELATIONSHIP, relationship);
159 * specifies the resource instance holding this requirement
162 public String getOwnerId() {
163 return (String) getToscaPresentationValue(JsonPresentationFields.OWNER_ID);
167 public void setOwnerId(String ownerId) {
168 setToscaPresentationValue(JsonPresentationFields.OWNER_ID, ownerId);
171 public String getOwnerName() {
172 return (String) getToscaPresentationValue(JsonPresentationFields.OWNER_NAME);
175 public void setOwnerName(String ownerName) {
176 setToscaPresentationValue(JsonPresentationFields.OWNER_NAME, ownerName);
179 public String getMinOccurrences() {
180 return (String) getToscaPresentationValue(JsonPresentationFields.MIN_OCCURRENCES);
183 public void setMinOccurrences(String minOccurrences) {
184 setToscaPresentationValue(JsonPresentationFields.MIN_OCCURRENCES, minOccurrences);
187 public String getLeftOccurrences() {
188 return (String) getToscaPresentationValue(JsonPresentationFields.LEFT_OCCURRENCES);
191 public void setLeftOccurrences(String leftOccurrences) {
192 setToscaPresentationValue(JsonPresentationFields.LEFT_OCCURRENCES, leftOccurrences);
195 public String getMaxOccurrences() {
196 return (String) getToscaPresentationValue(JsonPresentationFields.MAX_OCCURRENCES);
199 public void setMaxOccurrences(String maxOccurrences) {
200 setToscaPresentationValue(JsonPresentationFields.MAX_OCCURRENCES, maxOccurrences);
203 public void setPath(List<String> path) {
204 setToscaPresentationValue(JsonPresentationFields.PATH, path);
207 @SuppressWarnings({"unchecked"})
208 public List<String> getPath() {
209 return (List<String>) getToscaPresentationValue(JsonPresentationFields.PATH);
212 public void setSource(String source) {
213 setToscaPresentationValue(JsonPresentationFields.SOURCE, source);
216 public String getSource() {
217 return (String) getToscaPresentationValue(JsonPresentationFields.SOURCE);
221 * Adds the element to the path avoiding duplication
223 * @param elementInPath
225 public void addToPath(String elementInPath) {
226 List<String> path = getPath();
228 path = new ArrayList<>();
230 if (!path.contains(elementInPath)) {
231 path.add(elementInPath);