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