9c059b483c47c38a83c166d3d1ee58653b2a7646
[policy/models.git] / models-tosca / src / main / java / org / onap / policy / models / tosca / simple / concepts / JpaToscaPolicyTypes.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019-2020 Nordix Foundation.
4  *  Modifications Copyright (C) 2019 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
28 import javax.persistence.Entity;
29 import javax.persistence.Inheritance;
30 import javax.persistence.InheritanceType;
31 import javax.persistence.Table;
32
33 import lombok.Data;
34 import lombok.EqualsAndHashCode;
35 import lombok.NonNull;
36 import lombok.ToString;
37
38 import org.onap.policy.models.base.PfConceptContainer;
39 import org.onap.policy.models.base.PfConceptKey;
40 import org.onap.policy.models.base.PfValidationResult;
41 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
42 import org.onap.policy.models.tosca.utils.ToscaUtils;
43
44 /**
45  * This class is a container for TOSCA policy types.
46  *
47  * @author Liam Fallon (liam.fallon@est.tech)
48  */
49 @Entity
50 @Table(name = "ToscaPolicyTypes")
51 @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
52 @Data
53 @ToString(callSuper = true)
54 @EqualsAndHashCode(callSuper = true)
55 public class JpaToscaPolicyTypes extends PfConceptContainer<JpaToscaPolicyType, ToscaPolicyType> {
56     private static final long serialVersionUID = -4157979965271220098L;
57
58     public static final String DEFAULT_NAME = "ToscaPolicyTypesSimple";
59     public static final String DEFAULT_VERSION = "1.0.0";
60
61     /**
62      * The Default Constructor creates a {@link JpaToscaPolicyTypes} object with a null artifact key and creates an
63      * empty concept map.
64      */
65     public JpaToscaPolicyTypes() {
66         super(new PfConceptKey(DEFAULT_NAME, DEFAULT_VERSION));
67     }
68
69     /**
70      * The Key Constructor creates a {@link JpaToscaPolicyTypes} object with the given artifact key and creates an empty
71      * concept map.
72      *
73      * @param key the concept key
74      */
75     public JpaToscaPolicyTypes(final PfConceptKey key) {
76         super(key, new TreeMap<PfConceptKey, JpaToscaPolicyType>());
77     }
78
79     /**
80      * This Constructor creates an concept container with all of its fields defined.
81      *
82      * @param key the concept container key
83      * @param conceptMap the concepts to be stored in the concept container
84      */
85     public JpaToscaPolicyTypes(final PfConceptKey key, final Map<PfConceptKey, JpaToscaPolicyType> conceptMap) {
86         super(key, conceptMap);
87     }
88
89     /**
90      * Copy constructor.
91      *
92      * @param copyConcept the concept to copy from
93      */
94     public JpaToscaPolicyTypes(final JpaToscaPolicyTypes copyConcept) {
95         super(copyConcept);
96     }
97
98     /**
99      * Authorative constructor.
100      *
101      * @param authorativeConceptMapList the authorative concept to copy from
102      */
103     public JpaToscaPolicyTypes(final List<Map<String, ToscaPolicyType>> authorativeConceptMapList) {
104         super(new PfConceptKey(DEFAULT_NAME, DEFAULT_VERSION));
105         this.fromAuthorative(authorativeConceptMapList);
106     }
107
108     @Override
109     public PfValidationResult validate(@NonNull final PfValidationResult resultIn) {
110         PfValidationResult result = super.validate(resultIn);
111
112         for (JpaToscaPolicyType policyType : this.getConceptMap().values()) {
113             ToscaUtils.getEntityTypeAncestors(this, policyType, result);
114         }
115
116         return result;
117     }
118 }