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;
26 import org.onap.policy.common.logging.eelf.MessageCodes;
27 import org.onap.policy.common.logging.eelf.PolicyLogger;
28 import org.onap.policy.pap.xacml.rest.service.DictionaryService;
29 import org.onap.policy.xacml.api.XACMLErrorConstants;
31 public class DictionaryHandlerImpl implements DictionaryHandler {
33 * Get Equivalent for Dictionary Services.
36 public void doDictionaryAPIGet(HttpServletRequest request, HttpServletResponse response) {
37 String dictionaryType = request.getParameter("dictionaryType");
39 DictionaryService dictionary = new DictionaryService();
40 switch (dictionaryType) {
42 dictionary.getOnapDictionary(response);
45 dictionary.getAttributeDictionary(response);
48 dictionary.getActionPolicyDictionary(response);
50 case "BRMSParamTemplate":
51 dictionary.getBRMSParamDictionary(response);
54 dictionary.getVSCLAction(response);
57 dictionary.getVnfType(response);
60 dictionary.getPEPOptions(response);
63 dictionary.getVarbind(response);
66 dictionary.getServiceType(response);
69 dictionary.getSiteType(response);
72 dictionary.getSettingsDictionary(response);
74 case "RainyDayTreatments":
75 dictionary.getRainyDayDictionary(response);
77 case "DescriptiveScope":
78 dictionary.getDescriptiveDictionary(response);
81 dictionary.getActionListDictionary(response);
84 dictionary.getProtocolListDictionary(response);
87 dictionary.getZoneDictionary(response);
90 dictionary.getSecurityZoneDictionary(response);
93 dictionary.getPrefixListDictionary(response);
96 dictionary.getAddressGroupDictionary(response);
99 dictionary.getServiceGroupDictionary(response);
102 dictionary.getServiceListDictionary(response);
106 case "FirewallRuleList":
108 dictionary.getTermListDictionary(response);
110 case "MicroServiceLocation":
111 dictionary.getMicroServiceLocationDictionary(response);
113 case "MicroServiceConfigName":
114 dictionary.getMicroServiceConfigNameDictionary(response);
116 case "MicroServiceDictionaryData":
117 dictionary.getMicroServiceDictionaryData(response);
120 dictionary.getDCAEUUIDDictionary(response);
122 case "MicroServiceModels":
123 dictionary.getMicroServiceModelsDictionary(response);
125 case "MicroServiceDictionary":
126 dictionary.getMicroServiceDictionary(response);
128 case "OptimizationModels":
129 dictionary.getOptimizationModelsDictionary(response);
131 case "PolicyScopeService":
132 dictionary.getPSServiceDictionary(response);
134 case "PolicyScopeResource":
135 dictionary.getPSResourceDictionary(response);
137 case "PolicyScopeType":
138 dictionary.getPSTypeDictionary(response);
140 case "PolicyScopeClosedLoop":
141 dictionary.getPSClosedLoopDictionary(response);
143 case "GroupPolicyScopeList":
144 dictionary.getPSGroupScopeDictionary(response);
147 dictionary.getRiskTypeDictionary(response);
149 case "SafePolicyWarning":
150 dictionary.getSafePolicyWarningDictionary(response);
153 extendedOptions(dictionaryType, request, response, true);
155 } catch (Exception e) {
156 String message = XACMLErrorConstants.ERROR_DATA_ISSUE + " Error Querying the Database: " + e.getMessage();
157 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "DictionaryHandler", " Error Querying the Database.");
158 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
159 response.addHeader("error", "dictionaryDBQuery");
160 response.addHeader("error", message);
165 * Can be used to extend the services.
167 * getflag=true indicates Get Request. getflag=false indicates Put Request.
172 public String extendedOptions(String dictionaryType, HttpServletRequest request, HttpServletResponse response,
175 String message = XACMLErrorConstants.ERROR_DATA_ISSUE + " Invalid Dictionary in Request.";
176 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "DictionaryHandler", " Invalid Dictionary in Request.");
177 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
178 response.setHeader("error", "dictionary");
179 response.addHeader("error", message);
184 public void doDictionaryAPIPut(HttpServletRequest request, HttpServletResponse response) {
185 String result = null;
186 String dictionaryType = request.getParameter("dictionaryType");
187 String operation = request.getParameter("operation");
189 DictionaryService dictionary = new DictionaryService();
190 switch (dictionaryType) {
192 result = dictionary.saveOnapDictionary(request, response);
195 result = dictionary.saveAttributeDictionary(request, response);
198 result = dictionary.saveActionPolicyDictionary(request, response);
200 case "BRMSParamTemplate":
201 result = dictionary.saveBRMSParamDictionary(request, response);
204 result = dictionary.saveVSCLAction(request, response);
207 result = dictionary.saveVnfType(request, response);
210 result = dictionary.savePEPOptions(request, response);
213 result = dictionary.saveVarbind(request, response);
216 result = dictionary.saveServiceType(request, response);
219 result = dictionary.saveSiteType(request, response);
222 result = dictionary.saveSettingsDictionary(request, response);
224 case "RainyDayTreatments":
225 result = dictionary.saveRainyDayDictionary(request, response);
227 case "DescriptiveScope":
228 result = dictionary.saveDescriptiveDictionary(request, response);
231 result = dictionary.saveActionListDictionary(request, response);
234 result = dictionary.saveProtocolListDictionary(request, response);
237 result = dictionary.saveZoneDictionary(request, response);
240 result = dictionary.saveSecurityZoneDictionary(request, response);
243 result = dictionary.savePrefixListDictionary(request, response);
246 result = dictionary.saveAddressGroupDictionary(request, response);
249 result = dictionary.saveServiceGroupDictionary(request, response);
252 result = dictionary.saveServiceListDictionary(request, response);
256 case "FirewallRuleList":
258 result = dictionary.saveTermListDictionary(request, response);
260 case "MicroServiceLocation":
261 result = dictionary.saveMicroServiceLocationDictionary(request, response);
263 case "MicroServiceConfigName":
264 result = dictionary.saveMicroServiceConfigNameDictionary(request, response);
266 case "MicroServiceDictionaryData":
267 dictionary.saveMicroServiceDictionaryData(request, response);
270 result = dictionary.saveDCAEUUIDDictionary(request, response);
272 case "MicroServiceModels":
273 result = dictionary.saveMicroServiceModelsDictionary(request, response);
275 case "MicroServiceDictionary":
276 result = dictionary.saveMicroServiceDictionary(request, response);
278 case "OptimizationModels":
279 result = dictionary.saveOptimizationModelsDictionary(request, response);
281 case "PolicyScopeService":
282 result = dictionary.savePSServiceDictionary(request, response);
284 case "PolicyScopeResource":
285 result = dictionary.savePSResourceDictionary(request, response);
287 case "PolicyScopeType":
288 result = dictionary.savePSTypeDictionary(request, response);
290 case "PolicyScopeClosedLoop":
291 result = dictionary.savePSClosedLoopDictionary(request, response);
293 case "GroupPolicyScopeList":
294 result = dictionary.savePSGroupScopeDictionary(request, response);
297 result = dictionary.saveRiskTypeDictionary(request, response);
299 case "SafePolicyWarning":
300 result = dictionary.saveSafePolicyWarningDictionary(request, response);
303 result = extendedOptions(dictionaryType, request, response, false);
304 if (result == null) {
310 } catch (Exception e) {
311 String message = XACMLErrorConstants.ERROR_DATA_ISSUE + " Error Updating the Database: " + e.getMessage();
312 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "XACMLPapServlet", " Error Updating the Database.");
313 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
314 response.addHeader("error", message);
317 if (("Success").equalsIgnoreCase(result)) {
318 response.setStatus(HttpServletResponse.SC_OK);
319 response.addHeader("successMapKey", "success");
320 if (operation.equalsIgnoreCase("update")) {
321 response.addHeader("operation", "updateDictionary");
323 response.addHeader("operation", "createDictionary");
325 } else if (("Duplicate").equalsIgnoreCase(result)) {
326 response.setStatus(HttpServletResponse.SC_CONFLICT);
327 response.addHeader("error", "dictionaryItemExists");
328 } else if (("DuplicateGroup").equalsIgnoreCase(result)) {
329 response.setStatus(HttpServletResponse.SC_CONFLICT);
330 response.addHeader("error", "duplicateGroup");
332 String message = XACMLErrorConstants.ERROR_DATA_ISSUE + " Error Updating the Database.";
333 PolicyLogger.error(message);
334 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
335 response.addHeader("error", message);