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