2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020, 2023 Nordix Foundation.
4 * Modifications Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.models.tosca.simple.concepts;
24 import jakarta.persistence.CascadeType;
25 import jakarta.persistence.Entity;
26 import jakarta.persistence.FetchType;
27 import jakarta.persistence.Inheritance;
28 import jakarta.persistence.InheritanceType;
29 import jakarta.persistence.JoinColumn;
30 import jakarta.persistence.OneToOne;
31 import jakarta.persistence.Table;
32 import java.io.Serial;
33 import java.util.List;
35 import lombok.EqualsAndHashCode;
36 import lombok.NoArgsConstructor;
37 import lombok.NonNull;
38 import org.apache.commons.lang3.ObjectUtils;
39 import org.onap.policy.common.parameters.BeanValidationResult;
40 import org.onap.policy.common.parameters.annotations.Valid;
41 import org.onap.policy.models.base.PfConcept;
42 import org.onap.policy.models.base.PfConceptKey;
43 import org.onap.policy.models.base.PfKey;
44 import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeType;
47 * Class to represent the node type in TOSCA definition.
51 @Table(name = "ToscaNodeType")
52 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
54 @EqualsAndHashCode(callSuper = true)
56 public class JpaToscaNodeType extends JpaToscaWithToscaProperties<ToscaNodeType> {
58 private static final long serialVersionUID = -563659852901842616L;
62 @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
63 @JoinColumn(name = "requirementsName", referencedColumnName = "name")
64 @JoinColumn(name = "requirementsVersion", referencedColumnName = "version")
67 private JpaToscaRequirements requirements;
70 * The Key Constructor creates a {@link JpaToscaNodeType} object with the given concept key.
74 public JpaToscaNodeType(@NonNull final PfConceptKey key) {
81 * @param copyConcept the concept to copy from
83 public JpaToscaNodeType(final JpaToscaNodeType copyConcept) {
86 (copyConcept.requirements != null ? new JpaToscaRequirements(copyConcept.requirements) : null);
90 * Authorative constructor.
92 * @param authorativeConcept the authorative concept to copy from
94 public JpaToscaNodeType(final ToscaNodeType authorativeConcept) {
95 super(authorativeConcept);
99 public ToscaNodeType toAuthorative() {
100 var toscaNodeType = new ToscaNodeType();
101 super.setToscaEntity(toscaNodeType);
102 super.toAuthorative();
104 if (requirements != null) {
105 toscaNodeType.setRequirements(requirements.toAuthorative());
108 return toscaNodeType;
112 public void fromAuthorative(final ToscaNodeType toscaNodeType) {
113 super.fromAuthorative(toscaNodeType);
115 if (toscaNodeType.getRequirements() != null) {
116 requirements = new JpaToscaRequirements();
117 requirements.fromAuthorative(toscaNodeType.getRequirements());
122 public List<PfKey> getKeys() {
123 final List<PfKey> keyList = super.getKeys();
125 if (requirements != null) {
126 keyList.addAll(requirements.getKeys());
133 public void clean() {
136 if (requirements != null) {
137 requirements.clean();
142 public BeanValidationResult validate(String fieldName) {
143 return validateWithKey(fieldName);
147 public int compareTo(final PfConcept otherConcept) {
148 if (this == otherConcept) {
152 int result = super.compareTo(otherConcept);
157 final JpaToscaNodeType other = (JpaToscaNodeType) otherConcept;
159 return ObjectUtils.compare(requirements, other.requirements);