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 javax.ws.rs.core.Response;
27 import lombok.NonNull;
28 import org.onap.policy.common.utils.resources.ResourceUtils;
29 import org.onap.policy.models.base.PfConceptKey;
30 import org.onap.policy.models.base.PfModelException;
31 import org.onap.policy.models.base.PfModelRuntimeException;
32 import org.onap.policy.models.pap.concepts.PdpGroups;
33 import org.onap.policy.models.provider.PolicyModelsProvider;
34 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
35 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicy;
36 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
37 import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate;
38 import org.onap.policy.models.tosca.simple.serialization.ToscaServiceTemplateMessageBodyHandler;
41 * This class provides a dummy implementation of the Policy Models Provider for the ONAP Policy Framework.
43 * @author Liam Fallon (liam.fallon@est.tech)
44 * @author Chenfei Gao (cgao@research.att.com)
46 public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
48 * Constructor that takes the parameters.
50 * @param parameters the parameters for the provider
52 public DummyPolicyModelsProviderImpl(@NonNull final PolicyModelsProviderParameters parameters) {
56 public void init() throws PfModelException {
57 // Not required on the dummy provider
62 // Not required on the dummy provider
66 public ToscaServiceTemplate getPolicyTypes(@NonNull final PfConceptKey policyTypeKey) throws PfModelException {
67 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
71 public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
72 throws PfModelException {
73 return serviceTemplate;
77 public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
78 throws PfModelException {
79 return serviceTemplate;
83 public ToscaServiceTemplate deletePolicyTypes(@NonNull final PfConceptKey policyTypeKey) throws PfModelException {
84 return getDummyResponse("dummyimpl/DummyToscaPolicyTypeDeleteResponse.json");
88 public ToscaServiceTemplate getPolicies(@NonNull final PfConceptKey policyKey) throws PfModelException {
89 return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
93 public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
94 throws PfModelException {
95 return serviceTemplate;
99 public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
100 throws PfModelException {
101 return serviceTemplate;
105 public ToscaServiceTemplate deletePolicies(@NonNull final PfConceptKey policyKey) throws PfModelException {
106 return getDummyResponse("dummyimpl/DummyToscaPolicyDeleteResponse.json");
111 public LegacyOperationalPolicy getOperationalPolicy(@NonNull final String policyId) throws PfModelException {
112 return new LegacyOperationalPolicy();
116 public LegacyOperationalPolicy createOperationalPolicy(
117 @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
118 return legacyOperationalPolicy;
122 public LegacyOperationalPolicy updateOperationalPolicy(
123 @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
124 return legacyOperationalPolicy;
128 public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final String policyId) throws PfModelException {
129 return new LegacyOperationalPolicy();
133 public LegacyGuardPolicy getGuardPolicy(@NonNull final String policyId) throws PfModelException {
134 return new LegacyGuardPolicy();
138 public LegacyGuardPolicy createGuardPolicy(@NonNull final LegacyGuardPolicy legacyGuardPolicy)
139 throws PfModelException {
140 return legacyGuardPolicy;
144 public LegacyGuardPolicy updateGuardPolicy(@NonNull final LegacyGuardPolicy legacyGuardPolicy)
145 throws PfModelException {
146 return legacyGuardPolicy;
150 public LegacyGuardPolicy deleteGuardPolicy(@NonNull final String policyId) throws PfModelException {
151 return new LegacyGuardPolicy();
155 public PdpGroups getPdpGroups(@NonNull String pdpGroupFilter) throws PfModelException {
156 return new PdpGroups();
160 public PdpGroups createPdpGroups(@NonNull PdpGroups pdpGroups) throws PfModelException {
161 return new PdpGroups();
165 public PdpGroups updatePdpGroups(@NonNull PdpGroups pdpGroups) throws PfModelException {
166 return new PdpGroups();
170 public PdpGroups deletePdpGroups(@NonNull String pdpGroupFilter) throws PfModelException {
171 return new PdpGroups();
175 * Return a ToscaServicetemplate dummy response.
177 * @param fileName the file name containing the dummy response
178 * @return the ToscaServiceTemplate with the dummy response
180 protected ToscaServiceTemplate getDummyResponse(@NonNull final String fileName) {
181 Gson gson = new ToscaServiceTemplateMessageBodyHandler().getGson();
182 ToscaServiceTemplate serviceTemplate;
185 serviceTemplate = gson.fromJson(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
186 if (serviceTemplate == null) {
187 throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, "error reading specified file");
189 } catch (Exception exc) {
190 throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "error serializing object", exc);
193 return serviceTemplate;