Add PDP-Policy deployment table to DB
[policy/models.git] / models-provider / src / main / java / org / onap / policy / models / provider / impl / DummyPolicyModelsProviderImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019-2020 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.util.ArrayList;
26 import java.util.Collection;
27 import java.util.Date;
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.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.PdpPolicyStatus;
39 import org.onap.policy.models.pdp.concepts.PdpStatistics;
40 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
41 import org.onap.policy.models.provider.PolicyModelsProvider;
42 import org.onap.policy.models.provider.PolicyModelsProviderParameters;
43 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
44 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyFilter;
45 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
46 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
47 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
48 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplateFilter;
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
77     @Override
78     public List<ToscaServiceTemplate> getServiceTemplateList(String name, String version) throws PfModelException {
79         return new ArrayList<>();
80     }
81
82     @Override
83     public List<ToscaServiceTemplate> getFilteredServiceTemplateList(@NonNull ToscaServiceTemplateFilter filter)
84             throws PfModelException {
85         return new ArrayList<>();
86     }
87
88     @Override
89     public ToscaServiceTemplate createServiceTemplate(@NonNull ToscaServiceTemplate serviceTemplate)
90             throws PfModelException {
91         return serviceTemplate;
92     }
93
94     @Override
95     public ToscaServiceTemplate updateServiceTemplate(@NonNull ToscaServiceTemplate serviceTemplate)
96             throws PfModelException {
97         return serviceTemplate;
98     }
99
100     @Override
101     public ToscaServiceTemplate deleteServiceTemplate(@NonNull String name, @NonNull String version)
102             throws PfModelException {
103         return getDummyResponse("dummyimpl/DummyToscaServiceTemplateDeleteResponse.json");
104     }
105
106     @Override
107     public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException {
108         return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
109     }
110
111     @Override
112     public List<ToscaPolicyType> getPolicyTypeList(final String name, final String version) throws PfModelException {
113         return new ArrayList<>();
114     }
115
116     @Override
117     public ToscaServiceTemplate getFilteredPolicyTypes(ToscaPolicyTypeFilter filter) throws PfModelException {
118         return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
119     }
120
121     @Override
122     public List<ToscaPolicyType> getFilteredPolicyTypeList(ToscaPolicyTypeFilter filter) {
123         return new ArrayList<>();
124     }
125
126     @Override
127     public ToscaServiceTemplate createPolicyTypes(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
128         return serviceTemplate;
129     }
130
131     @Override
132     public ToscaServiceTemplate updatePolicyTypes(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
133         return serviceTemplate;
134     }
135
136     @Override
137     public ToscaServiceTemplate deletePolicyType(final String name, final String version) throws PfModelException {
138         return getDummyResponse("dummyimpl/DummyToscaPolicyTypeDeleteResponse.json");
139     }
140
141     @Override
142     public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException {
143         return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
144     }
145
146     @Override
147     public List<ToscaPolicy> getPolicyList(final String name, final String version) throws PfModelException {
148         return new ArrayList<>();
149     }
150
151     @Override
152     public ToscaServiceTemplate getFilteredPolicies(ToscaPolicyFilter filter) throws PfModelException {
153         return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
154     }
155
156     @Override
157     public List<ToscaPolicy> getFilteredPolicyList(ToscaPolicyFilter filter) throws PfModelException {
158         return new ArrayList<>();
159     }
160
161     @Override
162     public ToscaServiceTemplate createPolicies(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
163         return serviceTemplate;
164     }
165
166     @Override
167     public ToscaServiceTemplate updatePolicies(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
168         return serviceTemplate;
169     }
170
171     @Override
172     public ToscaServiceTemplate deletePolicy(final String name, final String version) throws PfModelException {
173         return getDummyResponse("dummyimpl/DummyToscaPolicyDeleteResponse.json");
174     }
175
176     @Override
177     public List<PdpGroup> getPdpGroups(final String name) throws PfModelException {
178         return new ArrayList<>();
179     }
180
181     @Override
182     public List<PdpGroup> getFilteredPdpGroups(PdpGroupFilter filter) throws PfModelException {
183         return new ArrayList<>();
184     }
185
186     @Override
187     public List<PdpGroup> createPdpGroups(final List<PdpGroup> pdpGroups) throws PfModelException {
188         return new ArrayList<>();
189     }
190
191     @Override
192     public List<PdpGroup> updatePdpGroups(final List<PdpGroup> pdpGroups) throws PfModelException {
193         return new ArrayList<>();
194     }
195
196     @Override
197     public void updatePdpSubGroup(final String pdpGroupName, final PdpSubGroup pdpSubGroup) throws PfModelException {
198         // Not implemented
199     }
200
201     @Override
202     public void updatePdp(String pdpGroupName, String pdpSubGroup, Pdp pdp) throws PfModelException {
203         // Not implemented
204     }
205
206     @Override
207     public PdpGroup deletePdpGroup(final String name) throws PfModelException {
208         return null;
209     }
210
211     @Override
212     public List<PdpStatistics> getPdpStatistics(final String name, final Date timestamp) throws PfModelException {
213         return new ArrayList<>();
214     }
215
216     @Override
217     public List<PdpStatistics> getFilteredPdpStatistics(String name, String pdpGroupName, String pdpSubGroup,
218             Date startTimeStamp, Date endTimeStamp, String sortOrder, int getRecordNum) {
219         // Not implemented
220         return new ArrayList<>();
221     }
222
223     @Override
224     public List<PdpStatistics> createPdpStatistics(final List<PdpStatistics> pdpStatisticsList)
225             throws PfModelException {
226         // Not implemented
227         return new ArrayList<>();
228     }
229
230     @Override
231     public List<PdpStatistics> updatePdpStatistics(final List<PdpStatistics> pdpStatisticsList)
232             throws PfModelException {
233         // Not implemented
234         return new ArrayList<>();
235     }
236
237     @Override
238     public List<PdpStatistics> deletePdpStatistics(final String name, final Date timestamp) {
239         // Not implemented
240         return new ArrayList<>();
241     }
242
243     @Override
244     public List<PdpPolicyStatus> getGroupPolicyStatus(String groupName) throws PfModelException {
245         // Not implemented
246         return new ArrayList<>();
247     }
248
249     @Override
250     public void cudPolicyStatus(Collection<PdpPolicyStatus> createObjs, Collection<PdpPolicyStatus> updateObjs,
251                     Collection<PdpPolicyStatus> deleteObjs) {
252         // Not implemented
253     }
254
255     /**
256      * Return a ToscaServicetemplate dummy response.
257      *
258      * @param fileName the file name containing the dummy response
259      * @return the ToscaServiceTemplate with the dummy response
260      */
261     protected ToscaServiceTemplate getDummyResponse(final String fileName) {
262         StandardCoder standardCoder = new StandardCoder();
263         ToscaServiceTemplate serviceTemplate;
264
265         try {
266             serviceTemplate =
267                     standardCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
268             if (serviceTemplate == null) {
269                 throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, "error reading specified file");
270             }
271         } catch (Exception exc) {
272             throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "error serializing object", exc);
273         }
274
275         return serviceTemplate;
276     }
277 }