2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017-2018 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=========================================================
20 package org.onap.policy.pap.xacml.rest.handler;
22 import javax.servlet.http.HttpServletRequest;
23 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.
34 public void doDictionaryAPIGet(HttpServletRequest request, HttpServletResponse response) {
35 String dictionaryType = request.getParameter("dictionaryType");
37 DictionaryService dictionary = new DictionaryService();
38 switch (dictionaryType) {
40 dictionary.getOnapDictionary(response);
43 dictionary.getAttributeDictionary(response);
46 dictionary.getActionPolicyDictionary(response);
48 case "BRMSParamTemplate":
49 dictionary.getBRMSParamDictionary(response);
52 dictionary.getVSCLAction(response);
55 dictionary.getVnfType(response);
58 dictionary.getPEPOptions(response);
61 dictionary.getVarbind(response);
64 dictionary.getServiceType(response);
67 dictionary.getSiteType(response);
70 dictionary.getSettingsDictionary(response);
72 case "RainyDayTreatments":
73 dictionary.getRainyDayDictionary(response);
75 case "DescriptiveScope":
76 dictionary.getDescriptiveDictionary(response);
79 dictionary.getActionListDictionary(response);
82 dictionary.getProtocolListDictionary(response);
85 dictionary.getZoneDictionary(response);
88 dictionary.getSecurityZoneDictionary(response);
91 dictionary.getPrefixListDictionary(response);
94 dictionary.getAddressGroupDictionary(response);
97 dictionary.getServiceGroupDictionary(response);
100 dictionary.getServiceListDictionary(response);
104 case "FirewallRuleList":
106 dictionary.getTermListDictionary(response);
108 case "MicroServiceLocation":
109 dictionary.getMicroServiceLocationDictionary(response);
111 case "MicroServiceConfigName":
112 dictionary.getMicroServiceConfigNameDictionary(response);
115 dictionary.getDCAEUUIDDictionary(response);
117 case "MicroServiceModels":
118 dictionary.getMicroServiceModelsDictionary(response);
120 case "MicroServiceDictionary":
121 dictionary.getMicroServiceDictionary(response);
123 case "OptimizationModels":
124 dictionary.getOptimizationModelsDictionary(response);
126 case "PolicyScopeService":
127 dictionary.getPSServiceDictionary(response);
129 case "PolicyScopeResource":
130 dictionary.getPSResourceDictionary(response);
132 case "PolicyScopeType":
133 dictionary.getPSTypeDictionary(response);
135 case "PolicyScopeClosedLoop":
136 dictionary.getPSClosedLoopDictionary(response);
138 case "GroupPolicyScopeList":
139 dictionary.getPSGroupScopeDictionary(response);
142 dictionary.getRiskTypeDictionary(response);
144 case "SafePolicyWarning":
145 dictionary.getSafePolicyWarningDictionary(response);
148 extendedOptions(dictionaryType, request, response, true);
151 } catch (Exception e) {
152 String message = XACMLErrorConstants.ERROR_DATA_ISSUE + " Error Querying the Database: " + e.getMessage();
153 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "DictionaryHandler", " Error Querying the Database.");
154 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
155 response.addHeader("error", "dictionaryDBQuery");
156 response.addHeader("error", message);
162 * Can be used to extend the services.
164 * getflag=true indicates Get Request.
165 * getflag=false indicates Put Request.
168 public String extendedOptions(String dictionaryType, HttpServletRequest request, HttpServletResponse response, boolean getflag) {
170 String message = XACMLErrorConstants.ERROR_DATA_ISSUE + " Invalid Dictionary in Request.";
171 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, "DictionaryHandler", " Invalid Dictionary in Request.");
172 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
173 response.setHeader("error", "dictionary");
174 response.addHeader("error", message);
178 public void doDictionaryAPIPut(HttpServletRequest request, HttpServletResponse response) {
179 String result = null;
180 String dictionaryType = request.getParameter("dictionaryType");
181 String operation = request.getParameter("operation");
183 DictionaryService dictionary = new DictionaryService();
184 switch (dictionaryType) {
186 result = dictionary.saveOnapDictionary(request, response);
189 result = dictionary.saveAttributeDictionary(request, response);
192 result = dictionary.saveActionPolicyDictionary(request, response);
194 case "BRMSParamTemplate":
195 result = dictionary.saveBRMSParamDictionary(request, response);
198 result = dictionary.saveVSCLAction(request, response);
201 result = dictionary.saveVnfType(request, response);
204 result = dictionary.savePEPOptions(request, response);
207 result = dictionary.saveVarbind(request, response);
210 result = dictionary.saveServiceType(request, response);
213 result = dictionary.saveSiteType(request, response);
216 result = dictionary.saveSettingsDictionary(request, response);
218 case "RainyDayTreatments":
219 result = dictionary.saveRainyDayDictionary(request, response);
221 case "DescriptiveScope":
222 result = dictionary.saveDescriptiveDictionary(request, response);
225 result = dictionary.saveActionListDictionary(request, response);
228 result = dictionary.saveProtocolListDictionary(request, response);
231 result = dictionary.saveZoneDictionary(request, response);
234 result = dictionary.saveSecurityZoneDictionary(request, response);
237 result = dictionary.savePrefixListDictionary(request, response);
240 result = dictionary.saveAddressGroupDictionary(request, response);
243 result = dictionary.saveServiceGroupDictionary(request, response);
246 result = dictionary.saveServiceListDictionary(request, response);
250 case "FirewallRuleList":
252 result = dictionary.saveTermListDictionary(request, response);
254 case "MicroServiceLocation":
255 result = dictionary.saveMicroServiceLocationDictionary(request, response);
257 case "MicroServiceConfigName":
258 result = dictionary.saveMicroServiceConfigNameDictionary(request, response);
261 result = dictionary.saveDCAEUUIDDictionary(request, response);
263 case "MicroServiceModels":
264 result = dictionary.saveMicroServiceModelsDictionary(request, response);
266 case "MicroServiceDictionary":
267 result = dictionary.saveMicroServiceDictionary(request, response);
269 case "OptimizationModels":
270 result = dictionary.saveOptimizationModelsDictionary(request, response);
272 case "PolicyScopeService":
273 result = dictionary.savePSServiceDictionary(request, response);
275 case "PolicyScopeResource":
276 result = dictionary.savePSResourceDictionary(request, response);
278 case "PolicyScopeType":
279 result = dictionary.savePSTypeDictionary(request, response);
281 case "PolicyScopeClosedLoop":
282 result = dictionary.savePSClosedLoopDictionary(request, response);
284 case "GroupPolicyScopeList":
285 result = dictionary.savePSGroupScopeDictionary(request, response);
288 result = dictionary.saveRiskTypeDictionary(request, response);
290 case "SafePolicyWarning":
291 result = dictionary.saveSafePolicyWarningDictionary(request, response);
294 result = extendedOptions(dictionaryType, request, response, false);
301 } catch (Exception e) {
302 String message = XACMLErrorConstants.ERROR_DATA_ISSUE + " Error Updating the Database: " + e.getMessage();
303 PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "XACMLPapServlet", " Error Updating the Database.");
304 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
305 response.addHeader("error", message);
308 if (result.equalsIgnoreCase("Success")) {
309 response.setStatus(HttpServletResponse.SC_OK);
310 response.addHeader("successMapKey", "success");
311 if (operation.equalsIgnoreCase("update")) {
312 response.addHeader("operation", "updateDictionary");
314 response.addHeader("operation", "createDictionary");
316 } else if (result.equalsIgnoreCase("Duplicate")) {
317 response.setStatus(HttpServletResponse.SC_CONFLICT);
318 response.addHeader("error", "dictionaryItemExists");
319 } else if (result.equalsIgnoreCase("DuplicateGroup")) {
320 response.setStatus(HttpServletResponse.SC_CONFLICT);
321 response.addHeader("error", "duplicateGroup");
323 String message = XACMLErrorConstants.ERROR_DATA_ISSUE + " Error Updating the Database.";
324 PolicyLogger.error(message);
325 response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
326 response.addHeader("error", message);