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