2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019-2020 Nordix Foundation.
4 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.models.provider.impl;
24 import java.util.ArrayList;
25 import java.util.Date;
26 import java.util.List;
27 import javax.ws.rs.core.Response;
28 import org.onap.policy.common.utils.coder.StandardCoder;
29 import org.onap.policy.common.utils.resources.ResourceUtils;
30 import org.onap.policy.models.base.PfModelException;
31 import org.onap.policy.models.base.PfModelRuntimeException;
32 import org.onap.policy.models.pdp.concepts.Pdp;
33 import org.onap.policy.models.pdp.concepts.PdpGroup;
34 import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
35 import org.onap.policy.models.pdp.concepts.PdpStatistics;
36 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
37 import org.onap.policy.models.provider.PolicyModelsProvider;
38 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
39 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
40 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
41 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
42 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
43 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
44 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
47 * This class provides a dummy implementation of the Policy Models Provider for the ONAP Policy Framework.
49 * @author Liam Fallon (liam.fallon@est.tech)
50 * @author Chenfei Gao (cgao@research.att.com)
52 public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
54 * Constructor that takes the parameters.
56 * @param parameters the parameters for the provider
58 public DummyPolicyModelsProviderImpl(final PolicyModelsProviderParameters parameters) {
59 // Default constructor
63 public void init() throws PfModelException {
64 // Not required on the dummy provider
69 // Not required on the dummy provider
73 public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException {
74 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
78 public List<ToscaPolicyType> getPolicyTypeList(final String name, final String version) throws PfModelException {
79 return new ArrayList<>();
83 public ToscaServiceTemplate getFilteredPolicyTypes(ToscaPolicyTypeFilter filter) throws PfModelException {
84 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
88 public List<ToscaPolicyType> getFilteredPolicyTypeList(ToscaPolicyTypeFilter filter) {
89 return new ArrayList<>();
93 public ToscaServiceTemplate createPolicyTypes(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
94 return serviceTemplate;
98 public ToscaServiceTemplate updatePolicyTypes(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
99 return serviceTemplate;
103 public ToscaServiceTemplate deletePolicyType(final String name, final String version) throws PfModelException {
104 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeDeleteResponse.json");
108 public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException {
109 return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
113 public List<ToscaPolicy> getPolicyList(final String name, final String version) throws PfModelException {
114 return new ArrayList<>();
118 public ToscaServiceTemplate getFilteredPolicies(ToscaPolicyFilter filter) throws PfModelException {
119 return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
123 public List<ToscaPolicy> getFilteredPolicyList(ToscaPolicyFilter filter) throws PfModelException {
124 return new ArrayList<>();
128 public ToscaServiceTemplate createPolicies(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
129 return serviceTemplate;
133 public ToscaServiceTemplate updatePolicies(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
134 return serviceTemplate;
138 public ToscaServiceTemplate deletePolicy(final String name, final String version) throws PfModelException {
139 return getDummyResponse("dummyimpl/DummyToscaPolicyDeleteResponse.json");
144 public LegacyOperationalPolicy getOperationalPolicy(final String policyId, final String policyVersion)
145 throws PfModelException {
146 return new LegacyOperationalPolicy();
150 public LegacyOperationalPolicy createOperationalPolicy(final LegacyOperationalPolicy legacyOperationalPolicy)
151 throws PfModelException {
152 return legacyOperationalPolicy;
156 public LegacyOperationalPolicy updateOperationalPolicy(final LegacyOperationalPolicy legacyOperationalPolicy)
157 throws PfModelException {
158 return legacyOperationalPolicy;
162 public LegacyOperationalPolicy deleteOperationalPolicy(final String policyId, final String policyVersion)
163 throws PfModelException {
164 return new LegacyOperationalPolicy();
168 public List<PdpGroup> getPdpGroups(final String name) throws PfModelException {
169 return new ArrayList<>();
173 public List<PdpGroup> getFilteredPdpGroups(PdpGroupFilter filter) throws PfModelException {
174 return new ArrayList<>();
178 public List<PdpGroup> createPdpGroups(final List<PdpGroup> pdpGroups) throws PfModelException {
179 return new ArrayList<>();
183 public List<PdpGroup> updatePdpGroups(final List<PdpGroup> pdpGroups) throws PfModelException {
184 return new ArrayList<>();
188 public void updatePdpSubGroup(final String pdpGroupName, final PdpSubGroup pdpSubGroup) throws PfModelException {
193 public void updatePdp(String pdpGroupName, String pdpSubGroup, Pdp pdp) throws PfModelException {
198 public PdpGroup deletePdpGroup(final String name) throws PfModelException {
203 public List<PdpStatistics> getPdpStatistics(final String name, final Date timestamp) throws PfModelException {
204 return new ArrayList<>();
208 public List<PdpStatistics> getFilteredPdpStatistics(String name, String pdpGroupName, String pdpSubGroup,
209 Date startTimeStamp, Date endTimeStamp, String sortOrder, int getRecordNum) {
211 return new ArrayList<>();
215 public List<PdpStatistics> createPdpStatistics(final List<PdpStatistics> pdpStatisticsList)
216 throws PfModelException {
218 return new ArrayList<>();
222 public List<PdpStatistics> updatePdpStatistics(final List<PdpStatistics> pdpStatisticsList)
223 throws PfModelException {
225 return new ArrayList<>();
229 public List<PdpStatistics> deletePdpStatistics(final String name, final Date timestamp) {
231 return new ArrayList<>();
235 * Return a ToscaServicetemplate dummy response.
237 * @param fileName the file name containing the dummy response
238 * @return the ToscaServiceTemplate with the dummy response
240 protected ToscaServiceTemplate getDummyResponse(final String fileName) {
241 StandardCoder standardCoder = new StandardCoder();
242 ToscaServiceTemplate serviceTemplate;
246 standardCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
247 if (serviceTemplate == null) {
248 throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, "error reading specified file");
250 } catch (Exception exc) {
251 throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "error serializing object", exc);
254 return serviceTemplate;