2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019-2020, 2023 Nordix Foundation.
7 * Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
21 * SPDX-License-Identifier: Apache-2.0
22 * ============LICENSE_END=========================================================
25 package org.onap.policy.models.tosca.simple.concepts;
27 import jakarta.persistence.CollectionTable;
28 import jakarta.persistence.ElementCollection;
29 import jakarta.persistence.Entity;
30 import jakarta.persistence.Inheritance;
31 import jakarta.persistence.InheritanceType;
32 import jakarta.persistence.JoinColumn;
33 import jakarta.persistence.Lob;
34 import jakarta.persistence.Table;
35 import java.io.Serial;
36 import java.util.List;
38 import lombok.EqualsAndHashCode;
39 import lombok.NoArgsConstructor;
40 import lombok.NonNull;
41 import org.onap.policy.common.parameters.BeanValidationResult;
42 import org.onap.policy.common.parameters.annotations.NotNull;
43 import org.onap.policy.common.parameters.annotations.Valid;
44 import org.onap.policy.models.base.PfConcept;
45 import org.onap.policy.models.base.PfConceptKey;
46 import org.onap.policy.models.base.PfKey;
47 import org.onap.policy.models.base.PfUtils;
48 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
51 * Class to represent the policy type in TOSCA definition.
53 * @author Chenfei Gao (cgao@research.att.com)
54 * @author Liam Fallon (liam.fallon@est.tech)
58 @Table(name = "ToscaPolicyType")
59 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
61 @EqualsAndHashCode(callSuper = true)
63 public class JpaToscaPolicyType extends JpaToscaWithToscaProperties<ToscaPolicyType> {
65 private static final long serialVersionUID = -563659852901842616L;
68 @CollectionTable(joinColumns = {
69 @JoinColumn(name = "toscaPolicyTypeName", referencedColumnName = "name"),
70 @JoinColumn(name = "toscaPolicyTypeVersion", referencedColumnName = "version")
72 private List<@NotNull @Valid PfConceptKey> targets;
76 private List<@NotNull @Valid JpaToscaTrigger> triggers;
79 * The Key Constructor creates a {@link JpaToscaPolicyType} object with the given concept key.
83 public JpaToscaPolicyType(@NonNull final PfConceptKey key) {
90 * @param copyConcept the concept to copy from
92 public JpaToscaPolicyType(final JpaToscaPolicyType copyConcept) {
94 this.targets = PfUtils.mapList(copyConcept.targets, PfConceptKey::new);
95 this.triggers = PfUtils.mapList(copyConcept.triggers, JpaToscaTrigger::new);
99 * Authorative constructor.
101 * @param authorativeConcept the authorative concept to copy from
103 public JpaToscaPolicyType(final ToscaPolicyType authorativeConcept) {
104 super(authorativeConcept);
108 public ToscaPolicyType toAuthorative() {
109 var toscaPolicyType = new ToscaPolicyType();
110 super.setToscaEntity(toscaPolicyType);
111 super.toAuthorative();
113 // TODO need to copy targets & triggers?
115 return toscaPolicyType;
119 public void fromAuthorative(final ToscaPolicyType toscaPolicyType) {
120 super.fromAuthorative(toscaPolicyType);
122 // TODO need to copy targets & triggers?
126 public List<PfKey> getKeys() {
127 final List<PfKey> keyList = super.getKeys();
129 if (targets != null) {
130 keyList.addAll(targets);
133 if (triggers != null) {
134 for (JpaToscaTrigger trigger : triggers) {
135 keyList.addAll(trigger.getKeys());
143 public void clean() {
146 if (targets != null) {
147 for (PfConceptKey target : targets) {
152 if (triggers != null) {
153 for (JpaToscaTrigger trigger : triggers) {
160 public BeanValidationResult validate(@NonNull String fieldName) {
161 return validateWithKey(fieldName);
165 public int compareTo(final PfConcept otherConcept) {
166 if (this == otherConcept) {
170 int result = super.compareTo(otherConcept);
175 final JpaToscaPolicyType other = (JpaToscaPolicyType) otherConcept;
177 result = PfUtils.compareCollections(targets, other.targets);
182 return PfUtils.compareCollections(triggers, other.triggers);