2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019-2020 Nordix Foundation.
4 * Modifications Copyright (C) 2019-2020 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;
26 import java.util.TreeMap;
27 import javax.persistence.Entity;
28 import javax.persistence.Inheritance;
29 import javax.persistence.InheritanceType;
30 import javax.persistence.Table;
32 import lombok.EqualsAndHashCode;
33 import lombok.NonNull;
34 import lombok.ToString;
35 import org.onap.policy.models.base.PfConceptContainer;
36 import org.onap.policy.models.base.PfConceptKey;
37 import org.onap.policy.models.base.PfValidationResult;
38 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
39 import org.onap.policy.models.tosca.utils.ToscaUtils;
42 * This class is a container for TOSCA policy types.
44 * @author Liam Fallon (liam.fallon@est.tech)
47 @Table(name = "ToscaPolicyTypes")
48 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
50 @ToString(callSuper = true)
51 @EqualsAndHashCode(callSuper = true)
52 public class JpaToscaPolicyTypes extends PfConceptContainer<JpaToscaPolicyType, ToscaPolicyType> {
53 private static final long serialVersionUID = -4157979965271220098L;
55 public static final String DEFAULT_NAME = "ToscaPolicyTypesSimple";
56 public static final String DEFAULT_VERSION = "1.0.0";
59 * The Default Constructor creates a {@link JpaToscaPolicyTypes} object with a null artifact key and creates an
62 public JpaToscaPolicyTypes() {
63 super(new PfConceptKey(DEFAULT_NAME, DEFAULT_VERSION));
67 * The Key Constructor creates a {@link JpaToscaPolicyTypes} object with the given artifact key and creates an empty
70 * @param key the concept key
72 public JpaToscaPolicyTypes(final PfConceptKey key) {
73 super(key, new TreeMap<>());
77 * This Constructor creates an concept container with all of its fields defined.
79 * @param key the concept container key
80 * @param conceptMap the concepts to be stored in the concept container
82 public JpaToscaPolicyTypes(final PfConceptKey key, final Map<PfConceptKey, JpaToscaPolicyType> conceptMap) {
83 super(key, conceptMap);
89 * @param copyConcept the concept to copy from
91 public JpaToscaPolicyTypes(final JpaToscaPolicyTypes copyConcept) {
96 * Authorative constructor.
98 * @param authorativeConceptMapList the authorative concept to copy from
100 public JpaToscaPolicyTypes(final List<Map<String, ToscaPolicyType>> authorativeConceptMapList) {
101 super(new PfConceptKey(DEFAULT_NAME, DEFAULT_VERSION));
102 this.fromAuthorative(authorativeConceptMapList);
106 public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
107 PfValidationResult result = super.validate(resultIn);
109 // Check that all ancestors of this policy type exist
110 for (JpaToscaPolicyType policyType : this.getConceptMap().values()) {
111 ToscaUtils.getEntityTypeAncestors(this, policyType, result);