Add impl of more PDP persistence
[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 java.util.ArrayList;
24 import java.util.List;
25
26 import lombok.NonNull;
27
28 import org.onap.policy.models.base.PfConceptKey;
29 import org.onap.policy.models.base.PfModelException;
30 import org.onap.policy.models.dao.PfDao;
31 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
32 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
33 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
34 import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
35 import org.onap.policy.models.tosca.simple.provider.SimpleToscaProvider;
36
37 /**
38  * This class provides the provision of information on TOSCA concepts in the database to callers.
39  *
40  * @author Liam Fallon (liam.fallon@est.tech)
41  */
42 public class AuthorativeToscaProvider {
43     /**
44      * Get policy types.
45      *
46      * @param dao the DAO to use to access the database
47      * @param name the name of the policy type to get.
48      * @param version the version of the policy type to get.
49      * @return the policy types found
50      * @throws PfModelException on errors getting policy types
51      */
52     public ToscaServiceTemplate getPolicyTypes(@NonNull final PfDao dao, final String name, final String version)
53             throws PfModelException {
54
55         return new SimpleToscaProvider().getPolicyTypes(dao, new PfConceptKey(name, version)).toAuthorative();
56     }
57
58     /**
59      * Get policy types.
60      *
61      * @param dao the DAO to use to access the database
62      * @param name the name of the policy type to get, set to null to get all policy types
63      * @param version the version of the policy type to get, set to null to get all versions
64      * @return the policy types found
65      * @throws PfModelException on errors getting policy types
66      */
67     public List<ToscaPolicyType> getPolicyTypeList(@NonNull final PfDao dao, final String name, final String version)
68             throws PfModelException {
69         return new ArrayList<>();
70     }
71
72     /**
73      * Get latest policy types.
74      *
75      * @param dao the DAO to use to access the database
76      * @param name the name of the policy type to get, set to null to get all policy types
77      * @return the policy types found
78      * @throws PfModelException on errors getting policy types
79      */
80     public ToscaServiceTemplate getLatestPolicyTypes(@NonNull final PfDao dao, final String name)
81             throws PfModelException {
82         return null;
83     }
84
85     /**
86      * Get latest policy types.
87      *
88      * @param dao the DAO to use to access the database
89      * @param name the name of the policy type to get, set to null to get all policy types
90      * @return the policy types found
91      * @throws PfModelException on errors getting policy types
92      */
93     public List<ToscaPolicyType> getLatestPolicyTypeList(@NonNull final PfDao dao, final String name)
94             throws PfModelException {
95         return new ArrayList<>();
96     }
97
98     /**
99      * Create policy types.
100      *
101      * @param dao the DAO to use to access the database
102      * @param serviceTemplate the service template containing the definition of the policy types to be created
103      * @return the TOSCA service template containing the created policy types
104      * @throws PfModelException on errors creating policy types
105      */
106     public ToscaServiceTemplate createPolicyTypes(@NonNull final PfDao dao,
107             @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
108
109         return new SimpleToscaProvider().createPolicyTypes(dao, new JpaToscaServiceTemplate(serviceTemplate))
110                 .toAuthorative();
111     }
112
113     /**
114      * Update policy types.
115      *
116      * @param dao the DAO to use to access the database
117      * @param serviceTemplate the service template containing the definition of the policy types to be modified
118      * @return the TOSCA service template containing the modified policy types
119      * @throws PfModelException on errors updating policy types
120      */
121     public ToscaServiceTemplate updatePolicyTypes(@NonNull final PfDao dao,
122             @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
123
124         return new SimpleToscaProvider().updatePolicyTypes(dao, new JpaToscaServiceTemplate(serviceTemplate))
125                 .toAuthorative();
126     }
127
128     /**
129      * Delete policy type.
130      *
131      * @param dao the DAO to use to access the database
132      * @param name the name of the policy type to delete.
133      * @param version the version of the policy type to delete.
134      * @return the TOSCA service template containing the policy type that was deleted
135      * @throws PfModelException on errors deleting policy types
136      */
137     public ToscaServiceTemplate deletePolicyType(@NonNull final PfDao dao, @NonNull final String name,
138             @NonNull final String version) throws PfModelException {
139
140         return new SimpleToscaProvider().deletePolicyType(dao, new PfConceptKey(name, version)).toAuthorative();
141     }
142
143     /**
144      * Get policies.
145      *
146      * @param dao the DAO to use to access the database
147      * @param name the name of the policy to get.
148      * @param version the version of the policy to get.
149      * @return the policies found
150      * @throws PfModelException on errors getting policies
151      */
152     public ToscaServiceTemplate getPolicies(@NonNull final PfDao dao, @NonNull final String name,
153             @NonNull final String version) throws PfModelException {
154
155         return new SimpleToscaProvider().getPolicies(dao, new PfConceptKey(name, version)).toAuthorative();
156     }
157
158     /**
159      * Get policies.
160      *
161      * @param dao the DAO to use to access the database
162      * @param name the name of the policy to get, null to get all policies
163      * @param version the version of the policy to get, null to get all versions of a policy
164      * @return the policies found
165      * @throws PfModelException on errors getting policies
166      */
167     public List<ToscaPolicy> getPolicyList(@NonNull final PfDao dao, final String name, final String version)
168             throws PfModelException {
169         return new ArrayList<>();
170     }
171
172     /**
173      * Get policies for a policy type name.
174      *
175      * @param dao the DAO to use to access the database
176      * @param policyTypeName the name of the policy type for which to get policies
177      * @param policyTypeVersion the version of the policy type, null returns all versions of deployed policies for
178      *        policy types
179      * @return the policies found
180      * @throws PfModelException on errors getting policies
181      */
182     public ToscaServiceTemplate getPolicies4PolicyType(@NonNull final PfDao dao, @NonNull final String policyTypeName,
183             final String policyTypeVersion) throws PfModelException {
184         return null;
185     }
186
187     /**
188      * Get policies for a policy type name.
189      *
190      * @param dao the DAO to use to access the database
191      * @param policyTypeName the name of the policy type for which to get policies
192      * @param policyTypeVersion the version of the policy type, null returns all versions of deployed policies for
193      *        policy types
194      * @return the policies found
195      * @throws PfModelException on errors getting policies
196      */
197     public List<ToscaPolicy> getPolicyList4PolicyType(@NonNull final PfDao dao, @NonNull final String policyTypeName,
198             final String policyTypeVersion) throws PfModelException {
199         return new ArrayList<>();
200     }
201
202     /**
203      * Get latest policies.
204      *
205      * @param dao the DAO to use to access the database
206      * @param name the name of the policy to get, null to get all policies
207      * @return the policies found
208      * @throws PfModelException on errors getting policies
209      */
210     public ToscaServiceTemplate getLatestPolicies(@NonNull final PfDao dao, final String name) throws PfModelException {
211         return null;
212     }
213
214     /**
215      * Get latest policies.
216      *
217      * @param dao the DAO to use to access the database
218      * @param name the name of the policy to get, null to get all policies
219      * @return the policies found
220      * @throws PfModelException on errors getting policies
221      */
222     public List<ToscaPolicy> getLatestPolicyList(@NonNull final PfDao dao, final String name) throws PfModelException {
223         return new ArrayList<>();
224     }
225
226     /**
227      * Create policies.
228      *
229      * @param dao the DAO to use to access the database
230      * @param serviceTemplate the service template containing the definitions of the new policies to be created.
231      * @return the TOSCA service template containing the policy types that were created
232      * @throws PfModelException on errors creating policies
233      */
234     public ToscaServiceTemplate createPolicies(@NonNull final PfDao dao,
235             @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
236
237         return new SimpleToscaProvider().createPolicies(dao, new JpaToscaServiceTemplate(serviceTemplate))
238                 .toAuthorative();
239     }
240
241     /**
242      * Update policies.
243      *
244      * @param dao the DAO to use to access the database
245      * @param serviceTemplate the service template containing the definitions of the policies to be updated.
246      * @return the TOSCA service template containing the policies that were updated
247      * @throws PfModelException on errors updating policies
248      */
249     public ToscaServiceTemplate updatePolicies(@NonNull final PfDao dao,
250             @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
251
252         return new SimpleToscaProvider().updatePolicies(dao, new JpaToscaServiceTemplate(serviceTemplate))
253                 .toAuthorative();
254     }
255
256     /**
257      * Delete policy.
258      *
259      * @param dao the DAO to use to access the database
260      * @param name the name of the policy to delete.
261      * @param version the version of the policy to delete.
262      * @return the TOSCA service template containing the policy that weas deleted
263      * @throws PfModelException on errors deleting policies
264      */
265     public ToscaServiceTemplate deletePolicy(@NonNull final PfDao dao, @NonNull final String name,
266             @NonNull final String version) throws PfModelException {
267
268         return new SimpleToscaProvider().deletePolicy(dao, new PfConceptKey(name, version)).toAuthorative();
269     }
270 }