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;
30 import lombok.NonNull;
32 import org.onap.policy.common.utils.coder.StandardCoder;
33 import org.onap.policy.common.utils.resources.ResourceUtils;
34 import org.onap.policy.models.base.PfModelException;
35 import org.onap.policy.models.base.PfModelRuntimeException;
36 import org.onap.policy.models.pdp.concepts.Pdp;
37 import org.onap.policy.models.pdp.concepts.PdpGroup;
38 import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
39 import org.onap.policy.models.pdp.concepts.PdpStatistics;
40 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
41 import org.onap.policy.models.provider.PolicyModelsProvider;
42 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
43 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
44 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
45 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
46 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
47 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
48 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
49 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
50 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
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(@NonNull final PolicyModelsProviderParameters parameters) {}
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(@NonNull ToscaPolicyTypeFilter filter) throws PfModelException {
92 public List<ToscaPolicyType> getFilteredPolicyTypeList(@NonNull ToscaPolicyTypeFilter filter) {
93 return new ArrayList<>();
97 public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
98 throws PfModelException {
99 return serviceTemplate;
103 public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
104 throws PfModelException {
105 return serviceTemplate;
109 public ToscaServiceTemplate deletePolicyType(@NonNull final String name, @NonNull final String version)
110 throws PfModelException {
111 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeDeleteResponse.json");
115 public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException {
116 return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
120 public List<ToscaPolicy> getPolicyList(final String name, final String version) throws PfModelException {
121 return new ArrayList<>();
125 public ToscaServiceTemplate getFilteredPolicies(@NonNull ToscaPolicyFilter filter) throws PfModelException {
130 public List<ToscaPolicy> getFilteredPolicyList(@NonNull ToscaPolicyFilter filter) throws PfModelException {
131 return new ArrayList<>();
135 public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
136 throws PfModelException {
137 return serviceTemplate;
141 public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
142 throws PfModelException {
143 return serviceTemplate;
147 public ToscaServiceTemplate deletePolicy(@NonNull final String name, @NonNull final String version)
148 throws PfModelException {
149 return getDummyResponse("dummyimpl/DummyToscaPolicyDeleteResponse.json");
154 public LegacyOperationalPolicy getOperationalPolicy(@NonNull final String policyId) throws PfModelException {
155 return new LegacyOperationalPolicy();
159 public LegacyOperationalPolicy createOperationalPolicy(
160 @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
161 return legacyOperationalPolicy;
165 public LegacyOperationalPolicy updateOperationalPolicy(
166 @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
167 return legacyOperationalPolicy;
171 public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final String policyId) throws PfModelException {
172 return new LegacyOperationalPolicy();
176 public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(@NonNull final String policyId) throws PfModelException {
177 return new HashMap<>();
181 public Map<String, LegacyGuardPolicyOutput> createGuardPolicy(
182 @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException {
183 return new HashMap<>();
187 public Map<String, LegacyGuardPolicyOutput> updateGuardPolicy(
188 @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException {
189 return new HashMap<>();
193 public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(@NonNull final String policyId)
194 throws PfModelException {
195 return new HashMap<>();
199 public List<PdpGroup> getPdpGroups(final String name, final String version) throws PfModelException {
200 return new ArrayList<>();
204 public List<PdpGroup> getFilteredPdpGroups(@NonNull PdpGroupFilter filter) throws PfModelException {
205 return new ArrayList<>();
209 public List<PdpGroup> createPdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException {
210 return new ArrayList<>();
214 public List<PdpGroup> updatePdpGroups(@NonNull final List<PdpGroup> pdpGroups) throws PfModelException {
215 return new ArrayList<>();
219 public void updatePdpSubGroup(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion,
220 @NonNull final PdpSubGroup pdpSubGroup) throws PfModelException {
225 public void updatePdp(@NonNull String pdpGroupName, @NonNull String pdpGroupVersion,
226 @NonNull String pdpSubGroup, @NonNull Pdp pdp) throws PfModelException {
231 public PdpGroup deletePdpGroup(@NonNull final String name, @NonNull final String version) throws PfModelException {
236 public List<PdpStatistics> getPdpStatistics(final String name, final String version) throws PfModelException {
237 return new ArrayList<>();
241 public void updatePdpStatistics(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion,
242 @NonNull final String pdpType, @NonNull final String pdpInstanceId,
243 @NonNull final PdpStatistics pdppStatistics) throws PfModelException {
248 * Return a ToscaServicetemplate dummy response.
250 * @param fileName the file name containing the dummy response
251 * @return the ToscaServiceTemplate with the dummy response
253 protected ToscaServiceTemplate getDummyResponse(@NonNull final String fileName) {
254 StandardCoder standardCoder = new StandardCoder();
255 ToscaServiceTemplate serviceTemplate;
259 standardCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
260 if (serviceTemplate == null) {
261 throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, "error reading specified file");
263 } catch (Exception exc) {
264 throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "error serializing object", exc);
267 return serviceTemplate;