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