Fix minor checksyle issues in models
[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         // Default constructor
65     }
66
67     @Override
68     public void init() throws PfModelException {
69         // Not required on the dummy provider
70     }
71
72     @Override
73     public void close() {
74         // Not required on the dummy provider
75     }
76
77     @Override
78     public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException {
79         return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
80     }
81
82     @Override
83     public List<ToscaPolicyType> getPolicyTypeList(final String name, final String version) throws PfModelException {
84         return new ArrayList<>();
85     }
86
87     @Override
88     public ToscaServiceTemplate getFilteredPolicyTypes(ToscaPolicyTypeFilter filter) throws PfModelException {
89         return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
90     }
91
92     @Override
93     public List<ToscaPolicyType> getFilteredPolicyTypeList(ToscaPolicyTypeFilter filter) {
94         return new ArrayList<>();
95     }
96
97     @Override
98     public ToscaServiceTemplate createPolicyTypes(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
99         return serviceTemplate;
100     }
101
102     @Override
103     public ToscaServiceTemplate updatePolicyTypes(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
104         return serviceTemplate;
105     }
106
107     @Override
108     public ToscaServiceTemplate deletePolicyType(final String name, final String version) throws PfModelException {
109         return getDummyResponse("dummyimpl/DummyToscaPolicyTypeDeleteResponse.json");
110     }
111
112     @Override
113     public ToscaServiceTemplate getPolicies(final String name, final String version) throws PfModelException {
114         return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
115     }
116
117     @Override
118     public List<ToscaPolicy> getPolicyList(final String name, final String version) throws PfModelException {
119         return new ArrayList<>();
120     }
121
122     @Override
123     public ToscaServiceTemplate getFilteredPolicies(ToscaPolicyFilter filter) throws PfModelException {
124         return getDummyResponse("dummyimpl/DummyToscaPolicyGetResponse.json");
125     }
126
127     @Override
128     public List<ToscaPolicy> getFilteredPolicyList(ToscaPolicyFilter filter) throws PfModelException {
129         return new ArrayList<>();
130     }
131
132     @Override
133     public ToscaServiceTemplate createPolicies(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
134         return serviceTemplate;
135     }
136
137     @Override
138     public ToscaServiceTemplate updatePolicies(final ToscaServiceTemplate serviceTemplate) throws PfModelException {
139         return serviceTemplate;
140     }
141
142     @Override
143     public ToscaServiceTemplate deletePolicy(final String name, final String version) throws PfModelException {
144         return getDummyResponse("dummyimpl/DummyToscaPolicyDeleteResponse.json");
145     }
146
147     @Override
148
149     public LegacyOperationalPolicy getOperationalPolicy(final String policyId, final String policyVersion)
150             throws PfModelException {
151         return new LegacyOperationalPolicy();
152     }
153
154     @Override
155     public LegacyOperationalPolicy createOperationalPolicy(final LegacyOperationalPolicy legacyOperationalPolicy)
156             throws PfModelException {
157         return legacyOperationalPolicy;
158     }
159
160     @Override
161     public LegacyOperationalPolicy updateOperationalPolicy(final LegacyOperationalPolicy legacyOperationalPolicy)
162             throws PfModelException {
163         return legacyOperationalPolicy;
164     }
165
166     @Override
167     public LegacyOperationalPolicy deleteOperationalPolicy(final String policyId, final String policyVersion)
168             throws PfModelException {
169         return new LegacyOperationalPolicy();
170     }
171
172     @Override
173     public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(final String policyId, final String policyVersion)
174             throws PfModelException {
175         return new HashMap<>();
176     }
177
178     @Override
179     public Map<String, LegacyGuardPolicyOutput> createGuardPolicy(final LegacyGuardPolicyInput legacyGuardPolicy)
180             throws PfModelException {
181         return new HashMap<>();
182     }
183
184     @Override
185     public Map<String, LegacyGuardPolicyOutput> updateGuardPolicy(final LegacyGuardPolicyInput legacyGuardPolicy)
186             throws PfModelException {
187         return new HashMap<>();
188     }
189
190     @Override
191     public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(final String policyId, final String policyVersion)
192             throws PfModelException {
193         return new HashMap<>();
194     }
195
196     @Override
197     public List<PdpGroup> getPdpGroups(final String name) throws PfModelException {
198         return new ArrayList<>();
199     }
200
201     @Override
202     public List<PdpGroup> getFilteredPdpGroups(PdpGroupFilter filter) throws PfModelException {
203         return new ArrayList<>();
204     }
205
206     @Override
207     public List<PdpGroup> createPdpGroups(final List<PdpGroup> pdpGroups) throws PfModelException {
208         return new ArrayList<>();
209     }
210
211     @Override
212     public List<PdpGroup> updatePdpGroups(final List<PdpGroup> pdpGroups) throws PfModelException {
213         return new ArrayList<>();
214     }
215
216     @Override
217     public void updatePdpSubGroup(final String pdpGroupName, final PdpSubGroup pdpSubGroup) throws PfModelException {
218         // Not implemented
219     }
220
221     @Override
222     public void updatePdp(String pdpGroupName, String pdpSubGroup, Pdp pdp) throws PfModelException {
223         // Not implemented
224     }
225
226     @Override
227     public PdpGroup deletePdpGroup(final String name) throws PfModelException {
228         return null;
229     }
230
231     @Override
232     public List<PdpStatistics> getPdpStatistics(final String name) throws PfModelException {
233         return new ArrayList<>();
234     }
235
236     @Override
237     public void updatePdpStatistics(final String pdpGroupName, final String pdpType, final String pdpInstanceId,
238             final PdpStatistics pdppStatistics) throws PfModelException {
239         // Not implemented
240     }
241
242     /**
243      * Return a ToscaServicetemplate dummy response.
244      *
245      * @param fileName the file name containing the dummy response
246      * @return the ToscaServiceTemplate with the dummy response
247      */
248     protected ToscaServiceTemplate getDummyResponse(final String fileName) {
249         StandardCoder standardCoder = new StandardCoder();
250         ToscaServiceTemplate serviceTemplate;
251
252         try {
253             serviceTemplate =
254                     standardCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
255             if (serviceTemplate == null) {
256                 throw new PfModelException(Response.Status.INTERNAL_SERVER_ERROR, "error reading specified file");
257             }
258         } catch (Exception exc) {
259             throw new PfModelRuntimeException(Response.Status.INTERNAL_SERVER_ERROR, "error serializing object", exc);
260         }
261
262         return serviceTemplate;
263     }
264 }