Merge "Add extra methods to Provider interface"
[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 import lombok.NonNull;
31
32 import org.apache.commons.lang3.tuple.Pair;
33 import org.onap.policy.common.utils.coder.StandardCoder;
34 import org.onap.policy.common.utils.resources.ResourceUtils;
35 import org.onap.policy.models.base.PfModelException;
36 import org.onap.policy.models.base.PfModelRuntimeException;
37 import org.onap.policy.models.pdp.concepts.PdpGroup;
38 import org.onap.policy.models.pdp.concepts.PdpGroups;
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.ToscaPolicyType;
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(@NonNull final PolicyModelsProviderParameters parameters) {}
63
64     @Override
65     public void init() throws PfModelException {
66         // Not required on the dummy provider
67     }
68
69     @Override
70     public void close() {
71         // Not required on the dummy provider
72     }
73
74     @Override
75     public ToscaServiceTemplate getPolicyTypes(final String name, final String version) throws PfModelException {
76         return getDummyResponse("dummyimpl/DummyToscaPolicyTypeGetResponse.json");
77     }
78
79     @Override
80     public List<ToscaPolicyType> getPolicyTypeList(final String name, final String version) throws PfModelException {
81         return new ArrayList<>();
82     }
83
84     @Override
85     public ToscaServiceTemplate getLatestPolicyTypes(final String name) throws PfModelException {
86         return null;
87     }
88
89     @Override
90     public List<ToscaPolicyType> getLatestPolicyTypeList(final String name) throws PfModelException {
91         return new ArrayList<>();
92     }
93
94     @Override
95     public ToscaServiceTemplate createPolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
96             throws PfModelException {
97         return serviceTemplate;
98     }
99
100     @Override
101     public ToscaServiceTemplate updatePolicyTypes(@NonNull final ToscaServiceTemplate serviceTemplate)
102             throws PfModelException {
103         return serviceTemplate;
104     }
105
106     @Override
107     public ToscaServiceTemplate deletePolicyType(@NonNull final String name, @NonNull final String version)
108             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 List<ToscaPolicy> getPolicyList4PolicyType(@NonNull final String policyTypeName) throws PfModelException {
124         return new ArrayList<>();
125     }
126
127     @Override
128     public ToscaServiceTemplate getLatestPolicies(final String name) throws PfModelException {
129         return null;
130     }
131
132     @Override
133     public List<ToscaPolicy> getLatestPolicyList(final String name) throws PfModelException {
134         return new ArrayList<>();
135     }
136
137     @Override
138     public ToscaServiceTemplate createPolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
139             throws PfModelException {
140         return serviceTemplate;
141     }
142
143     @Override
144     public ToscaServiceTemplate updatePolicies(@NonNull final ToscaServiceTemplate serviceTemplate)
145             throws PfModelException {
146         return serviceTemplate;
147     }
148
149     @Override
150     public ToscaServiceTemplate deletePolicy(@NonNull final String name, @NonNull final String version)
151             throws PfModelException {
152         return getDummyResponse("dummyimpl/DummyToscaPolicyDeleteResponse.json");
153     }
154
155     @Override
156
157     public LegacyOperationalPolicy getOperationalPolicy(@NonNull final String policyId) throws PfModelException {
158         return new LegacyOperationalPolicy();
159     }
160
161     @Override
162     public LegacyOperationalPolicy createOperationalPolicy(
163             @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
164         return legacyOperationalPolicy;
165     }
166
167     @Override
168     public LegacyOperationalPolicy updateOperationalPolicy(
169             @NonNull final LegacyOperationalPolicy legacyOperationalPolicy) throws PfModelException {
170         return legacyOperationalPolicy;
171     }
172
173     @Override
174     public LegacyOperationalPolicy deleteOperationalPolicy(@NonNull final String policyId) throws PfModelException {
175         return new LegacyOperationalPolicy();
176     }
177
178     @Override
179     public Map<String, LegacyGuardPolicyOutput> getGuardPolicy(@NonNull final String policyId) throws PfModelException {
180         return new HashMap<>();
181     }
182
183     @Override
184     public Map<String, LegacyGuardPolicyOutput> createGuardPolicy(
185             @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException {
186         return new HashMap<>();
187     }
188
189     @Override
190     public Map<String, LegacyGuardPolicyOutput> updateGuardPolicy(
191             @NonNull final LegacyGuardPolicyInput legacyGuardPolicy) throws PfModelException {
192         return new HashMap<>();
193     }
194
195     @Override
196     public Map<String, LegacyGuardPolicyOutput> deleteGuardPolicy(@NonNull final String policyId)
197             throws PfModelException {
198         return new HashMap<>();
199     }
200
201     @Override
202     public PdpGroups getPdpGroups(final String name, final String version) throws PfModelException {
203         return null;
204     }
205
206     @Override
207     public PdpGroups getLatestPdpGroups(final String name) throws PfModelException {
208         return null;
209     }
210
211     @Override
212     public PdpGroups getFilteredPdpGroups(@NonNull final String pdpType,
213             @NonNull final List<Pair<String, String>> supportedPolicyTypes) {
214         return null;
215     }
216
217     @Override
218     public PdpGroups createPdpGroups(@NonNull final PdpGroups pdpGroups) throws PfModelException {
219         return null;
220     }
221
222     @Override
223     public PdpGroups updatePdpGroups(@NonNull final PdpGroups pdpGroups) throws PfModelException {
224         return null;
225     }
226
227     @Override
228     public void updatePdpSubGroup(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion,
229             @NonNull final PdpSubGroup pdpSubGroup) throws PfModelException {
230         // Not implemented
231     }
232
233     @Override
234     public PdpGroup deletePdpGroup(@NonNull final String name, @NonNull final String version) throws PfModelException {
235         return null;
236     }
237
238     @Override
239     public List<PdpStatistics> getPdpStatistics(final String name, final String version) throws PfModelException {
240         return new ArrayList<>();
241     }
242
243     @Override
244     public void updatePdpStatistics(@NonNull final String pdpGroupName, @NonNull final String pdpGroupVersion,
245             @NonNull final String pdpType, @NonNull final String pdpInstanceId,
246             @NonNull final PdpStatistics pdppStatistics)  throws PfModelException {
247         // Not implemented
248     }
249
250     @Override
251     public Map<PdpGroup, List<ToscaPolicy>> getDeployedPolicyList(final String name) throws PfModelException {
252         return null;
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(@NonNull 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 }