2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.models.provider.impl;
23 import com.google.gson.Gson;
25 import javax.ws.rs.core.Response;
27 import lombok.NonNull;
29 import org.onap.policy.common.utils.resources.TextFileUtils;
30 import org.onap.policy.models.base.PfConceptKey;
31 import org.onap.policy.models.base.PfModelException;
32 import org.onap.policy.models.base.PfModelRuntimeException;
33 import org.onap.policy.models.pap.concepts.PdpGroups;
34 import org.onap.policy.models.provider.PolicyModelsProvider;
35 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
36 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicy;
37 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
38 import org.onap.policy.models.tosca.simple.concepts.ToscaServiceTemplate;
39 import org.onap.policy.models.tosca.simple.serialization.ToscaServiceTemplateMessageBodyHandler;
42 * This class provides a dummy implementation of the Policy Models Provider for the ONAP Policy Framework.
44 * @author Liam Fallon (liam.fallon@est.tech)
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("src/main/resources/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("src/main/resources/dummyimpl/DummyToscaPolicyTypeDeleteResponse.json");
88 public ToscaServiceTemplate getPolicies(@NonNull final PfConceptKey policyKey) throws PfModelException {
89 return getDummyResponse("src/main/resources/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("src/main/resources/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(TextFileUtils.getTextFileAsString(fileName), ToscaServiceTemplate.class);
186 } catch (Exception exc) {
187 throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "error serializing object", exc);
190 return serviceTemplate;