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