JPA concepts for TOSCA
[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 Nordix Foundation.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.models.tosca.simple.concepts;
22
23 import java.util.List;
24 import java.util.Map;
25 import java.util.TreeMap;
26 import javax.persistence.Entity;
27 import javax.persistence.Inheritance;
28 import javax.persistence.InheritanceType;
29 import javax.persistence.Table;
30 import lombok.Data;
31 import lombok.EqualsAndHashCode;
32 import lombok.NonNull;
33 import lombok.ToString;
34 import org.onap.policy.models.base.PfAuthorative;
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.ToscaCapabilityAssignment;
39 import org.onap.policy.models.tosca.utils.ToscaUtils;
40
41 /**
42  * This class is a container for TOSCA capability assignments.
43  *
44  * @author Liam Fallon (liam.fallon@est.tech)
45  */
46 @Entity
47 @Table(name = "ToscaCapabilityAssignments")
48 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
49 @Data
50 @ToString(callSuper = true)
51 @EqualsAndHashCode(callSuper = true)
52 public class JpaToscaCapabilityAssignments
53                 extends PfConceptContainer<JpaToscaCapabilityAssignment, ToscaCapabilityAssignment>
54                 implements PfAuthorative<List<Map<String, ToscaCapabilityAssignment>>> {
55     public static final String DEFAULT_NAME = "ToscaCapabilityAssignmentsSimple";
56     public static final String DEFAULT_VERSION = "1.0.0";
57     private static final long serialVersionUID = -7526648702327776101L;
58
59     /**
60      * The Default Constructor creates a {@link JpaToscaCapabilityAssignments} object with a null
61      * artifact key and creates an empty concept map.
62      */
63     public JpaToscaCapabilityAssignments() {
64         super(new PfConceptKey(DEFAULT_NAME, DEFAULT_VERSION));
65     }
66
67     /**
68      * The Key Constructor creates a {@link JpaToscaCapabilityAssignments} object with the given
69      * artifact key and creates an empty concept map.
70      *
71      * @param key the concept key
72      */
73     public JpaToscaCapabilityAssignments(final PfConceptKey key) {
74         super(key, new TreeMap<>());
75     }
76
77     /**
78      * This Constructor creates an concept container with all of its fields defined.
79      *
80      * @param key the concept container key
81      * @param conceptMap the concepts to be stored in the concept container
82      */
83     public JpaToscaCapabilityAssignments(final PfConceptKey key,
84                     final Map<PfConceptKey, JpaToscaCapabilityAssignment> conceptMap) {
85         super(key, conceptMap);
86     }
87
88     /**
89      * Copy constructor.
90      *
91      * @param copyConcept the concept to copy from
92      */
93     public JpaToscaCapabilityAssignments(final JpaToscaCapabilityAssignments copyConcept) {
94         super(copyConcept);
95     }
96
97     /**
98      * Authorative constructor.
99      *
100      * @param authorativeConceptMapList the authorative concept to copy from
101      */
102     public JpaToscaCapabilityAssignments(final List<Map<String, ToscaCapabilityAssignment>> authorativeConceptMapList) {
103         super(new PfConceptKey(DEFAULT_NAME, DEFAULT_VERSION));
104         this.fromAuthorative(authorativeConceptMapList);
105     }
106
107     @Override
108     public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
109         PfValidationResult result = super.validate(resultIn);
110
111         for (JpaToscaCapabilityAssignment assignment : this.getConceptMap().values()) {
112             ToscaUtils.getEntityTypeAncestors(this, assignment, result);
113         }
114
115         return result;
116     }
117 }