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 java.util.List;
25 import javax.persistence.CascadeType;
26 import javax.persistence.Entity;
27 import javax.persistence.FetchType;
28 import javax.persistence.Inheritance;
29 import javax.persistence.InheritanceType;
30 import javax.persistence.JoinColumn;
31 import javax.persistence.JoinColumns;
32 import javax.persistence.OneToOne;
33 import javax.persistence.Table;
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> {
57 private static final long serialVersionUID = -563659852901842616L;
61 @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
63 @JoinColumn(name = "requirementsName", referencedColumnName = "name"),
64 @JoinColumn(name = "requirementsVersion", referencedColumnName = "version")
68 private JpaToscaRequirements requirements;
71 * The Key Constructor creates a {@link JpaToscaNodeType} object with the given concept key.
75 public JpaToscaNodeType(@NonNull final PfConceptKey key) {
82 * @param copyConcept the concept to copy from
84 public JpaToscaNodeType(final JpaToscaNodeType copyConcept) {
87 (copyConcept.requirements != null ? new JpaToscaRequirements(copyConcept.requirements) : null);
91 * Authorative constructor.
93 * @param authorativeConcept the authorative concept to copy from
95 public JpaToscaNodeType(final ToscaNodeType authorativeConcept) {
96 super(authorativeConcept);
100 public ToscaNodeType toAuthorative() {
101 var toscaNodeType = new ToscaNodeType();
102 super.setToscaEntity(toscaNodeType);
103 super.toAuthorative();
105 if (requirements != null) {
106 toscaNodeType.setRequirements(requirements.toAuthorative());
109 return toscaNodeType;
113 public void fromAuthorative(final ToscaNodeType toscaNodeType) {
114 super.fromAuthorative(toscaNodeType);
116 if (toscaNodeType.getRequirements() != null) {
117 requirements = new JpaToscaRequirements();
118 requirements.fromAuthorative(toscaNodeType.getRequirements());
123 public List<PfKey> getKeys() {
124 final List<PfKey> keyList = super.getKeys();
126 if (requirements != null) {
127 keyList.addAll(requirements.getKeys());
134 public void clean() {
137 if (requirements != null) {
138 requirements.clean();
143 public BeanValidationResult validate(String fieldName) {
144 return validateWithKey(fieldName);
148 public int compareTo(final PfConcept otherConcept) {
149 if (this == otherConcept) {
153 int result = super.compareTo(otherConcept);
158 final JpaToscaNodeType other = (JpaToscaNodeType) otherConcept;
160 return ObjectUtils.compare(requirements, other.requirements);