2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019-2020 Nordix Foundation.
4 * Copyright (C) 2019 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.util.ArrayList;
26 import java.util.Date;
27 import java.util.List;
28 import javax.ws.rs.core.Response;
29 import lombok.NonNull;
30 import org.onap.policy.common.utils.coder.StandardCoder;
31 import org.onap.policy.common.utils.resources.ResourceUtils;
32 import org.onap.policy.models.base.PfModelException;
33 import org.onap.policy.models.base.PfModelRuntimeException;
34 import org.onap.policy.models.pdp.concepts.Pdp;
35 import org.onap.policy.models.pdp.concepts.PdpGroup;
36 import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
37 import org.onap.policy.models.pdp.concepts.PdpStatistics;
38 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
39 import org.onap.policy.models.provider.PolicyModelsProvider;
40 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
41 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
42 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
43 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
44 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
45 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
46 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplateFilter;
49 * This class provides a dummy implementation of the Policy Models Provider for the ONAP Policy Framework.
51 * @author Liam Fallon (liam.fallon@est.tech)
52 * @author Chenfei Gao (cgao@research.att.com)
54 public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
56 * Constructor that takes the parameters.
58 * @param parameters the parameters for the provider
60 public DummyPolicyModelsProviderImpl(final PolicyModelsProviderParameters parameters) {
61 // Default constructor
65 public void init() throws PfModelException {
66 // Not required on the dummy provider
71 // Not required on the dummy provider
76 public List<ToscaServiceTemplate> getServiceTemplateList(String name, String version) throws PfModelException {
77 return new ArrayList<>();
81 public List<ToscaServiceTemplate> getFilteredServiceTemplateList(@NonNull ToscaServiceTemplateFilter filter)
82 throws PfModelException {
83 return new ArrayList<>();
87 public ToscaServiceTemplate createServiceTemplate(@NonNull ToscaServiceTemplate serviceTemplate)
88 throws PfModelException {
89 return serviceTemplate;
93 public ToscaServiceTemplate updateServiceTemplate(@NonNull ToscaServiceTemplate serviceTemplate)
94 throws PfModelException {
95 return serviceTemplate;
99 public ToscaServiceTemplate deleteServiceTemplate(@NonNull String name, @NonNull String version)
100 throws PfModelException {
101 return getDummyResponse("dummyimpl/DummyToscaServiceTemplateDeleteResponse.json");
105 public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException {
106 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
110 public List<ToscaPolicyType> getPolicyTypeList(final String name, final String version) throws PfModelException {
111 return new ArrayList<>();
115 public ToscaServiceTemplate getFilteredPolicyTypes(ToscaPolicyTypeFilter filter) throws PfModelException {
116 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
120 public List<ToscaPolicyType> getFilteredPolicyTypeList(ToscaPolicyTypeFilter filter) {
121 return new ArrayList<>();
125 public ToscaServiceTemplate createPolicyTypes(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
126 return serviceTemplate;
130 public ToscaServiceTemplate updatePolicyTypes(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
131 return serviceTemplate;
135 public ToscaServiceTemplate deletePolicyType(final String name, final String version) throws PfModelException {
136 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeDeleteResponse.json");
140 public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException {
141 return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
145 public List<ToscaPolicy> getPolicyList(final String name, final String version) throws PfModelException {
146 return new ArrayList<>();
150 public ToscaServiceTemplate getFilteredPolicies(ToscaPolicyFilter filter) throws PfModelException {
151 return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
155 public List<ToscaPolicy> getFilteredPolicyList(ToscaPolicyFilter filter) throws PfModelException {
156 return new ArrayList<>();
160 public ToscaServiceTemplate createPolicies(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
161 return serviceTemplate;
165 public ToscaServiceTemplate updatePolicies(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
166 return serviceTemplate;
170 public ToscaServiceTemplate deletePolicy(final String name, final String version) throws PfModelException {
171 return getDummyResponse("dummyimpl/DummyToscaPolicyDeleteResponse.json");
175 public List<PdpGroup> getPdpGroups(final String name) throws PfModelException {
176 return new ArrayList<>();
180 public List<PdpGroup> getFilteredPdpGroups(PdpGroupFilter filter) throws PfModelException {
181 return new ArrayList<>();
185 public List<PdpGroup> createPdpGroups(final List<PdpGroup> pdpGroups) throws PfModelException {
186 return new ArrayList<>();
190 public List<PdpGroup> updatePdpGroups(final List<PdpGroup> pdpGroups) throws PfModelException {
191 return new ArrayList<>();
195 public void updatePdpSubGroup(final String pdpGroupName, final PdpSubGroup pdpSubGroup) throws PfModelException {
200 public void updatePdp(String pdpGroupName, String pdpSubGroup, Pdp pdp) throws PfModelException {
205 public PdpGroup deletePdpGroup(final String name) throws PfModelException {
210 public List<PdpStatistics> getPdpStatistics(final String name, final Date timestamp) throws PfModelException {
211 return new ArrayList<>();
215 public List<PdpStatistics> getFilteredPdpStatistics(String name, String pdpGroupName, String pdpSubGroup,
216 Date startTimeStamp, Date endTimeStamp, String sortOrder, int getRecordNum) {
218 return new ArrayList<>();
222 public List<PdpStatistics> createPdpStatistics(final List<PdpStatistics> pdpStatisticsList)
223 throws PfModelException {
225 return new ArrayList<>();
229 public List<PdpStatistics> updatePdpStatistics(final List<PdpStatistics> pdpStatisticsList)
230 throws PfModelException {
232 return new ArrayList<>();
236 public List<PdpStatistics> deletePdpStatistics(final String name, final Date timestamp) {
238 return new ArrayList<>();
242 * Return a ToscaServicetemplate dummy response.
244 * @param fileName the file name containing the dummy response
245 * @return the ToscaServiceTemplate with the dummy response
247 protected ToscaServiceTemplate getDummyResponse(final String fileName) {
248 StandardCoder standardCoder = new StandardCoder();
249 ToscaServiceTemplate serviceTemplate;
253 standardCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
254 if (serviceTemplate == null) {
255 throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, "error reading specified file");
257 } catch (Exception exc) {
258 throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "error serializing object", exc);
261 return serviceTemplate;