Support occurrences on node templates
[sdc.git] / common-be / src / main / java / org / openecomp / sdc / be / datatypes / elements / ComponentInstanceDataDefinition.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 org.apache.commons.collections.CollectionUtils;
24 import org.openecomp.sdc.be.datatypes.enums.CreatedFrom;
25 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
26 import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum;
27 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
28 import org.openecomp.sdc.common.util.ValidationUtils;
29
30 import java.util.ArrayList;
31 import java.util.HashMap;
32 import java.util.List;
33 import java.util.Map;
34 import java.util.Objects;
35 import java.util.stream.Collectors;
36
37 public class ComponentInstanceDataDefinition extends ToscaDataDefinition {
38
39     public ComponentInstanceDataDefinition() {
40         setPropertyValueCounter(1);
41         setAttributeValueCounter(1);
42         setInputValueCounter(1);
43         setIsProxy(false);
44     }
45
46     public ComponentInstanceDataDefinition(ComponentInstanceDataDefinition dataDefinition) {
47         setIcon(dataDefinition.getIcon());
48         setUniqueId(dataDefinition.getUniqueId());
49         setName(dataDefinition.getName());
50         setComponentUid(dataDefinition.getComponentUid());
51         setCreationTime(dataDefinition.getCreationTime());
52         setModificationTime(dataDefinition.getModificationTime());
53         setDescription(dataDefinition.getDescription());
54         setPosX(dataDefinition.getPosX());
55         setPosY(dataDefinition.getPosY());
56         setMinOccurrences(dataDefinition.getMinOccurrences());
57         setMaxOccurrences(dataDefinition.getMaxOccurrences());
58         setPropertyValueCounter(dataDefinition.getPropertyValueCounter());
59         setNormalizedName(dataDefinition.getNormalizedName());
60         setOriginType(dataDefinition.getOriginType());
61         setCustomizationUUID(dataDefinition.getCustomizationUUID());
62         setComponentName(dataDefinition.getComponentName());
63         setComponentVersion(dataDefinition.getComponentVersion());
64         setToscaComponentName(dataDefinition.getToscaComponentName());
65         setInvariantName(dataDefinition.getInvariantName());
66         setSourceModelInvariant(dataDefinition.getSourceModelInvariant());
67         setSourceModelName(dataDefinition.getSourceModelName());
68         setSourceModelUuid(dataDefinition.getSourceModelUuid());
69         setSourceModelUid(dataDefinition.getSourceModelUid());
70         setIsProxy(dataDefinition.getIsProxy());
71         setDirectives(dataDefinition.getDirectives());
72         setOriginArchived(dataDefinition.isOriginArchived());
73         setToscaArtifacts(dataDefinition.getToscaArtifacts());
74     }
75
76     public String getIcon() {
77         return (String) getToscaPresentationValue(JsonPresentationFields.CI_ICON);
78     }
79
80     public void setIcon(String icon) {
81         setToscaPresentationValue(JsonPresentationFields.CI_ICON, icon);
82     }
83
84     public String getUniqueId() {
85         return (String) getToscaPresentationValue(JsonPresentationFields.UNIQUE_ID);
86     }
87
88     public void setUniqueId(String uniqueId) {
89         setToscaPresentationValue(JsonPresentationFields.UNIQUE_ID, uniqueId);
90     }
91
92     public Long getCreationTime() {
93         return (Long) getToscaPresentationValue(JsonPresentationFields.CREATION_TIME);
94     }
95
96     public void setCreationTime(Long creationTime) {
97         setToscaPresentationValue(JsonPresentationFields.CREATION_TIME, creationTime);
98     }
99
100     public Long getModificationTime() {
101         return (Long) getToscaPresentationValue(JsonPresentationFields.MODIFICATION_TIME);
102     }
103
104     public void setModificationTime(Long modificationTime) {
105         setToscaPresentationValue(JsonPresentationFields.MODIFICATION_TIME, modificationTime);
106         }
107
108         public CreatedFrom getCreatedFrom() {
109                 String createdFrom = (String) getToscaPresentationValue(JsonPresentationFields.CREATED_FROM);
110                 return Objects.nonNull(createdFrom) ? CreatedFrom.valueOf(createdFrom) : null;
111         }
112
113         public void setCreatedFrom(CreatedFrom createdFrom) {
114                 if (Objects.nonNull(createdFrom)){
115                         setToscaPresentationValue(JsonPresentationFields.CREATED_FROM, createdFrom.name());
116                 }
117     }
118
119     public String getDescription() {
120         return (String) getToscaPresentationValue(JsonPresentationFields.DESCRIPTION);
121     }
122
123     public void setDescription(String description) {
124         setToscaPresentationValue(JsonPresentationFields.DESCRIPTION, description);
125     }
126
127     public String getPosX() {
128         return (String) getToscaPresentationValue(JsonPresentationFields.CI_POS_X);
129     }
130
131     public void setPosX(String posX) {
132         setToscaPresentationValue(JsonPresentationFields.CI_POS_X, posX);
133     }
134
135     public String getPosY() {
136         return (String) getToscaPresentationValue(JsonPresentationFields.CI_POS_Y);
137     }
138
139     public void setPosY(String posY) {
140         setToscaPresentationValue(JsonPresentationFields.CI_POS_Y, posY);
141     }
142
143     public String getMinOccurrences() {
144         return (String) getToscaPresentationValue(JsonPresentationFields.CI_MIN_OCCURRENCES);
145     }
146
147     public void setMinOccurrences(String minOccurrences) {
148         setToscaPresentationValue(JsonPresentationFields.CI_MIN_OCCURRENCES, minOccurrences);
149     }
150
151     public String getMaxOccurrences() {
152         return (String) getToscaPresentationValue(JsonPresentationFields.CI_MAX_OCCURRENCES);
153     }
154
155     public void setMaxOccurrences(String maxOccurrences) {
156         setToscaPresentationValue(JsonPresentationFields.CI_MAX_OCCURRENCES, maxOccurrences);
157     }
158
159     public String getComponentUid() {
160         return (String) getToscaPresentationValue(JsonPresentationFields.CI_COMPONENT_UID);
161     }
162
163     public void setComponentUid(String resourceUid) {
164         setToscaPresentationValue(JsonPresentationFields.CI_COMPONENT_UID, resourceUid);
165     }
166
167     public String getName() {
168         return (String) getToscaPresentationValue(JsonPresentationFields.NAME);
169     }
170
171     public void setName(String name) {
172         if (this.getInvariantName() == null && name != null) {
173             this.setInvariantName(ValidationUtils.normalizeComponentInstanceName(name));
174         }
175         setToscaPresentationValue(JsonPresentationFields.NAME, name);
176     }
177
178     public String getInvariantName() {
179         return (String) getToscaPresentationValue(JsonPresentationFields.CI_INVARIANT_NAME);
180     }
181
182     public void setInvariantName(String invariantName) {
183         setToscaPresentationValue(JsonPresentationFields.CI_INVARIANT_NAME, invariantName);
184     }
185
186     public Integer getPropertyValueCounter() {
187         return (Integer) getToscaPresentationValue(JsonPresentationFields.CI_PROP_VALUE_COUNTER);
188     }
189
190     public void setPropertyValueCounter(Integer propertyValueCounter) {
191         setToscaPresentationValue(JsonPresentationFields.CI_PROP_VALUE_COUNTER, propertyValueCounter);
192     }
193
194     public String getNormalizedName() {
195         return (String) getToscaPresentationValue(JsonPresentationFields.NORMALIZED_NAME);
196     }
197
198     public void setNormalizedName(String normalizedName) {
199         setToscaPresentationValue(JsonPresentationFields.NORMALIZED_NAME, normalizedName);
200     }
201
202     public OriginTypeEnum getOriginType() {
203         OriginTypeEnum originType = null;
204         String origType = (String) getToscaPresentationValue(JsonPresentationFields.CI_ORIGIN_TYPE);
205         if (origType != null && !origType.isEmpty()) {
206
207             originType = OriginTypeEnum.findByValue(origType);
208         }
209         return originType;
210     }
211
212     public void setOriginType(OriginTypeEnum originType) {
213         if (originType != null) {
214             setToscaPresentationValue(JsonPresentationFields.CI_ORIGIN_TYPE, originType.getValue());
215         }
216     }
217
218     public Integer getAttributeValueCounter() {
219         return (Integer) getToscaPresentationValue(JsonPresentationFields.CI_ATTR_VALUE_COUNTER);
220     }
221
222     public void setAttributeValueCounter(Integer attributeValueCounter) {
223         setToscaPresentationValue(JsonPresentationFields.CI_ATTR_VALUE_COUNTER, attributeValueCounter);
224     }
225
226     public Integer getInputValueCounter() {
227         return (Integer) getToscaPresentationValue(JsonPresentationFields.CI_INPUT_VALUE_COUNTER);
228     }
229
230     public void setInputValueCounter(Integer inputValueCounter) {
231         setToscaPresentationValue(JsonPresentationFields.CI_INPUT_VALUE_COUNTER, inputValueCounter);
232     }
233
234     public String getCustomizationUUID() {
235         return (String) getToscaPresentationValue(JsonPresentationFields.CUSTOMIZATION_UUID);
236     }
237
238     public void setCustomizationUUID(String customizationUUID) {
239         setToscaPresentationValue(JsonPresentationFields.CUSTOMIZATION_UUID, customizationUUID);
240     }
241
242     public String getComponentName() {
243         return (String) getToscaPresentationValue(JsonPresentationFields.CI_COMPONENT_NAME);
244     }
245
246     public void setComponentName(String resourceName) {
247         setToscaPresentationValue(JsonPresentationFields.CI_COMPONENT_NAME, resourceName);
248     }
249
250     public String getComponentVersion() {
251         return (String) getToscaPresentationValue(JsonPresentationFields.CI_COMPONENT_VERSION);
252     }
253
254     public String getToscaComponentName() {
255         return (String) getToscaPresentationValue(JsonPresentationFields.CI_TOSCA_COMPONENT_NAME);
256     }
257
258     public void setToscaComponentName(String toscaComponentName) {
259         setToscaPresentationValue(JsonPresentationFields.CI_TOSCA_COMPONENT_NAME, toscaComponentName);
260     }
261
262     public void setComponentVersion(String resourceVersion) {
263         setToscaPresentationValue(JsonPresentationFields.CI_COMPONENT_VERSION, resourceVersion);
264     }
265
266     public void setSourceModelUuid(String targetModelUuid) {
267         setToscaPresentationValue(JsonPresentationFields.CI_SOURCE_MODEL_UUID, targetModelUuid);
268     }
269
270     public void setSourceModelUid(String targetModelUid) {
271         setToscaPresentationValue(JsonPresentationFields.CI_SOURCE_MODEL_UID, targetModelUid);
272     }
273
274     public void setSourceModelName(String targetModelName) {
275         setToscaPresentationValue(JsonPresentationFields.CI_SOURCE_MODEL_NAME, targetModelName);
276     }
277
278     public void setSourceModelInvariant(String targetModelInvariant) {
279         setToscaPresentationValue(JsonPresentationFields.CI_SOURCE_MODEL_INVARIANT, targetModelInvariant);
280     }
281
282     public String getSourceModelUuid() {
283         return (String) getToscaPresentationValue(JsonPresentationFields.CI_SOURCE_MODEL_UUID);
284     }
285
286     public String getSourceModelUid() {
287         return (String) getToscaPresentationValue(JsonPresentationFields.CI_SOURCE_MODEL_UID);
288     }
289
290     public String getSourceModelName() {
291         return (String) getToscaPresentationValue(JsonPresentationFields.CI_SOURCE_MODEL_NAME);
292     }
293
294     public String getSourceModelInvariant() {
295         return (String) getToscaPresentationValue(JsonPresentationFields.CI_SOURCE_MODEL_INVARIANT);
296     }
297
298     public void setIsProxy(Boolean isProxy) {
299         if (isProxy == null) {
300             setToscaPresentationValue(JsonPresentationFields.CI_IS_PROXY, false);
301         } else {
302             setToscaPresentationValue(JsonPresentationFields.CI_IS_PROXY, isProxy);
303         }
304     }
305
306     public Boolean getIsProxy() {
307         Boolean isProxy = (Boolean) getToscaPresentationValue(JsonPresentationFields.CI_IS_PROXY);
308         return (isProxy != null) ? isProxy : false;
309     }
310     
311     public Boolean isServiceSubstitution() {
312         return getOriginType() == OriginTypeEnum.ServiceSubstitution;
313     }
314
315     public void setOriginArchived(Boolean originArchived) {
316         if (originArchived == null) {
317             setToscaPresentationValue(JsonPresentationFields.CI_IS_ORIGIN_ARCHIVED, false);
318         } else {
319             setToscaPresentationValue(JsonPresentationFields.CI_IS_ORIGIN_ARCHIVED, originArchived);
320         }
321     }
322
323     public List<String> getDirectives() {
324         return (List<String>) getToscaPresentationValue(JsonPresentationFields.CI_DIRECTIVES);
325     }
326
327     public void setDirectives(List<String> directives) {
328         if (directives == null) {
329             directives = new ArrayList<>();
330         }
331         setToscaPresentationValue(JsonPresentationFields.CI_DIRECTIVES, directives);
332     }
333
334     public  Map<String, ToscaArtifactDataDefinition> getToscaArtifacts() {
335         return ( Map<String, ToscaArtifactDataDefinition>) getToscaPresentationValue(JsonPresentationFields.CI_ARTIFACTS);
336     }
337
338     public  void setToscaArtifacts(Map<String, ToscaArtifactDataDefinition> artifacts) {
339         if (artifacts == null){
340             artifacts = new HashMap<>();
341         }
342         setToscaPresentationValue(JsonPresentationFields.CI_ARTIFACTS, artifacts);
343     }
344
345     public Boolean isOriginArchived() {
346         Boolean originArchived = (Boolean) getToscaPresentationValue(JsonPresentationFields.CI_IS_ORIGIN_ARCHIVED);
347         return (originArchived != null) ? originArchived : false;
348     }
349
350     private String getDirectivesString() {
351         if (CollectionUtils.isEmpty(getDirectives())) {
352             return "";
353         }
354         return getDirectives().stream().collect(Collectors.joining(","));
355     }
356
357     @Override
358     public String toString() {
359         return "ComponentInstanceDataDefinition [icon=" + getIcon() + ", uniqueId=" + getUniqueId() + ", name="
360                 + getName() + ", normalizedName=" + getNormalizedName() + ", componentUid=" + getComponentUid()
361                 + ", creationTime=" + getCreationTime() + ", modificationTime=" + getModificationTime()
362                 + ", description=" + getDescription() + ", posX=" + getPosX() + ", posY=" + getPosY()
363                 + ", propertyValueCounter=" + getPropertyValueCounter() + ", attributeValueCounter="
364                 + getAttributeValueCounter() + ", inputValueCounter=" + getInputValueCounter() + ", originType="
365                 + getOriginType() + ", customizationUUID=" + getCustomizationUUID() + ", componentName="
366                 + getComponentName() + ", componentVersion=" + getComponentVersion() + ", toscaComponentName="
367                 + getToscaComponentName() + ", directives =" + getDirectivesString() + ", minOccurrences ="
368                 + getMinOccurrences() + ", maxOccurrences =" + getMaxOccurrences() +"]";
369     }
370
371 }