Java 17 Upgrade
[policy/models.git] / models-tosca / src / main / java / org / onap / policy / models / tosca / simple / concepts / JpaToscaNodeTypes.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020, 2023 Nordix Foundation.
4  *  Modifications Copyright (C) 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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.models.tosca.simple.concepts;
23
24 import jakarta.persistence.Entity;
25 import jakarta.persistence.Inheritance;
26 import jakarta.persistence.InheritanceType;
27 import jakarta.persistence.Table;
28 import java.io.Serial;
29 import java.util.List;
30 import java.util.Map;
31 import java.util.TreeMap;
32 import lombok.Data;
33 import lombok.EqualsAndHashCode;
34 import lombok.NonNull;
35 import lombok.ToString;
36 import org.onap.policy.common.parameters.BeanValidationResult;
37 import org.onap.policy.models.base.PfConceptContainer;
38 import org.onap.policy.models.base.PfConceptKey;
39 import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeType;
40 import org.onap.policy.models.tosca.utils.ToscaUtils;
41
42 /**
43  * This class is a container for TOSCA node types.
44  */
45 @Entity
46 @Table(name = "ToscaNodeTypes")
47 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
48 @Data
49 @ToString(callSuper = true)
50 @EqualsAndHashCode(callSuper = true)
51 public class JpaToscaNodeTypes extends PfConceptContainer<JpaToscaNodeType, ToscaNodeType> {
52     public static final String DEFAULT_NAME = "ToscaNodeTypesSimple";
53     public static final String DEFAULT_VERSION = "1.0.0";
54     @Serial
55     private static final long serialVersionUID = -4157979965271220098L;
56
57     /**
58      * The Default Constructor creates a {@link JpaToscaNodeTypes} object with a null artifact key and creates an
59      * empty concept map.
60      */
61     public JpaToscaNodeTypes() {
62         super(new PfConceptKey(DEFAULT_NAME, DEFAULT_VERSION));
63     }
64
65     /**
66      * The Key Constructor creates a {@link JpaToscaNodeTypes} object with the given artifact key and creates an
67      * empty concept map.
68      *
69      * @param key the concept key
70      */
71     public JpaToscaNodeTypes(final PfConceptKey key) {
72         super(key, new TreeMap<>());
73     }
74
75     /**
76      * This Constructor creates a concept container with all of its fields defined.
77      *
78      * @param key        the concept container key
79      * @param conceptMap the concepts to be stored in the concept container
80      */
81     public JpaToscaNodeTypes(final PfConceptKey key, final Map<PfConceptKey, JpaToscaNodeType> conceptMap) {
82         super(key, conceptMap);
83     }
84
85     /**
86      * Copy constructor.
87      *
88      * @param copyConcept the concept to copy from
89      */
90     public JpaToscaNodeTypes(final JpaToscaNodeTypes copyConcept) {
91         super(copyConcept);
92     }
93
94     /**
95      * Authorative constructor.
96      *
97      * @param authorativeConceptMapList the authorative concept to copy from
98      */
99     public JpaToscaNodeTypes(final List<Map<String, ToscaNodeType>> authorativeConceptMapList) {
100         super(new PfConceptKey(DEFAULT_NAME, DEFAULT_VERSION));
101         this.fromAuthorative(authorativeConceptMapList);
102     }
103
104     @Override
105     public BeanValidationResult validate(@NonNull String fieldName) {
106         BeanValidationResult result = super.validate(fieldName);
107
108         // Check that all ancestors of this policy type exist
109         for (JpaToscaNodeType nodeType : this.getConceptMap().values()) {
110             ToscaUtils.getEntityTypeAncestors(this, nodeType, result);
111         }
112
113         return result;
114     }
115 }