Merge "Refactor to authorative TOSCA serializtion"
[policy/models.git] / models-tosca / src / main / java / org / onap / policy / models / tosca / authorative / provider / AuthorativeToscaProvider.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 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.authorative.provider;
22
23 import lombok.NonNull;
24
25 import org.onap.policy.models.base.PfConceptKey;
26 import org.onap.policy.models.base.PfModelException;
27 import org.onap.policy.models.dao.PfDao;
28 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
29 import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
30 import org.onap.policy.models.tosca.simple.provider.SimpleToscaProvider;
31
32 /**
33  * This class provides the provision of information on TOSCA concepts in the database to callers.
34  *
35  * @author Liam Fallon (liam.fallon@est.tech)
36  */
37 public class AuthorativeToscaProvider {
38     /**
39      * Get policy types.
40      *
41      * @param dao the DAO to use to access the database
42      * @param name the name of the policy type to get.
43      * @param version the version of the policy type to get.
44      * @return the policy types found
45      * @throws PfModelException on errors getting policy types
46      */
47     public ToscaServiceTemplate getPolicyTypes(@NonNull final PfDao dao, @NonNull final String name,
48             @NonNull final String version) throws PfModelException {
49
50         return new SimpleToscaProvider().getPolicyTypes(dao, new PfConceptKey(name, version)).toAuthorative();
51     }
52
53     /**
54      * Create policy types.
55      *
56      * @param dao the DAO to use to access the database
57      * @param serviceTemplate the service template containing the definition of the policy types to be created
58      * @return the TOSCA service template containing the created policy types
59      * @throws PfModelException on errors creating policy types
60      */
61     public ToscaServiceTemplate createPolicyTypes(@NonNull final PfDao dao,
62             @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
63
64         return new SimpleToscaProvider().createPolicyTypes(dao, new JpaToscaServiceTemplate(serviceTemplate))
65                 .toAuthorative();
66     }
67
68     /**
69      * Update policy types.
70      *
71      * @param dao the DAO to use to access the database
72      * @param serviceTemplate the service template containing the definition of the policy types to be modified
73      * @return the TOSCA service template containing the modified policy types
74      * @throws PfModelException on errors updating policy types
75      */
76     public ToscaServiceTemplate updatePolicyTypes(@NonNull final PfDao dao,
77             @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
78
79         return new SimpleToscaProvider().updatePolicyTypes(dao, new JpaToscaServiceTemplate(serviceTemplate))
80                 .toAuthorative();
81     }
82
83     /**
84      * Delete policy types.
85      *
86      * @param dao the DAO to use to access the database
87      * @param name the name of the policy type to delete.
88      * @param version the version of the policy type to delete.
89      * @return the TOSCA service template containing the policy types that were deleted
90      * @throws PfModelException on errors deleting policy types
91      */
92     public ToscaServiceTemplate deletePolicyTypes(@NonNull final PfDao dao, @NonNull final String name,
93             @NonNull final String version) throws PfModelException {
94
95         return new SimpleToscaProvider().deletePolicyTypes(dao, new PfConceptKey(name, version)).toAuthorative();
96     }
97
98     /**
99      * Get policies.
100      *
101      * @param dao the DAO to use to access the database
102      * @param name the name of the policy to get.
103      * @param version the version of the policy to get.
104      * @return the policies found
105      * @throws PfModelException on errors getting policies
106      */
107     public ToscaServiceTemplate getPolicies(@NonNull final PfDao dao, @NonNull final String name,
108             @NonNull final String version) throws PfModelException {
109
110         return new SimpleToscaProvider().getPolicies(dao, new PfConceptKey(name, version)).toAuthorative();
111     }
112
113     /**
114      * Create policies.
115      *
116      * @param dao the DAO to use to access the database
117      * @param serviceTemplate the service template containing the definitions of the new policies to be created.
118      * @return the TOSCA service template containing the policy types that were created
119      * @throws PfModelException on errors creating policies
120      */
121     public ToscaServiceTemplate createPolicies(@NonNull final PfDao dao,
122             @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
123
124         return new SimpleToscaProvider().createPolicies(dao, new JpaToscaServiceTemplate(serviceTemplate))
125                 .toAuthorative();
126     }
127
128     /**
129      * Update policies.
130      *
131      * @param dao the DAO to use to access the database
132      * @param serviceTemplate the service template containing the definitions of the policies to be updated.
133      * @return the TOSCA service template containing the policies that were updated
134      * @throws PfModelException on errors updating policies
135      */
136     public ToscaServiceTemplate updatePolicies(@NonNull final PfDao dao,
137             @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
138
139         return new SimpleToscaProvider().updatePolicies(dao, new JpaToscaServiceTemplate(serviceTemplate))
140                 .toAuthorative();
141     }
142
143     /**
144      * Delete policies.
145      *
146      * @param dao the DAO to use to access the database
147      * @param name the name of the policy to delete.
148      * @param version the version of the policy to delete.
149      * @return the TOSCA service template containing the policies that were deleted
150      * @throws PfModelException on errors deleting policies
151      */
152     public ToscaServiceTemplate deletePolicies(@NonNull final PfDao dao, @NonNull final String name,
153             @NonNull final String version) throws PfModelException {
154
155         return new SimpleToscaProvider().deletePolicies(dao, new PfConceptKey(name, version)).toAuthorative();
156     }
157 }