Remove unused statistics methods
[policy/models.git] / models-provider / src / main / java / org / onap / policy / models / provider / impl / DummyPolicyModelsProviderImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019-2021 Nordix Foundation.
4  *  Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
5  *  Modifications Copyright (C) 2020 Bell Canada. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * SPDX-License-Identifier: Apache-2.0
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.models.provider.impl;
24
25 import java.time.Instant;
26 import java.util.ArrayList;
27 import java.util.Collection;
28 import java.util.List;
29 import javax.ws.rs.core.Response;
30 import lombok.NonNull;
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.pap.concepts.PolicyAudit;
36 import org.onap.policy.models.pap.persistence.provider.PolicyAuditProvider.AuditFilter;
37 import org.onap.policy.models.pdp.concepts.Pdp;
38 import org.onap.policy.models.pdp.concepts.PdpGroup;
39 import org.onap.policy.models.pdp.concepts.PdpGroupFilter;
40 import org.onap.policy.models.pdp.concepts.PdpPolicyStatus;
41 import org.onap.policy.models.pdp.concepts.PdpStatistics;
42 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
43 import org.onap.policy.models.pdp.persistence.provider.PdpFilterParameters;
44 import org.onap.policy.models.provider.PolicyModelsProvider;
45 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
46 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
47 import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter;
48 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
49 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
50 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
51 import org.onap.policy.models.tosca.authorative.concepts.ToscaTypedEntityFilter;
52
53 /**
54  * This class provides a dummy implementation of the Policy Models Provider for the ONAP Policy Framework.
55  *
56  * @author Liam Fallon (liam.fallon@est.tech)
57  * @author Chenfei Gao (cgao@research.att.com)
58  */
59 public class DummyPolicyModelsProviderImpl implements PolicyModelsProvider {
60     /**
61      * Constructor that takes the parameters.
62      *
63      * @param parameters the parameters for the provider
64      */
65     public DummyPolicyModelsProviderImpl(final PolicyModelsProviderParameters parameters) {
66         // Default constructor
67     }
68
69     @Override
70     public void init() throws PfModelException {
71         // Not required on the dummy provider
72     }
73
74     @Override
75     public void close() {
76         // Not required on the dummy provider
77     }
78
79
80     @Override
81     public List<ToscaServiceTemplate> getServiceTemplateList(String name, String version) throws PfModelException {
82         return new ArrayList<>();
83     }
84
85     @Override
86     public List<ToscaServiceTemplate> getFilteredServiceTemplateList(
87             @NonNull ToscaEntityFilter<ToscaServiceTemplate> filter) throws PfModelException {
88         return new ArrayList<>();
89     }
90
91     @Override
92     public ToscaServiceTemplate createServiceTemplate(@NonNull ToscaServiceTemplate serviceTemplate)
93             throws PfModelException {
94         return serviceTemplate;
95     }
96
97     @Override
98     public ToscaServiceTemplate updateServiceTemplate(@NonNull ToscaServiceTemplate serviceTemplate)
99             throws PfModelException {
100         return serviceTemplate;
101     }
102
103     @Override
104     public ToscaServiceTemplate deleteServiceTemplate(@NonNull String name, @NonNull String version)
105             throws PfModelException {
106         return getDummyResponse("dummyimpl/DummyToscaServiceTemplateDeleteResponse.json");
107     }
108
109     @Override
110     public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException {
111         return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
112     }
113
114     @Override
115     public List<ToscaPolicyType> getPolicyTypeList(final String name, final String version) throws PfModelException {
116         return new ArrayList<>();
117     }
118
119     @Override
120     public ToscaServiceTemplate getFilteredPolicyTypes(ToscaEntityFilter<ToscaPolicyType> filter)
121             throws PfModelException {
122         return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
123     }
124
125     @Override
126     public List<ToscaPolicyType> getFilteredPolicyTypeList(ToscaEntityFilter<ToscaPolicyType> filter) {
127         return new ArrayList<>();
128     }
129
130     @Override
131     public ToscaServiceTemplate createPolicyTypes(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
132         return serviceTemplate;
133     }
134
135     @Override
136     public ToscaServiceTemplate updatePolicyTypes(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
137         return serviceTemplate;
138     }
139
140     @Override
141     public ToscaServiceTemplate deletePolicyType(final String name, final String version) throws PfModelException {
142         return getDummyResponse("dummyimpl/DummyToscaPolicyTypeDeleteResponse.json");
143     }
144
145     @Override
146     public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException {
147         return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
148     }
149
150     @Override
151     public List<ToscaPolicy> getPolicyList(final String name, final String version) throws PfModelException {
152         return new ArrayList<>();
153     }
154
155     @Override
156     public ToscaServiceTemplate getFilteredPolicies(ToscaTypedEntityFilter<ToscaPolicy> filter)
157             throws PfModelException {
158         return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
159     }
160
161     @Override
162     public List<ToscaPolicy> getFilteredPolicyList(ToscaTypedEntityFilter<ToscaPolicy> filter) throws PfModelException {
163         return new ArrayList<>();
164     }
165
166     @Override
167     public ToscaServiceTemplate createPolicies(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
168         return serviceTemplate;
169     }
170
171     @Override
172     public ToscaServiceTemplate updatePolicies(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
173         return serviceTemplate;
174     }
175
176     @Override
177     public ToscaServiceTemplate deletePolicy(final String name, final String version) throws PfModelException {
178         return getDummyResponse("dummyimpl/DummyToscaPolicyDeleteResponse.json");
179     }
180
181     @Override
182     public List<PdpGroup> getPdpGroups(final String name) throws PfModelException {
183         return new ArrayList<>();
184     }
185
186     @Override
187     public List<PdpGroup> getFilteredPdpGroups(PdpGroupFilter filter) throws PfModelException {
188         return new ArrayList<>();
189     }
190
191     @Override
192     public List<PdpGroup> createPdpGroups(final List<PdpGroup> pdpGroups) throws PfModelException {
193         return new ArrayList<>();
194     }
195
196     @Override
197     public List<PdpGroup> updatePdpGroups(final List<PdpGroup> pdpGroups) throws PfModelException {
198         return new ArrayList<>();
199     }
200
201     @Override
202     public void updatePdpSubGroup(final String pdpGroupName, final PdpSubGroup pdpSubGroup) throws PfModelException {
203         // Not implemented
204     }
205
206     @Override
207     public void updatePdp(String pdpGroupName, String pdpSubGroup, Pdp pdp) throws PfModelException {
208         // Not implemented
209     }
210
211     @Override
212     public PdpGroup deletePdpGroup(final String name) throws PfModelException {
213         return null;
214     }
215
216     @Override
217     public List<PdpStatistics> getFilteredPdpStatistics(PdpFilterParameters filterParams) throws PfModelException {
218         // Not implemented
219         return new ArrayList<>();
220     }
221
222     @Override
223     public List<PdpStatistics> createPdpStatistics(final List<PdpStatistics> pdpStatisticsList)
224             throws PfModelException {
225         // Not implemented
226         return new ArrayList<>();
227     }
228
229     @Override
230     public List<PdpStatistics> updatePdpStatistics(final List<PdpStatistics> pdpStatisticsList)
231             throws PfModelException {
232         // Not implemented
233         return new ArrayList<>();
234     }
235
236     @Override
237     public List<PdpStatistics> deletePdpStatistics(final String name, final Instant timestamp) {
238         // Not implemented
239         return new ArrayList<>();
240     }
241
242     @Override
243     public List<PdpPolicyStatus> getAllPolicyStatus() throws PfModelException {
244         // Not implemented
245         return new ArrayList<>();
246     }
247
248     @Override
249     public List<PdpPolicyStatus> getAllPolicyStatus(@NonNull ToscaConceptIdentifierOptVersion policy)
250             throws PfModelException {
251         // Not implemented
252         return new ArrayList<>();
253     }
254
255     @Override
256     public List<PdpPolicyStatus> getGroupPolicyStatus(String groupName) throws PfModelException {
257         // Not implemented
258         return new ArrayList<>();
259     }
260
261     @Override
262     public void cudPolicyStatus(Collection<PdpPolicyStatus> createObjs, Collection<PdpPolicyStatus> updateObjs,
263             Collection<PdpPolicyStatus> deleteObjs) {
264         // Not implemented
265     }
266
267     @Override
268     public void createAuditRecords(List<PolicyAudit> auditRecords) {
269         // Not implemented
270     }
271
272     @Override
273     public List<PolicyAudit> getAuditRecords(AuditFilter auditFilter) {
274         // Not implemented
275         return new ArrayList<>();
276     }
277
278     /**
279      * Return a ToscaServicetemplate dummy response.
280      *
281      * @param fileName the file name containing the dummy response
282      * @return the ToscaServiceTemplate with the dummy response
283      */
284     protected ToscaServiceTemplate getDummyResponse(final String fileName) {
285         var standardCoder = new StandardCoder();
286         ToscaServiceTemplate serviceTemplate;
287
288         try {
289             serviceTemplate =
290                     standardCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
291             if (serviceTemplate == null) {
292                 throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, "error reading specified file");
293             }
294         } catch (Exception exc) {
295             throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "error serializing object", exc);
296         }
297
298         return serviceTemplate;
299     }
300 }