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