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