Import VSP top. template handling non SDC model
[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     private boolean external = false;
48     @Getter
49     @Setter
50     private String externalName;
51
52     /**
53      * The default constructor initializing limits of the occurrences
54      */
55     public RequirementDataDefinition() {
56         this.setMinOccurrences(MIN_OCCURRENCES);
57         this.setMaxOccurrences(MAX_OCCURRENCES);
58         this.setLeftOccurrences(MAX_OCCURRENCES);
59     }
60
61     /**
62      * Deep copy constructor
63      *
64      * @param other
65      */
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());
81         } else {
82             this.setPath(Lists.newArrayList(other.getPath()));
83         }
84         this.setSource(other.getSource());
85         this.setExternal(other.isExternal());
86         this.setExternalName(other.getExternalName());
87     }
88
89     /**
90      * Unique id of the requirement
91      */
92     public String getUniqueId() {
93         return (String) getToscaPresentationValue(JsonPresentationFields.UNIQUE_ID);
94     }
95
96     public void setUniqueId(String uniqueId) {
97         setToscaPresentationValue(JsonPresentationFields.UNIQUE_ID, uniqueId);
98     }
99
100     public String getName() {
101         return (String) getToscaPresentationValue(JsonPresentationFields.NAME);
102     }
103
104     public void setName(String name) {
105         setToscaPresentationValue(JsonPresentationFields.NAME, name);
106     }
107
108     public String getParentName() {
109         return (String) getToscaPresentationValue(JsonPresentationFields.PARENT_NAME);
110     }
111
112     public void setParentName(String parentName) {
113         setToscaPresentationValue(JsonPresentationFields.PARENT_NAME, parentName);
114     }
115
116     public String getPreviousName() {
117         return (String) getToscaPresentationValue(JsonPresentationFields.PREVIOUS_NAME);
118     }
119
120     public void setPreviousName(String previousName) {
121         setToscaPresentationValue(JsonPresentationFields.PREVIOUS_NAME, previousName);
122     }
123
124     /**
125      * specify the capability type
126      */
127
128     public String getCapability() {
129         return (String) getToscaPresentationValue(JsonPresentationFields.CAPABILITY);
130     }
131
132     public void setCapability(String capability) {
133         setToscaPresentationValue(JsonPresentationFields.CAPABILITY, capability);
134     }
135
136     /**
137      * specify the node type(Optional by tosca)
138      */
139     public String getNode() {
140         return (String) getToscaPresentationValue(JsonPresentationFields.NODE);
141     }
142
143     public void setNode(String node) {
144         setToscaPresentationValue(JsonPresentationFields.NODE, node);
145     }
146
147     /**
148      * specify the relationship type(Optional by tosca)
149      */
150     public String getRelationship() {
151         return (String) getToscaPresentationValue(JsonPresentationFields.RELATIONSHIP);
152     }
153
154     public void setRelationship(String relationship) {
155         setToscaPresentationValue(JsonPresentationFields.RELATIONSHIP, relationship);
156     }
157
158     /**
159      * specifies the resource instance holding this requirement
160      */
161     @Override
162     public String getOwnerId() {
163         return (String) getToscaPresentationValue(JsonPresentationFields.OWNER_ID);
164     }
165
166     @Override
167     public void setOwnerId(String ownerId) {
168         setToscaPresentationValue(JsonPresentationFields.OWNER_ID, ownerId);
169     }
170
171     public String getOwnerName() {
172         return (String) getToscaPresentationValue(JsonPresentationFields.OWNER_NAME);
173     }
174
175     public void setOwnerName(String ownerName) {
176         setToscaPresentationValue(JsonPresentationFields.OWNER_NAME, ownerName);
177     }
178
179     public String getMinOccurrences() {
180         return (String) getToscaPresentationValue(JsonPresentationFields.MIN_OCCURRENCES);
181     }
182
183     public void setMinOccurrences(String minOccurrences) {
184         setToscaPresentationValue(JsonPresentationFields.MIN_OCCURRENCES, minOccurrences);
185     }
186
187     public String getLeftOccurrences() {
188         return (String) getToscaPresentationValue(JsonPresentationFields.LEFT_OCCURRENCES);
189     }
190
191     public void setLeftOccurrences(String leftOccurrences) {
192         setToscaPresentationValue(JsonPresentationFields.LEFT_OCCURRENCES, leftOccurrences);
193     }
194
195     public String getMaxOccurrences() {
196         return (String) getToscaPresentationValue(JsonPresentationFields.MAX_OCCURRENCES);
197     }
198
199     public void setMaxOccurrences(String maxOccurrences) {
200         setToscaPresentationValue(JsonPresentationFields.MAX_OCCURRENCES, maxOccurrences);
201     }
202
203     public void setPath(List<String> path) {
204         setToscaPresentationValue(JsonPresentationFields.PATH, path);
205     }
206
207     @SuppressWarnings({"unchecked"})
208     public List<String> getPath() {
209         return (List<String>) getToscaPresentationValue(JsonPresentationFields.PATH);
210     }
211
212     public void setSource(String source) {
213         setToscaPresentationValue(JsonPresentationFields.SOURCE, source);
214     }
215
216     public String getSource() {
217         return (String) getToscaPresentationValue(JsonPresentationFields.SOURCE);
218     }
219
220     /**
221      * Adds the element to the path avoiding duplication
222      *
223      * @param elementInPath
224      */
225     public void addToPath(String elementInPath) {
226         List<String> path = getPath();
227         if (path == null) {
228             path = new ArrayList<>();
229         }
230         if (!path.contains(elementInPath)) {
231             path.add(elementInPath);
232         }
233         setPath(path);
234     }
235
236 }