2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019-2020, 2023 Nordix Foundation.
4 * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
5 * Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.models.tosca.simple.concepts;
25 import jakarta.persistence.CascadeType;
26 import jakarta.persistence.Entity;
27 import jakarta.persistence.FetchType;
28 import jakarta.persistence.Inheritance;
29 import jakarta.persistence.InheritanceType;
30 import jakarta.persistence.JoinColumn;
31 import jakarta.persistence.JoinColumns;
32 import jakarta.persistence.OneToOne;
33 import jakarta.persistence.Table;
34 import java.util.List;
36 import lombok.EqualsAndHashCode;
37 import lombok.NonNull;
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.PfKey;
42 import org.onap.policy.models.base.PfModel;
43 import org.onap.policy.models.base.PfModelService;
46 * A container class for a TOSCA model with multiple service templates. This class is a container class that allows a
47 * model with many service templates to be constructed that contains a well-formed overall TOSCA model.
49 * <p>Validation runs {@link JpaToscaModel} validation on the model and all its sub concepts.
53 @Table(name = "ToscaModel")
54 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
56 @EqualsAndHashCode(callSuper = true)
57 public class JpaToscaModel extends PfModel {
58 private static final long serialVersionUID = 8800599637708309945L;
60 @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
61 @JoinColumn(name = "serviceTemplatesName", referencedColumnName = "name")
62 @JoinColumn(name = "serviceTemplatesVersion", referencedColumnName = "version")
64 private JpaToscaServiceTemplates serviceTemplates;
67 * The Default Constructor creates a {@link JpaToscaModel} object with a null concept key and creates an empty TOSCA
70 public JpaToscaModel() {
71 this(new PfConceptKey());
75 * The Key Constructor creates a {@link JpaToscaModel} object with the given concept key and creates an empty TOSCA
78 * @param key the TOSCA model key
80 public JpaToscaModel(final PfConceptKey key) {
81 this(key, new JpaToscaServiceTemplates(new PfConceptKey()));
85 * Constructor that initiates a {@link JpaToscaModel} with all its fields.
87 * @param key the TOSCA model key
88 * @param serviceTemplates the service templates in the event model
90 public JpaToscaModel(@NonNull final PfConceptKey key, @NonNull final JpaToscaServiceTemplates serviceTemplates) {
92 this.serviceTemplates = serviceTemplates;
98 * @param copyConcept the concept to copy from
100 public JpaToscaModel(@NonNull final JpaToscaModel copyConcept) {
102 this.serviceTemplates = new JpaToscaServiceTemplates(copyConcept.serviceTemplates);
106 public void register() {
107 PfModelService.registerModel(serviceTemplates.getId(), getServiceTemplates());
111 public List<PfKey> getKeys() {
112 final List<PfKey> keyList = super.getKeys();
114 keyList.addAll(serviceTemplates.getKeys());
120 public void clean() {
122 serviceTemplates.clean();
126 public int compareTo(final PfConcept otherConcept) {
127 if (otherConcept == null) {
131 if (this == otherConcept) {
135 if (getClass() != otherConcept.getClass()) {
136 return getClass().getName().compareTo(otherConcept.getClass().getName());
139 final JpaToscaModel other = (JpaToscaModel) otherConcept;
140 int result = super.compareTo(other);
145 return serviceTemplates.compareTo(other.serviceTemplates);