2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 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.OneToOne;
32 import javax.persistence.Table;
34 import lombok.EqualsAndHashCode;
35 import lombok.NoArgsConstructor;
36 import lombok.NonNull;
37 import org.apache.commons.lang3.ObjectUtils;
38 import org.onap.policy.common.parameters.BeanValidationResult;
39 import org.onap.policy.common.parameters.annotations.Valid;
40 import org.onap.policy.models.base.PfConcept;
41 import org.onap.policy.models.base.PfConceptKey;
42 import org.onap.policy.models.base.PfKey;
43 import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeType;
46 * Class to represent the node type in TOSCA definition.
50 @Table(name = "ToscaNodeType")
51 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
53 @EqualsAndHashCode(callSuper = true)
55 public class JpaToscaNodeType extends JpaToscaWithToscaProperties<ToscaNodeType> {
56 private static final long serialVersionUID = -563659852901842616L;
60 @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
61 @JoinColumn(name = "requirementsName", referencedColumnName = "name")
62 @JoinColumn(name = "requirementsVersion", referencedColumnName = "version")
65 private JpaToscaRequirements requirements;
68 * The Key Constructor creates a {@link JpaToscaNodeType} object with the given concept key.
72 public JpaToscaNodeType(@NonNull final PfConceptKey key) {
79 * @param copyConcept the concept to copy from
81 public JpaToscaNodeType(final JpaToscaNodeType copyConcept) {
84 (copyConcept.requirements != null ? new JpaToscaRequirements(copyConcept.requirements) : null);
88 * Authorative constructor.
90 * @param authorativeConcept the authorative concept to copy from
92 public JpaToscaNodeType(final ToscaNodeType authorativeConcept) {
93 super(authorativeConcept);
97 public ToscaNodeType toAuthorative() {
98 var toscaNodeType = new ToscaNodeType();
99 super.setToscaEntity(toscaNodeType);
100 super.toAuthorative();
102 if (requirements != null) {
103 toscaNodeType.setRequirements(requirements.toAuthorative());
106 return toscaNodeType;
110 public void fromAuthorative(final ToscaNodeType toscaNodeType) {
111 super.fromAuthorative(toscaNodeType);
113 if (toscaNodeType.getRequirements() != null) {
114 requirements = new JpaToscaRequirements();
115 requirements.fromAuthorative(toscaNodeType.getRequirements());
120 public List<PfKey> getKeys() {
121 final List<PfKey> keyList = super.getKeys();
123 if (requirements != null) {
124 keyList.addAll(requirements.getKeys());
131 public void clean() {
134 if (requirements != null) {
135 requirements.clean();
140 public BeanValidationResult validate(String fieldName) {
141 return validateWithKey(fieldName);
145 public int compareTo(final PfConcept otherConcept) {
146 if (this == otherConcept) {
150 int result = super.compareTo(otherConcept);
155 final JpaToscaNodeType other = (JpaToscaNodeType) otherConcept;
157 return ObjectUtils.compare(requirements, other.requirements);