Catalog alignment
[sdc.git] / common-be / src / main / java / org / openecomp / sdc / be / datatypes / elements / GroupDataDefinition.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 com.fasterxml.jackson.annotation.JsonInclude;
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.tosca.ToscaDataDefinition;
27
28 import java.util.ArrayList;
29 import java.util.HashMap;
30 import java.util.List;
31 import java.util.Map;
32
33 import static java.util.Collections.emptyMap;
34
35
36 public class GroupDataDefinition extends ToscaDataDefinition {
37     @JsonInclude
38     private String typeUid;
39     @JsonInclude
40     private Integer propertyValueCounter = 0;
41
42     public GroupDataDefinition() {
43     }
44
45     public GroupDataDefinition(Map<String, Object> gr) {
46         super(gr);
47         propertyValueCounter = 0;
48     }
49
50     public GroupDataDefinition(GroupDataDefinition other) {
51         this.setName(other.getName());
52         this.setUniqueId(other.getUniqueId());
53         this.setType(other.getType());
54         this.setVersion(other.getVersion());
55         this.setInvariantUUID(other.getInvariantUUID());
56         this.setDescription(other.getDescription());
57         this.propertyValueCounter = other.propertyValueCounter;
58         this.setGroupUUID(other.getGroupUUID());
59         this.setInvariantName(other.getInvariantName());
60         this.setCreatedFrom(other.getCreatedFrom());
61
62         if (other.getMembers() != null) {
63             this.setMembers(new HashMap<>(other.getMembers()));
64         }
65         if (other.getArtifacts() != null) {
66             this.setArtifacts(new ArrayList<>(other.getArtifacts()));
67         }
68
69         if (other.getArtifactsUuid() != null) {
70             this.setArtifactsUuid(new ArrayList<>(other.getArtifactsUuid()));
71         }
72         if (other.getProperties() != null) {
73             this.setProperties(new ArrayList<>(other.getProperties()));
74         }
75         this.setTypeUid(other.typeUid);
76     }
77
78
79     public String getName() {
80         return (String) getToscaPresentationValue(JsonPresentationFields.NAME);
81     }
82
83     public void setName(String name) {
84         setToscaPresentationValue(JsonPresentationFields.NAME, name);
85     }
86
87     public String getInvariantName() {
88         String invariantName = (String) getToscaPresentationValue(JsonPresentationFields.CI_INVARIANT_NAME);
89         return invariantName == null ? getName() : invariantName;
90     }
91
92     public void setInvariantName(String invariantName) {
93         setToscaPresentationValue(JsonPresentationFields.CI_INVARIANT_NAME, invariantName);
94     }
95
96     public CreatedFrom getCreatedFrom() {
97         String createdFrom = (String) getToscaPresentationValue(JsonPresentationFields.CREATED_FROM);
98         return createdFrom == null ? CreatedFrom.CSAR : CreatedFrom.valueOf(createdFrom);
99     }
100
101     public void setCreatedFrom(CreatedFrom createdFrom) {
102         setToscaPresentationValue(JsonPresentationFields.CREATED_FROM, createdFrom.name());
103     }
104
105     public String getUniqueId() {
106         return (String) getToscaPresentationValue(JsonPresentationFields.UNIQUE_ID);
107     }
108
109     public void setUniqueId(String uniqueId) {
110         setToscaPresentationValue(JsonPresentationFields.UNIQUE_ID, uniqueId);
111     }
112
113     public String getType() {
114         return (String) getToscaPresentationValue(JsonPresentationFields.TYPE);
115     }
116
117     public void setType(String type) {
118         setToscaPresentationValue(JsonPresentationFields.TYPE, type);
119     }
120
121     public String getVersion() {
122         return (String) getToscaPresentationValue(JsonPresentationFields.VERSION);
123     }
124
125     public void setVersion(String version) {
126         setToscaPresentationValue(JsonPresentationFields.VERSION, version);
127     }
128
129     public String getInvariantUUID() {
130         return (String) getToscaPresentationValue(JsonPresentationFields.INVARIANT_UUID);
131     }
132
133     public void setInvariantUUID(String invariantUUID) {
134         setToscaPresentationValue(JsonPresentationFields.INVARIANT_UUID, invariantUUID);
135     }
136
137     public String getDescription() {
138         return (String) getToscaPresentationValue(JsonPresentationFields.DESCRIPTION);
139     }
140
141     public void setDescription(String description) {
142         setToscaPresentationValue(JsonPresentationFields.DESCRIPTION, description);
143     }
144
145     public Integer getPropertyValueCounter() {
146         return propertyValueCounter;
147     }
148
149     public void setPropertyValueCounter(Integer propertyValueCounter) {
150         this.propertyValueCounter = propertyValueCounter;
151     }
152
153     public String getGroupUUID() {
154         return (String) getToscaPresentationValue(JsonPresentationFields.GROUP_UUID);
155     }
156
157     public void setGroupUUID(String groupUUID) {
158         setToscaPresentationValue(JsonPresentationFields.GROUP_UUID, groupUUID);
159     }
160
161     public Map<String, String> getMembers() {
162         return (Map<String, String>) getToscaPresentationValue(JsonPresentationFields.GROUP_MEMBER);
163     }
164
165     //this is used by GroupCompositionMixin
166     public Map<String, String> resolveMembersList() {
167         Map<String, String> members = getMembers();
168         if (members != null) {
169             return members;
170         }
171         return emptyMap();
172
173     }
174
175     public void setMembers(Map<String, String> members) {
176         setToscaPresentationValue(JsonPresentationFields.GROUP_MEMBER, members);
177     }
178
179     public List<String> getArtifacts() {
180         return (List<String>) getToscaPresentationValue(JsonPresentationFields.GROUP_ARTIFACTS);
181     }
182
183     public void setArtifacts(List<String> artifacts) {
184         setToscaPresentationValue(JsonPresentationFields.GROUP_ARTIFACTS, artifacts);
185     }
186
187     public List<String> getArtifactsUuid() {
188         return (List<String>) getToscaPresentationValue(JsonPresentationFields.GROUP_ARTIFACTS_UUID);
189     }
190
191     public void setArtifactsUuid(List<String> artifactsUuid) {
192         setToscaPresentationValue(JsonPresentationFields.GROUP_ARTIFACTS_UUID, artifactsUuid);
193     }
194
195     public List<PropertyDataDefinition> getProperties() {
196         return (List<PropertyDataDefinition>) getToscaPresentationValue(JsonPresentationFields.GROUP_PROPERTIES);
197     }
198
199     public void setProperties(List<PropertyDataDefinition> properties) {
200         setToscaPresentationValue(JsonPresentationFields.GROUP_PROPERTIES, properties);
201     }
202
203     public String getTypeUid() {
204         return typeUid;
205     }
206
207     public void setTypeUid(String typeUid) {
208         this.typeUid = typeUid;
209     }
210
211     public boolean isUserDefined() {
212         return CreatedFrom.UI.equals(getCreatedFrom());
213     }
214
215     public boolean isVspOriginated() {
216         return CreatedFrom.CSAR.equals(getCreatedFrom());
217     }
218
219     @Override
220     public String toString() {
221         return "GroupDataDefinition [propertyValueCounter=" + propertyValueCounter + ", toscaPresentation=" + toscaPresentation + ", getName()=" + getName() + ", getUniqueId()=" + getUniqueId() + ", getType()=" + getType() + ", getVersion()="
222                 + getVersion() + ", getInvariantUUID()=" + getInvariantUUID() + ", getDescription()=" + getDescription() + ", getPropertyValueCounter()=" + getPropertyValueCounter() + ", getGroupUUID()=" + getGroupUUID() + ", getMembers()="
223                 + getMembers() + ", getArtifacts()=" + getArtifacts() + ", getArtifactsUuid()=" + getArtifactsUuid() + ", getClass()=" + getClass() + ", hashCode()=" + hashCode() + ", toString()="
224                 + super.toString() + "]";
225     }
226
227
228     public boolean containsInstanceAsMember(String instanceId) {
229         return getMembers() != null && getMembers().values().contains(instanceId);
230     }
231 }