2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019-2020 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 class that allows a
44 * model with many service templates to be constructed that contains a well formed overall TOSCA model.
46 * <p>Validation runs {@link JpaToscaModel} validation on the model and all its sub concepts.
50 @Table(name = "ToscaModel")
51 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
53 @EqualsAndHashCode(callSuper = true)
54 public class JpaToscaModel extends PfModel {
55 private static final long serialVersionUID = 8800599637708309945L;
57 @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
58 private JpaToscaServiceTemplates serviceTemplates;
61 * The Default Constructor creates a {@link JpaToscaModel} object with a null concept key and creates an empty TOSCA
64 public JpaToscaModel() {
65 this(new PfConceptKey());
69 * The Key Constructor creates a {@link JpaToscaModel} object with the given concept key and creates an empty TOSCA
72 * @param key the TOSCA model key
74 public JpaToscaModel(final PfConceptKey key) {
75 this(key, new JpaToscaServiceTemplates(new PfConceptKey()));
79 * Constructor that initiates a {@link JpaToscaModel} with all its fields.
81 * @param key the TOSCA model key
82 * @param serviceTemplates the service templates in the event model
84 public JpaToscaModel(@NonNull final PfConceptKey key, @NonNull final JpaToscaServiceTemplates serviceTemplates) {
86 this.serviceTemplates = serviceTemplates;
92 * @param copyConcept the concept to copy from
94 public JpaToscaModel(@NonNull final JpaToscaModel copyConcept) {
96 this.serviceTemplates = new JpaToscaServiceTemplates(copyConcept.serviceTemplates);
100 public void register() {
101 PfModelService.registerModel(serviceTemplates.getId(), getServiceTemplates());
105 public List<PfKey> getKeys() {
106 final List<PfKey> keyList = super.getKeys();
108 keyList.addAll(serviceTemplates.getKeys());
114 public void clean() {
116 serviceTemplates.clean();
120 public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
121 PfValidationResult result = super.validate(resultIn);
123 return serviceTemplates.validate(result);
127 public int compareTo(final PfConcept otherConcept) {
128 if (otherConcept == null) {
132 if (this == otherConcept) {
136 if (getClass() != otherConcept.getClass()) {
137 return getClass().getName().compareTo(otherConcept.getClass().getName());
140 final JpaToscaModel other = (JpaToscaModel) otherConcept;
141 int result = super.compareTo(other);
146 return serviceTemplates.compareTo(other.serviceTemplates);