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