2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.be.datatypes.elements;
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;
27 import java.util.ArrayList;
28 import java.util.HashMap;
29 import java.util.List;
32 import static java.util.Collections.emptyMap;
35 public class GroupDataDefinition extends ToscaDataDefinition {
37 private String typeUid;
39 private Integer propertyValueCounter = 0;
41 public GroupDataDefinition() {
44 public GroupDataDefinition(Map<String, Object> gr) {
46 propertyValueCounter = 0;
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());
61 if (other.getMembers() != null) {
62 this.setMembers(new HashMap<>(other.getMembers()));
64 if (other.getArtifacts() != null) {
65 this.setArtifacts(new ArrayList<>(other.getArtifacts()));
68 if (other.getArtifactsUuid() != null) {
69 this.setArtifactsUuid(new ArrayList<>(other.getArtifactsUuid()));
71 if (other.getProperties() != null) {
72 this.setProperties(new ArrayList<>(other.getProperties()));
74 this.setTypeUid(other.typeUid);
78 public String getName() {
79 return (String) getToscaPresentationValue(JsonPresentationFields.NAME);
82 public void setName(String name) {
83 setToscaPresentationValue(JsonPresentationFields.NAME, name);
86 public String getInvariantName() {
87 String invariantName = (String) getToscaPresentationValue(JsonPresentationFields.CI_INVARIANT_NAME);
88 return invariantName == null ? getName() : invariantName;
91 public void setInvariantName(String invariantName) {
92 setToscaPresentationValue(JsonPresentationFields.CI_INVARIANT_NAME, invariantName);
95 public CreatedFrom getCreatedFrom() {
96 String createdFrom = (String) getToscaPresentationValue(JsonPresentationFields.CREATED_FROM);
97 return createdFrom == null ? CreatedFrom.CSAR : CreatedFrom.valueOf(createdFrom);
100 public void setCreatedFrom(CreatedFrom createdFrom) {
101 setToscaPresentationValue(JsonPresentationFields.CREATED_FROM, createdFrom.name());
104 public String getUniqueId() {
105 return (String) getToscaPresentationValue(JsonPresentationFields.UNIQUE_ID);
108 public void setUniqueId(String uniqueId) {
109 setToscaPresentationValue(JsonPresentationFields.UNIQUE_ID, uniqueId);
112 public String getType() {
113 return (String) getToscaPresentationValue(JsonPresentationFields.TYPE);
116 public void setType(String type) {
117 setToscaPresentationValue(JsonPresentationFields.TYPE, type);
120 public String getVersion() {
121 return (String) getToscaPresentationValue(JsonPresentationFields.VERSION);
124 public void setVersion(String version) {
125 setToscaPresentationValue(JsonPresentationFields.VERSION, version);
128 public String getInvariantUUID() {
129 return (String) getToscaPresentationValue(JsonPresentationFields.INVARIANT_UUID);
132 public void setInvariantUUID(String invariantUUID) {
133 setToscaPresentationValue(JsonPresentationFields.INVARIANT_UUID, invariantUUID);
136 public String getDescription() {
137 return (String) getToscaPresentationValue(JsonPresentationFields.DESCRIPTION);
140 public void setDescription(String description) {
141 setToscaPresentationValue(JsonPresentationFields.DESCRIPTION, description);
144 public Integer getPropertyValueCounter() {
145 return propertyValueCounter;
148 public void setPropertyValueCounter(Integer propertyValueCounter) {
149 this.propertyValueCounter = propertyValueCounter;
152 public String getGroupUUID() {
153 return (String) getToscaPresentationValue(JsonPresentationFields.GROUP_UUID);
156 public void setGroupUUID(String groupUUID) {
157 setToscaPresentationValue(JsonPresentationFields.GROUP_UUID, groupUUID);
160 public Map<String, String> getMembers() {
161 return (Map<String, String>) getToscaPresentationValue(JsonPresentationFields.GROUP_MEMBER);
163 //this is used by GroupCompositionMixin
164 public Map<String, String> resolveMembersList() {
165 Map<String, String> members = getMembers();
166 if (members != null) {
173 public void setMembers(Map<String, String> members) {
174 setToscaPresentationValue(JsonPresentationFields.GROUP_MEMBER, members);
177 public List<String> getArtifacts() {
178 return (List<String>) getToscaPresentationValue(JsonPresentationFields.GROUP_ARTIFACTS);
181 public void setArtifacts(List<String> artifacts) {
182 setToscaPresentationValue(JsonPresentationFields.GROUP_ARTIFACTS, artifacts);
185 public List<String> getArtifactsUuid() {
186 return (List<String>) getToscaPresentationValue(JsonPresentationFields.GROUP_ARTIFACTS_UUID);
189 public void setArtifactsUuid(List<String> artifactsUuid) {
190 setToscaPresentationValue(JsonPresentationFields.GROUP_ARTIFACTS_UUID, artifactsUuid);
193 public List<PropertyDataDefinition> getProperties() {
194 return (List<PropertyDataDefinition>) getToscaPresentationValue(JsonPresentationFields.GROUP_PROPERTIES);
197 public void setProperties(List<PropertyDataDefinition> properties) {
198 setToscaPresentationValue(JsonPresentationFields.GROUP_PROPERTIES, properties);
201 public String getTypeUid() {
205 public void setTypeUid(String typeUid) {
206 this.typeUid = typeUid;
209 public boolean isUserDefined() {
210 return CreatedFrom.UI.equals(getCreatedFrom());
213 public boolean isVspOriginated() {
214 return CreatedFrom.CSAR.equals(getCreatedFrom());
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() + "]";
226 public boolean containsInstanceAsMember(String instanceId) {
227 return getMembers() != null && getMembers().values().contains(instanceId);