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 java.util.List;
26 import javax.persistence.CascadeType;
27 import javax.persistence.Entity;
28 import javax.persistence.FetchType;
29 import javax.persistence.Inheritance;
30 import javax.persistence.InheritanceType;
31 import javax.persistence.JoinColumn;
32 import javax.persistence.JoinColumns;
33 import javax.persistence.OneToOne;
34 import javax.persistence.Table;
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)
62 @JoinColumn(name = "serviceTemplatesName", referencedColumnName = "name"),
63 @JoinColumn(name = "serviceTemplatesVersion", referencedColumnName = "version")
66 private JpaToscaServiceTemplates serviceTemplates;
69 * The Default Constructor creates a {@link JpaToscaModel} object with a null concept key and creates an empty TOSCA
72 public JpaToscaModel() {
73 this(new PfConceptKey());
77 * The Key Constructor creates a {@link JpaToscaModel} object with the given concept key and creates an empty TOSCA
80 * @param key the TOSCA model key
82 public JpaToscaModel(final PfConceptKey key) {
83 this(key, new JpaToscaServiceTemplates(new PfConceptKey()));
87 * Constructor that initiates a {@link JpaToscaModel} with all its fields.
89 * @param key the TOSCA model key
90 * @param serviceTemplates the service templates in the event model
92 public JpaToscaModel(@NonNull final PfConceptKey key, @NonNull final JpaToscaServiceTemplates serviceTemplates) {
94 this.serviceTemplates = serviceTemplates;
100 * @param copyConcept the concept to copy from
102 public JpaToscaModel(@NonNull final JpaToscaModel copyConcept) {
104 this.serviceTemplates = new JpaToscaServiceTemplates(copyConcept.serviceTemplates);
108 public void register() {
109 PfModelService.registerModel(serviceTemplates.getId(), getServiceTemplates());
113 public List<PfKey> getKeys() {
114 final List<PfKey> keyList = super.getKeys();
116 keyList.addAll(serviceTemplates.getKeys());
122 public void clean() {
124 serviceTemplates.clean();
128 public int compareTo(final PfConcept otherConcept) {
129 if (otherConcept == null) {
133 if (this == otherConcept) {
137 if (getClass() != otherConcept.getClass()) {
138 return getClass().getName().compareTo(otherConcept.getClass().getName());
141 final JpaToscaModel other = (JpaToscaModel) otherConcept;
142 int result = super.compareTo(other);
147 return serviceTemplates.compareTo(other.serviceTemplates);