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