X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=ONAP-PAP-REST%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fpap%2Fxacml%2Frest%2Fcontroller%2FFirewallDictionaryController.java;h=3a4d7b71b4312829b463d736002f2668fa0da09c;hb=b0f132227b0d77ea847f40d07f57d9d053c1555e;hp=d4594c020127c8b7deb099e26d691c5f0c98ab5d;hpb=7925630b5edc79119f29392edc6ddc84cf7c3757;p=policy%2Fengine.git diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryController.java index d4594c020..3a4d7b71b 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/FirewallDictionaryController.java @@ -22,7 +22,6 @@ package org.onap.policy.pap.xacml.rest.controller; import java.io.IOException; import java.io.PrintWriter; -import java.io.UnsupportedEncodingException; import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Date; @@ -73,26 +72,58 @@ public class FirewallDictionaryController { private static final Logger LOGGER = FlexLogger.getLogger(FirewallDictionaryController.class); private static CommonClassDao commonClassDao; + private static String prefixListName = "prefixListName"; + private static String successMapKey = "successMapKey"; + private static String successMessage = "success"; + private static String operation = "operation"; + private static String getDictionary = "getDictionary"; + private static String errorMsg = "error"; + private static String dictionaryDBQuery = "dictionaryDBQuery"; + private static String apiflag = "apiflag"; + private static String dictionaryFields ="dictionaryFields"; + private static String update = "update"; + private static String duplicateResponseString = "Duplicate"; + private static String successMsg = "Success"; + private static String utf8 = "UTF-8"; + private static String applicationJsonContentType = "application / json"; + private static String existsResponseString = "Exists"; + private static String protocolName = "protocolName"; + private static String groupNameStart = "Group_"; + private static String option = "option"; + private static String zoneName = "zoneName"; + private static String serviceName = "serviceName"; + private static String termName = "termName"; + private static String userid = "userid"; + private static String tagPickerName = "tagPickerName"; + private static String fwTagPickerDictionaryData = "fwTagPickerDictionaryData"; + private static String fwTagDictionaryDatas = "fwTagDictionaryDatas"; + @Autowired public FirewallDictionaryController(CommonClassDao commonClassDao){ FirewallDictionaryController.commonClassDao = commonClassDao; } + public static void setCommonClassDao(CommonClassDao clDao){ + commonClassDao = clDao; + } + + /* + * This is an empty constructor + */ public FirewallDictionaryController(){} public UserInfo getUserInfo(String loginId){ - UserInfo name = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId); - return name; + return (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId); } @RequestMapping(value={"/get_PrefixListDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getPrefixListDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + public void getPrefixListDictionaryEntityDataByName(HttpServletResponse response){ try{ Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); - model.put("prefixListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PrefixList.class, "prefixListName"))); + model.put("prefixListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PrefixList.class, prefixListName))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -103,31 +134,31 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/get_PrefixListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getPrefixListDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getPrefixListDictionaryEntityData(HttpServletResponse response){ try{ Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("prefixListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PrefixList.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); - response.addHeader("successMapKey", "success"); - response.addHeader("operation", "getDictionary"); + response.addHeader(successMapKey, successMessage); + response.addHeader(operation, getDictionary); response.getWriter().write(j.toString()); } catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW, e); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - response.addHeader("error", "dictionaryDBQuery"); + response.addHeader(errorMsg, dictionaryDBQuery); } } @RequestMapping(value={"/fw_dictionary/save_prefixList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView savePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView savePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ try { boolean duplicateflag = false; boolean isFakeUpdate = false; boolean fromAPI = false; - if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) { fromAPI = true; } ObjectMapper mapper = new ObjectMapper(); @@ -135,14 +166,13 @@ public class FirewallDictionaryController { JsonNode root = mapper.readTree(request.getReader()); PrefixList prefixList; if (fromAPI) { - prefixList = (PrefixList)mapper.readValue(root.get("dictionaryFields").toString(), PrefixList.class); + prefixList = (PrefixList)mapper.readValue(root.get(dictionaryFields).toString(), PrefixList.class); //check if update operation or create, get id for data to be updated and update attributeData - if (request.getParameter("operation").equals("update")) { - List duplicateData = commonClassDao.checkDuplicateEntry(prefixList.getPrefixListName(), "prefixListName", PrefixList.class); - int id = 0; + if ((update).equals(request.getParameter(operation))) { + List duplicateData = commonClassDao.checkDuplicateEntry(prefixList.getPrefixListName(), prefixListName, PrefixList.class); PrefixList data = (PrefixList) duplicateData.get(0); - id = data.getId(); + int id = data.getId(); if(id==0){ isFakeUpdate=true; prefixList.setId(1); @@ -154,7 +184,7 @@ public class FirewallDictionaryController { prefixList = (PrefixList)mapper.readValue(root.get("prefixListDictionaryData").toString(), PrefixList.class); } if(prefixList.getId() == 0){ - List duplicateData = commonClassDao.checkDuplicateEntry(prefixList.getPrefixListName(), "prefixListName", PrefixList.class); + List duplicateData = commonClassDao.checkDuplicateEntry(prefixList.getPrefixListName(), prefixListName, PrefixList.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ @@ -167,26 +197,26 @@ public class FirewallDictionaryController { } String responseString = ""; if(duplicateflag){ - responseString = "Duplicate"; + responseString = duplicateResponseString; }else{ responseString = mapper.writeValueAsString(commonClassDao.getData(PrefixList.class)); } if (fromAPI) { - if (responseString!=null && !responseString.equals("Duplicate")) { + if (responseString!=null && !(duplicateResponseString).equals(responseString)) { if(isFakeUpdate){ - responseString = "Exists"; + responseString = existsResponseString; } else { - responseString = "Success"; + responseString = successMsg; } } ModelAndView result = new ModelAndView(); result.setViewName(responseString); return result; } else { - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + response.setContentType(applicationJsonContentType); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); JSONObject j = new JSONObject("{prefixListDictionaryDatas: " + responseString + "}"); @@ -195,8 +225,8 @@ public class FirewallDictionaryController { } }catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW, e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -204,16 +234,16 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/fw_dictionary/remove_PrefixList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView removePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ try{ ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); PrefixList prefixList = (PrefixList)mapper.readValue(root.get("data").toString(), PrefixList.class); commonClassDao.delete(prefixList); - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + response.setContentType(applicationJsonContentType); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); String responseString = mapper.writeValueAsString(commonClassDao.getData(PrefixList.class)); @@ -223,8 +253,8 @@ public class FirewallDictionaryController { } catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -232,22 +262,22 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/fw_dictionary/validate_prefixList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView validatePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView validatePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ try { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); PrefixList prefixList = (PrefixList)mapper.readValue(root.get("prefixListDictionaryData").toString(), PrefixList.class); - String responseValidation = "success"; + String responseValidation = successMessage; try{ CIDR.newCIDR(prefixList.getPrefixListValue()); }catch(UnknownHostException e){ LOGGER.error(e); - responseValidation = "error"; + responseValidation = errorMsg; } - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + response.setContentType(applicationJsonContentType); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); JSONObject j = new JSONObject("{result: " + responseValidation + "}"); @@ -256,8 +286,8 @@ public class FirewallDictionaryController { } catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -265,26 +295,26 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/get_PortListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getPortListDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getPortListDictionaryEntityData(HttpServletResponse response){ try{ Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("portListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PortList.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); - response.addHeader("successMapKey", "success"); - response.addHeader("operation", "getDictionary"); + response.addHeader(successMapKey, successMessage); + response.addHeader(operation, getDictionary); response.getWriter().write(j.toString()); } catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - response.addHeader("error", "dictionaryDBQuery"); + response.addHeader(errorMsg, dictionaryDBQuery); } } @RequestMapping(value={"/fw_dictionary/save_portName"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView savePortListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView savePortListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ try { boolean duplicateflag = false; ObjectMapper mapper = new ObjectMapper(); @@ -301,14 +331,14 @@ public class FirewallDictionaryController { }else{ commonClassDao.update(portList); } - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + response.setContentType(applicationJsonContentType); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); String responseString = ""; if(duplicateflag){ - responseString = "Duplicate"; + responseString = duplicateResponseString; }else{ responseString = mapper.writeValueAsString(commonClassDao.getData(PortList.class)); } @@ -320,8 +350,8 @@ public class FirewallDictionaryController { } catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -329,16 +359,16 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/fw_dictionary/remove_PortList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removePortListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView removePortListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ try{ ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); PortList portList = (PortList)mapper.readValue(root.get("data").toString(), PortList.class); commonClassDao.delete(portList); - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + response.setContentType(applicationJsonContentType); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); String responseString = mapper.writeValueAsString(commonClassDao.getData(PortList.class)); @@ -348,8 +378,8 @@ public class FirewallDictionaryController { } catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -357,30 +387,30 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/get_ProtocolListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getProtocolListDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getProtocolListDictionaryEntityData(HttpServletResponse response){ try{ - Map model = new HashMap(); + Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("protocolListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ProtocolList.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); - response.addHeader("successMapKey", "success"); - response.addHeader("operation", "getDictionary"); + response.addHeader(successMapKey, successMessage); + response.addHeader(operation, getDictionary); response.getWriter().write(j.toString()); } catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - response.addHeader("error", "dictionaryDBQuery"); + response.addHeader(errorMsg, dictionaryDBQuery); } } @RequestMapping(value={"/get_ProtocolListDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getProtocolListDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + public void getProtocolListDictionaryEntityDataByName(HttpServletResponse response){ try{ - Map model = new HashMap(); + Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); - model.put("protocolListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ProtocolList.class, "protocolName"))); + model.put("protocolListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ProtocolList.class, protocolName))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -391,12 +421,12 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/fw_dictionary/save_protocolList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView saveProtocolListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView saveProtocolListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ try { boolean duplicateflag = false; boolean isFakeUpdate = false; boolean fromAPI = false; - if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) { fromAPI = true; } ObjectMapper mapper = new ObjectMapper(); @@ -404,14 +434,13 @@ public class FirewallDictionaryController { JsonNode root = mapper.readTree(request.getReader()); ProtocolList protocolList; if (fromAPI) { - protocolList = (ProtocolList)mapper.readValue(root.get("dictionaryFields").toString(), ProtocolList.class); + protocolList = (ProtocolList)mapper.readValue(root.get(dictionaryFields).toString(), ProtocolList.class); //check if update operation or create, get id for data to be updated and update attributeData - if (request.getParameter("operation").equals("update")) { - List duplicateData = commonClassDao.checkDuplicateEntry(protocolList.getProtocolName(), "protocolName", ProtocolList.class); - int id = 0; + if ((update).equals(request.getParameter(operation))) { + List duplicateData = commonClassDao.checkDuplicateEntry(protocolList.getProtocolName(), protocolName, ProtocolList.class); ProtocolList data = (ProtocolList) duplicateData.get(0); - id = data.getId(); + int id = data.getId(); if(id==0){ isFakeUpdate=true; protocolList.setId(1); @@ -423,7 +452,7 @@ public class FirewallDictionaryController { protocolList = (ProtocolList)mapper.readValue(root.get("protocolListDictionaryData").toString(), ProtocolList.class); } if(protocolList.getId() == 0){ - List duplicateData = commonClassDao.checkDuplicateEntry(protocolList.getProtocolName(), "protocolName", ProtocolList.class); + List duplicateData = commonClassDao.checkDuplicateEntry(protocolList.getProtocolName(), protocolName, ProtocolList.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ @@ -436,26 +465,26 @@ public class FirewallDictionaryController { } String responseString = ""; if(duplicateflag){ - responseString = "Duplicate"; + responseString = duplicateResponseString; }else{ responseString = mapper.writeValueAsString(commonClassDao.getData(ProtocolList.class)); } if (fromAPI) { - if (responseString!=null && !responseString.equals("Duplicate")) { + if (responseString!=null && !(duplicateResponseString).equals(responseString)) { if(isFakeUpdate){ - responseString = "Exists"; + responseString = existsResponseString; } else { - responseString = "Success"; + responseString = successMsg; } } ModelAndView result = new ModelAndView(); result.setViewName(responseString); return result; } else { - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + response.setContentType(applicationJsonContentType); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); JSONObject j = new JSONObject("{protocolListDictionaryDatas: " + responseString + "}"); @@ -464,8 +493,8 @@ public class FirewallDictionaryController { } }catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -473,16 +502,16 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/fw_dictionary/remove_protocol"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removeProtocolListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView removeProtocolListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ try{ ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); ProtocolList protocolList = (ProtocolList)mapper.readValue(root.get("data").toString(), ProtocolList.class); commonClassDao.delete(protocolList); - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + response.setContentType(applicationJsonContentType); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); @@ -493,8 +522,8 @@ public class FirewallDictionaryController { } catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -502,7 +531,7 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/get_AddressGroupDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getAddressGroupDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + public void getAddressGroupDictionaryEntityDataByName(HttpServletResponse response){ try{ Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); @@ -517,31 +546,31 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/get_AddressGroupData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getAddressGroupDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getAddressGroupDictionaryEntityData(HttpServletResponse response){ try{ Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("addressGroupDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(AddressGroup.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); - response.addHeader("successMapKey", "success"); - response.addHeader("operation", "getDictionary"); + response.addHeader(successMapKey, successMessage); + response.addHeader(operation, getDictionary); response.getWriter().write(j.toString()); } catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - response.addHeader("error", "dictionaryDBQuery"); + response.addHeader(errorMsg, dictionaryDBQuery); } } @RequestMapping(value={"/fw_dictionary/save_addressGroup"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView saveAddressGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView saveAddressGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ try { boolean duplicateflag = false; boolean isFakeUpdate = false; boolean fromAPI = false; - if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) { fromAPI = true; } ObjectMapper mapper = new ObjectMapper(); @@ -550,20 +579,19 @@ public class FirewallDictionaryController { AddressGroup addressGroup; GridData gridData; if (fromAPI) { - addressGroup = (AddressGroup)mapper.readValue(root.get("dictionaryFields").toString(), AddressGroup.class); - gridData = (GridData)mapper.readValue(root.get("dictionaryFields").toString(), GridData.class); + addressGroup = (AddressGroup)mapper.readValue(root.get(dictionaryFields).toString(), AddressGroup.class); + gridData = (GridData)mapper.readValue(root.get(dictionaryFields).toString(), GridData.class); - if(!addressGroup.getGroupName().startsWith("Group_")){ - String groupName = "Group_"+addressGroup.getGroupName(); + if(!addressGroup.getGroupName().startsWith(groupNameStart)){ + String groupName = groupNameStart+addressGroup.getGroupName(); addressGroup.setGroupName(groupName); } //check if update operation or create, get id for data to be updated and update attributeData - if (request.getParameter("operation").equals("update")) { + if ((update).equals(request.getParameter(operation))) { List duplicateData = commonClassDao.checkDuplicateEntry(addressGroup.getGroupName(), "name", AddressGroup.class); - int id = 0; AddressGroup data = (AddressGroup) duplicateData.get(0); - id = data.getId(); + int id = data.getId(); if(id==0){ isFakeUpdate=true; addressGroup.setId(1); @@ -574,17 +602,17 @@ public class FirewallDictionaryController { } else { addressGroup = (AddressGroup)mapper.readValue(root.get("addressGroupDictionaryData").toString(), AddressGroup.class); gridData = (GridData)mapper.readValue(root.get("addressGroupDictionaryData").toString(), GridData.class); - if(!addressGroup.getGroupName().startsWith("Group_")){ - String groupName = "Group_"+addressGroup.getGroupName(); + if(!addressGroup.getGroupName().startsWith(groupNameStart)){ + String groupName = groupNameStart+addressGroup.getGroupName(); addressGroup.setGroupName(groupName); } } String userValue = ""; int counter = 0; - if(gridData.getAttributes().size() > 0){ + if(!gridData.getAttributes().isEmpty()){ for(Object attribute : gridData.getAttributes()){ if(attribute instanceof LinkedHashMap){ - String key = ((LinkedHashMap) attribute).get("option").toString(); + String key = ((LinkedHashMap) attribute).get(option).toString(); if(counter>0){ userValue = userValue + ","; } @@ -608,25 +636,25 @@ public class FirewallDictionaryController { } String responseString = ""; if(duplicateflag){ - responseString = "Duplicate"; + responseString = duplicateResponseString; }else{ responseString = mapper.writeValueAsString(commonClassDao.getData(AddressGroup.class)); } if (fromAPI) { - if (responseString!=null && !responseString.equals("Duplicate")) { + if (responseString!=null && !(duplicateResponseString).equals(responseString)) { if(isFakeUpdate){ - responseString = "Exists"; + responseString = existsResponseString; } else { - responseString = "Success"; + responseString = successMsg; } } ModelAndView result = new ModelAndView(); result.setViewName(responseString); return result; } else { - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + response.setContentType(applicationJsonContentType); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); JSONObject j = new JSONObject("{addressGroupDictionaryDatas: " + responseString + "}"); @@ -635,8 +663,8 @@ public class FirewallDictionaryController { } }catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -644,16 +672,16 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/fw_dictionary/remove_AddressGroup"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removeAddressGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView removeAddressGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ try{ ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); AddressGroup addressGroup = (AddressGroup)mapper.readValue(root.get("data").toString(), AddressGroup.class); commonClassDao.delete(addressGroup); - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + response.setContentType(applicationJsonContentType); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); @@ -664,8 +692,8 @@ public class FirewallDictionaryController { } catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -673,7 +701,7 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/get_ActionListDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getActionListDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + public void getActionListDictionaryEntityDataByName(HttpServletResponse response){ try{ Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); @@ -694,31 +722,31 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/get_ActionListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getActionListDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getActionListDictionaryEntityData(HttpServletResponse response){ try{ Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("actionListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ActionList.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); - response.addHeader("successMapKey", "success"); - response.addHeader("operation", "getDictionary"); + response.addHeader(successMapKey, successMessage); + response.addHeader(operation, getDictionary); response.getWriter().write(j.toString()); } catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - response.addHeader("error", "dictionaryDBQuery"); + response.addHeader(errorMsg, dictionaryDBQuery); } } @RequestMapping(value={"/fw_dictionary/save_ActionList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView saveActionListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView saveActionListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ try { boolean duplicateflag = false; boolean isFakeUpdate = false; boolean fromAPI = false; - if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) { fromAPI = true; } ObjectMapper mapper = new ObjectMapper(); @@ -726,14 +754,13 @@ public class FirewallDictionaryController { JsonNode root = mapper.readTree(request.getReader()); ActionList actionList; if (fromAPI) { - actionList = (ActionList)mapper.readValue(root.get("dictionaryFields").toString(), ActionList.class); + actionList = (ActionList)mapper.readValue(root.get(dictionaryFields).toString(), ActionList.class); //check if update operation or create, get id for data to be updated and update attributeData - if (request.getParameter("operation").equals("update")) { + if ((update).equals(request.getParameter(operation))) { List duplicateData = commonClassDao.checkDuplicateEntry(actionList.getActionName(), "actionName", ActionList.class); - int id = 0; ActionList data = (ActionList) duplicateData.get(0); - id = data.getId(); + int id = data.getId(); if(id==0){ isFakeUpdate=true; actionList.setId(1); @@ -758,26 +785,26 @@ public class FirewallDictionaryController { } String responseString = ""; if(duplicateflag){ - responseString = "Duplicate"; + responseString = duplicateResponseString; }else{ responseString = mapper.writeValueAsString(commonClassDao.getData(ActionList.class)); } if (fromAPI) { - if (responseString!=null && !responseString.equals("Duplicate")) { + if (responseString!=null && !(duplicateResponseString).equals(responseString)) { if(isFakeUpdate){ - responseString = "Exists"; + responseString = existsResponseString; } else { - responseString = "Success"; + responseString = successMsg; } } ModelAndView result = new ModelAndView(); result.setViewName(responseString); return result; } else { - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + response.setContentType(applicationJsonContentType); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); JSONObject j = new JSONObject("{actionListDictionaryDatas: " + responseString + "}"); @@ -786,8 +813,8 @@ public class FirewallDictionaryController { } }catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -795,16 +822,16 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/fw_dictionary/remove_ActionList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removeActionListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView removeActionListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ try{ ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); ActionList actionList = (ActionList)mapper.readValue(root.get("data").toString(), ActionList.class); commonClassDao.delete(actionList); - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + response.setContentType(applicationJsonContentType); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); String responseString = mapper.writeValueAsString(commonClassDao.getData(ActionList.class)); @@ -814,8 +841,8 @@ public class FirewallDictionaryController { } catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -823,26 +850,26 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/get_ServiceGroupData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getServiceGroupDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getServiceGroupDictionaryEntityData(HttpServletResponse response){ try{ Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("serviceGroupDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(GroupServiceList.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); - response.addHeader("successMapKey", "success"); - response.addHeader("operation", "getDictionary"); + response.addHeader(successMapKey, successMessage); + response.addHeader(operation, getDictionary); response.getWriter().write(j.toString()); } catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - response.addHeader("error", "dictionaryDBQuery"); + response.addHeader(errorMsg, dictionaryDBQuery); } } @RequestMapping(value={"/get_ServiceGroupDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getServiceGroupDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + public void getServiceGroupDictionaryEntityDataByName(HttpServletResponse response){ try{ Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); @@ -857,12 +884,12 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/fw_dictionary/save_serviceGroup"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView saveServiceGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView saveServiceGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ try { boolean duplicateflag = false; boolean isFakeUpdate = false; boolean fromAPI = false; - if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) { fromAPI = true; } ObjectMapper mapper = new ObjectMapper(); @@ -871,19 +898,18 @@ public class FirewallDictionaryController { GroupServiceList groupServiceList; GridData gridData; if (fromAPI) { - groupServiceList = (GroupServiceList)mapper.readValue(root.get("dictionaryFields").toString(), GroupServiceList.class); - gridData = (GridData)mapper.readValue(root.get("dictionaryFields").toString(), GridData.class); + groupServiceList = (GroupServiceList)mapper.readValue(root.get(dictionaryFields).toString(), GroupServiceList.class); + gridData = (GridData)mapper.readValue(root.get(dictionaryFields).toString(), GridData.class); - if(!groupServiceList.getGroupName().startsWith("Group_")){ - String groupName = "Group_"+groupServiceList.getGroupName(); + if(!groupServiceList.getGroupName().startsWith(groupNameStart)){ + String groupName = groupNameStart+groupServiceList.getGroupName(); groupServiceList.setGroupName(groupName); } //check if update operation or create, get id for data to be updated and update attributeData - if (request.getParameter("operation").equals("update")) { + if ((update).equals(request.getParameter(operation))) { List duplicateData = commonClassDao.checkDuplicateEntry(groupServiceList.getGroupName(), "name", GroupServiceList.class); - int id = 0; GroupServiceList data = (GroupServiceList) duplicateData.get(0); - id = data.getId(); + int id = data.getId(); if(id==0){ isFakeUpdate=true; @@ -896,16 +922,16 @@ public class FirewallDictionaryController { groupServiceList = (GroupServiceList)mapper.readValue(root.get("serviceGroupDictionaryData").toString(), GroupServiceList.class); gridData = (GridData)mapper.readValue(root.get("serviceGroupDictionaryData").toString(), GridData.class); } - if(!groupServiceList.getGroupName().startsWith("Group_")){ - String groupName = "Group_"+groupServiceList.getGroupName(); + if(!groupServiceList.getGroupName().startsWith(groupNameStart)){ + String groupName = groupNameStart+groupServiceList.getGroupName(); groupServiceList.setGroupName(groupName); } String userValue = ""; int counter = 0; - if(gridData.getAttributes().size() > 0){ + if(!gridData.getAttributes().isEmpty()){ for(Object attribute : gridData.getAttributes()){ if(attribute instanceof LinkedHashMap){ - String key = ((LinkedHashMap) attribute).get("option").toString(); + String key = ((LinkedHashMap) attribute).get(option).toString(); if(counter>0){ userValue = userValue + ","; } @@ -929,26 +955,26 @@ public class FirewallDictionaryController { } String responseString = ""; if(duplicateflag){ - responseString = "Duplicate"; + responseString = duplicateResponseString; }else{ responseString = mapper.writeValueAsString(commonClassDao.getData(GroupServiceList.class)); } if (fromAPI) { - if (responseString!=null && !responseString.equals("Duplicate")) { + if (responseString!=null && !(duplicateResponseString).equals(responseString)) { if(isFakeUpdate){ - responseString = "Exists"; + responseString = existsResponseString; } else { - responseString = "Success"; + responseString = successMsg; } } ModelAndView result = new ModelAndView(); result.setViewName(responseString); return result; } else { - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + response.setContentType(applicationJsonContentType); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); JSONObject j = new JSONObject("{serviceGroupDictionaryDatas: " + responseString + "}"); @@ -957,8 +983,8 @@ public class FirewallDictionaryController { } }catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -966,16 +992,16 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/fw_dictionary/remove_serviceGroup"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removeServiceGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView removeServiceGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ try{ ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); GroupServiceList groupServiceList = (GroupServiceList)mapper.readValue(root.get("data").toString(), GroupServiceList.class); commonClassDao.delete(groupServiceList); - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + response.setContentType(applicationJsonContentType); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); @@ -986,9 +1012,9 @@ public class FirewallDictionaryController { return null; } catch (Exception e){ - System.out.println(e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + LOGGER.error(e); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -996,11 +1022,11 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/get_SecurityZoneDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getSecurityZoneDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + public void getSecurityZoneDictionaryEntityDataByName(HttpServletResponse response){ try{ Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); - model.put("securityZoneDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(SecurityZone.class, "zoneName"))); + model.put("securityZoneDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(SecurityZone.class, zoneName))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -1011,31 +1037,31 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/get_SecurityZoneData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getSecurityZoneDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getSecurityZoneDictionaryEntityData(HttpServletResponse response){ try{ Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("securityZoneDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(SecurityZone.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); - response.addHeader("successMapKey", "success"); - response.addHeader("operation", "getDictionary"); + response.addHeader(successMapKey, successMessage); + response.addHeader(operation, getDictionary); response.getWriter().write(j.toString()); } catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - response.addHeader("error", "dictionaryDBQuery"); + response.addHeader(errorMsg, dictionaryDBQuery); } } @RequestMapping(value={"/fw_dictionary/save_securityZone"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView saveSecurityZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView saveSecurityZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ try { boolean duplicateflag = false; boolean isFakeUpdate = false; boolean fromAPI = false; - if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) { fromAPI = true; } ObjectMapper mapper = new ObjectMapper(); @@ -1043,14 +1069,13 @@ public class FirewallDictionaryController { JsonNode root = mapper.readTree(request.getReader()); SecurityZone securityZone; if (fromAPI) { - securityZone = (SecurityZone)mapper.readValue(root.get("dictionaryFields").toString(), SecurityZone.class); + securityZone = (SecurityZone)mapper.readValue(root.get(dictionaryFields).toString(), SecurityZone.class); //check if update operation or create, get id for data to be updated and update attributeData - if (request.getParameter("operation").equals("update")) { - List duplicateData = commonClassDao.checkDuplicateEntry(securityZone.getZoneName(), "zoneName", SecurityZone.class); - int id = 0; + if ((update).equals(request.getParameter(operation))) { + List duplicateData = commonClassDao.checkDuplicateEntry(securityZone.getZoneName(), zoneName, SecurityZone.class); SecurityZone data = (SecurityZone) duplicateData.get(0); - id = data.getId(); + int id = data.getId(); if(id==0){ isFakeUpdate=true; securityZone.setId(1); @@ -1062,7 +1087,7 @@ public class FirewallDictionaryController { securityZone = (SecurityZone)mapper.readValue(root.get("securityZoneDictionaryData").toString(), SecurityZone.class); } if(securityZone.getId() == 0){ - List duplicateData = commonClassDao.checkDuplicateEntry(securityZone.getZoneName(), "zoneName", SecurityZone.class); + List duplicateData = commonClassDao.checkDuplicateEntry(securityZone.getZoneName(), zoneName, SecurityZone.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ @@ -1075,26 +1100,26 @@ public class FirewallDictionaryController { } String responseString = ""; if(duplicateflag){ - responseString = "Duplicate"; + responseString = duplicateResponseString; }else{ responseString = mapper.writeValueAsString(commonClassDao.getData(SecurityZone.class)); } if (fromAPI) { - if (responseString!=null && !responseString.equals("Duplicate")) { + if (responseString!=null && !(duplicateResponseString).equals(responseString)) { if(isFakeUpdate){ - responseString = "Exists"; + responseString = existsResponseString; } else { - responseString = "Success"; + responseString = successMsg; } } ModelAndView result = new ModelAndView(); result.setViewName(responseString); return result; } else { - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + response.setContentType(applicationJsonContentType); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); JSONObject j = new JSONObject("{securityZoneDictionaryDatas: " + responseString + "}"); @@ -1104,8 +1129,8 @@ public class FirewallDictionaryController { }catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -1113,16 +1138,16 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/fw_dictionary/remove_securityZone"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removeSecurityZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException { + public ModelAndView removeSecurityZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { try{ ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); SecurityZone securityZone = (SecurityZone)mapper.readValue(root.get("data").toString(), SecurityZone.class); commonClassDao.delete(securityZone); - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + response.setContentType(applicationJsonContentType); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); @@ -1134,8 +1159,8 @@ public class FirewallDictionaryController { } catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -1144,30 +1169,30 @@ public class FirewallDictionaryController { @RequestMapping(value={"/get_ServiceListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getServiceListDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getServiceListDictionaryEntityData(HttpServletResponse response){ try{ Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("serviceListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ServiceList.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); - response.addHeader("successMapKey", "success"); - response.addHeader("operation", "getDictionary"); + response.addHeader(successMapKey, successMessage); + response.addHeader(operation, getDictionary); response.getWriter().write(j.toString()); } catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - response.addHeader("error", "dictionaryDBQuery"); + response.addHeader(errorMsg, dictionaryDBQuery); } } @RequestMapping(value={"/get_ServiceListDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getServiceListDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + public void getServiceListDictionaryEntityDataByName(HttpServletResponse response){ try{ Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); - model.put("serviceListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ServiceList.class, "serviceName"))); + model.put("serviceListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ServiceList.class, serviceName))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -1178,12 +1203,12 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/fw_dictionary/save_serviceList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView saveServiceListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView saveServiceListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ try { boolean duplicateflag = false; boolean isFakeUpdate = false; boolean fromAPI = false; - if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) { fromAPI = true; } ObjectMapper mapper = new ObjectMapper(); @@ -1192,15 +1217,14 @@ public class FirewallDictionaryController { ServiceList serviceList; GridData serviceListGridData; if (fromAPI) { - serviceList = (ServiceList)mapper.readValue(root.get("dictionaryFields").toString(), ServiceList.class); - serviceListGridData = (GridData)mapper.readValue(root.get("dictionaryFields").toString(), GridData.class); + serviceList = (ServiceList)mapper.readValue(root.get(dictionaryFields).toString(), ServiceList.class); + serviceListGridData = (GridData)mapper.readValue(root.get(dictionaryFields).toString(), GridData.class); //check if update operation or create, get id for data to be updated and update attributeData - if (request.getParameter("operation").equals("update")) { - List duplicateData = commonClassDao.checkDuplicateEntry(serviceList.getServiceName(), "serviceName", ServiceList.class); - int id = 0; + if ((update).equals(request.getParameter(operation))) { + List duplicateData = commonClassDao.checkDuplicateEntry(serviceList.getServiceName(), serviceName, ServiceList.class); ServiceList data = (ServiceList) duplicateData.get(0); - id = data.getId(); + int id = data.getId(); if(id==0){ isFakeUpdate=true; serviceList.setId(1); @@ -1214,10 +1238,10 @@ public class FirewallDictionaryController { } String tcpValue = ""; int counter = 0; - if(serviceListGridData.getTransportProtocols().size() > 0){ + if(!serviceListGridData.getTransportProtocols().isEmpty()){ for(Object attribute : serviceListGridData.getTransportProtocols()){ if(attribute instanceof LinkedHashMap){ - String key = ((LinkedHashMap) attribute).get("option").toString(); + String key = ((LinkedHashMap) attribute).get(option).toString(); if(counter>0){ tcpValue = tcpValue + ","; } @@ -1229,10 +1253,10 @@ public class FirewallDictionaryController { serviceList.setServiceTransProtocol(tcpValue); String appValue = ""; int counter1 = 0; - if(serviceListGridData.getAppProtocols().size() > 0){ + if(!serviceListGridData.getAppProtocols().isEmpty()){ for(Object attribute : serviceListGridData.getAppProtocols()){ if(attribute instanceof LinkedHashMap){ - String key = ((LinkedHashMap) attribute).get("option").toString(); + String key = ((LinkedHashMap) attribute).get(option).toString(); if(counter1>0){ appValue = appValue + ","; } @@ -1244,7 +1268,7 @@ public class FirewallDictionaryController { serviceList.setServiceAppProtocol(appValue); serviceList.setServiceType("SERVICE"); if(serviceList.getId() == 0){ - List duplicateData = commonClassDao.checkDuplicateEntry(serviceList.getServiceName(), "serviceName", ServiceList.class); + List duplicateData = commonClassDao.checkDuplicateEntry(serviceList.getServiceName(), serviceName, ServiceList.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ @@ -1258,25 +1282,25 @@ public class FirewallDictionaryController { String responseString = ""; if(duplicateflag){ - responseString = "Duplicate"; + responseString = duplicateResponseString; }else{ responseString = mapper.writeValueAsString(commonClassDao.getData(ServiceList.class)); } if (fromAPI) { - if (responseString!=null && !responseString.equals("Duplicate")) { + if (responseString!=null && !(duplicateResponseString).equals(responseString)) { if(isFakeUpdate){ - responseString = "Exists"; + responseString = existsResponseString; } else { - responseString = "Success"; + responseString = successMsg; } } ModelAndView result = new ModelAndView(); result.setViewName(responseString); return result; } else { - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + response.setContentType(applicationJsonContentType); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); JSONObject j = new JSONObject("{serviceListDictionaryDatas: " + responseString + "}"); @@ -1285,8 +1309,8 @@ public class FirewallDictionaryController { } }catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -1295,16 +1319,16 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/fw_dictionary/remove_serviceList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removeServiceListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException { + public ModelAndView removeServiceListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { try{ ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); ServiceList serviceList = (ServiceList)mapper.readValue(root.get("data").toString(), ServiceList.class); commonClassDao.delete(serviceList); - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + response.setContentType(applicationJsonContentType); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); @@ -1315,9 +1339,9 @@ public class FirewallDictionaryController { return null; } catch (Exception e){ - System.out.println(e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + LOGGER.error(e); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -1325,15 +1349,15 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/get_ZoneData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getZoneDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getZoneDictionaryEntityData(HttpServletResponse response){ try{ Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("zoneDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(Zone.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); - response.addHeader("successMapKey", "success"); - response.addHeader("operation", "getDictionary"); + response.addHeader(successMapKey, successMessage); + response.addHeader(operation, getDictionary); response.getWriter().write(j.toString()); } catch (Exception e){ @@ -1342,11 +1366,11 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/get_ZoneDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getZoneDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + public void getZoneDictionaryEntityDataByName(HttpServletResponse response){ try{ Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); - model.put("zoneDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(Zone.class, "zoneName"))); + model.put("zoneDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(Zone.class, zoneName))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -1357,12 +1381,12 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/fw_dictionary/save_zoneName"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView saveZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView saveZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ try { boolean duplicateflag = false; boolean isFakeUpdate = false; boolean fromAPI = false; - if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) { fromAPI = true; } ObjectMapper mapper = new ObjectMapper(); @@ -1370,14 +1394,13 @@ public class FirewallDictionaryController { JsonNode root = mapper.readTree(request.getReader()); Zone zone; if (fromAPI) { - zone = (Zone)mapper.readValue(root.get("dictionaryFields").toString(), Zone.class); + zone = (Zone)mapper.readValue(root.get(dictionaryFields).toString(), Zone.class); //check if update operation or create, get id for data to be updated and update attributeData - if (request.getParameter("operation").equals("update")) { - List duplicateData = commonClassDao.checkDuplicateEntry(zone.getZoneName(), "zoneName", Zone.class); - int id = 0; + if ((update).equals(request.getParameter(operation))) { + List duplicateData = commonClassDao.checkDuplicateEntry(zone.getZoneName(), zoneName, Zone.class); Zone data = (Zone) duplicateData.get(0); - id = data.getId(); + int id = data.getId(); if(id==0){ isFakeUpdate=true; zone.setId(1); @@ -1389,7 +1412,7 @@ public class FirewallDictionaryController { zone = (Zone)mapper.readValue(root.get("zoneDictionaryData").toString(), Zone.class); } if(zone.getId() == 0){ - List duplicateData = commonClassDao.checkDuplicateEntry(zone.getZoneName(), "zoneName", Zone.class); + List duplicateData = commonClassDao.checkDuplicateEntry(zone.getZoneName(), zoneName, Zone.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ @@ -1402,26 +1425,26 @@ public class FirewallDictionaryController { } String responseString = ""; if(duplicateflag){ - responseString = "Duplicate"; + responseString = duplicateResponseString; }else{ responseString = mapper.writeValueAsString(commonClassDao.getData(Zone.class)); } if (fromAPI) { - if (responseString!=null && !responseString.equals("Duplicate")) { + if (responseString!=null && !(duplicateResponseString).equals(responseString)) { if(isFakeUpdate){ - responseString = "Exists"; + responseString = existsResponseString; } else { - responseString = "Success"; + responseString = successMsg; } } ModelAndView result = new ModelAndView(); result.setViewName(responseString); return result; } else { - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + response.setContentType(applicationJsonContentType); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); JSONObject j = new JSONObject("{zoneDictionaryDatas: " + responseString + "}"); @@ -1430,8 +1453,8 @@ public class FirewallDictionaryController { } }catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -1439,16 +1462,16 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/fw_dictionary/remove_zone"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removeZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView removeZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ try{ ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); Zone zone = (Zone)mapper.readValue(root.get("data").toString(), Zone.class); commonClassDao.delete(zone); - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + response.setContentType(applicationJsonContentType); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); @@ -1460,8 +1483,8 @@ public class FirewallDictionaryController { } catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -1469,11 +1492,11 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/get_TermListDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getTermListDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + public void getTermListDictionaryEntityDataByName(HttpServletResponse response){ try{ - Map model = new HashMap(); + Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); - model.put("termListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(TermList.class, "termName"))); + model.put("termListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(TermList.class, termName))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -1484,31 +1507,31 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/get_TermListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getTermListDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getTermListDictionaryEntityData(HttpServletResponse response){ try{ - Map model = new HashMap(); + Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("termListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(TermList.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); - response.addHeader("successMapKey", "success"); - response.addHeader("operation", "getDictionary"); + response.addHeader(successMapKey, successMessage); + response.addHeader(operation, getDictionary); response.getWriter().write(j.toString()); } catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - response.addHeader("error", "dictionaryDBQuery"); + response.addHeader(errorMsg, dictionaryDBQuery); } } @RequestMapping(value={"/fw_dictionary/save_termList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView saveTermListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView saveTermListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ try { boolean duplicateflag = false; boolean isFakeUpdate = false; boolean fromAPI = false; - if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) { fromAPI = true; } ObjectMapper mapper = new ObjectMapper(); @@ -1518,16 +1541,15 @@ public class FirewallDictionaryController { TermListData termListDatas; String userId = null; if (fromAPI) { - termList = (TermList)mapper.readValue(root.get("dictionaryFields").toString(), TermList.class); - termListDatas = (TermListData)mapper.readValue(root.get("dictionaryFields").toString(), TermListData.class); + termList = (TermList)mapper.readValue(root.get(dictionaryFields).toString(), TermList.class); + termListDatas = (TermListData)mapper.readValue(root.get(dictionaryFields).toString(), TermListData.class); userId = "API"; //check if update operation or create, get id for data to be updated and update attributeData - if (request.getParameter("operation").equals("update")) { - List duplicateData = commonClassDao.checkDuplicateEntry(termList.getTermName(), "termName", TermList.class); - int id = 0; + if ((update).equals(request.getParameter(operation))) { + List duplicateData = commonClassDao.checkDuplicateEntry(termList.getTermName(), termName, TermList.class); TermList data = (TermList) duplicateData.get(0); - id = data.getId(); + int id = data.getId(); if(id==0){ isFakeUpdate=true; termList.setId(1); @@ -1539,14 +1561,14 @@ public class FirewallDictionaryController { } else { termList = (TermList)mapper.readValue(root.get("termListDictionaryData").toString(), TermList.class); termListDatas = (TermListData)mapper.readValue(root.get("termListDictionaryData").toString(), TermListData.class); - userId = root.get("userid").textValue(); + userId = root.get(userid).textValue(); } String fromZoneValue = ""; int counter = 0; - if(termListDatas.getFromZoneDatas().size() > 0){ + if(!termListDatas.getFromZoneDatas().isEmpty()){ for(Object fromZone : termListDatas.getFromZoneDatas()){ if(fromZone instanceof LinkedHashMap){ - String key = ((LinkedHashMap) fromZone).get("option").toString(); + String key = ((LinkedHashMap) fromZone).get(option).toString(); if(counter>0){ fromZoneValue = fromZoneValue + ","; } @@ -1559,10 +1581,10 @@ public class FirewallDictionaryController { String toZoneValue = ""; int toZonecounter = 0; - if(termListDatas.getToZoneDatas().size() > 0){ + if(!termListDatas.getToZoneDatas().isEmpty()){ for(Object toZone : termListDatas.getToZoneDatas()){ if(toZone instanceof LinkedHashMap){ - String key = ((LinkedHashMap) toZone).get("option").toString(); + String key = ((LinkedHashMap) toZone).get(option).toString(); if(toZonecounter>0){ toZoneValue = toZoneValue + ","; } @@ -1575,10 +1597,10 @@ public class FirewallDictionaryController { String srcListValues = ""; int srcListcounter = 0; - if(termListDatas.getSourceListDatas().size() > 0){ + if(!termListDatas.getSourceListDatas().isEmpty()){ for(Object srcList : termListDatas.getSourceListDatas()){ if(srcList instanceof LinkedHashMap){ - String key = ((LinkedHashMap) srcList).get("option").toString(); + String key = ((LinkedHashMap) srcList).get(option).toString(); if(srcListcounter>0){ srcListValues = srcListValues + ","; } @@ -1591,10 +1613,10 @@ public class FirewallDictionaryController { String desListValues = ""; int destListcounter = 0; - if(termListDatas.getDestinationListDatas().size() > 0){ + if(!termListDatas.getDestinationListDatas().isEmpty()){ for(Object desList : termListDatas.getDestinationListDatas()){ if(desList instanceof LinkedHashMap){ - String key = ((LinkedHashMap) desList).get("option").toString(); + String key = ((LinkedHashMap) desList).get(option).toString(); if(destListcounter>0){ desListValues = desListValues + ","; } @@ -1607,10 +1629,10 @@ public class FirewallDictionaryController { String srcSerValue = ""; int srcSercounter = 0; - if(termListDatas.getSourceServiceDatas().size() > 0){ + if(!termListDatas.getSourceServiceDatas().isEmpty()){ for(Object srcSrc : termListDatas.getSourceServiceDatas()){ if(srcSrc instanceof LinkedHashMap){ - String key = ((LinkedHashMap) srcSrc).get("option").toString(); + String key = ((LinkedHashMap) srcSrc).get(option).toString(); if(srcSercounter>0){ srcSerValue = srcSerValue + ","; } @@ -1623,10 +1645,10 @@ public class FirewallDictionaryController { String desSrcValue = ""; int desSrccounter = 0; - if(termListDatas.getDestinationServiceDatas().size() > 0){ + if(!termListDatas.getDestinationServiceDatas().isEmpty()){ for(Object desSrc : termListDatas.getDestinationServiceDatas()){ if(desSrc instanceof LinkedHashMap){ - String key = ((LinkedHashMap) desSrc).get("option").toString(); + String key = ((LinkedHashMap) desSrc).get(option).toString(); if(desSrccounter>0){ desSrcValue = desSrcValue + ","; } @@ -1639,10 +1661,10 @@ public class FirewallDictionaryController { String actionValue = ""; int actioncounter = 0; - if(termListDatas.getActionListDatas().size() > 0){ + if(!termListDatas.getActionListDatas().isEmpty()){ for(Object actionList : termListDatas.getActionListDatas()){ if(actionList instanceof LinkedHashMap){ - String key = ((LinkedHashMap) actionList).get("option").toString(); + String key = ((LinkedHashMap) actionList).get(option).toString(); if(actioncounter>0){ actionValue = actionValue + ","; } @@ -1654,7 +1676,7 @@ public class FirewallDictionaryController { termList.setAction(actionValue); if(termList.getId() == 0){ - List duplicateData = commonClassDao.checkDuplicateEntry(termList.getTermName(), "termName", TermList.class); + List duplicateData = commonClassDao.checkDuplicateEntry(termList.getTermName(), termName, TermList.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ @@ -1670,26 +1692,26 @@ public class FirewallDictionaryController { } String responseString = ""; if(duplicateflag){ - responseString = "Duplicate"; + responseString = duplicateResponseString; }else{ responseString = mapper.writeValueAsString(commonClassDao.getData(TermList.class)); } if (fromAPI) { - if (responseString!=null && !responseString.equals("Duplicate")) { + if (responseString!=null && !(duplicateResponseString).equals(responseString)) { if(isFakeUpdate){ - responseString = "Exists"; + responseString = existsResponseString; } else { - responseString = "Success"; + responseString = successMsg; } } ModelAndView result = new ModelAndView(); result.setViewName(responseString); return result; } else { - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + response.setContentType(applicationJsonContentType); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); JSONObject j = new JSONObject("{termListDictionaryDatas: " + responseString + "}"); @@ -1698,8 +1720,8 @@ public class FirewallDictionaryController { } }catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -1707,16 +1729,16 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/fw_dictionary/remove_termList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removeTermListDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView removeTermListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ try{ ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); TermList termList = (TermList)mapper.readValue(root.get("data").toString(), TermList.class); commonClassDao.delete(termList); - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + response.setContentType(applicationJsonContentType); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); @@ -1728,8 +1750,8 @@ public class FirewallDictionaryController { } catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -1737,7 +1759,7 @@ public class FirewallDictionaryController { } //ParentList Dictionary Data @RequestMapping(value={"/get_FWDictionaryListDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getFWDictListDictionaryEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + public void getFWDictListDictionaryEntityDataByName(HttpServletResponse response){ try{ Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); @@ -1752,26 +1774,26 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/get_FWDictionaryListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getFWDictionaryListEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getFWDictionaryListEntityData(HttpServletResponse response){ try{ Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("fwDictListDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(FirewallDictionaryList.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); - response.addHeader("successMapKey", "success"); - response.addHeader("operation", "getDictionary"); + response.addHeader(successMapKey, successMessage); + response.addHeader(operation, getDictionary); response.getWriter().write(j.toString()); } catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - response.addHeader("error", "dictionaryDBQuery"); + response.addHeader(errorMsg, dictionaryDBQuery); } } @RequestMapping(value={"/fw_dictionary/save_FWDictionaryList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView saveFWDictionaryList(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView saveFWDictionaryList(HttpServletRequest request, HttpServletResponse response) throws IOException{ try { boolean duplicateflag = false; ObjectMapper mapper = new ObjectMapper(); @@ -1781,10 +1803,10 @@ public class FirewallDictionaryController { GridData gridData = (GridData)mapper.readValue(root.get("fwDictListDictionaryData").toString(), GridData.class); String userSLValue = ""; int slcounter = 0; - if(gridData.getAttributes().size() > 0){ + if(!gridData.getAttributes().isEmpty()){ for(Object attribute : gridData.getAttributes()){ if(attribute instanceof LinkedHashMap){ - String key = ((LinkedHashMap) attribute).get("option").toString(); + String key = ((LinkedHashMap) attribute).get(option).toString(); if(slcounter>0){ userSLValue = userSLValue + ","; } @@ -1796,10 +1818,10 @@ public class FirewallDictionaryController { fwDictList.setServiceList(userSLValue); String userALValue = ""; int alcounter = 0; - if(gridData.getAlAttributes().size() > 0){ + if(!gridData.getAlAttributes().isEmpty()){ for(Object attribute : gridData.getAlAttributes()){ if(attribute instanceof LinkedHashMap){ - String key = ((LinkedHashMap) attribute).get("option").toString(); + String key = ((LinkedHashMap) attribute).get(option).toString(); if(alcounter>0){ userALValue = userALValue + ","; } @@ -1819,14 +1841,14 @@ public class FirewallDictionaryController { }else{ commonClassDao.update(fwDictList); } - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + response.setContentType(applicationJsonContentType); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); String responseString = ""; if(duplicateflag){ - responseString = "Duplicate"; + responseString = duplicateResponseString; }else{ responseString = mapper.writeValueAsString(commonClassDao.getData(FirewallDictionaryList.class)); } @@ -1838,8 +1860,8 @@ public class FirewallDictionaryController { } catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -1847,16 +1869,16 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/fw_dictionary/remove_FWDictionaryList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removeFWDictionaryListy(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException { + public ModelAndView removeFWDictionaryListy(HttpServletRequest request, HttpServletResponse response) throws IOException { try{ ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); FirewallDictionaryList fwDictList = (FirewallDictionaryList)mapper.readValue(root.get("data").toString(), FirewallDictionaryList.class); commonClassDao.delete(fwDictList); - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + response.setContentType(applicationJsonContentType); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); @@ -1868,8 +1890,8 @@ public class FirewallDictionaryController { } catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -1878,11 +1900,11 @@ public class FirewallDictionaryController { @RequestMapping(value={"/get_TagPickerNameByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getTagPickerNameEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + public void getTagPickerNameEntityDataByName(HttpServletResponse response){ try{ - Map model = new HashMap(); + Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); - model.put("fwTagPickerDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(FWTagPicker.class, "tagPickerName"))); + model.put("fwTagPickerDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(FWTagPicker.class, tagPickerName))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -1893,9 +1915,9 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/get_TagPickerListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getTagPickerDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getTagPickerDictionaryEntityData(HttpServletResponse response){ try{ - Map model = new HashMap(); + Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("fwTagPickerDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(FWTagPicker.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); @@ -1908,11 +1930,11 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/fw_dictionary/save_fwTagPicker"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView saveFirewallTagPickerDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView saveFirewallTagPickerDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ try { boolean duplicateflag = false; boolean fromAPI = false; - if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) { fromAPI = true; } @@ -1925,32 +1947,31 @@ public class FirewallDictionaryController { TagGridValues data; String userId = null; if (fromAPI) { - fwTagPicker = (FWTagPicker)mapper.readValue(root.get("fwTagPickerDictionaryData").toString(), FWTagPicker.class); - data = (TagGridValues)mapper.readValue(root.get("fwTagPickerDictionaryData").toString(), TagGridValues.class); + fwTagPicker = (FWTagPicker)mapper.readValue(root.get(fwTagPickerDictionaryData).toString(), FWTagPicker.class); + data = (TagGridValues)mapper.readValue(root.get(fwTagPickerDictionaryData).toString(), TagGridValues.class); userId = "API"; //check if update operation or create, get id for data to be updated and update attributeData - if (request.getParameter("operation").equals("update")) { - List duplicateData = commonClassDao.checkDuplicateEntry(fwTagPicker.getTagPickerName(), "tagPickerName", FWTagPicker.class); - int id = 0; + if ((update).equals(request.getParameter(operation))) { + List duplicateData = commonClassDao.checkDuplicateEntry(fwTagPicker.getTagPickerName(), tagPickerName, FWTagPicker.class); FWTagPicker dbdata = (FWTagPicker) duplicateData.get(0); - id = dbdata.getId(); + int id = dbdata.getId(); fwTagPicker.setId(id); fwTagPicker.setUserCreatedBy(this.getUserInfo(userId)); } } else { - fwTagPicker = (FWTagPicker)mapper.readValue(root.get("fwTagPickerDictionaryData").toString(), FWTagPicker.class); - data = (TagGridValues)mapper.readValue(root.get("fwTagPickerDictionaryData").toString(), TagGridValues.class); - userId = root.get("userid").textValue(); + fwTagPicker = (FWTagPicker)mapper.readValue(root.get(fwTagPickerDictionaryData).toString(), FWTagPicker.class); + data = (TagGridValues)mapper.readValue(root.get(fwTagPickerDictionaryData).toString(), TagGridValues.class); + userId = root.get(userid).textValue(); } String header = ""; int counter = 0; - if(data.getTags().size() > 0){ + if(!data.getTags().isEmpty()){ for(Object attribute : data.getTags()){ if(attribute instanceof LinkedHashMap){ - String key = ((LinkedHashMap) attribute).get("option").toString(); + String key = ((LinkedHashMap) attribute).get(option).toString(); String value = ((LinkedHashMap) attribute).get("number").toString(); if(counter>0){ header = header + "#"; @@ -1963,7 +1984,7 @@ public class FirewallDictionaryController { } fwTagPicker.setTagValues(header); if(fwTagPicker.getId() == 0){ - List duplicateData = commonClassDao.checkDuplicateEntry(fwTagPicker.getTagPickerName(), "tagPickerName", FWTagPicker.class); + List duplicateData = commonClassDao.checkDuplicateEntry(fwTagPicker.getTagPickerName(), tagPickerName, FWTagPicker.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ @@ -1979,22 +2000,22 @@ public class FirewallDictionaryController { String responseString = ""; if(duplicateflag){ - responseString = "Duplicate"; + responseString = duplicateResponseString; }else{ responseString = mapper.writeValueAsString(commonClassDao.getData(FWTagPicker.class)); } if (fromAPI) { - if (responseString!=null && !responseString.equals("Duplicate")) { - responseString = "Success"; + if (responseString!=null && !(duplicateResponseString).equals(responseString)) { + responseString = successMsg; } ModelAndView result = new ModelAndView(); result.setViewName(responseString); return result; } else { - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + response.setContentType(applicationJsonContentType); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); JSONObject j = new JSONObject("{fwTagPickerDictionaryDatas: " + responseString + "}"); @@ -2004,8 +2025,8 @@ public class FirewallDictionaryController { } catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -2013,16 +2034,16 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/fw_dictionary/remove_tagPicker"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removeFirewallTagPickerDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException { + public ModelAndView removeFirewallTagPickerDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { try{ ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); FWTagPicker fwTagPicker = (FWTagPicker)mapper.readValue(root.get("data").toString(), FWTagPicker.class); commonClassDao.delete(fwTagPicker); - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + response.setContentType(applicationJsonContentType); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); String responseString = mapper.writeValueAsString(commonClassDao.getData(FWTagPicker.class)); @@ -2032,8 +2053,8 @@ public class FirewallDictionaryController { } catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -2042,11 +2063,11 @@ public class FirewallDictionaryController { @RequestMapping(value={"/get_TagNameByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getTagNameEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + public void getTagNameEntityDataByName(HttpServletResponse response){ try{ Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); - model.put("fwTagDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(FWTag.class, "fwTagName"))); + model.put(fwTagDictionaryDatas, mapper.writeValueAsString(commonClassDao.getDataByColumn(FWTag.class, "fwTagName"))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -2057,11 +2078,11 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/get_TagListData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getTagDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getTagDictionaryEntityData(HttpServletResponse response){ try{ Map model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); - model.put("fwTagDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(FWTag.class))); + model.put(fwTagDictionaryDatas, mapper.writeValueAsString(commonClassDao.getData(FWTag.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -2072,11 +2093,11 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/fw_dictionary/save_fwTag"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView saveFirewallTagDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView saveFirewallTagDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ try { boolean duplicateflag = false; boolean fromAPI = false; - if (request.getParameter("apiflag")!=null && request.getParameter("apiflag").equalsIgnoreCase("api")) { + if (request.getParameter(apiflag)!=null && ("api").equalsIgnoreCase(request.getParameter(apiflag))) { fromAPI = true; } @@ -2089,16 +2110,15 @@ public class FirewallDictionaryController { TagGridValues tagGridValues; String userId = null; if (fromAPI) { - fwTag = (FWTag)mapper.readValue(root.get("fwTagDictionaryDatas").toString(), FWTag.class); - tagGridValues = (TagGridValues)mapper.readValue(root.get("fwTagDictionaryDatas").toString(), TagGridValues.class); + fwTag = (FWTag)mapper.readValue(root.get(fwTagDictionaryDatas).toString(), FWTag.class); + tagGridValues = (TagGridValues)mapper.readValue(root.get(fwTagDictionaryDatas).toString(), TagGridValues.class); userId = "API"; //check if update operation or create, get id for data to be updated and update attributeData - if (request.getParameter("operation").equals("update")) { + if ((update).equals(request.getParameter(operation))) { List duplicateData = commonClassDao.checkDuplicateEntry(fwTag.getFwTagName(), "tagName", FWTag.class); - int id = 0; FWTag data = (FWTag) duplicateData.get(0); - id = data.getId(); + int id = data.getId(); fwTag.setId(id); fwTag.setUserCreatedBy(this.getUserInfo(userId)); @@ -2106,12 +2126,12 @@ public class FirewallDictionaryController { } else { fwTag = (FWTag)mapper.readValue(root.get("fwTagDictionaryData").toString(), FWTag.class); tagGridValues = (TagGridValues)mapper.readValue(root.get("fwTagDictionaryData").toString(), TagGridValues.class); - userId = root.get("userid").textValue(); + userId = root.get(userid).textValue(); } String userValue = ""; int counter = 0; - if(tagGridValues.getTags().size() > 0){ + if(!tagGridValues.getTags().isEmpty()){ for(Object attribute : tagGridValues.getTags()){ if(attribute instanceof LinkedHashMap){ String key = ((LinkedHashMap) attribute).get("tags").toString(); @@ -2141,22 +2161,22 @@ public class FirewallDictionaryController { String responseString = ""; if(duplicateflag){ - responseString = "Duplicate"; + responseString = duplicateResponseString; }else{ responseString = mapper.writeValueAsString(commonClassDao.getData(FWTag.class)); } if (fromAPI) { - if (responseString!=null && !responseString.equals("Duplicate")) { - responseString = "Success"; + if (responseString!=null && !(duplicateResponseString).equals(responseString)) { + responseString = successMsg; } ModelAndView result = new ModelAndView(); result.setViewName(responseString); return result; } else { - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + response.setContentType(applicationJsonContentType); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); JSONObject j = new JSONObject("{fwTagDictionaryDatas: " + responseString + "}"); @@ -2166,8 +2186,8 @@ public class FirewallDictionaryController { } catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -2175,16 +2195,16 @@ public class FirewallDictionaryController { } @RequestMapping(value={"/fw_dictionary/remove_tagList"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removeFirewallTagDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView removeFirewallTagDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ try{ ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); FWTag fwTag = (FWTag)mapper.readValue(root.get("data").toString(), FWTag.class); commonClassDao.delete(fwTag); - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + response.setContentType(applicationJsonContentType); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); @@ -2196,8 +2216,8 @@ public class FirewallDictionaryController { } catch (Exception e){ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -2206,77 +2226,77 @@ public class FirewallDictionaryController { } class TagGridValues{ - private ArrayList tags; + private List tags; - public ArrayList getTags() { + public List getTags() { return tags; } - public void setTags(ArrayList tags) { + public void setTags(List tags) { this.tags = tags; } } class AGGridData{ - private ArrayList attributes; + private List attributes; - public ArrayList getAttributes() { + public List getAttributes() { return attributes; } - public void setAttributes(ArrayList attributes) { + public void setAttributes(List attributes) { this.attributes = attributes; } } class TermListData{ - private ArrayList fromZoneDatas; - private ArrayList toZoneDatas; - private ArrayList sourceListDatas; - private ArrayList destinationListDatas; - private ArrayList sourceServiceDatas; - private ArrayList destinationServiceDatas; - private ArrayList actionListDatas; - public ArrayList getFromZoneDatas() { + private List fromZoneDatas; + private List toZoneDatas; + private List sourceListDatas; + private List destinationListDatas; + private List sourceServiceDatas; + private List destinationServiceDatas; + private List actionListDatas; + public List getFromZoneDatas() { return fromZoneDatas; } - public void setFromZoneDatas(ArrayList fromZoneDatas) { + public void setFromZoneDatas(List fromZoneDatas) { this.fromZoneDatas = fromZoneDatas; } - public ArrayList getToZoneDatas() { + public List getToZoneDatas() { return toZoneDatas; } - public void setToZoneDatas(ArrayList toZoneDatas) { + public void setToZoneDatas(List toZoneDatas) { this.toZoneDatas = toZoneDatas; } - public ArrayList getSourceListDatas() { + public List getSourceListDatas() { return sourceListDatas; } - public void setSourceListDatas(ArrayList sourceListDatas) { + public void setSourceListDatas(List sourceListDatas) { this.sourceListDatas = sourceListDatas; } - public ArrayList getDestinationListDatas() { + public List getDestinationListDatas() { return destinationListDatas; } - public void setDestinationListDatas(ArrayList destinationListDatas) { + public void setDestinationListDatas(List destinationListDatas) { this.destinationListDatas = destinationListDatas; } - public ArrayList getSourceServiceDatas() { + public List getSourceServiceDatas() { return sourceServiceDatas; } - public void setSourceServiceDatas(ArrayList sourceServiceDatas) { + public void setSourceServiceDatas(List sourceServiceDatas) { this.sourceServiceDatas = sourceServiceDatas; } - public ArrayList getDestinationServiceDatas() { + public List getDestinationServiceDatas() { return destinationServiceDatas; } - public void setDestinationServiceDatas(ArrayList destinationServiceDatas) { + public void setDestinationServiceDatas(List destinationServiceDatas) { this.destinationServiceDatas = destinationServiceDatas; } - public ArrayList getActionListDatas() { + public List getActionListDatas() { return actionListDatas; } - public void setActionListDatas(ArrayList actionListDatas) { + public void setActionListDatas(List actionListDatas) { this.actionListDatas = actionListDatas; } }