2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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=========================================================
20 package org.openecomp.sdc.be.datatypes.elements;
22 import static java.util.Collections.emptyList;
24 import java.util.List;
26 import lombok.NoArgsConstructor;
27 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
30 * public class representing the component policy, described by the next properties:
32 * name uniqueId type (policy type name) typeUid (policy type uniqueId) version (version) derivedFrom (policy type derivedFrom) description policyUUID
33 * invariantUUID members metadata properties targets isFromCsar
36 public class PolicyDataDefinition extends PropertyDataDefinition {
38 public PolicyDataDefinition(PropertyDataDefinition propertyDataDefinition) {
39 super(propertyDataDefinition);
43 * public constructor from superclass
47 public PolicyDataDefinition(Map<String, Object> policy) {
52 * public copy constructor
56 public PolicyDataDefinition(PolicyDataDefinition other) {
58 this.setName(other.getName());
59 this.setUniqueId(other.getUniqueId());
60 this.setPolicyTypeName(other.getPolicyTypeName());
61 this.setPolicyTypeUid(other.getPolicyTypeUid());
62 this.setVersion(other.getVersion());
63 this.setDerivedFrom(other.getDerivedFrom());
64 this.setDescription(other.getDescription());
65 this.setPolicyUUID(other.getPolicyUUID());
66 this.setInvariantUUID(other.getInvariantUUID());
67 this.setInvariantName(other.getInvariantName());
68 this.setComponentName(other.getComponentName());
69 this.setIsFromCsar(other.getIsFromCsar());
70 this.setValue(other.getValue());
71 this.setOwnerId(other.getOwnerId());
72 this.setType(other.getType());
73 this.setInstanceUniqueId(other.getInstanceUniqueId());
74 this.setInputPath(other.getInputPath());
75 if (other.getProperties() != null) {
76 this.setProperties(other.getProperties());
78 if (other.getTargets() != null) {
79 this.setTargets(other.getTargets());
83 public Boolean getIsFromCsar() {
84 Boolean isFromCsar = (Boolean) getToscaPresentationValue(JsonPresentationFields.IS_FROM_CSAR);
85 return (isFromCsar != null) ? isFromCsar : false;
88 private void setIsFromCsar(Boolean isFromCsar) {
89 if (isFromCsar == null) {
90 setToscaPresentationValue(JsonPresentationFields.IS_FROM_CSAR, false);
92 setToscaPresentationValue(JsonPresentationFields.IS_FROM_CSAR, isFromCsar);
96 public String getComponentName() {
97 return (String) getToscaPresentationValue(JsonPresentationFields.CI_COMPONENT_NAME);
100 public void setComponentName(String componentName) {
101 setToscaPresentationValue(JsonPresentationFields.CI_COMPONENT_NAME, componentName);
104 public String getInvariantName() {
105 return (String) getToscaPresentationValue(JsonPresentationFields.CI_INVARIANT_NAME);
108 public void setInvariantName(Object invariantName) {
109 setToscaPresentationValue(JsonPresentationFields.CI_INVARIANT_NAME, invariantName);
112 public String getPolicyTypeName() {
113 return (String) getToscaPresentationValue(JsonPresentationFields.TYPE);
116 public void setPolicyTypeName(String policyTypeName) {
117 setToscaPresentationValue(JsonPresentationFields.TYPE, policyTypeName);
120 public String getPolicyTypeUid() {
121 return (String) getToscaPresentationValue(JsonPresentationFields.TYPE_UNIQUE_ID);
124 public void setPolicyTypeUid(String policyTypeUid) {
125 setToscaPresentationValue(JsonPresentationFields.TYPE_UNIQUE_ID, policyTypeUid);
129 public String getVersion() {
130 return (String) getToscaPresentationValue(JsonPresentationFields.VERSION);
133 public void setVersion(String version) {
134 setToscaPresentationValue(JsonPresentationFields.VERSION, version);
137 public String getDerivedFrom() {
138 return (String) getToscaPresentationValue(JsonPresentationFields.DERIVED_FROM);
141 public void setDerivedFrom(String derivedFrom) {
142 setToscaPresentationValue(JsonPresentationFields.DERIVED_FROM, derivedFrom);
146 public String getDescription() {
147 return (String) getToscaPresentationValue(JsonPresentationFields.DESCRIPTION);
151 public void setDescription(String description) {
152 setToscaPresentationValue(JsonPresentationFields.DESCRIPTION, description);
155 public String getPolicyUUID() {
156 return (String) getToscaPresentationValue(JsonPresentationFields.UUID);
159 public void setPolicyUUID(String policyUUID) {
160 setToscaPresentationValue(JsonPresentationFields.UUID, policyUUID);
163 public String getInvariantUUID() {
164 return (String) getToscaPresentationValue(JsonPresentationFields.INVARIANT_UUID);
167 public void setInvariantUUID(String invariantUUID) {
168 setToscaPresentationValue(JsonPresentationFields.INVARIANT_UUID, invariantUUID);
171 @SuppressWarnings("unchecked")
172 public List<PropertyDataDefinition> getProperties() {
173 return (List<PropertyDataDefinition>) getToscaPresentationValue(JsonPresentationFields.PROPERTIES);
176 public void setProperties(List<PropertyDataDefinition> properties) {
177 setToscaPresentationValue(JsonPresentationFields.PROPERTIES, properties);
180 @SuppressWarnings("unchecked")
181 public Map<PolicyTargetType, List<String>> getTargets() {
182 return (Map<PolicyTargetType, List<String>>) getToscaPresentationValue(JsonPresentationFields.TARGETS);
185 public void setTargets(Map<PolicyTargetType, List<String>> metadata) {
186 setToscaPresentationValue(JsonPresentationFields.TARGETS, metadata);
189 public List<String> resolveComponentInstanceTargets() {
190 return resolveTargetsByType(PolicyTargetType.COMPONENT_INSTANCES);
193 public List<String> resolveGroupTargets() {
194 return resolveTargetsByType(PolicyTargetType.GROUPS);
197 public boolean containsTarget(String targetId, PolicyTargetType policyTargetType) {
198 return resolveTargetsByType(policyTargetType).contains(targetId);
201 private List<String> resolveTargetsByType(PolicyTargetType targetType) {
202 Map<PolicyTargetType, List<String>> targets = getTargets();
203 return targets == null || !targets.containsKey(targetType) ? emptyList() : targets.get(targetType);