2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019-2021 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;
29 import javax.ws.rs.core.Response;
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.pap.concepts.PolicyAudit;
36 import org.onap.policy.models.pap.persistence.provider.PolicyAuditProvider.AuditFilter;
37 import org.onap.policy.models.pdp.concepts.Pdp;
38 import org.onap.policy.models.pdp.concepts.PdpGroup;
39 import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
40 import org.onap.policy.models.pdp.concepts.PdpPolicyStatus;
41 import org.onap.policy.models.pdp.concepts.PdpStatistics;
42 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
43 import org.onap.policy.models.provider.PolicyModelsProvider;
44 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
45 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
46 import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter;
47 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
48 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
49 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
50 import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter;
53 * This class provides a dummy implementation of the Policy Models Provider for the ONAP Policy Framework.
55 * @author Liam Fallon (liam.fallon@est.tech)
56 * @author Chenfei Gao (cgao@research.att.com)
58 public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
60 * Constructor that takes the parameters.
62 * @param parameters the parameters for the provider
64 public DummyPolicyModelsProviderImpl(final PolicyModelsProviderParameters parameters) {
65 // Default constructor
69 public void init() throws PfModelException {
70 // Not required on the dummy provider
75 // Not required on the dummy provider
80 public List<ToscaServiceTemplate> getServiceTemplateList(String name, String version) throws PfModelException {
81 return new ArrayList<>();
85 public List<ToscaServiceTemplate> getFilteredServiceTemplateList(
86 @NonNull ToscaEntityFilter<ToscaServiceTemplate> filter) throws PfModelException {
87 return new ArrayList<>();
91 public ToscaServiceTemplate createServiceTemplate(@NonNull ToscaServiceTemplate serviceTemplate)
92 throws PfModelException {
93 return serviceTemplate;
97 public ToscaServiceTemplate updateServiceTemplate(@NonNull ToscaServiceTemplate serviceTemplate)
98 throws PfModelException {
99 return serviceTemplate;
103 public ToscaServiceTemplate deleteServiceTemplate(@NonNull String name, @NonNull String version)
104 throws PfModelException {
105 return getDummyResponse("dummyimpl/DummyToscaServiceTemplateDeleteResponse.json");
109 public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException {
110 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
114 public List<ToscaPolicyType> getPolicyTypeList(final String name, final String version) throws PfModelException {
115 return new ArrayList<>();
119 public ToscaServiceTemplate getFilteredPolicyTypes(ToscaEntityFilter<ToscaPolicyType> filter)
120 throws PfModelException {
121 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
125 public List<ToscaPolicyType> getFilteredPolicyTypeList(ToscaEntityFilter<ToscaPolicyType> filter) {
126 return new ArrayList<>();
130 public ToscaServiceTemplate createPolicyTypes(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
131 return serviceTemplate;
135 public ToscaServiceTemplate updatePolicyTypes(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
136 return serviceTemplate;
140 public ToscaServiceTemplate deletePolicyType(final String name, final String version) throws PfModelException {
141 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeDeleteResponse.json");
145 public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException {
146 return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
150 public List<ToscaPolicy> getPolicyList(final String name, final String version) throws PfModelException {
151 return new ArrayList<>();
155 public ToscaServiceTemplate getFilteredPolicies(ToscaTypedEntityFilter<ToscaPolicy> filter)
156 throws PfModelException {
157 return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
161 public List<ToscaPolicy> getFilteredPolicyList(ToscaTypedEntityFilter<ToscaPolicy> filter) throws PfModelException {
162 return new ArrayList<>();
166 public ToscaServiceTemplate createPolicies(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
167 return serviceTemplate;
171 public ToscaServiceTemplate updatePolicies(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
172 return serviceTemplate;
176 public ToscaServiceTemplate deletePolicy(final String name, final String version) throws PfModelException {
177 return getDummyResponse("dummyimpl/DummyToscaPolicyDeleteResponse.json");
181 public List<PdpGroup> getPdpGroups(final String name) throws PfModelException {
182 return new ArrayList<>();
186 public List<PdpGroup> getFilteredPdpGroups(PdpGroupFilter filter) throws PfModelException {
187 return new ArrayList<>();
191 public List<PdpGroup> createPdpGroups(final List<PdpGroup> pdpGroups) throws PfModelException {
192 return new ArrayList<>();
196 public List<PdpGroup> updatePdpGroups(final List<PdpGroup> pdpGroups) throws PfModelException {
197 return new ArrayList<>();
201 public void updatePdpSubGroup(final String pdpGroupName, final PdpSubGroup pdpSubGroup) throws PfModelException {
206 public void updatePdp(String pdpGroupName, String pdpSubGroup, Pdp pdp) throws PfModelException {
211 public PdpGroup deletePdpGroup(final String name) throws PfModelException {
216 public List<PdpStatistics> getPdpStatistics(final String name, final Instant timestamp) throws PfModelException {
217 return new ArrayList<>();
221 public List<PdpStatistics> getFilteredPdpStatistics(String name, String pdpGroupName, String pdpSubGroup,
222 Instant startTimeStamp, Instant endTimeStamp, String sortOrder, int getRecordNum) {
224 return new ArrayList<>();
228 public List<PdpStatistics> createPdpStatistics(final List<PdpStatistics> pdpStatisticsList)
229 throws PfModelException {
231 return new ArrayList<>();
235 public List<PdpStatistics> updatePdpStatistics(final List<PdpStatistics> pdpStatisticsList)
236 throws PfModelException {
238 return new ArrayList<>();
242 public List<PdpStatistics> deletePdpStatistics(final String name, final Instant timestamp) {
244 return new ArrayList<>();
248 public List<PdpPolicyStatus> getAllPolicyStatus() throws PfModelException {
250 return new ArrayList<>();
254 public List<PdpPolicyStatus> getAllPolicyStatus(@NonNull ToscaConceptIdentifierOptVersion policy)
255 throws PfModelException {
257 return new ArrayList<>();
261 public List<PdpPolicyStatus> getGroupPolicyStatus(String groupName) throws PfModelException {
263 return new ArrayList<>();
267 public void cudPolicyStatus(Collection<PdpPolicyStatus> createObjs, Collection<PdpPolicyStatus> updateObjs,
268 Collection<PdpPolicyStatus> deleteObjs) {
273 public void createAuditRecords(List<PolicyAudit> auditRecords) {
278 public List<PolicyAudit> getAuditRecords(AuditFilter auditFilter, @NonNull Integer numRecords) {
280 return new ArrayList<>();
284 * Return a ToscaServicetemplate dummy response.
286 * @param fileName the file name containing the dummy response
287 * @return the ToscaServiceTemplate with the dummy response
289 protected ToscaServiceTemplate getDummyResponse(final String fileName) {
290 var standardCoder = new StandardCoder();
291 ToscaServiceTemplate serviceTemplate;
295 standardCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
296 if (serviceTemplate == null) {
297 throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, "error reading specified file");
299 } catch (Exception exc) {
300 throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "error serializing object", exc);
303 return serviceTemplate;