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