2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.pap.xacml.rest.handler;
23 import javax.servlet.http.HttpServletRequest;
24 import javax.servlet.http.HttpServletResponse;
25 import org.onap.policy.common.logging.eelf.MessageCodes;
26 import org.onap.policy.common.logging.eelf.PolicyLogger;
27 import org.onap.policy.pap.xacml.rest.service.DictionaryService;
28 import org.onap.policy.xacml.api.XACMLErrorConstants;
30 public class DictionaryHandlerImpl implements DictionaryHandler {
32 * Get Equivalent for Dictionary Services.
35 public void doDictionaryAPIGet(HttpServletRequest request, HttpServletResponse response) {
36 String dictionaryType = request.getParameter("dictionaryType");
38 DictionaryService dictionary = new DictionaryService();
39 switch (dictionaryType) {
41 dictionary.getOnapDictionary(response);
44 dictionary.getAttributeDictionary(response);
47 dictionary.getActionPolicyDictionary(response);
49 case "BRMSParamTemplate":
50 dictionary.getBRMSParamDictionary(response);
53 dictionary.getVSCLAction(response);
56 dictionary.getVnfType(response);
59 dictionary.getPEPOptions(response);
62 dictionary.getVarbind(response);
65 dictionary.getServiceType(response);
68 dictionary.getSiteType(response);
71 dictionary.getSettingsDictionary(response);
73 case "RainyDayTreatments":
74 dictionary.getRainyDayDictionary(response);
76 case "DescriptiveScope":
77 dictionary.getDescriptiveDictionary(response);
80 dictionary.getActionListDictionary(response);
83 dictionary.getProtocolListDictionary(response);
86 dictionary.getZoneDictionary(response);
89 dictionary.getSecurityZoneDictionary(response);
92 dictionary.getPrefixListDictionary(response);
95 dictionary.getAddressGroupDictionary(response);
98 dictionary.getServiceGroupDictionary(response);
101 dictionary.getServiceListDictionary(response);
105 case "FirewallRuleList":
107 dictionary.getTermListDictionary(response);
109 case "MicroServiceLocation":
110 dictionary.getMicroServiceLocationDictionary(response);
112 case "MicroServiceConfigName":
113 dictionary.getMicroServiceConfigNameDictionary(response);
115 case "MicroServiceDictionaryData":
116 dictionary.getMicroServiceDictionaryData(response);
119 dictionary.getDCAEUUIDDictionary(response);
121 case "MicroServiceModels":
122 dictionary.getMicroServiceModelsDictionary(response);
124 case "MicroServiceDictionary":
125 dictionary.getMicroServiceDictionary(response);
127 case "OptimizationModels":
128 dictionary.getOptimizationModelsDictionary(response);
130 case "PolicyScopeService":
131 dictionary.getPSServiceDictionary(response);
133 case "PolicyScopeResource":
134 dictionary.getPSResourceDictionary(response);
136 case "PolicyScopeType":
137 dictionary.getPSTypeDictionary(response);
139 case "PolicyScopeClosedLoop":
140 dictionary.getPSClosedLoopDictionary(response);
142 case "GroupPolicyScopeList":
143 dictionary.getPSGroupScopeDictionary(response);
146 dictionary.getRiskTypeDictionary(response);
148 case "SafePolicyWarning":
149 dictionary.getSafePolicyWarningDictionary(response);
152 extendedOptions(dictionaryType, request, response, true);
154 } catch (Exception e) {
155 String message = XACMLErrorConstants.ERROR_DATA_ISSUE + " Error Querying the Database: " + e.getMessage();
156 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "DictionaryHandler", " Error Querying the Database.");
157 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
158 response.addHeader("error", "dictionaryDBQuery");
159 response.addHeader("error", message);
164 * Can be used to extend the services.
166 * getflag=true indicates Get Request. getflag=false indicates Put Request.
171 public String extendedOptions(String dictionaryType, HttpServletRequest request, HttpServletResponse response,
174 String message = XACMLErrorConstants.ERROR_DATA_ISSUE + " Invalid Dictionary in Request.";
175 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "DictionaryHandler", " Invalid Dictionary in Request.");
176 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
177 response.setHeader("error", "dictionary");
178 response.addHeader("error", message);
183 public void doDictionaryAPIPut(HttpServletRequest request, HttpServletResponse response) {
184 String result = null;
185 String dictionaryType = request.getParameter("dictionaryType");
186 String operation = request.getParameter("operation");
188 DictionaryService dictionary = new DictionaryService();
189 switch (dictionaryType) {
191 result = dictionary.saveOnapDictionary(request, response);
194 result = dictionary.saveAttributeDictionary(request, response);
197 result = dictionary.saveActionPolicyDictionary(request, response);
199 case "BRMSParamTemplate":
200 result = dictionary.saveBRMSParamDictionary(request, response);
203 result = dictionary.saveVSCLAction(request, response);
206 result = dictionary.saveVnfType(request, response);
209 result = dictionary.savePEPOptions(request, response);
212 result = dictionary.saveVarbind(request, response);
215 result = dictionary.saveServiceType(request, response);
218 result = dictionary.saveSiteType(request, response);
221 result = dictionary.saveSettingsDictionary(request, response);
223 case "RainyDayTreatments":
224 result = dictionary.saveRainyDayDictionary(request, response);
226 case "DescriptiveScope":
227 result = dictionary.saveDescriptiveDictionary(request, response);
230 result = dictionary.saveActionListDictionary(request, response);
233 result = dictionary.saveProtocolListDictionary(request, response);
236 result = dictionary.saveZoneDictionary(request, response);
239 result = dictionary.saveSecurityZoneDictionary(request, response);
242 result = dictionary.savePrefixListDictionary(request, response);
245 result = dictionary.saveAddressGroupDictionary(request, response);
248 result = dictionary.saveServiceGroupDictionary(request, response);
251 result = dictionary.saveServiceListDictionary(request, response);
255 case "FirewallRuleList":
257 result = dictionary.saveTermListDictionary(request, response);
259 case "MicroServiceLocation":
260 result = dictionary.saveMicroServiceLocationDictionary(request, response);
262 case "MicroServiceConfigName":
263 result = dictionary.saveMicroServiceConfigNameDictionary(request, response);
265 case "MicroServiceDictionaryData":
266 dictionary.saveMicroServiceDictionaryData(request, response);
269 result = dictionary.saveDCAEUUIDDictionary(request, response);
271 case "MicroServiceModels":
272 result = dictionary.saveMicroServiceModelsDictionary(request, response);
274 case "MicroServiceDictionary":
275 result = dictionary.saveMicroServiceDictionary(request, response);
277 case "OptimizationModels":
278 result = dictionary.saveOptimizationModelsDictionary(request, response);
280 case "PolicyScopeService":
281 result = dictionary.savePSServiceDictionary(request, response);
283 case "PolicyScopeResource":
284 result = dictionary.savePSResourceDictionary(request, response);
286 case "PolicyScopeType":
287 result = dictionary.savePSTypeDictionary(request, response);
289 case "PolicyScopeClosedLoop":
290 result = dictionary.savePSClosedLoopDictionary(request, response);
292 case "GroupPolicyScopeList":
293 result = dictionary.savePSGroupScopeDictionary(request, response);
296 result = dictionary.saveRiskTypeDictionary(request, response);
298 case "SafePolicyWarning":
299 result = dictionary.saveSafePolicyWarningDictionary(request, response);
302 result = extendedOptions(dictionaryType, request, response, false);
303 if (result == null) {
309 } catch (Exception e) {
310 String message = XACMLErrorConstants.ERROR_DATA_ISSUE + " Error Updating the Database: " + e.getMessage();
311 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "XACMLPapServlet", " Error Updating the Database.");
312 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
313 response.addHeader("error", message);
316 if (result.equalsIgnoreCase("Success")) {
317 response.setStatus(HttpServletResponse.SC_OK);
318 response.addHeader("successMapKey", "success");
319 if (operation.equalsIgnoreCase("update")) {
320 response.addHeader("operation", "updateDictionary");
322 response.addHeader("operation", "createDictionary");
324 } else if (result.equalsIgnoreCase("Duplicate")) {
325 response.setStatus(HttpServletResponse.SC_CONFLICT);
326 response.addHeader("error", "dictionaryItemExists");
327 } else if (result.equalsIgnoreCase("DuplicateGroup")) {
328 response.setStatus(HttpServletResponse.SC_CONFLICT);
329 response.addHeader("error", "duplicateGroup");
331 String message = XACMLErrorConstants.ERROR_DATA_ISSUE + " Error Updating the Database.";
332 PolicyLogger.error(message);
333 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
334 response.addHeader("error", message);