Merge "Parse new model ids from operation policy"
[policy/models.git] / models-provider / src / main / java / org / onap / policy / models / provider / impl / DummyPolicyModelsProviderImpl.java
1 /*-
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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.models.provider.impl;
23
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28
29 import javax.ws.rs.core.Response;
30
31 import org.onap.policy.common.utils.coder.StandardCoder;
32 import org.onap.policy.common.utils.resources.ResourceUtils;
33 import org.onap.policy.models.base.PfModelException;
34 import org.onap.policy.models.base.PfModelRuntimeException;
35 import org.onap.policy.models.pdp.concepts.Pdp;
36 import org.onap.policy.models.pdp.concepts.PdpGroup;
37 import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
38 import org.onap.policy.models.pdp.concepts.PdpStatistics;
39 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
40 import org.onap.policy.models.provider.PolicyModelsProvider;
41 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
42 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
43 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
44 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
45 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
46 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
47 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyInput;
48 import org.onap.policy.models.tosca.legacy.concepts.LegacyGuardPolicyOutput;
49 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
50
51 /**
52  * This class provides a dummy implementation of the Policy Models Provider for the ONAP Policy Framework.
53  *
54  * @author Liam Fallon (liam.fallon@est.tech)
55  * @author Chenfei Gao (cgao@research.att.com)
56  */
57 public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
58     /**
59      * Constructor that takes the parameters.
60      *
61      * @param parameters the parameters for the provider
62      */
63     public DummyPolicyModelsProviderImpl(final PolicyModelsProviderParameters parameters) {}
64
65     @Override
66     public void init() throws PfModelException {
67         // Not required on the dummy provider
68     }
69
70     @Override
71     public void close() {
72         // Not required on the dummy provider
73     }
74
75     @Override
76     public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException {
77         return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
78     }
79
80     @Override
81     public List<ToscaPolicyType> getPolicyTypeList(final String name, final String version) throws PfModelException {
82         return new ArrayList<>();
83     }
84
85     @Override
86     public ToscaServiceTemplate getFilteredPolicyTypes(ToscaPolicyTypeFilter filter) throws PfModelException {
87         return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
88     }
89
90     @Override
91     public List<ToscaPolicyType> getFilteredPolicyTypeList(ToscaPolicyTypeFilter filter) {
92         return new ArrayList<>();
93     }
94
95     @Override
96     public ToscaServiceTemplate createPolicyTypes(final ToscaServiceTemplate serviceTemplate)
97             throws PfModelException {
98         return serviceTemplate;
99     }
100
101     @Override
102     public ToscaServiceTemplate updatePolicyTypes(final ToscaServiceTemplate serviceTemplate)
103             throws PfModelException {
104         return serviceTemplate;
105     }
106
107     @Override
108     public ToscaServiceTemplate deletePolicyType(final String name, final String version)
109             throws PfModelException {
110         return getDummyResponse("dummyimpl/DummyToscaPolicyTypeDeleteResponse.json");
111     }
112
113     @Override
114     public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException {
115         return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
116     }
117
118     @Override
119     public List<ToscaPolicy> getPolicyList(final String name, final String version) throws PfModelException {
120         return new ArrayList<>();
121     }
122
123     @Override
124     public ToscaServiceTemplate getFilteredPolicies(ToscaPolicyFilter filter) throws PfModelException {
125         return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
126     }
127
128     @Override
129     public List<ToscaPolicy> getFilteredPolicyList(ToscaPolicyFilter filter) throws PfModelException {
130         return new ArrayList<>();
131     }
132
133     @Override
134     public ToscaServiceTemplate createPolicies(final ToscaServiceTemplate serviceTemplate)
135             throws PfModelException {
136         return serviceTemplate;
137     }
138
139     @Override
140     public ToscaServiceTemplate updatePolicies(final ToscaServiceTemplate serviceTemplate)
141             throws PfModelException {
142         return serviceTemplate;
143     }
144
145     @Override
146     public ToscaServiceTemplate deletePolicy(final String name, final String version)
147             throws PfModelException {
148         return getDummyResponse("dummyimpl/DummyToscaPolicyDeleteResponse.json");
149     }
150
151     @Override
152
153     public LegacyOperationalPolicy getOperationalPolicy(final String policyId) throws PfModelException {
154         return new LegacyOperationalPolicy();
155     }
156
157     @Override
158     public LegacyOperationalPolicy createOperationalPolicy(
159             final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
160         return legacyOperationalPolicy;
161     }
162
163     @Override
164     public LegacyOperationalPolicy updateOperationalPolicy(
165             final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
166         return legacyOperationalPolicy;
167     }
168
169     @Override
170     public LegacyOperationalPolicy deleteOperationalPolicy(final String policyId) throws PfModelException {
171         return new LegacyOperationalPolicy();
172     }
173
174     @Override
175     public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(final String policyId) throws PfModelException {
176         return new HashMap<>();
177     }
178
179     @Override
180     public Map<String, LegacyGuardPolicyOutput> createGuardPolicy(
181             final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException {
182         return new HashMap<>();
183     }
184
185     @Override
186     public Map<String, LegacyGuardPolicyOutput> updateGuardPolicy(
187             final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException {
188         return new HashMap<>();
189     }
190
191     @Override
192     public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(final String policyId)
193             throws PfModelException {
194         return new HashMap<>();
195     }
196
197     @Override
198     public List<PdpGroup> getPdpGroups(final String name, final String version) throws PfModelException {
199         return new ArrayList<>();
200     }
201
202     @Override
203     public List<PdpGroup> getFilteredPdpGroups(PdpGroupFilter filter) throws PfModelException {
204         return new ArrayList<>();
205     }
206
207     @Override
208     public List<PdpGroup> createPdpGroups(final List<PdpGroup> pdpGroups) throws PfModelException {
209         return new ArrayList<>();
210     }
211
212     @Override
213     public List<PdpGroup> updatePdpGroups(final List<PdpGroup> pdpGroups) throws PfModelException {
214         return new ArrayList<>();
215     }
216
217     @Override
218     public void updatePdpSubGroup(final String pdpGroupName, final String pdpGroupVersion,
219             final PdpSubGroup pdpSubGroup) throws PfModelException {
220         // Not implemented
221     }
222
223     @Override
224     public void updatePdp(String pdpGroupName, String pdpGroupVersion,
225             String pdpSubGroup, Pdp pdp) throws PfModelException {
226         // Not implemented
227     }
228
229     @Override
230     public PdpGroup deletePdpGroup(final String name, final String version) throws PfModelException {
231         return null;
232     }
233
234     @Override
235     public List<PdpStatistics> getPdpStatistics(final String name, final String version) throws PfModelException {
236         return new ArrayList<>();
237     }
238
239     @Override
240     public void updatePdpStatistics(final String pdpGroupName, final String pdpGroupVersion,
241             final String pdpType, final String pdpInstanceId,
242             final PdpStatistics pdppStatistics) throws PfModelException {
243         // Not implemented
244     }
245
246     /**
247      * Return a ToscaServicetemplate dummy response.
248      *
249      * @param fileName the file name containing the dummy response
250      * @return the ToscaServiceTemplate with the dummy response
251      */
252     protected ToscaServiceTemplate getDummyResponse(final String fileName) {
253         StandardCoder standardCoder = new StandardCoder();
254         ToscaServiceTemplate serviceTemplate;
255
256         try {
257             serviceTemplate =
258                     standardCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
259             if (serviceTemplate == null) {
260                 throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, "error reading specified file");
261             }
262         } catch (Exception exc) {
263             throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "error serializing object", exc);
264         }
265
266         return serviceTemplate;
267     }
268 }