2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019-2023 Nordix Foundation.
4 * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
5 * Modifications Copyright (C) 2020, 2022 Bell Canada. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * SPDX-License-Identifier: Apache-2.0
20 * ============LICENSE_END=========================================================
23 package org.onap.policy.models.provider.impl;
25 import jakarta.ws.rs.core.Response;
26 import java.util.ArrayList;
27 import java.util.Collection;
28 import java.util.List;
30 import lombok.NonNull;
31 import org.onap.policy.common.utils.coder.StandardCoder;
32 import org.onap.policy.common.utils.resources.ResourceUtils;
33 import org.onap.policy.models.base.PfModelException;
34 import org.onap.policy.models.base.PfModelRuntimeException;
35 import org.onap.policy.models.pdp.concepts.Pdp;
36 import org.onap.policy.models.pdp.concepts.PdpGroup;
37 import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
38 import org.onap.policy.models.pdp.concepts.PdpPolicyStatus;
39 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
40 import org.onap.policy.models.provider.PolicyModelsProvider;
41 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
42 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
43 import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter;
44 import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityKey;
45 import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
46 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
47 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
48 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
49 import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter;
52 * This class provides a dummy implementation of the Policy Models Provider for the ONAP Policy Framework.
54 * @author Liam Fallon (liam.fallon@est.tech)
55 * @author Chenfei Gao (cgao@research.att.com)
57 public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
59 * Constructor that takes the parameters.
61 * @param parameters the parameters for the provider
63 public DummyPolicyModelsProviderImpl(final PolicyModelsProviderParameters parameters) {
64 // Default constructor
69 // Not required on the dummy provider
74 // Not required on the dummy provider
79 public List<ToscaServiceTemplate> getServiceTemplateList(String name, String version) {
80 return new ArrayList<>();
84 public List<ToscaServiceTemplate> getFilteredServiceTemplateList(
85 @NonNull ToscaEntityFilter<ToscaServiceTemplate> filter) {
86 return new ArrayList<>();
90 public ToscaServiceTemplate createServiceTemplate(@NonNull ToscaServiceTemplate serviceTemplate)
91 throws PfModelException {
92 return serviceTemplate;
96 public ToscaServiceTemplate updateServiceTemplate(@NonNull ToscaServiceTemplate serviceTemplate)
97 throws PfModelException {
98 return serviceTemplate;
102 public ToscaServiceTemplate deleteServiceTemplate(@NonNull String name, @NonNull String version)
103 throws PfModelException {
104 return getDummyResponse("dummyimpl/DummyToscaServiceTemplateDeleteResponse.json");
108 public ToscaServiceTemplate getPolicyTypes(final String name, final String version) {
109 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
113 public List<ToscaPolicyType> getPolicyTypeList(final String name, final String version) {
114 return new ArrayList<>();
118 public ToscaServiceTemplate getFilteredPolicyTypes(ToscaEntityFilter<ToscaPolicyType> filter) {
119 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
123 public List<ToscaPolicyType> getFilteredPolicyTypeList(ToscaEntityFilter<ToscaPolicyType> filter) {
124 return new ArrayList<>();
128 public ToscaServiceTemplate createPolicyTypes(final ToscaServiceTemplate serviceTemplate) {
129 return serviceTemplate;
133 public ToscaServiceTemplate updatePolicyTypes(final ToscaServiceTemplate serviceTemplate) {
134 return serviceTemplate;
138 public ToscaServiceTemplate deletePolicyType(final String name, final String version) {
139 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeDeleteResponse.json");
143 public ToscaServiceTemplate getPolicies(final String name, final String version) {
144 return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
148 public List<ToscaPolicy> getPolicyList(final String name, final String version) {
149 return new ArrayList<>();
153 public ToscaServiceTemplate getFilteredPolicies(ToscaTypedEntityFilter<ToscaPolicy> filter) {
154 return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
158 public List<ToscaPolicy> getFilteredPolicyList(ToscaTypedEntityFilter<ToscaPolicy> filter) {
159 return new ArrayList<>();
163 public ToscaServiceTemplate createPolicies(final ToscaServiceTemplate serviceTemplate) {
164 return serviceTemplate;
168 public ToscaServiceTemplate updatePolicies(final ToscaServiceTemplate serviceTemplate) {
169 return serviceTemplate;
173 public ToscaServiceTemplate deletePolicy(final String name, final String version) {
174 return getDummyResponse("dummyimpl/DummyToscaPolicyDeleteResponse.json");
178 public ToscaServiceTemplate createToscaNodeTemplates(@NonNull ToscaServiceTemplate serviceTemplate) {
179 return getDummyNodeTemplateResponse("dummyimpl/DummyToscaNodeTemplateResponse.json");
183 public ToscaServiceTemplate updateToscaNodeTemplates(@NonNull ToscaServiceTemplate serviceTemplate)
184 throws PfModelRuntimeException {
185 return getDummyNodeTemplateResponse("dummyimpl/DummyToscaNodeTemplateResponse.json");
189 public ToscaServiceTemplate deleteToscaNodeTemplate(@NonNull String name, @NonNull String version) {
190 return getDummyNodeTemplateResponse("dummyimpl/DummyToscaNodeTemplateResponse.json");
194 public List<Map<ToscaEntityKey, Map<String, Object>>> getNodeTemplateMetadataSets(@NonNull String name,
195 @NonNull String version) {
196 return new ArrayList<>();
200 public List<ToscaNodeTemplate> getToscaNodeTemplate(final String name, final String version) {
201 return new ArrayList<>();
205 public List<PdpGroup> getPdpGroups(final String name) {
206 return new ArrayList<>();
210 public List<PdpGroup> getFilteredPdpGroups(PdpGroupFilter filter) {
211 return new ArrayList<>();
215 public List<PdpGroup> createPdpGroups(final List<PdpGroup> pdpGroups) {
216 return new ArrayList<>();
220 public List<PdpGroup> updatePdpGroups(final List<PdpGroup> pdpGroups) {
221 return new ArrayList<>();
225 public void updatePdpSubGroup(final String pdpGroupName, final PdpSubGroup pdpSubGroup) {
230 public void updatePdp(String pdpGroupName, String pdpSubGroup, Pdp pdp) {
235 public PdpGroup deletePdpGroup(final String name) {
240 public List<PdpPolicyStatus> getAllPolicyStatus() {
242 return new ArrayList<>();
246 public List<PdpPolicyStatus> getAllPolicyStatus(@NonNull ToscaConceptIdentifierOptVersion policy) {
248 return new ArrayList<>();
252 public List<PdpPolicyStatus> getGroupPolicyStatus(String groupName) {
254 return new ArrayList<>();
258 public void cudPolicyStatus(Collection<PdpPolicyStatus> createObjs, Collection<PdpPolicyStatus> updateObjs,
259 Collection<PdpPolicyStatus> deleteObjs) {
264 * Return a ToscaServicetemplate dummy response.
266 * @param fileName the file name containing the dummy response
267 * @return the ToscaServiceTemplate with the dummy response
269 protected ToscaServiceTemplate getDummyResponse(final String fileName) {
270 var standardCoder = new StandardCoder();
271 ToscaServiceTemplate serviceTemplate;
275 standardCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
276 if (serviceTemplate == null) {
277 throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, "error reading specified file");
279 } catch (Exception exc) {
280 throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "error serializing object", exc);
283 return serviceTemplate;
287 * Return a tosca node template dummy response.
289 * @param fileName the file name containing the dummy response
290 * @return the service template with the dummy response
292 protected ToscaServiceTemplate getDummyNodeTemplateResponse(final String fileName) {
293 var standardCoder = new StandardCoder();
294 ToscaServiceTemplate serviceTemplate;
298 standardCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
299 if (serviceTemplate == null) {
300 throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, "error reading specified file");
302 } catch (Exception exc) {
303 throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "error serializing object", exc);
306 return serviceTemplate;