2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * Modifications Copyright (C) 2019 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.OneToOne;
31 import javax.persistence.Table;
33 import lombok.EqualsAndHashCode;
34 import lombok.NonNull;
35 import org.onap.policy.models.base.PfConcept;
36 import org.onap.policy.models.base.PfConceptKey;
37 import org.onap.policy.models.base.PfKey;
38 import org.onap.policy.models.base.PfModel;
39 import org.onap.policy.models.base.PfModelService;
40 import org.onap.policy.models.base.PfValidationResult;
43 * A container class for a TOSCA model with multiple service templates. This class is a container
44 * class that allows a model with many service templates to be constructed that contains a well
45 * formed overall TOSCA model.
47 * <p>Validation runs {@link JpaToscaModel} validation on the model and all its sub concepts.
51 @Table(name = "ToscaModel")
52 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
54 @EqualsAndHashCode(callSuper = true)
55 public class JpaToscaModel extends PfModel {
56 private static final long serialVersionUID = 8800599637708309945L;
58 @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
59 private JpaToscaServiceTemplates serviceTemplates;
62 * The Default Constructor creates a {@link JpaToscaModel} object with a null concept key and
63 * creates an empty TOSCA model.
65 public JpaToscaModel() {
66 this(new PfConceptKey());
70 * The Key Constructor creates a {@link JpaToscaModel} object with the given concept key and
71 * creates an empty TOSCA model.
73 * @param key the TOSCA model key
75 public JpaToscaModel(final PfConceptKey key) {
76 this(key, new JpaToscaServiceTemplates(new PfConceptKey()));
80 * Constructor that initiates a {@link JpaToscaModel} with all its fields.
82 * @param key the TOSCA model key
83 * @param serviceTemplates the service templates in the event model
85 public JpaToscaModel(@NonNull final PfConceptKey key, @NonNull final JpaToscaServiceTemplates serviceTemplates) {
87 this.serviceTemplates = serviceTemplates;
93 * @param copyConcept the concept to copy from
95 public JpaToscaModel(@NonNull final JpaToscaModel copyConcept) {
97 this.serviceTemplates = new JpaToscaServiceTemplates(copyConcept.serviceTemplates);
101 public void register() {
102 PfModelService.registerModel(serviceTemplates.getId(), getServiceTemplates());
106 public List<PfKey> getKeys() {
107 final List<PfKey> keyList = super.getKeys();
109 keyList.addAll(serviceTemplates.getKeys());
115 public void clean() {
117 serviceTemplates.clean();
121 public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
122 PfValidationResult result = super.validate(resultIn);
124 return serviceTemplates.validate(result);
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 if (!super.equals(other)) {
143 return super.compareTo(other);
146 return serviceTemplates.compareTo(other.serviceTemplates);