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.Date;
26 import java.util.HashMap;
27 import java.util.List;
29 import javax.ws.rs.core.Response;
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.legacy.concepts.LegacyGuardPolicyInput;
47 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
48 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
51 * This class provides a dummy implementation of the Policy Models Provider for the ONAP Policy Framework.
53 * @author Liam Fallon (liam.fallon@est.tech)
54 * @author Chenfei Gao (cgao@research.att.com)
56 public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
58 * Constructor that takes the parameters.
60 * @param parameters the parameters for the provider
62 public DummyPolicyModelsProviderImpl(final PolicyModelsProviderParameters parameters) {
63 // Default constructor
67 public void init() throws PfModelException {
68 // Not required on the dummy provider
73 // Not required on the dummy provider
77 public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException {
78 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
82 public List<ToscaPolicyType> getPolicyTypeList(final String name, final String version) throws PfModelException {
83 return new ArrayList<>();
87 public ToscaServiceTemplate getFilteredPolicyTypes(ToscaPolicyTypeFilter filter) throws PfModelException {
88 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
92 public List<ToscaPolicyType> getFilteredPolicyTypeList(ToscaPolicyTypeFilter filter) {
93 return new ArrayList<>();
97 public ToscaServiceTemplate createPolicyTypes(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
98 return serviceTemplate;
102 public ToscaServiceTemplate updatePolicyTypes(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
103 return serviceTemplate;
107 public ToscaServiceTemplate deletePolicyType(final String name, final String version) throws PfModelException {
108 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeDeleteResponse.json");
112 public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException {
113 return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
117 public List<ToscaPolicy> getPolicyList(final String name, final String version) throws PfModelException {
118 return new ArrayList<>();
122 public ToscaServiceTemplate getFilteredPolicies(ToscaPolicyFilter filter) throws PfModelException {
123 return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
127 public List<ToscaPolicy> getFilteredPolicyList(ToscaPolicyFilter filter) throws PfModelException {
128 return new ArrayList<>();
132 public ToscaServiceTemplate createPolicies(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
133 return serviceTemplate;
137 public ToscaServiceTemplate updatePolicies(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
138 return serviceTemplate;
142 public ToscaServiceTemplate deletePolicy(final String name, final String version) throws PfModelException {
143 return getDummyResponse("dummyimpl/DummyToscaPolicyDeleteResponse.json");
148 public LegacyOperationalPolicy getOperationalPolicy(final String policyId, final String policyVersion)
149 throws PfModelException {
150 return new LegacyOperationalPolicy();
154 public LegacyOperationalPolicy createOperationalPolicy(final LegacyOperationalPolicy legacyOperationalPolicy)
155 throws PfModelException {
156 return legacyOperationalPolicy;
160 public LegacyOperationalPolicy updateOperationalPolicy(final LegacyOperationalPolicy legacyOperationalPolicy)
161 throws PfModelException {
162 return legacyOperationalPolicy;
166 public LegacyOperationalPolicy deleteOperationalPolicy(final String policyId, final String policyVersion)
167 throws PfModelException {
168 return new LegacyOperationalPolicy();
172 public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(final String policyId, final String policyVersion)
173 throws PfModelException {
174 return new HashMap<>();
178 public Map<String, LegacyGuardPolicyOutput> createGuardPolicy(final LegacyGuardPolicyInput legacyGuardPolicy)
179 throws PfModelException {
180 return new HashMap<>();
184 public Map<String, LegacyGuardPolicyOutput> updateGuardPolicy(final LegacyGuardPolicyInput legacyGuardPolicy)
185 throws PfModelException {
186 return new HashMap<>();
190 public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(final String policyId, final String policyVersion)
191 throws PfModelException {
192 return new HashMap<>();
196 public List<PdpGroup> getPdpGroups(final String name) throws PfModelException {
197 return new ArrayList<>();
201 public List<PdpGroup> getFilteredPdpGroups(PdpGroupFilter filter) throws PfModelException {
202 return new ArrayList<>();
206 public List<PdpGroup> createPdpGroups(final List<PdpGroup> pdpGroups) throws PfModelException {
207 return new ArrayList<>();
211 public List<PdpGroup> updatePdpGroups(final List<PdpGroup> pdpGroups) throws PfModelException {
212 return new ArrayList<>();
216 public void updatePdpSubGroup(final String pdpGroupName, final PdpSubGroup pdpSubGroup) throws PfModelException {
221 public void updatePdp(String pdpGroupName, String pdpSubGroup, Pdp pdp) throws PfModelException {
226 public PdpGroup deletePdpGroup(final String name) throws PfModelException {
231 public List<PdpStatistics> getPdpStatistics(final String name, final Date timestamp) throws PfModelException {
232 return new ArrayList<>();
236 public List<PdpStatistics> getFilteredPdpStatistics(String name, String pdpGroupName, String pdpSubGroup,
237 Date startTimeStamp, Date endTimeStamp) {
239 return new ArrayList<>();
243 public List<PdpStatistics> createPdpStatistics(final List<PdpStatistics> pdpStatisticsList)
244 throws PfModelException {
246 return new ArrayList<>();
250 public List<PdpStatistics> updatePdpStatistics(final List<PdpStatistics> pdpStatisticsList)
251 throws PfModelException {
253 return new ArrayList<>();
257 public List<PdpStatistics> deletePdpStatistics(final String name, final Date timestamp) {
263 * Return a ToscaServicetemplate dummy response.
265 * @param fileName the file name containing the dummy response
266 * @return the ToscaServiceTemplate with the dummy response
268 protected ToscaServiceTemplate getDummyResponse(final String fileName) {
269 StandardCoder standardCoder = new StandardCoder();
270 ToscaServiceTemplate serviceTemplate;
274 standardCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
275 if (serviceTemplate == null) {
276 throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, "error reading specified file");
278 } catch (Exception exc) {
279 throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "error serializing object", exc);
282 return serviceTemplate;