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 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;
28 import java.util.ArrayList;
29 import java.util.HashMap;
30 import java.util.List;
33 import static java.util.Collections.emptyMap;
36 public class GroupDataDefinition extends ToscaDataDefinition {
38 private String typeUid;
40 private Integer propertyValueCounter = 0;
42 public GroupDataDefinition() {
45 public GroupDataDefinition(Map<String, Object> gr) {
47 propertyValueCounter = 0;
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());
62 if (other.getMembers() != null) {
63 this.setMembers(new HashMap<>(other.getMembers()));
65 if (other.getArtifacts() != null) {
66 this.setArtifacts(new ArrayList<>(other.getArtifacts()));
69 if (other.getArtifactsUuid() != null) {
70 this.setArtifactsUuid(new ArrayList<>(other.getArtifactsUuid()));
72 if (other.getProperties() != null) {
73 this.setProperties(new ArrayList<>(other.getProperties()));
75 this.setTypeUid(other.typeUid);
79 public String getName() {
80 return (String) getToscaPresentationValue(JsonPresentationFields.NAME);
83 public void setName(String name) {
84 setToscaPresentationValue(JsonPresentationFields.NAME, name);
87 public String getInvariantName() {
88 String invariantName = (String) getToscaPresentationValue(JsonPresentationFields.CI_INVARIANT_NAME);
89 return invariantName == null ? getName() : invariantName;
92 public void setInvariantName(String invariantName) {
93 setToscaPresentationValue(JsonPresentationFields.CI_INVARIANT_NAME, invariantName);
96 public CreatedFrom getCreatedFrom() {
97 String createdFrom = (String) getToscaPresentationValue(JsonPresentationFields.CREATED_FROM);
98 return createdFrom == null ? CreatedFrom.CSAR : CreatedFrom.valueOf(createdFrom);
101 public void setCreatedFrom(CreatedFrom createdFrom) {
102 setToscaPresentationValue(JsonPresentationFields.CREATED_FROM, createdFrom.name());
105 public String getUniqueId() {
106 return (String) getToscaPresentationValue(JsonPresentationFields.UNIQUE_ID);
109 public void setUniqueId(String uniqueId) {
110 setToscaPresentationValue(JsonPresentationFields.UNIQUE_ID, uniqueId);
113 public String getType() {
114 return (String) getToscaPresentationValue(JsonPresentationFields.TYPE);
117 public void setType(String type) {
118 setToscaPresentationValue(JsonPresentationFields.TYPE, type);
121 public String getVersion() {
122 return (String) getToscaPresentationValue(JsonPresentationFields.VERSION);
125 public void setVersion(String version) {
126 setToscaPresentationValue(JsonPresentationFields.VERSION, version);
129 public String getInvariantUUID() {
130 return (String) getToscaPresentationValue(JsonPresentationFields.INVARIANT_UUID);
133 public void setInvariantUUID(String invariantUUID) {
134 setToscaPresentationValue(JsonPresentationFields.INVARIANT_UUID, invariantUUID);
137 public String getDescription() {
138 return (String) getToscaPresentationValue(JsonPresentationFields.DESCRIPTION);
141 public void setDescription(String description) {
142 setToscaPresentationValue(JsonPresentationFields.DESCRIPTION, description);
145 public Integer getPropertyValueCounter() {
146 return propertyValueCounter;
149 public void setPropertyValueCounter(Integer propertyValueCounter) {
150 this.propertyValueCounter = propertyValueCounter;
153 public String getGroupUUID() {
154 return (String) getToscaPresentationValue(JsonPresentationFields.GROUP_UUID);
157 public void setGroupUUID(String groupUUID) {
158 setToscaPresentationValue(JsonPresentationFields.GROUP_UUID, groupUUID);
161 public Map<String, String> getMembers() {
162 return (Map<String, String>) getToscaPresentationValue(JsonPresentationFields.GROUP_MEMBER);
165 //this is used by GroupCompositionMixin
166 public Map<String, String> resolveMembersList() {
167 Map<String, String> members = getMembers();
168 if (members != null) {
175 public void setMembers(Map<String, String> members) {
176 setToscaPresentationValue(JsonPresentationFields.GROUP_MEMBER, members);
179 public List<String> getArtifacts() {
180 return (List<String>) getToscaPresentationValue(JsonPresentationFields.GROUP_ARTIFACTS);
183 public void setArtifacts(List<String> artifacts) {
184 setToscaPresentationValue(JsonPresentationFields.GROUP_ARTIFACTS, artifacts);
187 public List<String> getArtifactsUuid() {
188 return (List<String>) getToscaPresentationValue(JsonPresentationFields.GROUP_ARTIFACTS_UUID);
191 public void setArtifactsUuid(List<String> artifactsUuid) {
192 setToscaPresentationValue(JsonPresentationFields.GROUP_ARTIFACTS_UUID, artifactsUuid);
195 public List<PropertyDataDefinition> getProperties() {
196 return (List<PropertyDataDefinition>) getToscaPresentationValue(JsonPresentationFields.GROUP_PROPERTIES);
199 public void setProperties(List<PropertyDataDefinition> properties) {
200 setToscaPresentationValue(JsonPresentationFields.GROUP_PROPERTIES, properties);
203 public String getTypeUid() {
207 public void setTypeUid(String typeUid) {
208 this.typeUid = typeUid;
211 public boolean isUserDefined() {
212 return CreatedFrom.UI.equals(getCreatedFrom());
215 public boolean isVspOriginated() {
216 return CreatedFrom.CSAR.equals(getCreatedFrom());
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() + "]";
228 public boolean containsInstanceAsMember(String instanceId) {
229 return getMembers() != null && getMembers().values().contains(instanceId);