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