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.HashMap;
27 import javax.ws.rs.core.Response;
28 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.PdpGroups;
35 import org.onap.policy.models.provider.PolicyModelsProvider;
36 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
37 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
38 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
39 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
40 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
43 * This class provides a dummy implementation of the Policy Models Provider for the ONAP Policy Framework.
45 * @author Liam Fallon (liam.fallon@est.tech)
46 * @author Chenfei Gao (cgao@research.att.com)
48 public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
50 * Constructor that takes the parameters.
52 * @param parameters the parameters for the provider
54 public DummyPolicyModelsProviderImpl(@NonNull final PolicyModelsProviderParameters parameters) {}
57 public void init() throws PfModelException {
58 // Not required on the dummy provider
63 // Not required on the dummy provider
67 public ToscaServiceTemplate getPolicyTypes(@NonNull final String name, @NonNull final String version)
68 throws PfModelException {
69 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
73 public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
74 throws PfModelException {
75 return serviceTemplate;
79 public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
80 throws PfModelException {
81 return serviceTemplate;
85 public ToscaServiceTemplate deletePolicyTypes(@NonNull final String name, @NonNull final String version)
86 throws PfModelException {
87 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeDeleteResponse.json");
91 public ToscaServiceTemplate getPolicies(@NonNull final String name, @NonNull final String version)
92 throws PfModelException {
93 return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
97 public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
98 throws PfModelException {
99 return serviceTemplate;
103 public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
104 throws PfModelException {
105 return serviceTemplate;
109 public ToscaServiceTemplate deletePolicies(@NonNull final String name, @NonNull final String version)
110 throws PfModelException {
111 return getDummyResponse("dummyimpl/DummyToscaPolicyDeleteResponse.json");
116 public LegacyOperationalPolicy getOperationalPolicy(@NonNull final String policyId) throws PfModelException {
117 return new LegacyOperationalPolicy();
121 public LegacyOperationalPolicy createOperationalPolicy(
122 @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
123 return legacyOperationalPolicy;
127 public LegacyOperationalPolicy updateOperationalPolicy(
128 @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
129 return legacyOperationalPolicy;
133 public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final String policyId) throws PfModelException {
134 return new LegacyOperationalPolicy();
138 public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(@NonNull final String policyId) throws PfModelException {
139 return new HashMap<>();
143 public Map<String, LegacyGuardPolicyOutput> createGuardPolicy(
144 @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException {
145 return new HashMap<>();
149 public Map<String, LegacyGuardPolicyOutput> updateGuardPolicy(
150 @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException {
151 return new HashMap<>();
155 public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(@NonNull final String policyId)
156 throws PfModelException {
157 return new HashMap<>();
161 public PdpGroups getPdpGroups(@NonNull String pdpGroupFilter) throws PfModelException {
162 return new PdpGroups();
166 public PdpGroups createPdpGroups(@NonNull PdpGroups pdpGroups) throws PfModelException {
167 return new PdpGroups();
171 public PdpGroups updatePdpGroups(@NonNull PdpGroups pdpGroups) throws PfModelException {
172 return new PdpGroups();
176 public PdpGroups deletePdpGroups(@NonNull String pdpGroupFilter) throws PfModelException {
177 return new PdpGroups();
181 * Return a ToscaServicetemplate dummy response.
183 * @param fileName the file name containing the dummy response
184 * @return the ToscaServiceTemplate with the dummy response
186 protected ToscaServiceTemplate getDummyResponse(@NonNull final String fileName) {
187 StandardCoder standardCoder = new StandardCoder();
188 ToscaServiceTemplate serviceTemplate;
192 standardCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
193 if (serviceTemplate == null) {
194 throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, "error reading specified file");
196 } catch (Exception exc) {
197 throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "error serializing object", exc);
200 return serviceTemplate;