Java 17 Upgrade
[policy/models.git] / models-tosca / src / main / java / org / onap / policy / models / tosca / simple / concepts / JpaToscaCapabilityAssignments.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.PfAuthorative;
38 import org.onap.policy.models.base.PfConceptContainer;
39 import org.onap.policy.models.base.PfConceptKey;
40 import org.onap.policy.models.tosca.authorative.concepts.ToscaCapabilityAssignment;
41 import org.onap.policy.models.tosca.utils.ToscaUtils;
42
43 /**
44  * This class is a container for TOSCA capability assignments.
45  *
46  * @author Liam Fallon (liam.fallon@est.tech)
47  */
48 @Entity
49 @Table(name = "ToscaCapabilityAssignments")
50 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
51 @Data
52 @ToString(callSuper = true)
53 @EqualsAndHashCode(callSuper = true)
54 public class JpaToscaCapabilityAssignments
55                 extends PfConceptContainer<JpaToscaCapabilityAssignment, ToscaCapabilityAssignment>
56                 implements PfAuthorative<List<Map<String, ToscaCapabilityAssignment>>> {
57     public static final String DEFAULT_NAME = "ToscaCapabilityAssignmentsSimple";
58     public static final String DEFAULT_VERSION = "1.0.0";
59     @Serial
60     private static final long serialVersionUID = -7526648702327776101L;
61
62     /**
63      * The Default Constructor creates a {@link JpaToscaCapabilityAssignments} object with a null
64      * artifact key and creates an empty concept map.
65      */
66     public JpaToscaCapabilityAssignments() {
67         super(new PfConceptKey(DEFAULT_NAME, DEFAULT_VERSION));
68     }
69
70     /**
71      * The Key Constructor creates a {@link JpaToscaCapabilityAssignments} object with the given
72      * artifact key and creates an empty concept map.
73      *
74      * @param key the concept key
75      */
76     public JpaToscaCapabilityAssignments(final PfConceptKey key) {
77         super(key, new TreeMap<>());
78     }
79
80     /**
81      * This Constructor creates a concept container with all of its fields defined.
82      *
83      * @param key the concept container key
84      * @param conceptMap the concepts to be stored in the concept container
85      */
86     public JpaToscaCapabilityAssignments(final PfConceptKey key,
87                     final Map<PfConceptKey, JpaToscaCapabilityAssignment> conceptMap) {
88         super(key, conceptMap);
89     }
90
91     /**
92      * Copy constructor.
93      *
94      * @param copyConcept the concept to copy from
95      */
96     public JpaToscaCapabilityAssignments(final JpaToscaCapabilityAssignments copyConcept) {
97         super(copyConcept);
98     }
99
100     /**
101      * Authorative constructor.
102      *
103      * @param authorativeConceptMapList the authorative concept to copy from
104      */
105     public JpaToscaCapabilityAssignments(final List<Map<String, ToscaCapabilityAssignment>> authorativeConceptMapList) {
106         super(new PfConceptKey(DEFAULT_NAME, DEFAULT_VERSION));
107         this.fromAuthorative(authorativeConceptMapList);
108     }
109
110     @Override
111     public BeanValidationResult validate(@NonNull String fieldName) {
112         BeanValidationResult result = super.validate(fieldName);
113
114         for (JpaToscaCapabilityAssignment assignment : this.getConceptMap().values()) {
115             ToscaUtils.getEntityTypeAncestors(this, assignment, result);
116         }
117
118         return result;
119     }
120 }