2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019-2022 Nordix Foundation.
4 * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
5 * Modifications Copyright (C) 2020 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 java.time.Instant;
26 import java.util.ArrayList;
27 import java.util.Collection;
28 import java.util.List;
30 import javax.ws.rs.core.Response;
31 import lombok.NonNull;
32 import org.onap.policy.common.utils.coder.StandardCoder;
33 import org.onap.policy.common.utils.resources.ResourceUtils;
34 import org.onap.policy.models.base.PfConceptKey;
35 import org.onap.policy.models.base.PfModelException;
36 import org.onap.policy.models.base.PfModelRuntimeException;
37 import org.onap.policy.models.pap.concepts.PolicyAudit;
38 import org.onap.policy.models.pap.persistence.provider.PolicyAuditProvider.AuditFilter;
39 import org.onap.policy.models.pdp.concepts.Pdp;
40 import org.onap.policy.models.pdp.concepts.PdpGroup;
41 import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
42 import org.onap.policy.models.pdp.concepts.PdpPolicyStatus;
43 import org.onap.policy.models.pdp.concepts.PdpStatistics;
44 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
45 import org.onap.policy.models.pdp.persistence.provider.PdpFilterParameters;
46 import org.onap.policy.models.provider.PolicyModelsProvider;
47 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
48 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
49 import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter;
50 import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityKey;
51 import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
52 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
53 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
54 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
55 import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter;
58 * This class provides a dummy implementation of the Policy Models Provider for the ONAP Policy Framework.
60 * @author Liam Fallon (liam.fallon@est.tech)
61 * @author Chenfei Gao (cgao@research.att.com)
63 public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
65 * Constructor that takes the parameters.
67 * @param parameters the parameters for the provider
69 public DummyPolicyModelsProviderImpl(final PolicyModelsProviderParameters parameters) {
70 // Default constructor
74 public void init() throws PfModelException {
75 // Not required on the dummy provider
80 // Not required on the dummy provider
85 public List<ToscaServiceTemplate> getServiceTemplateList(String name, String version) throws PfModelException {
86 return new ArrayList<>();
90 public List<ToscaServiceTemplate> getFilteredServiceTemplateList(
91 @NonNull ToscaEntityFilter<ToscaServiceTemplate> filter) throws PfModelException {
92 return new ArrayList<>();
96 public ToscaServiceTemplate createServiceTemplate(@NonNull ToscaServiceTemplate serviceTemplate)
97 throws PfModelException {
98 return serviceTemplate;
102 public ToscaServiceTemplate updateServiceTemplate(@NonNull ToscaServiceTemplate serviceTemplate)
103 throws PfModelException {
104 return serviceTemplate;
108 public ToscaServiceTemplate deleteServiceTemplate(@NonNull String name, @NonNull String version)
109 throws PfModelException {
110 return getDummyResponse("dummyimpl/DummyToscaServiceTemplateDeleteResponse.json");
114 public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException {
115 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
119 public List<ToscaPolicyType> getPolicyTypeList(final String name, final String version) throws PfModelException {
120 return new ArrayList<>();
124 public ToscaServiceTemplate getFilteredPolicyTypes(ToscaEntityFilter<ToscaPolicyType> filter)
125 throws PfModelException {
126 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
130 public List<ToscaPolicyType> getFilteredPolicyTypeList(ToscaEntityFilter<ToscaPolicyType> filter) {
131 return new ArrayList<>();
135 public ToscaServiceTemplate createPolicyTypes(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
136 return serviceTemplate;
140 public ToscaServiceTemplate updatePolicyTypes(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
141 return serviceTemplate;
145 public ToscaServiceTemplate deletePolicyType(final String name, final String version) throws PfModelException {
146 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeDeleteResponse.json");
150 public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException {
151 return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
155 public List<ToscaPolicy> getPolicyList(final String name, final String version) throws PfModelException {
156 return new ArrayList<>();
160 public ToscaServiceTemplate getFilteredPolicies(ToscaTypedEntityFilter<ToscaPolicy> filter)
161 throws PfModelException {
162 return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
166 public List<ToscaPolicy> getFilteredPolicyList(ToscaTypedEntityFilter<ToscaPolicy> filter) throws PfModelException {
167 return new ArrayList<>();
171 public ToscaServiceTemplate createPolicies(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
172 return serviceTemplate;
176 public ToscaServiceTemplate updatePolicies(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
177 return serviceTemplate;
181 public ToscaServiceTemplate deletePolicy(final String name, final String version) throws PfModelException {
182 return getDummyResponse("dummyimpl/DummyToscaPolicyDeleteResponse.json");
186 public ToscaServiceTemplate createToscaNodeTemplates(@NonNull ToscaServiceTemplate serviceTemplate)
187 throws PfModelException {
188 return getDummyNodeTemplateResponse("dummyimpl/DummyToscaNodeTemplateResponse.json");
192 public ToscaServiceTemplate updateToscaNodeTemplates(@NonNull ToscaServiceTemplate serviceTemplate)
193 throws PfModelRuntimeException, PfModelException {
194 return getDummyNodeTemplateResponse("dummyimpl/DummyToscaNodeTemplateResponse.json");
198 public ToscaServiceTemplate deleteToscaNodeTemplate(@NonNull String name, @NonNull String version)
199 throws PfModelException {
200 return getDummyNodeTemplateResponse("dummyimpl/DummyToscaNodeTemplateResponse.json");
204 public List<Map<ToscaEntityKey, Map<String, Object>>> getNodeTemplateMetadataSets(@NonNull String name,
205 @NonNull String version)
206 throws PfModelException {
207 return new ArrayList<>();
211 public List<Map<PfConceptKey, ToscaNodeTemplate>> getToscaNodeTemplate(final String name,
212 final String version)
213 throws PfModelException {
214 return new ArrayList<>();
218 public List<PdpGroup> getPdpGroups(final String name) throws PfModelException {
219 return new ArrayList<>();
223 public List<PdpGroup> getFilteredPdpGroups(PdpGroupFilter filter) throws PfModelException {
224 return new ArrayList<>();
228 public List<PdpGroup> createPdpGroups(final List<PdpGroup> pdpGroups) throws PfModelException {
229 return new ArrayList<>();
233 public List<PdpGroup> updatePdpGroups(final List<PdpGroup> pdpGroups) throws PfModelException {
234 return new ArrayList<>();
238 public void updatePdpSubGroup(final String pdpGroupName, final PdpSubGroup pdpSubGroup) throws PfModelException {
243 public void updatePdp(String pdpGroupName, String pdpSubGroup, Pdp pdp) throws PfModelException {
248 public PdpGroup deletePdpGroup(final String name) throws PfModelException {
253 public List<PdpStatistics> getFilteredPdpStatistics(PdpFilterParameters filterParams) throws PfModelException {
255 return new ArrayList<>();
259 public List<PdpStatistics> createPdpStatistics(final List<PdpStatistics> pdpStatisticsList)
260 throws PfModelException {
262 return new ArrayList<>();
266 public List<PdpStatistics> updatePdpStatistics(final List<PdpStatistics> pdpStatisticsList)
267 throws PfModelException {
269 return new ArrayList<>();
273 public List<PdpStatistics> deletePdpStatistics(final String name, final Instant timestamp) {
275 return new ArrayList<>();
279 public List<PdpPolicyStatus> getAllPolicyStatus() throws PfModelException {
281 return new ArrayList<>();
285 public List<PdpPolicyStatus> getAllPolicyStatus(@NonNull ToscaConceptIdentifierOptVersion policy)
286 throws PfModelException {
288 return new ArrayList<>();
292 public List<PdpPolicyStatus> getGroupPolicyStatus(String groupName) throws PfModelException {
294 return new ArrayList<>();
298 public void cudPolicyStatus(Collection<PdpPolicyStatus> createObjs, Collection<PdpPolicyStatus> updateObjs,
299 Collection<PdpPolicyStatus> deleteObjs) {
304 public void createAuditRecords(List<PolicyAudit> auditRecords) {
309 public List<PolicyAudit> getAuditRecords(AuditFilter auditFilter) {
311 return new ArrayList<>();
315 * Return a ToscaServicetemplate dummy response.
317 * @param fileName the file name containing the dummy response
318 * @return the ToscaServiceTemplate with the dummy response
320 protected ToscaServiceTemplate getDummyResponse(final String fileName) {
321 var standardCoder = new StandardCoder();
322 ToscaServiceTemplate serviceTemplate;
326 standardCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
327 if (serviceTemplate == null) {
328 throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, "error reading specified file");
330 } catch (Exception exc) {
331 throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "error serializing object", exc);
334 return serviceTemplate;
338 * Return a tosca node template dummy response.
340 * @param fileName the file name containing the dummy response
341 * @return the service template with the dummy response
343 protected ToscaServiceTemplate getDummyNodeTemplateResponse(final String fileName) {
344 var standardCoder = new StandardCoder();
345 ToscaServiceTemplate serviceTemplate;
349 standardCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
350 if (serviceTemplate == null) {
351 throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, "error reading specified file");
353 } catch (Exception exc) {
354 throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "error serializing object", exc);
357 return serviceTemplate;