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.provider.PolicyModelsProvider;
34 import org.onap.policy.models.tosca.concepts.ToscaServiceTemplate;
35 import org.onap.policy.models.tosca.serialization.legacy.LegacyGuardPolicy;
36 import org.onap.policy.models.tosca.serialization.legacy.LegacyOperationalPolicy;
37 import org.onap.policy.models.tosca.serialization.simple.ToscaServiceTemplateMessageBodyHandler;
40 * This class provides a dummy implementation of the Policy Models Provider for the ONAP Policy
43 * @author Liam Fallon (liam.fallon@est.tech)
45 public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
47 public ToscaServiceTemplate getPolicyTypes(@NonNull PfConceptKey policyTypeKey) throws PfModelException {
48 return getDummyResponse("src/main/resources/dummyimpl/DummyToscaPolicyTypeGetResponse.json");
52 public ToscaServiceTemplate createPolicyTypes(@NonNull ToscaServiceTemplate serviceTemplate)
53 throws PfModelException {
54 return serviceTemplate;
58 public ToscaServiceTemplate updatePolicyTypes(@NonNull ToscaServiceTemplate serviceTemplate)
59 throws PfModelException {
60 return serviceTemplate;
64 public ToscaServiceTemplate deletePolicyTypes(@NonNull PfConceptKey policyTypeKey) throws PfModelException {
65 return getDummyResponse("src/main/resources/dummyimpl/DummyToscaPolicyTypeDeleteResponse.json");
69 public ToscaServiceTemplate getPolicies(@NonNull PfConceptKey policyKey) throws PfModelException {
70 return getDummyResponse("src/main/resources/dummyimpl/DummyToscaPolicyGetResponse.json");
74 public ToscaServiceTemplate createPolicies(@NonNull ToscaServiceTemplate serviceTemplate) throws PfModelException {
75 return serviceTemplate;
79 public ToscaServiceTemplate updatePolicies(@NonNull ToscaServiceTemplate serviceTemplate) throws PfModelException {
80 return serviceTemplate;
84 public ToscaServiceTemplate deletePolicies(@NonNull PfConceptKey policyKey) throws PfModelException {
85 return getDummyResponse("src/main/resources/dummyimpl/DummyToscaPolicyDeleteResponse.json");
89 public LegacyOperationalPolicy getOperationalPolicy(@NonNull String policyId) throws PfModelException {
90 return new LegacyOperationalPolicy();
94 public LegacyOperationalPolicy createOperationalPolicy(@NonNull LegacyOperationalPolicy legacyOperationalPolicy)
95 throws PfModelException {
96 return legacyOperationalPolicy;
100 public LegacyOperationalPolicy updateOperationalPolicy(@NonNull LegacyOperationalPolicy legacyOperationalPolicy)
101 throws PfModelException {
102 return legacyOperationalPolicy;
106 public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull String policyId) throws PfModelException {
107 return new LegacyOperationalPolicy();
111 public LegacyGuardPolicy getGuardPolicy(@NonNull String policyId) throws PfModelException {
112 return new LegacyGuardPolicy();
116 public LegacyGuardPolicy createGuardPolicy(@NonNull LegacyGuardPolicy legacyGuardPolicy) throws PfModelException {
117 return legacyGuardPolicy;
121 public LegacyGuardPolicy updateGuardPolicy(@NonNull LegacyGuardPolicy legacyGuardPolicy) throws PfModelException {
122 return legacyGuardPolicy;
126 public LegacyGuardPolicy deleteGuardPolicy(@NonNull String policyId) throws PfModelException {
127 return new LegacyGuardPolicy();
131 public Object getPdpGroups(@NonNull Object somePdpGroupFilter) throws PfModelException {
136 public Object createPdpGroups(@NonNull Object somePdpGroupSpecification) throws PfModelException {
141 public Object updatePdpGroups(@NonNull Object somePdpGroupSpecification) throws PfModelException {
146 public Object deletePdpGroups(@NonNull Object somePdpGroupFilter) throws PfModelException {
151 * Return a ToscaServicetemplate dummy response.
153 * @param fileName the file name containing the dummy response
154 * @return the ToscaServiceTemplate with the dummy response
156 private ToscaServiceTemplate getDummyResponse(@NonNull final String fileName) {
157 Gson gson = new ToscaServiceTemplateMessageBodyHandler().getGson();
158 ToscaServiceTemplate serviceTemplate;
161 serviceTemplate = gson.fromJson(TextFileUtils.getTextFileAsString(fileName), ToscaServiceTemplate.class);
162 } catch (Exception exc) {
163 throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "error serializing object", exc);
166 return serviceTemplate;