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 com.google.gson.Gson;
26 import java.util.HashMap;
29 import javax.ws.rs.core.Response;
30 import lombok.NonNull;
31 import org.onap.policy.common.utils.resources.ResourceUtils;
32 import org.onap.policy.models.base.PfConceptKey;
33 import org.onap.policy.models.base.PfModelException;
34 import org.onap.policy.models.base.PfModelRuntimeException;
35 import org.onap.policy.models.pdp.concepts.PdpGroups;
36 import org.onap.policy.models.provider.PolicyModelsProvider;
37 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
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;
41 import org.onap.policy.models.tosca.simple.concepts.JpaToscaServiceTemplate;
42 import org.onap.policy.models.tosca.simple.serialization.ToscaServiceTemplateMessageBodyHandler;
45 * This class provides a dummy implementation of the Policy Models Provider for the ONAP Policy Framework.
47 * @author Liam Fallon (liam.fallon@est.tech)
48 * @author Chenfei Gao (cgao@research.att.com)
50 public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
52 * Constructor that takes the parameters.
54 * @param parameters the parameters for the provider
56 public DummyPolicyModelsProviderImpl(@NonNull final PolicyModelsProviderParameters parameters) {}
59 public void init() throws PfModelException {
60 // Not required on the dummy provider
65 // Not required on the dummy provider
69 public JpaToscaServiceTemplate getPolicyTypes(@NonNull final PfConceptKey policyTypeKey) throws PfModelException {
70 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
74 public JpaToscaServiceTemplate createPolicyTypes(@NonNull final JpaToscaServiceTemplate serviceTemplate)
75 throws PfModelException {
76 return serviceTemplate;
80 public JpaToscaServiceTemplate updatePolicyTypes(@NonNull final JpaToscaServiceTemplate serviceTemplate)
81 throws PfModelException {
82 return serviceTemplate;
86 public JpaToscaServiceTemplate deletePolicyTypes(@NonNull final PfConceptKey policyTypeKey)
87 throws PfModelException {
88 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeDeleteResponse.json");
92 public JpaToscaServiceTemplate getPolicies(@NonNull final PfConceptKey policyKey) throws PfModelException {
93 return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
97 public JpaToscaServiceTemplate createPolicies(@NonNull final JpaToscaServiceTemplate serviceTemplate)
98 throws PfModelException {
99 return serviceTemplate;
103 public JpaToscaServiceTemplate updatePolicies(@NonNull final JpaToscaServiceTemplate serviceTemplate)
104 throws PfModelException {
105 return serviceTemplate;
109 public JpaToscaServiceTemplate deletePolicies(@NonNull final PfConceptKey policyKey) throws PfModelException {
110 return getDummyResponse("dummyimpl/DummyToscaPolicyDeleteResponse.json");
115 public LegacyOperationalPolicy getOperationalPolicy(@NonNull final String policyId) throws PfModelException {
116 return new LegacyOperationalPolicy();
120 public LegacyOperationalPolicy createOperationalPolicy(
121 @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
122 return legacyOperationalPolicy;
126 public LegacyOperationalPolicy updateOperationalPolicy(
127 @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
128 return legacyOperationalPolicy;
132 public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final String policyId) throws PfModelException {
133 return new LegacyOperationalPolicy();
137 public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(@NonNull final String policyId) throws PfModelException {
138 return new HashMap<>();
142 public Map<String, LegacyGuardPolicyOutput> createGuardPolicy(
143 @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException {
144 return new HashMap<>();
148 public Map<String, LegacyGuardPolicyOutput> updateGuardPolicy(
149 @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException {
150 return new HashMap<>();
154 public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(@NonNull final String policyId)
155 throws PfModelException {
156 return new HashMap<>();
160 public PdpGroups getPdpGroups(@NonNull String pdpGroupFilter) throws PfModelException {
161 return new PdpGroups();
165 public PdpGroups createPdpGroups(@NonNull PdpGroups pdpGroups) throws PfModelException {
166 return new PdpGroups();
170 public PdpGroups updatePdpGroups(@NonNull PdpGroups pdpGroups) throws PfModelException {
171 return new PdpGroups();
175 public PdpGroups deletePdpGroups(@NonNull String pdpGroupFilter) throws PfModelException {
176 return new PdpGroups();
180 * Return a ToscaServicetemplate dummy response.
182 * @param fileName the file name containing the dummy response
183 * @return the ToscaServiceTemplate with the dummy response
185 protected JpaToscaServiceTemplate getDummyResponse(@NonNull final String fileName) {
186 Gson gson = new ToscaServiceTemplateMessageBodyHandler().getGson();
187 JpaToscaServiceTemplate serviceTemplate;
190 serviceTemplate = gson.fromJson(ResourceUtils.getResourceAsString(fileName), JpaToscaServiceTemplate.class);
191 if (serviceTemplate == null) {
192 throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, "error reading specified file");
194 } catch (Exception exc) {
195 throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "error serializing object", exc);
198 return serviceTemplate;