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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.models.tosca.authorative.provider;
23 import java.util.ArrayList;
24 import java.util.List;
26 import lombok.NonNull;
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;
38 * This class provides the provision of information on TOSCA concepts in the database to callers.
40 * @author Liam Fallon (liam.fallon@est.tech)
42 public class AuthorativeToscaProvider {
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
52 public ToscaServiceTemplate getPolicyTypes(@NonNull final PfDao dao, final String name, final String version)
53 throws PfModelException {
55 return new SimpleToscaProvider().getPolicyTypes(dao, new PfConceptKey(name, version)).toAuthorative();
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
67 public List<ToscaPolicyType> getPolicyTypeList(@NonNull final PfDao dao, final String name, final String version)
68 throws PfModelException {
69 return new ArrayList<>();
73 * Get latest policy types.
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
80 public ToscaServiceTemplate getLatestPolicyTypes(@NonNull final PfDao dao, final String name)
81 throws PfModelException {
86 * Get latest policy types.
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
93 public List<ToscaPolicyType> getLatestPolicyTypeList(@NonNull final PfDao dao, final String name)
94 throws PfModelException {
95 return new ArrayList<>();
99 * Create policy types.
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
106 public ToscaServiceTemplate createPolicyTypes(@NonNull final PfDao dao,
107 @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
109 return new SimpleToscaProvider().createPolicyTypes(dao, new JpaToscaServiceTemplate(serviceTemplate))
114 * Update policy types.
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
121 public ToscaServiceTemplate updatePolicyTypes(@NonNull final PfDao dao,
122 @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
124 return new SimpleToscaProvider().updatePolicyTypes(dao, new JpaToscaServiceTemplate(serviceTemplate))
129 * Delete policy type.
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
137 public ToscaServiceTemplate deletePolicyType(@NonNull final PfDao dao, @NonNull final String name,
138 @NonNull final String version) throws PfModelException {
140 return new SimpleToscaProvider().deletePolicyType(dao, new PfConceptKey(name, version)).toAuthorative();
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
152 public ToscaServiceTemplate getPolicies(@NonNull final PfDao dao, @NonNull final String name,
153 @NonNull final String version) throws PfModelException {
155 return new SimpleToscaProvider().getPolicies(dao, new PfConceptKey(name, version)).toAuthorative();
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
167 public List<ToscaPolicy> getPolicyList(@NonNull final PfDao dao, final String name, final String version)
168 throws PfModelException {
169 return new ArrayList<>();
173 * Get policies for a policy type name.
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
179 * @return the policies found
180 * @throws PfModelException on errors getting policies
182 public List<ToscaPolicy> getPolicyList4PolicyType(@NonNull final PfDao dao, @NonNull final String policyTypeName,
183 final String policyTypeVersion) throws PfModelException {
184 return new ArrayList<>();
188 * Get latest policies.
190 * @param dao the DAO to use to access the database
191 * @param name the name of the policy to get, null to get all policies
192 * @return the policies found
193 * @throws PfModelException on errors getting policies
195 public ToscaServiceTemplate getLatestPolicies(@NonNull final PfDao dao, final String name) throws PfModelException {
200 * Get latest policies.
202 * @param dao the DAO to use to access the database
203 * @param name the name of the policy to get, null to get all policies
204 * @return the policies found
205 * @throws PfModelException on errors getting policies
207 public List<ToscaPolicy> getLatestPolicyList(@NonNull final PfDao dao, final String name) throws PfModelException {
208 return new ArrayList<>();
214 * @param dao the DAO to use to access the database
215 * @param serviceTemplate the service template containing the definitions of the new policies to be created.
216 * @return the TOSCA service template containing the policy types that were created
217 * @throws PfModelException on errors creating policies
219 public ToscaServiceTemplate createPolicies(@NonNull final PfDao dao,
220 @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
222 return new SimpleToscaProvider().createPolicies(dao, new JpaToscaServiceTemplate(serviceTemplate))
229 * @param dao the DAO to use to access the database
230 * @param serviceTemplate the service template containing the definitions of the policies to be updated.
231 * @return the TOSCA service template containing the policies that were updated
232 * @throws PfModelException on errors updating policies
234 public ToscaServiceTemplate updatePolicies(@NonNull final PfDao dao,
235 @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
237 return new SimpleToscaProvider().updatePolicies(dao, new JpaToscaServiceTemplate(serviceTemplate))
244 * @param dao the DAO to use to access the database
245 * @param name the name of the policy to delete.
246 * @param version the version of the policy to delete.
247 * @return the TOSCA service template containing the policy that weas deleted
248 * @throws PfModelException on errors deleting policies
250 public ToscaServiceTemplate deletePolicy(@NonNull final PfDao dao, @NonNull final String name,
251 @NonNull final String version) throws PfModelException {
253 return new SimpleToscaProvider().deletePolicy(dao, new PfConceptKey(name, version)).toAuthorative();