2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 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.HashMap;
26 import java.util.List;
29 import javax.ws.rs.core.Response;
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.PdpStatistics;
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.ToscaPolicy;
43 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
44 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
45 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
46 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
47 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
48 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
49 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
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) {}
66 public void init() throws PfModelException {
67 // Not required on the dummy provider
72 // Not required on the dummy provider
76 public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException {
77 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
81 public List<ToscaPolicyType> getPolicyTypeList(final String name, final String version) throws PfModelException {
82 return new ArrayList<>();
86 public ToscaServiceTemplate getFilteredPolicyTypes(ToscaPolicyTypeFilter filter) throws PfModelException {
87 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
91 public List<ToscaPolicyType> getFilteredPolicyTypeList(ToscaPolicyTypeFilter filter) {
92 return new ArrayList<>();
96 public ToscaServiceTemplate createPolicyTypes(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
97 return serviceTemplate;
101 public ToscaServiceTemplate updatePolicyTypes(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
102 return serviceTemplate;
106 public ToscaServiceTemplate deletePolicyType(final String name, final String version) throws PfModelException {
107 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeDeleteResponse.json");
111 public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException {
112 return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
116 public List<ToscaPolicy> getPolicyList(final String name, final String version) throws PfModelException {
117 return new ArrayList<>();
121 public ToscaServiceTemplate getFilteredPolicies(ToscaPolicyFilter filter) throws PfModelException {
122 return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
126 public List<ToscaPolicy> getFilteredPolicyList(ToscaPolicyFilter filter) throws PfModelException {
127 return new ArrayList<>();
131 public ToscaServiceTemplate createPolicies(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
132 return serviceTemplate;
136 public ToscaServiceTemplate updatePolicies(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
137 return serviceTemplate;
141 public ToscaServiceTemplate deletePolicy(final String name, final String version) throws PfModelException {
142 return getDummyResponse("dummyimpl/DummyToscaPolicyDeleteResponse.json");
147 public LegacyOperationalPolicy getOperationalPolicy(final String policyId, final String policyVersion)
148 throws PfModelException {
149 return new LegacyOperationalPolicy();
153 public LegacyOperationalPolicy createOperationalPolicy(final LegacyOperationalPolicy legacyOperationalPolicy)
154 throws PfModelException {
155 return legacyOperationalPolicy;
159 public LegacyOperationalPolicy updateOperationalPolicy(final LegacyOperationalPolicy legacyOperationalPolicy)
160 throws PfModelException {
161 return legacyOperationalPolicy;
165 public LegacyOperationalPolicy deleteOperationalPolicy(final String policyId, final String policyVersion)
166 throws PfModelException {
167 return new LegacyOperationalPolicy();
171 public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(final String policyId, final String policyVersion)
172 throws PfModelException {
173 return new HashMap<>();
177 public Map<String, LegacyGuardPolicyOutput> createGuardPolicy(final LegacyGuardPolicyInput legacyGuardPolicy)
178 throws PfModelException {
179 return new HashMap<>();
183 public Map<String, LegacyGuardPolicyOutput> updateGuardPolicy(final LegacyGuardPolicyInput legacyGuardPolicy)
184 throws PfModelException {
185 return new HashMap<>();
189 public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(final String policyId, final String policyVersion)
190 throws PfModelException {
191 return new HashMap<>();
195 public List<PdpGroup> getPdpGroups(final String name) throws PfModelException {
196 return new ArrayList<>();
200 public List<PdpGroup> getFilteredPdpGroups(PdpGroupFilter filter) throws PfModelException {
201 return new ArrayList<>();
205 public List<PdpGroup> createPdpGroups(final List<PdpGroup> pdpGroups) throws PfModelException {
206 return new ArrayList<>();
210 public List<PdpGroup> updatePdpGroups(final List<PdpGroup> pdpGroups) throws PfModelException {
211 return new ArrayList<>();
215 public void updatePdpSubGroup(final String pdpGroupName, final PdpSubGroup pdpSubGroup) throws PfModelException {
220 public void updatePdp(String pdpGroupName, String pdpSubGroup, Pdp pdp) throws PfModelException {
225 public PdpGroup deletePdpGroup(final String name) throws PfModelException {
230 public List<PdpStatistics> getPdpStatistics(final String name) throws PfModelException {
231 return new ArrayList<>();
235 public void updatePdpStatistics(final String pdpGroupName, final String pdpType, final String pdpInstanceId,
236 final PdpStatistics pdppStatistics) throws PfModelException {
241 * Return a ToscaServicetemplate dummy response.
243 * @param fileName the file name containing the dummy response
244 * @return the ToscaServiceTemplate with the dummy response
246 protected ToscaServiceTemplate getDummyResponse(final String fileName) {
247 StandardCoder standardCoder = new StandardCoder();
248 ToscaServiceTemplate serviceTemplate;
252 standardCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
253 if (serviceTemplate == null) {
254 throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, "error reading specified file");
256 } catch (Exception exc) {
257 throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "error serializing object", exc);
260 return serviceTemplate;