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 lombok.NonNull;
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;
33 * This class provides the provision of information on TOSCA concepts in the database to callers.
35 * @author Liam Fallon (liam.fallon@est.tech)
37 public class AuthorativeToscaProvider {
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
47 public ToscaServiceTemplate getPolicyTypes(@NonNull final PfDao dao, @NonNull final String name,
48 @NonNull final String version) throws PfModelException {
50 return new SimpleToscaProvider().getPolicyTypes(dao, new PfConceptKey(name, version)).toAuthorative();
54 * Create policy types.
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
61 public ToscaServiceTemplate createPolicyTypes(@NonNull final PfDao dao,
62 @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
64 return new SimpleToscaProvider().createPolicyTypes(dao, new JpaToscaServiceTemplate(serviceTemplate))
69 * Update policy types.
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
76 public ToscaServiceTemplate updatePolicyTypes(@NonNull final PfDao dao,
77 @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
79 return new SimpleToscaProvider().updatePolicyTypes(dao, new JpaToscaServiceTemplate(serviceTemplate))
84 * Delete policy types.
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
92 public ToscaServiceTemplate deletePolicyTypes(@NonNull final PfDao dao, @NonNull final String name,
93 @NonNull final String version) throws PfModelException {
95 return new SimpleToscaProvider().deletePolicyTypes(dao, new PfConceptKey(name, version)).toAuthorative();
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
107 public ToscaServiceTemplate getPolicies(@NonNull final PfDao dao, @NonNull final String name,
108 @NonNull final String version) throws PfModelException {
110 return new SimpleToscaProvider().getPolicies(dao, new PfConceptKey(name, version)).toAuthorative();
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
121 public ToscaServiceTemplate createPolicies(@NonNull final PfDao dao,
122 @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
124 return new SimpleToscaProvider().createPolicies(dao, new JpaToscaServiceTemplate(serviceTemplate))
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
136 public ToscaServiceTemplate updatePolicies(@NonNull final PfDao dao,
137 @NonNull final ToscaServiceTemplate serviceTemplate) throws PfModelException {
139 return new SimpleToscaProvider().updatePolicies(dao, new JpaToscaServiceTemplate(serviceTemplate))
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
152 public ToscaServiceTemplate deletePolicies(@NonNull final PfDao dao, @NonNull final String name,
153 @NonNull final String version) throws PfModelException {
155 return new SimpleToscaProvider().deletePolicies(dao, new PfConceptKey(name, version)).toAuthorative();