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