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 * ================================================================================
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 jakarta.persistence.ElementCollection;
27 import jakarta.persistence.Entity;
28 import jakarta.persistence.Inheritance;
29 import jakarta.persistence.InheritanceType;
30 import jakarta.persistence.Table;
31 import java.io.Serial;
32 import java.util.ArrayList;
33 import java.util.List;
35 import lombok.EqualsAndHashCode;
36 import lombok.NoArgsConstructor;
37 import lombok.NonNull;
38 import org.onap.policy.common.parameters.annotations.NotNull;
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.PfUtils;
43 import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
46 * Class to represent custom data type in TOSCA definition.
48 * @author Chenfei Gao (cgao@research.att.com)
49 * @author Liam Fallon (liam.fallon@est.tech)
52 @Table(name = "ToscaDataType")
53 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
55 @EqualsAndHashCode(callSuper = true)
57 public class JpaToscaDataType extends JpaToscaWithToscaProperties<ToscaDataType> {
59 private static final long serialVersionUID = -3922690413436539164L;
62 private List<@NotNull @Valid JpaToscaConstraint> constraints;
65 * The Key Constructor creates a {@link JpaToscaDataType} object with the given concept key.
69 public JpaToscaDataType(@NonNull final PfConceptKey key) {
76 * @param copyConcept the concept to copy from
78 public JpaToscaDataType(final JpaToscaDataType copyConcept) {
80 // Constraints are immutable
81 this.constraints = (copyConcept.constraints != null ? new ArrayList<>(copyConcept.constraints) : null);
85 * Authorative constructor.
87 * @param authorativeConcept the authorative concept to copy from
89 public JpaToscaDataType(final ToscaDataType authorativeConcept) {
90 super(authorativeConcept);
94 public ToscaDataType toAuthorative() {
95 var toscaDataType = new ToscaDataType();
96 super.setToscaEntity(toscaDataType);
97 super.toAuthorative();
99 toscaDataType.setConstraints(PfUtils.mapList(constraints, JpaToscaConstraint::toAuthorative));
101 return toscaDataType;
105 public void fromAuthorative(final ToscaDataType toscaDataType) {
106 super.fromAuthorative(toscaDataType);
108 constraints = PfUtils.mapList(toscaDataType.getConstraints(), JpaToscaConstraint::newInstance);
112 public int compareTo(final PfConcept otherConcept) {
113 if (this == otherConcept) {
117 int result = super.compareTo(otherConcept);
122 final JpaToscaDataType other = (JpaToscaDataType) otherConcept;
124 return PfUtils.compareCollections(constraints, other.constraints);