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