2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019-2020 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
20 * SPDX-License-Identifier: Apache-2.0
21 * ============LICENSE_END=========================================================
24 package org.onap.policy.models.tosca.simple.concepts;
26 import java.util.List;
27 import javax.persistence.ElementCollection;
28 import javax.persistence.Entity;
29 import javax.persistence.Inheritance;
30 import javax.persistence.InheritanceType;
31 import javax.persistence.Table;
33 import lombok.EqualsAndHashCode;
34 import lombok.NoArgsConstructor;
35 import lombok.NonNull;
36 import org.onap.policy.common.parameters.BeanValidationResult;
37 import org.onap.policy.common.parameters.annotations.NotNull;
38 import org.onap.policy.common.parameters.annotations.Valid;
39 import org.onap.policy.models.base.PfConcept;
40 import org.onap.policy.models.base.PfConceptKey;
41 import org.onap.policy.models.base.PfKey;
42 import org.onap.policy.models.base.PfUtils;
43 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
46 * Class to represent the policy type in TOSCA definition.
48 * @author Chenfei Gao (cgao@research.att.com)
49 * @author Liam Fallon (liam.fallon@est.tech)
53 @Table(name = "ToscaPolicyType")
54 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
56 @EqualsAndHashCode(callSuper = true)
58 public class JpaToscaPolicyType extends JpaToscaWithToscaProperties<ToscaPolicyType> {
59 private static final long serialVersionUID = -563659852901842616L;
62 private List<@NotNull @Valid PfConceptKey> targets;
65 private List<@NotNull @Valid JpaToscaTrigger> triggers;
68 * The Key Constructor creates a {@link JpaToscaPolicyType} object with the given concept key.
72 public JpaToscaPolicyType(@NonNull final PfConceptKey key) {
79 * @param copyConcept the concept to copy from
81 public JpaToscaPolicyType(final JpaToscaPolicyType copyConcept) {
83 this.targets = PfUtils.mapList(copyConcept.targets, PfConceptKey::new);
84 this.triggers = PfUtils.mapList(copyConcept.triggers, JpaToscaTrigger::new);
88 * Authorative constructor.
90 * @param authorativeConcept the authorative concept to copy from
92 public JpaToscaPolicyType(final ToscaPolicyType authorativeConcept) {
93 super(authorativeConcept);
97 public ToscaPolicyType toAuthorative() {
98 ToscaPolicyType toscaPolicyType = new ToscaPolicyType();
99 super.setToscaEntity(toscaPolicyType);
100 super.toAuthorative();
102 // TODO need to copy targets & triggers?
104 return toscaPolicyType;
108 public void fromAuthorative(final ToscaPolicyType toscaPolicyType) {
109 super.fromAuthorative(toscaPolicyType);
111 // TODO need to copy targets & triggers?
115 public List<PfKey> getKeys() {
116 final List<PfKey> keyList = super.getKeys();
118 if (targets != null) {
119 keyList.addAll(targets);
122 if (triggers != null) {
123 for (JpaToscaTrigger trigger : triggers) {
124 keyList.addAll(trigger.getKeys());
132 public void clean() {
135 if (targets != null) {
136 for (PfConceptKey target : targets) {
141 if (triggers != null) {
142 for (JpaToscaTrigger trigger : triggers) {
149 public BeanValidationResult validate(@NonNull String fieldName) {
150 return validateWithKey(fieldName);
154 public int compareTo(final PfConcept otherConcept) {
155 if (this == otherConcept) {
159 int result = super.compareTo(otherConcept);
164 final JpaToscaPolicyType other = (JpaToscaPolicyType) otherConcept;
166 result = PfUtils.compareCollections(targets, other.targets);
171 return PfUtils.compareCollections(triggers, other.triggers);