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.ToscaServiceTemplate;
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 ToscaServiceTemplate getPolicyTypes(@NonNull final PfConceptKey policyTypeKey) throws PfModelException {
70 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
74 public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
75 throws PfModelException {
76 return serviceTemplate;
80 public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
81 throws PfModelException {
82 return serviceTemplate;
86 public ToscaServiceTemplate deletePolicyTypes(@NonNull final PfConceptKey policyTypeKey) throws PfModelException {
87 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeDeleteResponse.json");
91 public ToscaServiceTemplate getPolicies(@NonNull final PfConceptKey policyKey) throws PfModelException {
92 return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
96 public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
97 throws PfModelException {
98 return serviceTemplate;
102 public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
103 throws PfModelException {
104 return serviceTemplate;
108 public ToscaServiceTemplate deletePolicies(@NonNull final PfConceptKey policyKey) throws PfModelException {
109 return getDummyResponse("dummyimpl/DummyToscaPolicyDeleteResponse.json");
114 public LegacyOperationalPolicy getOperationalPolicy(@NonNull final String policyId) throws PfModelException {
115 return new LegacyOperationalPolicy();
119 public LegacyOperationalPolicy createOperationalPolicy(
120 @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
121 return legacyOperationalPolicy;
125 public LegacyOperationalPolicy updateOperationalPolicy(
126 @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
127 return legacyOperationalPolicy;
131 public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final String policyId) throws PfModelException {
132 return new LegacyOperationalPolicy();
136 public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(@NonNull final String policyId) throws PfModelException {
137 return new HashMap<>();
141 public Map<String, LegacyGuardPolicyOutput> createGuardPolicy(
142 @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException {
143 return new HashMap<>();
147 public Map<String, LegacyGuardPolicyOutput> updateGuardPolicy(
148 @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException {
149 return new HashMap<>();
153 public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(@NonNull final String policyId)
154 throws PfModelException {
155 return new HashMap<>();
159 public PdpGroups getPdpGroups(@NonNull String pdpGroupFilter) throws PfModelException {
160 return new PdpGroups();
164 public PdpGroups createPdpGroups(@NonNull PdpGroups pdpGroups) throws PfModelException {
165 return new PdpGroups();
169 public PdpGroups updatePdpGroups(@NonNull PdpGroups pdpGroups) throws PfModelException {
170 return new PdpGroups();
174 public PdpGroups deletePdpGroups(@NonNull String pdpGroupFilter) throws PfModelException {
175 return new PdpGroups();
179 * Return a ToscaServicetemplate dummy response.
181 * @param fileName the file name containing the dummy response
182 * @return the ToscaServiceTemplate with the dummy response
184 protected ToscaServiceTemplate getDummyResponse(@NonNull final String fileName) {
185 Gson gson = new ToscaServiceTemplateMessageBodyHandler().getGson();
186 ToscaServiceTemplate serviceTemplate;
189 serviceTemplate = gson.fromJson(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
190 if (serviceTemplate == null) {
191 throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, "error reading specified file");
193 } catch (Exception exc) {
194 throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "error serializing object", exc);
197 return serviceTemplate;