4b7b6aa41348b6167ba5a863b0b4cca347d22499
[sdc.git] / common-be / src / main / java / org / openecomp / sdc / be / datatypes / elements / RequirementDataDefinition.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.openecomp.sdc.be.datatypes.elements;
22
23 import com.google.common.collect.Lists;
24 import lombok.EqualsAndHashCode;
25 import lombok.Getter;
26 import lombok.Setter;
27 import lombok.ToString;
28 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
29 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
30
31 import java.util.ArrayList;
32 import java.util.List;
33
34 /**
35  * Represents the requirement of the component or component instance
36  */
37 @EqualsAndHashCode
38 @ToString
39 public class RequirementDataDefinition extends ToscaDataDefinition {
40
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";
44     
45     @Getter
46     @Setter
47     public boolean external = false;
48
49     /**
50      * The default constructor initializing limits of the occurrences
51      */
52     public RequirementDataDefinition() {
53         this.setMinOccurrences(MIN_OCCURRENCES);
54         this.setMaxOccurrences(MAX_OCCURRENCES);
55         this.setLeftOccurrences(MAX_OCCURRENCES);
56     }
57
58     /**
59      * Deep copy constructor
60      *
61      * @param other
62      */
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());
78         } else {
79             this.setPath(Lists.newArrayList(other.getPath()));
80         }
81         this.setSource(other.getSource());
82         this.setExternal(other.isExternal());
83     }
84
85     /**
86      * Unique id of the requirement
87      */
88     public String getUniqueId() {
89         return (String) getToscaPresentationValue(JsonPresentationFields.UNIQUE_ID);
90     }
91
92     public void setUniqueId(String uniqueId) {
93         setToscaPresentationValue(JsonPresentationFields.UNIQUE_ID, uniqueId);
94     }
95
96     public String getName() {
97         return (String) getToscaPresentationValue(JsonPresentationFields.NAME);
98     }
99
100     public void setName(String name) {
101         setToscaPresentationValue(JsonPresentationFields.NAME, name);
102     }
103
104     public String getParentName() {
105         return (String) getToscaPresentationValue(JsonPresentationFields.PARENT_NAME);
106     }
107
108     public void setParentName(String parentName) {
109         setToscaPresentationValue(JsonPresentationFields.PARENT_NAME, parentName);
110     }
111
112     public String getPreviousName() {
113         return (String) getToscaPresentationValue(JsonPresentationFields.PREVIOUS_NAME);
114     }
115
116     public void setPreviousName(String previousName) {
117         setToscaPresentationValue(JsonPresentationFields.PREVIOUS_NAME, previousName);
118     }
119
120     /**
121      * specify the capability type
122      */
123
124     public String getCapability() {
125         return (String) getToscaPresentationValue(JsonPresentationFields.CAPABILITY);
126     }
127
128     public void setCapability(String capability) {
129         setToscaPresentationValue(JsonPresentationFields.CAPABILITY, capability);
130     }
131
132     /**
133      * specify the node type(Optional by tosca)
134      */
135     public String getNode() {
136         return (String) getToscaPresentationValue(JsonPresentationFields.NODE);
137     }
138
139     public void setNode(String node) {
140         setToscaPresentationValue(JsonPresentationFields.NODE, node);
141     }
142
143     /**
144      * specify the relationship type(Optional by tosca)
145      */
146     public String getRelationship() {
147         return (String) getToscaPresentationValue(JsonPresentationFields.RELATIONSHIP);
148     }
149
150     public void setRelationship(String relationship) {
151         setToscaPresentationValue(JsonPresentationFields.RELATIONSHIP, relationship);
152     }
153
154     /**
155      * specifies the resource instance holding this requirement
156      */
157     @Override
158     public String getOwnerId() {
159         return (String) getToscaPresentationValue(JsonPresentationFields.OWNER_ID);
160     }
161
162     @Override
163     public void setOwnerId(String ownerId) {
164         setToscaPresentationValue(JsonPresentationFields.OWNER_ID, ownerId);
165     }
166
167     public String getOwnerName() {
168         return (String) getToscaPresentationValue(JsonPresentationFields.OWNER_NAME);
169     }
170
171     public void setOwnerName(String ownerName) {
172         setToscaPresentationValue(JsonPresentationFields.OWNER_NAME, ownerName);
173     }
174
175     public String getMinOccurrences() {
176         return (String) getToscaPresentationValue(JsonPresentationFields.MIN_OCCURRENCES);
177     }
178
179     public void setMinOccurrences(String minOccurrences) {
180         setToscaPresentationValue(JsonPresentationFields.MIN_OCCURRENCES, minOccurrences);
181     }
182
183     public String getLeftOccurrences() {
184         return (String) getToscaPresentationValue(JsonPresentationFields.LEFT_OCCURRENCES);
185     }
186
187     public void setLeftOccurrences(String leftOccurrences) {
188         setToscaPresentationValue(JsonPresentationFields.LEFT_OCCURRENCES, leftOccurrences);
189     }
190
191     public String getMaxOccurrences() {
192         return (String) getToscaPresentationValue(JsonPresentationFields.MAX_OCCURRENCES);
193     }
194
195     public void setMaxOccurrences(String maxOccurrences) {
196         setToscaPresentationValue(JsonPresentationFields.MAX_OCCURRENCES, maxOccurrences);
197     }
198
199     public void setPath(List<String> path) {
200         setToscaPresentationValue(JsonPresentationFields.PATH, path);
201     }
202
203     @SuppressWarnings({"unchecked"})
204     public List<String> getPath() {
205         return (List<String>) getToscaPresentationValue(JsonPresentationFields.PATH);
206     }
207
208     public void setSource(String source) {
209         setToscaPresentationValue(JsonPresentationFields.SOURCE, source);
210     }
211
212     public String getSource() {
213         return (String) getToscaPresentationValue(JsonPresentationFields.SOURCE);
214     }
215
216     /**
217      * Adds the element to the path avoiding duplication
218      *
219      * @param elementInPath
220      */
221     public void addToPath(String elementInPath) {
222         List<String> path = getPath();
223         if (path == null) {
224             path = new ArrayList<>();
225         }
226         if (!path.contains(elementInPath)) {
227             path.add(elementInPath);
228         }
229         setPath(path);
230     }
231
232 }