2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2019-2020 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 java.util.ArrayList;
27 import java.util.List;
28 import javax.persistence.ElementCollection;
29 import javax.persistence.Entity;
30 import javax.persistence.Inheritance;
31 import javax.persistence.InheritanceType;
32 import javax.persistence.Table;
34 import lombok.EqualsAndHashCode;
35 import lombok.NoArgsConstructor;
36 import lombok.NonNull;
37 import org.onap.policy.common.parameters.annotations.NotNull;
38 import org.onap.policy.common.parameters.annotations.Valid;
39 import org.onap.policy.models.base.PfConcept;
40 import org.onap.policy.models.base.PfConceptKey;
41 import org.onap.policy.models.base.PfUtils;
42 import org.onap.policy.models.tosca.authorative.concepts.ToscaDataType;
45 * Class to represent custom data type in TOSCA definition.
47 * @author Chenfei Gao (cgao@research.att.com)
48 * @author Liam Fallon (liam.fallon@est.tech)
51 @Table(name = "ToscaDataType")
52 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
54 @EqualsAndHashCode(callSuper = true)
56 public class JpaToscaDataType extends JpaToscaWithToscaProperties<ToscaDataType> {
57 private static final long serialVersionUID = -3922690413436539164L;
60 private List<@NotNull @Valid JpaToscaConstraint> constraints;
63 * The Key Constructor creates a {@link JpaToscaDataType} object with the given concept key.
67 public JpaToscaDataType(@NonNull final PfConceptKey key) {
74 * @param copyConcept the concept to copy from
76 public JpaToscaDataType(final JpaToscaDataType copyConcept) {
78 // Constraints are immutable
79 this.constraints = (copyConcept.constraints != null ? new ArrayList<>(copyConcept.constraints) : null);
83 * Authorative constructor.
85 * @param authorativeConcept the authorative concept to copy from
87 public JpaToscaDataType(final ToscaDataType authorativeConcept) {
88 super(authorativeConcept);
92 public ToscaDataType toAuthorative() {
93 var toscaDataType = new ToscaDataType();
94 super.setToscaEntity(toscaDataType);
95 super.toAuthorative();
97 toscaDataType.setConstraints(PfUtils.mapList(constraints, JpaToscaConstraint::toAuthorative));
103 public void fromAuthorative(final ToscaDataType toscaDataType) {
104 super.fromAuthorative(toscaDataType);
106 constraints = PfUtils.mapList(toscaDataType.getConstraints(), JpaToscaConstraint::newInstance);
110 public int compareTo(final PfConcept otherConcept) {
111 if (this == otherConcept) {
115 int result = super.compareTo(otherConcept);
120 final JpaToscaDataType other = (JpaToscaDataType) otherConcept;
122 return PfUtils.compareCollections(constraints, other.constraints);