diff options
Diffstat (limited to 'ONAP-PAP-REST/src/main/java/org')
16 files changed, 1404 insertions, 1450 deletions
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ActionPolicyDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ActionPolicyDictionaryController.java index 85890fc43..eaa0bb409 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ActionPolicyDictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ActionPolicyDictionaryController.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.util.ArrayList; import java.util.Date; import java.util.HashMap; @@ -56,25 +55,29 @@ public class ActionPolicyDictionaryController { private static final Logger LOGGER = FlexLogger.getLogger(ActionPolicyDictionaryController.class); private static CommonClassDao commonClassDao; - + private static String utf8 = "UTF-8"; + private static String attributeName = "attributeName"; @Autowired public ActionPolicyDictionaryController(CommonClassDao commonClassDao){ ActionPolicyDictionaryController.commonClassDao = commonClassDao; } - - public ActionPolicyDictionaryController(){} + /* + * This is an empty constructor + */ + public ActionPolicyDictionaryController(){ + + } 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_ActionPolicyDictDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getActionEntitybyName(HttpServletRequest request, HttpServletResponse response){ + public void getActionEntitybyName(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); - model.put("actionPolicyDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ActionPolicyDict.class, "attributeName"))); + model.put("actionPolicyDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ActionPolicyDict.class, attributeName))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -85,7 +88,7 @@ public class ActionPolicyDictionaryController { } @RequestMapping(value={"/get_ActionPolicyDictData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getActionPolicyDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getActionPolicyDictionaryEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); @@ -104,13 +107,13 @@ public class ActionPolicyDictionaryController { } @RequestMapping(value={"/action_dictionary/save_ActionDict"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView saveActionPolicyDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException { + public ModelAndView saveActionPolicyDictionary(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(); @@ -126,11 +129,10 @@ public class ActionPolicyDictionaryController { 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<Object> duplicateData = commonClassDao.checkDuplicateEntry(actionPolicyDict.getAttributeName(), "attributeName", ActionPolicyDict.class); - int id = 0; + if (("update").equals(request.getParameter("operation"))) { + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(actionPolicyDict.getAttributeName(), attributeName, ActionPolicyDict.class); ActionPolicyDict data = (ActionPolicyDict) duplicateData.get(0); - id = data.getId(); + int id = data.getId(); if(id==0){ isFakeUpdate=true; actionPolicyDict.setId(1); @@ -146,7 +148,7 @@ public class ActionPolicyDictionaryController { } String header = ""; int counter = 0; - if(adapter.getHeaders().size() > 0){ + if(!adapter.getHeaders().isEmpty()){ for(Object attribute : adapter.getHeaders()){ if(attribute instanceof LinkedHashMap<?, ?>){ String key = ((LinkedHashMap<?, ?>) attribute).get("option").toString(); @@ -162,7 +164,7 @@ public class ActionPolicyDictionaryController { } actionPolicyDict.setHeader(header); if(actionPolicyDict.getId() == 0){ - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(actionPolicyDict.getAttributeName(), "attributeName", ActionPolicyDict.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(actionPolicyDict.getAttributeName(), attributeName, ActionPolicyDict.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ @@ -186,7 +188,7 @@ public class ActionPolicyDictionaryController { } if (fromAPI) { - if (responseString!=null && !responseString.equals("Duplicate")) { + if (responseString!=null && !("Duplicate").equals(responseString)) { if(isFakeUpdate) { responseString = "Exists"; } else { @@ -198,9 +200,9 @@ public class ActionPolicyDictionaryController { result.setViewName(responseString); return result; } else { - response.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); JSONObject j = new JSONObject("{actionPolicyDictionaryDatas: " + responseString + "}"); @@ -210,9 +212,9 @@ public class ActionPolicyDictionaryController { } } catch (Exception e){ - LOGGER.error(e.getMessage(),e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + LOGGER.error(e.getMessage()); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -220,16 +222,16 @@ public class ActionPolicyDictionaryController { } @RequestMapping(value={"/action_dictionary/remove_actionPolicyDict"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removeActionPolicyDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException { + public ModelAndView removeActionPolicyDictionary(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()); ActionPolicyDict actionPolicyDict = (ActionPolicyDict)mapper.readValue(root.get("data").toString(), ActionPolicyDict.class); commonClassDao.delete(actionPolicyDict); - response.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); @@ -240,9 +242,9 @@ public class ActionPolicyDictionaryController { return null; } catch (Exception e){ - LOGGER.error(e.getMessage(),e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + LOGGER.error(e.getMessage()); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -251,13 +253,13 @@ public class ActionPolicyDictionaryController { } class ActionAdapter{ - private ArrayList<Object> headers; + private List<Object> headers; - public ArrayList<Object> getHeaders() { + public List<Object> getHeaders() { return headers; } - public void setHeaders(ArrayList<Object> headers) { + public void setHeaders(List<Object> headers) { this.headers = headers; } } diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/BRMSDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/BRMSDictionaryController.java index a459adaec..beee437e4 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/BRMSDictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/BRMSDictionaryController.java @@ -23,7 +23,6 @@ package org.onap.policy.pap.xacml.rest.controller; import java.io.IOException; import java.io.PrintWriter; import java.io.StringWriter; -import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; import java.util.Date; import java.util.HashMap; @@ -64,27 +63,44 @@ public class BRMSDictionaryController{ private static CommonClassDao commonClassDao; - + private static String rule; + private static String utf8 = "UTF-8"; + private static String applicationJsonContentType = "application / json"; + private static String successMsg = "Success"; + private static String successMessage = "success"; + private static String duplicateResponseString = "Duplicate"; + private static String ruleName = "ruleName"; + private static String successMapKey = "successMapKey"; + private static String errorMsg = "error"; + private static String errorMessage = "Error"; + private static String dictionaryDBQuery = "dictionaryDBQuery"; + private static String operation = "operation"; + private static String getDictionary = "getDictionary"; + private static String apiflag = "apiflag"; + private static String dictionaryFields ="dictionaryFields"; + private static String update = "update"; + private static String userid = "userid"; + private static String dependencyName = "dependencyName"; + private static String controllerName = "controllerName"; @Autowired public BRMSDictionaryController(CommonClassDao commonClassDao){ BRMSDictionaryController.commonClassDao = commonClassDao; } - + /* + * This is an empty constructor + */ public BRMSDictionaryController() {} - - private String rule; 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_BRMSParamDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getBRMSParamDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getBRMSParamDictionaryByNameEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); - model.put("brmsParamDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(BRMSParamTemplate.class, "ruleName"))); + model.put("brmsParamDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(BRMSParamTemplate.class, ruleName))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -95,26 +111,26 @@ public class BRMSDictionaryController{ } @RequestMapping(value={"/get_BRMSParamData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getBRMSParamDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getBRMSParamDictionaryEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("brmsParamDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(BRMSParamTemplate.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={"/brms_dictionary/set_BRMSParamData"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public void SetRuleData(HttpServletRequest request, HttpServletResponse response) throws IOException{ + public void SetRuleData(HttpServletRequest request) throws IOException{ StringWriter writer = new StringWriter(); IOUtils.copy(request.getInputStream() , writer, StandardCharsets.UTF_8); String cleanStreamBoundary = writer.toString().replaceFirst("------(.*)(?s).*octet-stream", ""); @@ -122,11 +138,11 @@ public class BRMSDictionaryController{ } @RequestMapping(value={"/brms_dictionary/save_BRMSParam"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView saveBRMSParamDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException { + public ModelAndView saveBRMSParamDictionary(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; } ObjectMapper mapper = new ObjectMapper(); @@ -136,26 +152,25 @@ public class BRMSDictionaryController{ BRMSParamTemplate bRMSParamTemplateData; String userId = null; if(fromAPI) { - bRMSParamTemplateData = (BRMSParamTemplate)mapper.readValue(root.get("dictionaryFields").toString(), BRMSParamTemplate.class); + bRMSParamTemplateData = (BRMSParamTemplate)mapper.readValue(root.get(dictionaryFields).toString(), BRMSParamTemplate.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<Object> duplicateData = commonClassDao.checkDuplicateEntry(bRMSParamTemplateData.getRuleName(), "ruleName", BRMSParamTemplate.class); - int id = 0; + if ((update).equals(request.getParameter(operation))) { + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(bRMSParamTemplateData.getRuleName(), ruleName, BRMSParamTemplate.class); BRMSParamTemplate data = (BRMSParamTemplate) duplicateData.get(0); - id = data.getId(); + int id = data.getId(); bRMSParamTemplateData.setId(id); bRMSParamTemplateData.setUserCreatedBy(this.getUserInfo(userId)); } } else { bRMSParamTemplateData = (BRMSParamTemplate)mapper.readValue(root.get("brmsParamDictionaryData").toString(), BRMSParamTemplate.class); - userId = root.get("userid").textValue(); + userId = root.get(userid).textValue(); } bRMSParamTemplateData.setRule(rule); if(bRMSParamTemplateData.getId() == 0){ - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(bRMSParamTemplateData.getRuleName(), "ruleName", BRMSParamTemplate.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(bRMSParamTemplateData.getRuleName(), ruleName, BRMSParamTemplate.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ @@ -165,27 +180,27 @@ public class BRMSDictionaryController{ }else{ commonClassDao.update(bRMSParamTemplateData); } - response.setCharacterEncoding("UTF-8"); - response.setContentType("application / json"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + response.setContentType(applicationJsonContentType); + request.setCharacterEncoding(utf8); String responseString = ""; if(duplicateflag){ - responseString = "Duplicate"; + responseString = duplicateResponseString; }else{ responseString = mapper.writeValueAsString(BRMSDictionaryController.commonClassDao.getData(BRMSParamTemplate.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("{brmsParamDictionaryDatas: " + responseString + "}"); @@ -194,9 +209,9 @@ public class BRMSDictionaryController{ } } catch (Exception e){ - LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW , e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + e); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -204,16 +219,16 @@ public class BRMSDictionaryController{ } @RequestMapping(value={"/brms_dictionary/remove_brmsParam"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removeBRMSParamDictionary(HttpServletRequest request, HttpServletResponse response)throws UnsupportedEncodingException, IOException { + public ModelAndView removeBRMSParamDictionary(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()); BRMSParamTemplate bRMSParamTemplateData = (BRMSParamTemplate)mapper.readValue(root.get("data").toString(), BRMSParamTemplate.class); commonClassDao.delete(bRMSParamTemplateData); - 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(); @@ -225,8 +240,8 @@ public class BRMSDictionaryController{ } 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()); } @@ -234,11 +249,11 @@ public class BRMSDictionaryController{ } @RequestMapping(value={"/get_BRMSDependencyDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getBRMSDependencyDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getBRMSDependencyDictionaryByNameEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); - model.put("brmsDependencyDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(BRMSDependency.class, "dependencyName"))); + model.put("brmsDependencyDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(BRMSDependency.class, dependencyName))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -249,32 +264,32 @@ public class BRMSDictionaryController{ } @RequestMapping(value={"/get_BRMSDependencyData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getBRMSDependencyDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getBRMSDependencyDictionaryEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("brmsDependencyDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(BRMSDependency.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={"/brms_dictionary/save_BRMSDependencyData"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView saveBRMSDependencyDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException { + public ModelAndView saveBRMSDependencyDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { try { boolean duplicateflag = false; LOGGER.debug("DictionaryController: saveBRMSDependencyDictionary() is called"); 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; } @@ -285,12 +300,12 @@ public class BRMSDictionaryController{ BRMSDependency brmsDependency; String userId = null; if (fromAPI) { - brmsDependency = (BRMSDependency)mapper.readValue(root.get("dictionaryFields").toString(), BRMSDependency.class); + brmsDependency = (BRMSDependency)mapper.readValue(root.get(dictionaryFields).toString(), BRMSDependency.class); userId = "API"; //check if update operation or create, get id for data to be updated - if (request.getParameter("operation").equals("update")) { - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(brmsDependency.getDependencyName(), "dependencyName", BRMSDependency.class); + if ((update).equals(request.getParameter(operation))) { + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(brmsDependency.getDependencyName(), dependencyName, BRMSDependency.class); int id = 0; BRMSDependency data = (BRMSDependency) duplicateData.get(0); id = data.getId(); @@ -299,13 +314,13 @@ public class BRMSDictionaryController{ } } else { brmsDependency = (BRMSDependency)mapper.readValue(root.get("brmsDependencyDictionaryData").toString(), BRMSDependency.class); - userId = root.get("userid").textValue(); + userId = root.get(userid).textValue(); } LOGGER.audit("the userId from the onap portal is: " + userId); String responseString = null; - if(brmsDependency.getDependency()!=null && !brmsDependency.getDependency().trim().equals("")){ + if(brmsDependency.getDependency()!=null && !("").equals(brmsDependency.getDependency().trim())){ PEDependency dependency = null; try{ dependency = PolicyUtils.jsonStringToObject(brmsDependency.getDependency(), PEDependency.class); @@ -313,10 +328,10 @@ public class BRMSDictionaryController{ LOGGER.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID + "wrong data given for BRMS PEDependency Dictionary : " + brmsDependency.getDependency(),e); } if(dependency==null){ - responseString = "Error"; + responseString = errorMessage; }else{ if(brmsDependency.getId() == 0){ - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(brmsDependency.getDependencyName(), "dependencyName", BRMSDependency.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(brmsDependency.getDependencyName(), dependencyName, BRMSDependency.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ @@ -331,23 +346,23 @@ public class BRMSDictionaryController{ commonClassDao.update(brmsDependency); } if(duplicateflag) { - responseString = "Duplicate"; + responseString = duplicateResponseString; } else { responseString = mapper.writeValueAsString(commonClassDao.getData(BRMSDependency.class)); } } } if (fromAPI) { - if (responseString!=null && !responseString.equals("Duplicate") && !responseString.equals("Error")) { - responseString = "Success"; + if (responseString!=null && !(duplicateResponseString).equals(responseString) && !(errorMessage).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("{brmsDependencyDictionaryDatas: " + responseString + "}"); out.write(j.toString()); @@ -356,8 +371,8 @@ public class BRMSDictionaryController{ } } 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()); } @@ -365,16 +380,16 @@ public class BRMSDictionaryController{ } @RequestMapping(value={"/brms_dictionary/remove_brmsDependency"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removeBRMSDependencyDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException { + public ModelAndView removeBRMSDependencyDictionary(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()); BRMSDependency brmsDependency = (BRMSDependency)mapper.readValue(root.get("data").toString(), BRMSDependency.class); commonClassDao.delete(brmsDependency); - 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(BRMSDependency.class)); JSONObject j = new JSONObject("{brmsDependencyDictionaryDatas: " + responseString + "}"); @@ -383,8 +398,8 @@ public class BRMSDictionaryController{ } 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()); } @@ -393,11 +408,11 @@ public class BRMSDictionaryController{ @RequestMapping(value={"/get_BRMSControllerDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getBRMSControllerDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getBRMSControllerDictionaryByNameEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); - model.put("brmsControllerDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(BRMSController.class, "controllerName"))); + model.put("brmsControllerDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(BRMSController.class, controllerName))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -408,31 +423,31 @@ public class BRMSDictionaryController{ } @RequestMapping(value={"/get_BRMSControllerData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getBRMSControllerDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getBRMSControllerDictionaryEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("brmsControllerDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(BRMSController.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={"/brms_dictionary/save_BRMSControllerData"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView saveBRMSControllerDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView saveBRMSControllerDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ try { boolean duplicateflag = false; LOGGER.debug("DictionaryController: saveBRMSControllerDictionary() is called"); 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(); @@ -441,11 +456,11 @@ public class BRMSDictionaryController{ BRMSController brmsController; String userId = null; if (fromAPI) { - brmsController = (BRMSController)mapper.readValue(root.get("dictionaryFields").toString(), BRMSController.class); + brmsController = (BRMSController)mapper.readValue(root.get(dictionaryFields).toString(), BRMSController.class); userId = "API"; //check if update operation or create, get id for data to be updated - if (request.getParameter("operation").equals("update")) { - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(brmsController.getControllerName(), "controllerName", BRMSController.class); + if ((update).equals(request.getParameter(operation))) { + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(brmsController.getControllerName(), controllerName, BRMSController.class); int id = 0; BRMSController data = (BRMSController) duplicateData.get(0); id = data.getId(); @@ -454,11 +469,11 @@ public class BRMSDictionaryController{ } } else { brmsController = (BRMSController)mapper.readValue(root.get("brmsControllerDictionaryData").toString(), BRMSController.class); - userId = root.get("userid").textValue(); + userId = root.get(userid).textValue(); } LOGGER.audit("the userId from the onap portal is: " + userId); String responseString = null; - if(brmsController.getController()!=null && !brmsController.getController().trim().equals("")){ + if(brmsController.getController()!=null && !("").equals(brmsController.getController().trim())){ PEDependency dependency = null; try{ dependency = PolicyUtils.jsonStringToObject(brmsController.getController(), PEDependency.class); @@ -466,10 +481,10 @@ public class BRMSDictionaryController{ LOGGER.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID + "wrong data given for BRMS Controller Dictionary : " + brmsController.getController(),e); } if(dependency==null){ - responseString = "Error"; + responseString = errorMessage; }else{ if(brmsController.getId() == 0){ - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(brmsController.getControllerName(), "controllerName", BRMSController.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(brmsController.getControllerName(), controllerName, BRMSController.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ @@ -484,23 +499,23 @@ public class BRMSDictionaryController{ commonClassDao.update(brmsController); } if(duplicateflag) { - responseString = "Duplicate"; + responseString = duplicateResponseString; } else { responseString = mapper.writeValueAsString(commonClassDao.getData(BRMSController.class)); } } } if (fromAPI) { - if (responseString!=null && !responseString.equals("Duplicate") && !responseString.equals("Error")) { - responseString = "Success"; + if (responseString!=null && !(duplicateResponseString).equals(responseString) && !(errorMessage).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("{brmsControllerDictionaryDatas: " + responseString + "}"); out.write(j.toString()); @@ -508,8 +523,8 @@ public class BRMSDictionaryController{ } } 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()); } @@ -517,16 +532,16 @@ public class BRMSDictionaryController{ } @RequestMapping(value={"/brms_dictionary/remove_brmsController"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removeBRMSControllerDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView removeBRMSControllerDictionary(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()); BRMSController brmsController = (BRMSController)mapper.readValue(root.get("data").toString(), BRMSController.class); commonClassDao.delete(brmsController); - 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(BRMSController.class)); JSONObject j = new JSONObject("{brmsControllerDictionaryDatas: " + responseString + "}"); @@ -535,8 +550,8 @@ public class BRMSDictionaryController{ } 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()); } @@ -544,11 +559,11 @@ public class BRMSDictionaryController{ } public BRMSDependency getDependencyDataByID(String dependencyName){ - return (BRMSDependency) commonClassDao.getEntityItem(BRMSDependency.class, "dependencyName", dependencyName); + return (BRMSDependency) commonClassDao.getEntityItem(BRMSDependency.class, dependencyName, dependencyName); } public BRMSController getControllerDataByID(String controllerName){ - return (BRMSController) commonClassDao.getEntityItem(BRMSController.class, "controllerName", controllerName); + return (BRMSController) commonClassDao.getEntityItem(BRMSController.class, controllerName, controllerName); } } diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java index a2a6d6e70..d142a46f3 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/ClosedLoopDictionaryController.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.util.Date; import java.util.HashMap; import java.util.LinkedHashMap; @@ -62,26 +61,47 @@ public class ClosedLoopDictionaryController{ private static final Logger LOGGER = FlexLogger.getLogger(ClosedLoopDictionaryController.class); private static CommonClassDao commonClassDao; + private static String vsclaction = "vsclaction"; + private static String successMapKey = "successMapKey"; + private static String successMessage = "success"; + private static String operation = "operation"; + private static String getDictionary = "getDictionary"; + private static String dictionaryDBQuery = "dictionaryDBQuery"; + private static String errorMsg = "error"; + private static String vnftype = "vnftype"; + private static String pepName = "pepName"; + private static String varbindName = "varbindName"; + private static String serviceName = "serviceName"; + private static String siteName = "siteName"; + private static String apiflag = "apiflag"; + private static String dictionaryFields = "dictionaryFields"; + private static String update = "update"; + private static String duplicateResponseString = "Duplicate"; + private static String userid = "userid"; + private static String utf8 = "UTF-8"; + private static String applicationJsonContentType = "application / json"; + private static String successMsg = "Success"; @Autowired public ClosedLoopDictionaryController(CommonClassDao commonClassDao){ ClosedLoopDictionaryController.commonClassDao = commonClassDao; } - + /* + * This is an empty constructor + */ public ClosedLoopDictionaryController(){} 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_VSCLActionDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getVSCLActionDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getVSCLActionDictionaryByNameEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); - model.put("vsclActionDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(VSCLAction.class, "vsclaction"))); + model.put("vsclActionDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(VSCLAction.class, vsclaction))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -93,34 +113,34 @@ public class ClosedLoopDictionaryController{ @RequestMapping(value={"/get_VSCLActionData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getVSCLActionDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getVSCLActionDictionaryEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("vsclActionDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(VSCLAction.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_VNFTypeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getVNFTypeDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getVNFTypeDictionaryByNameEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); - model.put("vnfTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(VNFType.class, "vnftype"))); + model.put("vnfTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(VNFType.class, vnftype))); 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){ @@ -129,30 +149,30 @@ public class ClosedLoopDictionaryController{ } @RequestMapping(value={"/get_VNFTypeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getVNFTypeDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getVNFTypeDictionaryEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("vnfTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(VNFType.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_PEPOptionsDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getPEPOptionsDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getPEPOptionsDictionaryByNameEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); - model.put("pepOptionsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PEPOptions.class, "pepName"))); + model.put("pepOptionsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(PEPOptions.class, pepName))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -163,30 +183,30 @@ public class ClosedLoopDictionaryController{ } @RequestMapping(value={"/get_PEPOptionsData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getPEPOptionsDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getPEPOptionsDictionaryEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("pepOptionsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PEPOptions.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_VarbindDictionaryDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getVarbindDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getVarbindDictionaryByNameEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); - model.put("varbindDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(VarbindDictionary.class, "varbindName"))); + model.put("varbindDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(VarbindDictionary.class, varbindName))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -197,30 +217,30 @@ public class ClosedLoopDictionaryController{ } @RequestMapping(value={"/get_VarbindDictionaryData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getVarbindDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getVarbindDictionaryEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("varbindDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(VarbindDictionary.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_ClosedLoopServicesDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getClosedLoopServiceDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getClosedLoopServiceDictionaryByNameEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); - model.put("closedLoopServiceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ClosedLoopD2Services.class, "serviceName"))); + model.put("closedLoopServiceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ClosedLoopD2Services.class, serviceName))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -231,30 +251,30 @@ public class ClosedLoopDictionaryController{ } @RequestMapping(value={"/get_ClosedLoopServicesData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getClosedLoopServiceDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getClosedLoopServiceDictionaryEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("closedLoopServiceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.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_ClosedLoopSiteDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getClosedLoopSiteDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getClosedLoopSiteDictionaryByNameEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); - model.put("closedLoopSiteDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ClosedLoopSite.class, "siteName"))); + model.put("closedLoopSiteDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(ClosedLoopSite.class, siteName))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -265,31 +285,31 @@ public class ClosedLoopDictionaryController{ } @RequestMapping(value={"/get_ClosedLoopSiteData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getClosedLoopSiteDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getClosedLoopSiteDictionaryEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("closedLoopSiteDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(ClosedLoopSite.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={"/cl_dictionary/save_vsclAction"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView saveVSCLAction(HttpServletRequest request, HttpServletResponse response)throws UnsupportedEncodingException, IOException{ + public ModelAndView saveVSCLAction(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(); @@ -298,15 +318,14 @@ public class ClosedLoopDictionaryController{ VSCLAction vSCLAction; String userId = null; if (fromAPI) { - vSCLAction = (VSCLAction)mapper.readValue(root.get("dictionaryFields").toString(), VSCLAction.class); + vSCLAction = (VSCLAction)mapper.readValue(root.get(dictionaryFields).toString(), VSCLAction.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<Object> duplicateData = commonClassDao.checkDuplicateEntry(vSCLAction.getVsclaction(), "vsclaction", VSCLAction.class); - int id = 0; + if ((update).equals(request.getParameter(operation))) { + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(vSCLAction.getVsclaction(), vsclaction, VSCLAction.class); VSCLAction data = (VSCLAction) duplicateData.get(0); - id = data.getId(); + int id = data.getId(); if(id==0){ isFakeUpdate=true; vSCLAction.setId(1); @@ -319,10 +338,10 @@ public class ClosedLoopDictionaryController{ } else { vSCLAction = (VSCLAction)mapper.readValue(root.get("vsclActionDictionaryData").toString(), VSCLAction.class); - userId = root.get("userid").textValue(); + userId = root.get(userid).textValue(); } if(vSCLAction.getId() == 0){ - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(vSCLAction.getVsclaction(), "vsclaction", VSCLAction.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(vSCLAction.getVsclaction(), vsclaction, VSCLAction.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ @@ -340,16 +359,16 @@ public class ClosedLoopDictionaryController{ String responseString = ""; if(duplicateflag){ - responseString = "Duplicate"; + responseString = duplicateResponseString; }else{ responseString = mapper.writeValueAsString(commonClassDao.getData(VSCLAction.class)); } if (fromAPI) { - if (responseString!=null && !responseString.equals("Duplicate")) { + if (responseString!=null && !(duplicateResponseString).equals(responseString)) { if(isFakeUpdate) { responseString = "Exists"; } else { - responseString = "Success"; + responseString = successMsg; } } @@ -357,9 +376,9 @@ public class ClosedLoopDictionaryController{ 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("{vsclActionDictionaryDatas: " + responseString + "}"); @@ -369,8 +388,8 @@ public class ClosedLoopDictionaryController{ } 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()); } @@ -378,16 +397,16 @@ public class ClosedLoopDictionaryController{ } @RequestMapping(value={"/cl_dictionary/remove_VsclAction"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removeVSCLAction(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException { + public ModelAndView removeVSCLAction(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()); VSCLAction vSCLAction = (VSCLAction)mapper.readValue(root.get("data").toString(), VSCLAction.class); commonClassDao.delete(vSCLAction); - 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(); @@ -399,8 +418,8 @@ public class ClosedLoopDictionaryController{ } 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()); } @@ -408,13 +427,13 @@ public class ClosedLoopDictionaryController{ } @RequestMapping(value={"/cl_dictionary/save_vnfType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView saveVnfType(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView saveVnfType(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(); @@ -424,15 +443,14 @@ public class ClosedLoopDictionaryController{ String userId = null; if (fromAPI) { - vNFType = (VNFType)mapper.readValue(root.get("dictionaryFields").toString(), VNFType.class); + vNFType = (VNFType)mapper.readValue(root.get(dictionaryFields).toString(), VNFType.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<Object> duplicateData = commonClassDao.checkDuplicateEntry(vNFType.getVnftype(), "vnftype", VNFType.class); - int id = 0; + if ((update).equals(request.getParameter(operation))) { + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(vNFType.getVnftype(), vnftype, VNFType.class); VNFType data = (VNFType) duplicateData.get(0); - id = data.getId(); + int id = data.getId(); if(id==0){ isFakeUpdate=true; vNFType.setId(1); @@ -443,10 +461,10 @@ public class ClosedLoopDictionaryController{ } } else { vNFType = (VNFType)mapper.readValue(root.get("vnfTypeDictionaryData").toString(), VNFType.class); - userId = root.get("userid").textValue(); + userId = root.get(userid).textValue(); } if(vNFType.getId() == 0){ - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(vNFType.getVnftype(), "vnftype", VNFType.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(vNFType.getVnftype(), vnftype, VNFType.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ @@ -463,25 +481,25 @@ public class ClosedLoopDictionaryController{ } String responseString = ""; if(duplicateflag){ - responseString = "Duplicate"; + responseString = duplicateResponseString; }else{ responseString = mapper.writeValueAsString(commonClassDao.getData(VNFType.class)); } if (fromAPI) { - if (responseString!=null && !responseString.equals("Duplicate")) { + if (responseString!=null && !(duplicateResponseString).equals(responseString)) { if(isFakeUpdate) { responseString = "Exists"; } 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("{vnfTypeDictionaryDatas: " + responseString + "}"); @@ -491,8 +509,8 @@ public class ClosedLoopDictionaryController{ } 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()); } @@ -500,16 +518,16 @@ public class ClosedLoopDictionaryController{ } @RequestMapping(value={"/cl_dictionary/remove_vnfType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removeVnfType(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException { + public ModelAndView removeVnfType(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()); VNFType vNFType = (VNFType)mapper.readValue(root.get("data").toString(), VNFType.class); commonClassDao.delete(vNFType); - 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(); @@ -521,8 +539,8 @@ public class ClosedLoopDictionaryController{ } 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()); } @@ -530,12 +548,12 @@ public class ClosedLoopDictionaryController{ } @RequestMapping(value={"/cl_dictionary/save_pepOptions"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView savePEPOptions(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView savePEPOptions(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(); @@ -545,16 +563,15 @@ public class ClosedLoopDictionaryController{ GridData gridData; String userId = null; if (fromAPI) { - pEPOptions = (PEPOptions)mapper.readValue(root.get("dictionaryFields").toString(), PEPOptions.class); - gridData = (GridData)mapper.readValue(root.get("dictionaryFields").toString(), GridData.class); + pEPOptions = (PEPOptions)mapper.readValue(root.get(dictionaryFields).toString(), PEPOptions.class); + gridData = (GridData)mapper.readValue(root.get(dictionaryFields).toString(), GridData.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<Object> duplicateData = commonClassDao.checkDuplicateEntry(pEPOptions.getPepName(), "pepName", PEPOptions.class); - int id = 0; + if ((update).equals(request.getParameter(operation))) { + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(pEPOptions.getPepName(), pepName, PEPOptions.class); PEPOptions data = (PEPOptions) duplicateData.get(0); - id = data.getId(); + int id = data.getId(); if(id==0){ isFakeUpdate=true; pEPOptions.setId(1); @@ -566,11 +583,11 @@ public class ClosedLoopDictionaryController{ } else { pEPOptions = (PEPOptions)mapper.readValue(root.get("pepOptionsDictionaryData").toString(), PEPOptions.class); gridData = (GridData)mapper.readValue(root.get("pepOptionsDictionaryData").toString(), GridData.class); - userId = root.get("userid").textValue(); + userId = root.get(userid).textValue(); } String actions = ""; 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(); @@ -586,7 +603,7 @@ public class ClosedLoopDictionaryController{ } pEPOptions.setActions(actions); if(pEPOptions.getId() == 0){ - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(pEPOptions.getPepName(), "pepName", PEPOptions.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(pEPOptions.getPepName(), pepName, PEPOptions.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ @@ -603,16 +620,16 @@ public class ClosedLoopDictionaryController{ } String responseString = ""; if(duplicateflag){ - responseString = "Duplicate"; + responseString = duplicateResponseString; }else{ responseString = mapper.writeValueAsString(commonClassDao.getData(PEPOptions.class)); } if (fromAPI) { - if (responseString!=null && !responseString.equals("Duplicate")) { + if (responseString!=null && !(duplicateResponseString).equals(responseString)) { if(isFakeUpdate){ responseString = "Exists"; } else { - responseString = "Success"; + responseString = successMsg; } } @@ -620,9 +637,9 @@ public class ClosedLoopDictionaryController{ 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("{pepOptionsDictionaryDatas: " + responseString + "}"); @@ -632,8 +649,8 @@ public class ClosedLoopDictionaryController{ }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()); } @@ -641,16 +658,16 @@ public class ClosedLoopDictionaryController{ } @RequestMapping(value={"/cl_dictionary/remove_pepOptions"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removePEPOptions(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException { + public ModelAndView removePEPOptions(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()); PEPOptions pEPOptions = (PEPOptions)mapper.readValue(root.get("data").toString(), PEPOptions.class); commonClassDao.delete(pEPOptions); - 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(); @@ -662,8 +679,8 @@ public class ClosedLoopDictionaryController{ } 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()); } @@ -671,12 +688,12 @@ public class ClosedLoopDictionaryController{ } @RequestMapping(value={"/cl_dictionary/save_service"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView saveServiceType(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView saveServiceType(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(); @@ -685,15 +702,14 @@ public class ClosedLoopDictionaryController{ ClosedLoopD2Services serviceData; String userId = null; if (fromAPI) { - serviceData = (ClosedLoopD2Services)mapper.readValue(root.get("dictionaryFields").toString(), ClosedLoopD2Services.class); + serviceData = (ClosedLoopD2Services)mapper.readValue(root.get(dictionaryFields).toString(), ClosedLoopD2Services.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<Object> duplicateData = commonClassDao.checkDuplicateEntry(serviceData.getServiceName(), "serviceName", ClosedLoopD2Services.class); - int id = 0; + if ((update).equals(request.getParameter(operation))) { + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(serviceData.getServiceName(), serviceName, ClosedLoopD2Services.class); ClosedLoopD2Services data = (ClosedLoopD2Services) duplicateData.get(0); - id = data.getId(); + int id = data.getId(); if(id==0){ isFakeUpdate=true; serviceData.setId(1); @@ -704,10 +720,10 @@ public class ClosedLoopDictionaryController{ } } else { serviceData = (ClosedLoopD2Services)mapper.readValue(root.get("closedLoopServiceDictionaryData").toString(), ClosedLoopD2Services.class); - userId = root.get("userid").textValue(); + userId = root.get(userid).textValue(); } if(serviceData.getId() == 0){ - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(serviceData.getServiceName(), "serviceName", ClosedLoopD2Services.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(serviceData.getServiceName(), serviceName, ClosedLoopD2Services.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ @@ -724,25 +740,25 @@ public class ClosedLoopDictionaryController{ } String responseString = ""; if(duplicateflag){ - responseString = "Duplicate"; + responseString = duplicateResponseString; }else{ responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class)); } if (fromAPI) { - if (responseString!=null && !responseString.equals("Duplicate")) { + if (responseString!=null && !(duplicateResponseString).equals(responseString)) { if(isFakeUpdate){ responseString = "Exists"; } 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("{closedLoopServiceDictionaryDatas: " + responseString + "}"); @@ -751,8 +767,8 @@ public class ClosedLoopDictionaryController{ } }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()); } @@ -760,16 +776,16 @@ public class ClosedLoopDictionaryController{ } @RequestMapping(value={"/cl_dictionary/remove_Service"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removeServiceType(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException { + public ModelAndView removeServiceType(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()); ClosedLoopD2Services closedLoopD2Services = (ClosedLoopD2Services)mapper.readValue(root.get("data").toString(), ClosedLoopD2Services.class); commonClassDao.delete(closedLoopD2Services); - 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(); @@ -781,8 +797,8 @@ public class ClosedLoopDictionaryController{ } 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()); } @@ -790,13 +806,13 @@ public class ClosedLoopDictionaryController{ } @RequestMapping(value={"/cl_dictionary/save_siteName"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView saveSiteType(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView saveSiteType(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(); @@ -805,14 +821,13 @@ public class ClosedLoopDictionaryController{ ClosedLoopSite siteData; String userId = null; if (fromAPI) { - siteData = (ClosedLoopSite)mapper.readValue(root.get("dictionaryFields").toString(), ClosedLoopSite.class); + siteData = (ClosedLoopSite)mapper.readValue(root.get(dictionaryFields).toString(), ClosedLoopSite.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<Object> duplicateData = commonClassDao.checkDuplicateEntry(siteData.getSiteName(), "siteName", ClosedLoopSite.class); - int id = 0; + if ((update).equals(request.getParameter(operation))) { + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(siteData.getSiteName(), siteName, ClosedLoopSite.class); ClosedLoopSite data = (ClosedLoopSite) duplicateData.get(0); - id = data.getId(); + int id = data.getId(); if(id==0){ isFakeUpdate=true; siteData.setId(1); @@ -823,10 +838,10 @@ public class ClosedLoopDictionaryController{ } } else { siteData = (ClosedLoopSite)mapper.readValue(root.get("closedLoopSiteDictionaryData").toString(), ClosedLoopSite.class); - userId = root.get("userid").textValue(); + userId = root.get(userid).textValue(); } if(siteData.getId() == 0){ - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(siteData.getSiteName(), "siteName", ClosedLoopSite.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(siteData.getSiteName(), siteName, ClosedLoopSite.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ @@ -843,26 +858,26 @@ public class ClosedLoopDictionaryController{ } String responseString = ""; if(duplicateflag){ - responseString = "Duplicate"; + responseString = duplicateResponseString; }else{ responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopSite.class)); } if (fromAPI) { - if (responseString!=null && !responseString.equals("Duplicate")) { + if (responseString!=null && !(duplicateResponseString).equals(responseString)) { if(isFakeUpdate){ responseString = "Exists"; } 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("{closedLoopSiteDictionaryDatas: " + responseString + "}"); @@ -871,8 +886,8 @@ public class ClosedLoopDictionaryController{ } }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()); } @@ -880,16 +895,16 @@ public class ClosedLoopDictionaryController{ } @RequestMapping(value={"/cl_dictionary/remove_site"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removeSiteType(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException { + public ModelAndView removeSiteType(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()); ClosedLoopSite closedLoopSite = (ClosedLoopSite)mapper.readValue(root.get("data").toString(), ClosedLoopSite.class); commonClassDao.delete(closedLoopSite); - 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(); @@ -901,8 +916,8 @@ public class ClosedLoopDictionaryController{ } 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()); } @@ -910,12 +925,12 @@ public class ClosedLoopDictionaryController{ } @RequestMapping(value={"/cl_dictionary/save_varbind"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView saveVarbind(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView saveVarbind(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(); @@ -924,15 +939,14 @@ public class ClosedLoopDictionaryController{ VarbindDictionary varbindDictionary; String userId = null; if (fromAPI) { - varbindDictionary = (VarbindDictionary)mapper.readValue(root.get("dictionaryFields").toString(), VarbindDictionary.class); + varbindDictionary = (VarbindDictionary)mapper.readValue(root.get(dictionaryFields).toString(), VarbindDictionary.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<Object> duplicateData = commonClassDao.checkDuplicateEntry(varbindDictionary.getVarbindName(), "varbindName", VarbindDictionary.class); - int id = 0; + if ((update).equals(request.getParameter(operation))) { + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(varbindDictionary.getVarbindName(), varbindName, VarbindDictionary.class); VarbindDictionary data = (VarbindDictionary) duplicateData.get(0); - id = data.getId(); + int id = data.getId(); if(id==0){ isFakeUpdate=true; varbindDictionary.setId(1); @@ -943,10 +957,10 @@ public class ClosedLoopDictionaryController{ } } else { varbindDictionary = (VarbindDictionary)mapper.readValue(root.get("varbindDictionaryData").toString(), VarbindDictionary.class); - userId = root.get("userid").textValue(); + userId = root.get(userid).textValue(); } if(varbindDictionary.getId() == 0){ - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(varbindDictionary.getVarbindName(), "varbindName", VarbindDictionary.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(varbindDictionary.getVarbindName(), varbindName, VarbindDictionary.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ @@ -963,26 +977,26 @@ public class ClosedLoopDictionaryController{ } String responseString = ""; if(duplicateflag){ - responseString = "Duplicate"; + responseString = duplicateResponseString; }else{ responseString = mapper.writeValueAsString(commonClassDao.getData(VarbindDictionary.class)); } if (fromAPI) { - if (responseString!=null && !responseString.equals("Duplicate")) { + if (responseString!=null && !(duplicateResponseString).equals(responseString)) { if(isFakeUpdate){ responseString = "Exists"; } 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("{varbindDictionaryDatas: " + responseString + "}"); @@ -991,8 +1005,8 @@ public class ClosedLoopDictionaryController{ } }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()); } @@ -1000,16 +1014,16 @@ public class ClosedLoopDictionaryController{ } @RequestMapping(value={"/cl_dictionary/remove_varbindDict"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removeVarbind(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView removeVarbind(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()); VarbindDictionary varbindDictionary = (VarbindDictionary)mapper.readValue(root.get("data").toString(), VarbindDictionary.class); commonClassDao.delete(varbindDictionary); - 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(); @@ -1021,8 +1035,8 @@ public class ClosedLoopDictionaryController{ } 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()); } diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.java index 3ae9a465d..aac777a67 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DecisionPolicyDictionaryController.java @@ -89,7 +89,7 @@ public class DecisionPolicyDictionaryController { @RequestMapping(value={"/get_SettingsDictionaryData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getSettingsDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getSettingsDictionaryEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryController.java index b5973d732..40b0b5d62 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DescriptiveDictionaryController.java @@ -86,7 +86,7 @@ public class DescriptiveDictionaryController { } @RequestMapping(value={"/get_DescriptiveScope"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getDescriptiveDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getDescriptiveDictionaryEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryController.java index db6acc82c..1fef35459 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/DictionaryController.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.util.ArrayList; import java.util.Date; import java.util.HashMap; @@ -61,17 +60,25 @@ public class DictionaryController { private static final Log LOGGER = LogFactory.getLog(DictionaryController.class); private static CommonClassDao commonClassDao; - + private static String xacmlId = "xacmlId"; + private static String apiflag = "apiflag"; + private static String operation = "operation"; + private static String dictionaryFields ="dictionaryFields"; + private static String duplicateResponseString = "Duplicate"; + private static String utf8 = "UTF-8"; + private static String applicationJsonContentType = "application / json"; + private static String onapName = "onapName"; @Autowired public DictionaryController(CommonClassDao commonClassDao){ DictionaryController.commonClassDao = commonClassDao; } - + /* + * This is an empty constructor + */ public DictionaryController(){} public UserInfo getUserInfo(String loginId){ - UserInfo name = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId); - return name; + return (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId); } @@ -79,7 +86,7 @@ public class DictionaryController { List<Object> list = commonClassDao.getData(Category.class); for (int i = 0; i < list.size() ; i++) { Category value = (Category) list.get(i); - if (value.getShortName().equals("resource")) { + if (("resource").equals(value.getShortName())) { return value; } } @@ -87,12 +94,11 @@ public class DictionaryController { } @RequestMapping(value={"/get_AttributeDatabyAttributeName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getAttributeDictionaryEntityDatabyAttributeName(HttpServletRequest request, HttpServletResponse response){ + public void getAttributeDictionaryEntityDatabyAttributeName(HttpServletResponse response){ try{ - System.out.println(); Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); - model.put("attributeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(Attribute.class, "xacmlId"))); + model.put("attributeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(Attribute.class, xacmlId))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -104,16 +110,15 @@ public class DictionaryController { //Attribute Dictionary @RequestMapping(value="/get_AttributeData", method= RequestMethod.GET , produces=MediaType.APPLICATION_JSON_VALUE) - public void getAttributeDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getAttributeDictionaryEntityData(HttpServletResponse response){ try{ - System.out.println(); Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("attributeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(Attribute.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.addHeader("successMapKey", "success"); - response.addHeader("operation", "getDictionary"); + response.addHeader(operation, "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e){ @@ -124,12 +129,12 @@ public class DictionaryController { } @RequestMapping(value={"/attribute_dictionary/save_attribute"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView saveAttributeDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView saveAttributeDictionary(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(); @@ -139,17 +144,15 @@ public class DictionaryController { AttributeValues attributeValueData = null; String userId = null; if (fromAPI) { - //JsonNode json = root.get("dictionaryFields"); - attributeData = (Attribute)mapper.readValue(root.get("dictionaryFields").toString(), Attribute.class); - attributeValueData = (AttributeValues)mapper.readValue(root.get("dictionaryFields").toString(), AttributeValues.class); + attributeData = (Attribute)mapper.readValue(root.get(dictionaryFields).toString(), Attribute.class); + attributeValueData = (AttributeValues)mapper.readValue(root.get(dictionaryFields).toString(), AttributeValues.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<Object> duplicateData = commonClassDao.checkDuplicateEntry(attributeData.getXacmlId(), "xacmlId", Attribute.class); - int id = 0; + if (("update").equals(request.getParameter(operation))) { + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(attributeData.getXacmlId(), xacmlId, Attribute.class); Attribute data = (Attribute) duplicateData.get(0); - id = data.getId(); + int id = data.getId(); if(id==0){ isFakeUpdate=true; attributeData.setId(1); @@ -165,7 +168,7 @@ public class DictionaryController { } String userValue = ""; int counter = 0; - if(attributeValueData.getUserDataTypeValues().size() > 0){ + if(!attributeValueData.getUserDataTypeValues().isEmpty()){ for(Object attribute : attributeValueData.getUserDataTypeValues()){ if(attribute instanceof LinkedHashMap<?, ?>){ String key = ((LinkedHashMap<?, ?>) attribute).get("attributeValues").toString(); @@ -181,21 +184,21 @@ public class DictionaryController { if(attributeData.getDatatypeBean().getShortName() != null){ String datatype = attributeData.getDatatypeBean().getShortName(); Datatype a = new Datatype(); - if(datatype.equalsIgnoreCase("string")){ + if(("string").equalsIgnoreCase(datatype)){ a.setId(26); - }else if(datatype.equalsIgnoreCase("integer")){ + }else if(("integer").equalsIgnoreCase(datatype)){ a.setId(12); - }else if(datatype.equalsIgnoreCase("boolean")){ + }else if(("boolean").equalsIgnoreCase(datatype)){ a.setId(18); - }else if(datatype.equalsIgnoreCase("double")){ + }else if(("double").equalsIgnoreCase(datatype)){ a.setId(25); - }else if(datatype.equalsIgnoreCase("user")){ + }else if(("user").equalsIgnoreCase(datatype)){ a.setId(29); } attributeData.setDatatypeBean(a); } if(attributeData.getId() == 0){ - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(attributeData.getXacmlId(), "xacmlId", Attribute.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(attributeData.getXacmlId(), xacmlId, Attribute.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ @@ -213,13 +216,13 @@ public class DictionaryController { } String responseString = null; if(duplicateflag) { - responseString = "Duplicate"; + responseString = duplicateResponseString; } else { responseString = mapper.writeValueAsString(commonClassDao.getData(Attribute.class)); } if (fromAPI) { - if (responseString!=null && !responseString.equals("Duplicate")) { + if (responseString!=null && !(duplicateResponseString).equals(responseString)) { if(isFakeUpdate) { responseString = "Exists"; } else { @@ -230,9 +233,9 @@ public class DictionaryController { 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("{attributeDictionaryDatas: " + responseString + "}"); @@ -241,8 +244,8 @@ public class DictionaryController { } }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()); } @@ -250,16 +253,16 @@ public class DictionaryController { } @RequestMapping(value={"/attribute_dictionary/remove_attribute"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removeAttributeDictionary(HttpServletRequest request, HttpServletResponse response)throws UnsupportedEncodingException, IOException { + public ModelAndView removeAttributeDictionary(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()); Attribute attributeData = (Attribute)mapper.readValue(root.get("data").toString(), Attribute.class); commonClassDao.delete(attributeData); - 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(Attribute.class)); @@ -269,8 +272,8 @@ public class DictionaryController { } 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()); } @@ -279,12 +282,12 @@ public class DictionaryController { //OnapName Dictionary @RequestMapping(value={"/get_OnapNameDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getOnapNameDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getOnapNameDictionaryByNameEntityData(HttpServletResponse response){ LOGGER.info("get_OnapNameDataByName is called"); try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); - model.put("onapNameDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(OnapName.class, "onapName"))); + model.put("onapNameDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(OnapName.class, onapName))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -295,7 +298,7 @@ public class DictionaryController { } @RequestMapping(value={"/get_OnapNameData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getOnapNameDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getOnapNameDictionaryEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); @@ -303,7 +306,7 @@ public class DictionaryController { JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.addHeader("successMapKey", "success"); - response.addHeader("operation", "getDictionary"); + response.addHeader(operation, "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e){ @@ -314,12 +317,12 @@ public class DictionaryController { } @RequestMapping(value={"/onap_dictionary/save_onapName"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView saveOnapDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView saveOnapDictionary(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(); @@ -328,15 +331,14 @@ public class DictionaryController { OnapName onapData; String userId = null; if (fromAPI) { - onapData = (OnapName)mapper.readValue(root.get("dictionaryFields").toString(), OnapName.class); + onapData = (OnapName)mapper.readValue(root.get(dictionaryFields).toString(), OnapName.class); userId = "API"; //check if update operation or create, get id for data to be updated - if (request.getParameter("operation").equals("update")) { - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getOnapName(), "onapName", OnapName.class); - int id = 0; + if (("update").equals(request.getParameter(operation))) { + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getOnapName(), onapName, OnapName.class); OnapName data = (OnapName) duplicateData.get(0); - id = data.getId(); + int id = data.getId(); if(id==0){ isFakeUpdate=true; onapData.setId(1); @@ -350,7 +352,7 @@ public class DictionaryController { userId = root.get("userid").textValue(); } if(onapData.getId() == 0){ - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getOnapName(), "onapName", OnapName.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getOnapName(), onapName, OnapName.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ @@ -367,12 +369,12 @@ public class DictionaryController { } String responseString = null; if(duplicateflag) { - responseString = "Duplicate"; + responseString = duplicateResponseString; } else { responseString = mapper.writeValueAsString(commonClassDao.getData(OnapName.class)); } if (fromAPI) { - if (responseString!=null && !responseString.equals("Duplicate")) { + if (responseString!=null && !(duplicateResponseString).equals(responseString)) { if(isFakeUpdate){ responseString = "Exists"; } else { @@ -384,9 +386,9 @@ public class DictionaryController { 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("{onapNameDictionaryDatas: " + responseString + "}"); @@ -395,8 +397,8 @@ public class DictionaryController { } }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()); } @@ -404,16 +406,16 @@ public class DictionaryController { } @RequestMapping(value={"/onap_dictionary/remove_onap"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removeOnapDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException { + public ModelAndView removeOnapDictionary(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()); OnapName onapData = (OnapName)mapper.readValue(root.get("data").toString(), OnapName.class); commonClassDao.delete(onapData); - 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(); @@ -425,8 +427,8 @@ public class DictionaryController { } 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()); } @@ -436,13 +438,13 @@ public class DictionaryController { } class AttributeValues{ - private ArrayList<Object> userDataTypeValues; + private List<Object> userDataTypeValues; - public ArrayList<Object> getUserDataTypeValues() { + public List<Object> getUserDataTypeValues() { return userDataTypeValues; } - public void setUserDataTypeValues(ArrayList<Object> userDataTypeValues) { + public void setUserDataTypeValues(List<Object> userDataTypeValues) { this.userDataTypeValues = userDataTypeValues; } } diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/EnforcerDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/EnforcerDictionaryController.java index 6c5d3a9e3..cd4c1a435 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/EnforcerDictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/EnforcerDictionaryController.java @@ -56,7 +56,7 @@ public class EnforcerDictionaryController { CommonClassDao commonClassDao; @RequestMapping(value={"/get_EnforcerTypeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getEnforcerDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getEnforcerDictionaryEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); 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..86706d154 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,53 @@ 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; } - + /* + * 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<String, Object> 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 +129,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<String, Object> 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 +161,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<Object> duplicateData = commonClassDao.checkDuplicateEntry(prefixList.getPrefixListName(), "prefixListName", PrefixList.class); - int id = 0; + if ((update).equals(request.getParameter(operation))) { + List<Object> 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 +179,7 @@ public class FirewallDictionaryController { prefixList = (PrefixList)mapper.readValue(root.get("prefixListDictionaryData").toString(), PrefixList.class); } if(prefixList.getId() == 0){ - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(prefixList.getPrefixListName(), "prefixListName", PrefixList.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(prefixList.getPrefixListName(), prefixListName, PrefixList.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ @@ -167,26 +192,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 +220,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 +229,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 +248,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 +257,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 +281,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 +290,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<String, Object> 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 +326,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 +345,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 +354,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 +373,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 +382,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<String, Object> model = new HashMap<String, Object>(); + Map<String, Object> 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<String, Object> model = new HashMap<String, Object>(); + Map<String, Object> 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 +416,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 +429,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<Object> duplicateData = commonClassDao.checkDuplicateEntry(protocolList.getProtocolName(), "protocolName", ProtocolList.class); - int id = 0; + if ((update).equals(request.getParameter(operation))) { + List<Object> 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 +447,7 @@ public class FirewallDictionaryController { protocolList = (ProtocolList)mapper.readValue(root.get("protocolListDictionaryData").toString(), ProtocolList.class); } if(protocolList.getId() == 0){ - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(protocolList.getProtocolName(), "protocolName", ProtocolList.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(protocolList.getProtocolName(), protocolName, ProtocolList.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ @@ -436,26 +460,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 +488,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 +497,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 +517,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 +526,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<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); @@ -517,31 +541,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<String, Object> 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 +574,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<Object> 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 +597,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 +631,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 +658,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 +667,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 +687,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 +696,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<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); @@ -694,31 +717,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<String, Object> 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 +749,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<Object> 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 +780,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 +808,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 +817,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 +836,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 +845,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<String, Object> 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<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); @@ -857,12 +879,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 +893,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<Object> 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 +917,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 +950,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 +978,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 +987,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 +1007,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 +1017,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<String, Object> 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 +1032,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<String, Object> 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 +1064,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<Object> duplicateData = commonClassDao.checkDuplicateEntry(securityZone.getZoneName(), "zoneName", SecurityZone.class); - int id = 0; + if ((update).equals(request.getParameter(operation))) { + List<Object> 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 +1082,7 @@ public class FirewallDictionaryController { securityZone = (SecurityZone)mapper.readValue(root.get("securityZoneDictionaryData").toString(), SecurityZone.class); } if(securityZone.getId() == 0){ - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(securityZone.getZoneName(), "zoneName", SecurityZone.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(securityZone.getZoneName(), zoneName, SecurityZone.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ @@ -1075,26 +1095,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 +1124,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 +1133,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 +1154,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 +1164,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<String, Object> 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<String, Object> 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 +1198,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 +1212,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<Object> duplicateData = commonClassDao.checkDuplicateEntry(serviceList.getServiceName(), "serviceName", ServiceList.class); - int id = 0; + if ((update).equals(request.getParameter(operation))) { + List<Object> 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 +1233,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 +1248,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 +1263,7 @@ public class FirewallDictionaryController { serviceList.setServiceAppProtocol(appValue); serviceList.setServiceType("SERVICE"); if(serviceList.getId() == 0){ - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(serviceList.getServiceName(), "serviceName", ServiceList.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(serviceList.getServiceName(), serviceName, ServiceList.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ @@ -1258,25 +1277,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 +1304,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 +1314,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 +1334,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 +1344,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<String, Object> 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 +1361,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<String, Object> 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 +1376,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 +1389,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<Object> duplicateData = commonClassDao.checkDuplicateEntry(zone.getZoneName(), "zoneName", Zone.class); - int id = 0; + if ((update).equals(request.getParameter(operation))) { + List<Object> 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 +1407,7 @@ public class FirewallDictionaryController { zone = (Zone)mapper.readValue(root.get("zoneDictionaryData").toString(), Zone.class); } if(zone.getId() == 0){ - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(zone.getZoneName(), "zoneName", Zone.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(zone.getZoneName(), zoneName, Zone.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ @@ -1402,26 +1420,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 +1448,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 +1457,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 +1478,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 +1487,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<String, Object> model = new HashMap<String, Object>(); + Map<String, Object> 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 +1502,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<String, Object> model = new HashMap<String, Object>(); + Map<String, Object> 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 +1536,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<Object> duplicateData = commonClassDao.checkDuplicateEntry(termList.getTermName(), "termName", TermList.class); - int id = 0; + if ((update).equals(request.getParameter(operation))) { + List<Object> 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 +1556,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 +1576,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 +1592,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 +1608,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 +1624,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 +1640,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 +1656,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 +1671,7 @@ public class FirewallDictionaryController { termList.setAction(actionValue); if(termList.getId() == 0){ - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(termList.getTermName(), "termName", TermList.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(termList.getTermName(), termName, TermList.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ @@ -1670,26 +1687,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 +1715,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 +1724,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 +1745,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 +1754,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<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); @@ -1752,26 +1769,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<String, Object> 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 +1798,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 +1813,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 +1836,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 +1855,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 +1864,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 +1885,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 +1895,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<String, Object> model = new HashMap<String, Object>(); + Map<String, Object> 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 +1910,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<String, Object> model = new HashMap<String, Object>(); + Map<String, Object> 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 +1925,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 +1942,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<Object> duplicateData = commonClassDao.checkDuplicateEntry(fwTagPicker.getTagPickerName(), "tagPickerName", FWTagPicker.class); - int id = 0; + if ((update).equals(request.getParameter(operation))) { + List<Object> 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 +1979,7 @@ public class FirewallDictionaryController { } fwTagPicker.setTagValues(header); if(fwTagPicker.getId() == 0){ - List<Object> duplicateData = commonClassDao.checkDuplicateEntry(fwTagPicker.getTagPickerName(), "tagPickerName", FWTagPicker.class); + List<Object> duplicateData = commonClassDao.checkDuplicateEntry(fwTagPicker.getTagPickerName(), tagPickerName, FWTagPicker.class); if(!duplicateData.isEmpty()){ duplicateflag = true; }else{ @@ -1979,22 +1995,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 +2020,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 +2029,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 +2048,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 +2058,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<String, Object> 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 +2073,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<String, Object> 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 +2088,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 +2105,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<Object> 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 +2121,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 +2156,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 +2181,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 +2190,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 +2211,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 +2221,77 @@ public class FirewallDictionaryController { } class TagGridValues{ - private ArrayList<Object> tags; + private List<Object> tags; - public ArrayList<Object> getTags() { + public List<Object> getTags() { return tags; } - public void setTags(ArrayList<Object> tags) { + public void setTags(List<Object> tags) { this.tags = tags; } } class AGGridData{ - private ArrayList<Object> attributes; + private List<Object> attributes; - public ArrayList<Object> getAttributes() { + public List<Object> getAttributes() { return attributes; } - public void setAttributes(ArrayList<Object> attributes) { + public void setAttributes(List<Object> attributes) { this.attributes = attributes; } } class TermListData{ - private ArrayList<Object> fromZoneDatas; - private ArrayList<Object> toZoneDatas; - private ArrayList<Object> sourceListDatas; - private ArrayList<Object> destinationListDatas; - private ArrayList<Object> sourceServiceDatas; - private ArrayList<Object> destinationServiceDatas; - private ArrayList<Object> actionListDatas; - public ArrayList<Object> getFromZoneDatas() { + private List<Object> fromZoneDatas; + private List<Object> toZoneDatas; + private List<Object> sourceListDatas; + private List<Object> destinationListDatas; + private List<Object> sourceServiceDatas; + private List<Object> destinationServiceDatas; + private List<Object> actionListDatas; + public List<Object> getFromZoneDatas() { return fromZoneDatas; } - public void setFromZoneDatas(ArrayList<Object> fromZoneDatas) { + public void setFromZoneDatas(List<Object> fromZoneDatas) { this.fromZoneDatas = fromZoneDatas; } - public ArrayList<Object> getToZoneDatas() { + public List<Object> getToZoneDatas() { return toZoneDatas; } - public void setToZoneDatas(ArrayList<Object> toZoneDatas) { + public void setToZoneDatas(List<Object> toZoneDatas) { this.toZoneDatas = toZoneDatas; } - public ArrayList<Object> getSourceListDatas() { + public List<Object> getSourceListDatas() { return sourceListDatas; } - public void setSourceListDatas(ArrayList<Object> sourceListDatas) { + public void setSourceListDatas(List<Object> sourceListDatas) { this.sourceListDatas = sourceListDatas; } - public ArrayList<Object> getDestinationListDatas() { + public List<Object> getDestinationListDatas() { return destinationListDatas; } - public void setDestinationListDatas(ArrayList<Object> destinationListDatas) { + public void setDestinationListDatas(List<Object> destinationListDatas) { this.destinationListDatas = destinationListDatas; } - public ArrayList<Object> getSourceServiceDatas() { + public List<Object> getSourceServiceDatas() { return sourceServiceDatas; } - public void setSourceServiceDatas(ArrayList<Object> sourceServiceDatas) { + public void setSourceServiceDatas(List<Object> sourceServiceDatas) { this.sourceServiceDatas = sourceServiceDatas; } - public ArrayList<Object> getDestinationServiceDatas() { + public List<Object> getDestinationServiceDatas() { return destinationServiceDatas; } - public void setDestinationServiceDatas(ArrayList<Object> destinationServiceDatas) { + public void setDestinationServiceDatas(List<Object> destinationServiceDatas) { this.destinationServiceDatas = destinationServiceDatas; } - public ArrayList<Object> getActionListDatas() { + public List<Object> getActionListDatas() { return actionListDatas; } - public void setActionListDatas(ArrayList<Object> actionListDatas) { + public void setActionListDatas(List<Object> actionListDatas) { this.actionListDatas = actionListDatas; } } diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.java index 526e28649..0170a71e0 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/MicroServiceDictionaryController.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.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -64,40 +63,52 @@ public class MicroServiceDictionaryController { private static final Logger LOGGER = FlexLogger.getLogger(MicroServiceDictionaryController.class); private static CommonClassDao commonClassDao; - - public static void setCommonClassDao(CommonClassDao commonClassDao) { - MicroServiceDictionaryController.commonClassDao = commonClassDao; - } - + + private static String successMapKey= "successMapKey"; + private static String successMsg = "success"; + private static String operation = "operation"; + private static String getDictionary = "getDictionary"; + private static String errorMsg = "error"; + private static String dictionaryDBQuery = "dictionaryDBQuery"; + private HashMap<String,MSAttributeObject > classMap; + private List<String> modelList = new ArrayList<>(); + private static String apiflag = "apiflag"; + private static String dictionaryFields ="dictionaryFields"; + private static String update = "update"; + private static String duplicateResponseString = "Duplicate"; + private static String successMessage = "Success"; + private static String utf8 = "UTF-8"; + private static String applicationJsonContentType = "application / json"; + private static String existsResponseString = "Exists"; + private static String microServiceModelsDictionaryDatas = "microServiceModelsDictionaryDatas"; + private static String modelName = "modelName"; + private static String microServiceModelsDictionaryData = "microServiceModelsDictionaryData"; + private static String description = "description"; + private static String version = "version"; + private static String classMapData = "classMap"; + /* + * This is an empty constructor + */ + public MicroServiceDictionaryController(){} + @Autowired public MicroServiceDictionaryController(CommonClassDao commonClassDao){ MicroServiceDictionaryController.commonClassDao = commonClassDao; } - - public MicroServiceDictionaryController(){} + public static void setCommonClassDao(CommonClassDao commonClassDao) { + MicroServiceDictionaryController.commonClassDao = commonClassDao; + } public UserInfo getUserInfo(String loginId){ - UserInfo name = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId); - return name; + return (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId); } - - private static String SUCCESSKEY= "successMapKey"; - private static String SUCCESS = "success"; - private static String OPERATION = "operation"; - private static String GETDICTIONARY = "getDictionary"; - private static String ERROR = "error"; - private static String DICTIONARYDBQUERY = "dictionaryDBQuery"; - private HashMap<String,MSAttributeObject > classMap; - private List<String> modelList = new ArrayList<>(); - - MSModelUtils utils = new MSModelUtils(XACMLPapServlet.getMsOnapName(), XACMLPapServlet.getMsPolicyName()); private MicroServiceModels newModel; @RequestMapping(value={"/get_DCAEUUIDDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getDCAEUUIDDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getDCAEUUIDDictionaryByNameEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); @@ -112,31 +123,31 @@ public class MicroServiceDictionaryController { } @RequestMapping(value={"/get_DCAEUUIDData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getDCAEUUIDDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getDCAEUUIDDictionaryEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("dcaeUUIDDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(DCAEuuid.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); - response.addHeader(SUCCESSKEY, SUCCESS); - response.addHeader(OPERATION, GETDICTIONARY); + response.addHeader(successMapKey, successMsg); + response.addHeader(operation, getDictionary); response.getWriter().write(j.toString()); } catch (Exception e){ response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - response.addHeader(ERROR, DICTIONARYDBQUERY); + response.addHeader(errorMsg, dictionaryDBQuery); LOGGER.error(e); } } @RequestMapping(value={"/ms_dictionary/save_dcaeUUID"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView saveDCAEUUIDDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView saveDCAEUUIDDictionary(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(); @@ -144,14 +155,13 @@ public class MicroServiceDictionaryController { JsonNode root = mapper.readTree(request.getReader()); DCAEuuid dCAEuuid; if (fromAPI) { - dCAEuuid = (DCAEuuid)mapper.readValue(root.get("dictionaryFields").toString(), DCAEuuid.class); + dCAEuuid = (DCAEuuid)mapper.readValue(root.get(dictionaryFields).toString(), DCAEuuid.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<Object> duplicateData = commonClassDao.checkDuplicateEntry(dCAEuuid.getName(), "name", DCAEuuid.class); - int id = 0; DCAEuuid data = (DCAEuuid) duplicateData.get(0); - id = data.getId(); + int id = data.getId(); if(id==0){ isFakeUpdate=true; dCAEuuid.setId(1); @@ -176,26 +186,26 @@ public class MicroServiceDictionaryController { } String responseString = ""; if(duplicateflag){ - responseString = "Duplicate"; + responseString = duplicateResponseString; }else{ responseString = mapper.writeValueAsString(commonClassDao.getData(DCAEuuid.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 = successMessage; } } 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("{dcaeUUIDDictionaryDatas: " + responseString + "}"); @@ -203,8 +213,8 @@ public class MicroServiceDictionaryController { return null; } }catch (Exception e){ - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); LOGGER.error(e); @@ -213,16 +223,16 @@ public class MicroServiceDictionaryController { } @RequestMapping(value={"/ms_dictionary/remove_dcaeuuid"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removeDCAEUUIDDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException { + public ModelAndView removeDCAEUUIDDictionary(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()); DCAEuuid dCAEuuid = (DCAEuuid)mapper.readValue(root.get("data").toString(), DCAEuuid.class); commonClassDao.delete(dCAEuuid); - 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(); @@ -234,8 +244,8 @@ public class MicroServiceDictionaryController { } catch (Exception e){ LOGGER.error(e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -244,7 +254,7 @@ public class MicroServiceDictionaryController { @RequestMapping(value={"/get_MicroServiceConfigNameDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getMicroServiceConfigNameByNameDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getMicroServiceConfigNameByNameDictionaryEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); @@ -261,31 +271,31 @@ public class MicroServiceDictionaryController { @RequestMapping(value={"/get_MicroServiceConfigNameData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getMicroServiceConfigNameDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getMicroServiceConfigNameDictionaryEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("microServiceCongigNameDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(MicroServiceConfigName.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); - response.addHeader(SUCCESSKEY, SUCCESS); - response.addHeader(OPERATION, GETDICTIONARY); + response.addHeader(successMapKey, successMsg); + response.addHeader(operation, getDictionary); response.getWriter().write(j.toString()); } catch (Exception e){ response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - response.addHeader(ERROR, DICTIONARYDBQUERY); + response.addHeader(errorMsg, dictionaryDBQuery); LOGGER.error(e); } } @RequestMapping(value={"/ms_dictionary/save_configName"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView saveMicroServiceConfigNameDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView saveMicroServiceConfigNameDictionary(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(); @@ -293,14 +303,13 @@ public class MicroServiceDictionaryController { JsonNode root = mapper.readTree(request.getReader()); MicroServiceConfigName microServiceConfigName; if (fromAPI) { - microServiceConfigName = (MicroServiceConfigName)mapper.readValue(root.get("dictionaryFields").toString(), MicroServiceConfigName.class); + microServiceConfigName = (MicroServiceConfigName)mapper.readValue(root.get(dictionaryFields).toString(), MicroServiceConfigName.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<Object> duplicateData = commonClassDao.checkDuplicateEntry(microServiceConfigName.getName(), "name", MicroServiceConfigName.class); - int id = 0; MicroServiceConfigName data = (MicroServiceConfigName) duplicateData.get(0); - id = data.getId(); + int id = data.getId(); if(id==0){ isFakeUpdate=true; @@ -326,26 +335,26 @@ public class MicroServiceDictionaryController { } String responseString = ""; if(duplicateflag){ - responseString = "Duplicate"; + responseString = duplicateResponseString; }else{ responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceConfigName.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 = successMessage; } } 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("{microServiceCongigNameDictionaryDatas: " + responseString + "}"); @@ -353,8 +362,8 @@ public class MicroServiceDictionaryController { return null; } }catch (Exception e){ - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); LOGGER.error(e); @@ -363,16 +372,16 @@ public class MicroServiceDictionaryController { } @RequestMapping(value={"/ms_dictionary/remove_msConfigName"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removeMicroServiceConfigNameDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException { + public ModelAndView removeMicroServiceConfigNameDictionary(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()); MicroServiceConfigName microServiceConfigName = (MicroServiceConfigName)mapper.readValue(root.get("data").toString(), MicroServiceConfigName.class); commonClassDao.delete(microServiceConfigName); - 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(); @@ -384,8 +393,8 @@ public class MicroServiceDictionaryController { } catch (Exception e){ LOGGER.error(e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -393,7 +402,7 @@ public class MicroServiceDictionaryController { } @RequestMapping(value={"/get_MicroServiceLocationDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getMicroServiceLocationByNameDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getMicroServiceLocationByNameDictionaryEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); @@ -408,31 +417,31 @@ public class MicroServiceDictionaryController { } @RequestMapping(value={"/get_MicroServiceLocationData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getMicroServiceLocationDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getMicroServiceLocationDictionaryEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("microServiceLocationDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(MicroServiceLocation.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); - response.addHeader(SUCCESSKEY, SUCCESS); - response.addHeader(OPERATION, GETDICTIONARY); + response.addHeader(successMapKey, successMsg); + response.addHeader(operation, getDictionary); response.getWriter().write(j.toString()); } catch (Exception e){ response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - response.addHeader(ERROR, DICTIONARYDBQUERY); + response.addHeader(errorMsg, dictionaryDBQuery); LOGGER.error(e); } } @RequestMapping(value={"/ms_dictionary/save_location"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView saveMicroServiceLocationDictionary(HttpServletRequest request, HttpServletResponse response)throws UnsupportedEncodingException, IOException{ + public ModelAndView saveMicroServiceLocationDictionary(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(); @@ -440,14 +449,13 @@ public class MicroServiceDictionaryController { JsonNode root = mapper.readTree(request.getReader()); MicroServiceLocation microServiceLocation; if (fromAPI) { - microServiceLocation = (MicroServiceLocation)mapper.readValue(root.get("dictionaryFields").toString(), MicroServiceLocation.class); + microServiceLocation = (MicroServiceLocation)mapper.readValue(root.get(dictionaryFields).toString(), MicroServiceLocation.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<Object> duplicateData = commonClassDao.checkDuplicateEntry(microServiceLocation.getName(), "name", MicroServiceLocation.class); - int id = 0; MicroServiceLocation data = (MicroServiceLocation) duplicateData.get(0); - id = data.getId(); + int id = data.getId(); if(id==0){ isFakeUpdate=true; @@ -473,26 +481,26 @@ public class MicroServiceDictionaryController { } String responseString = ""; if(duplicateflag){ - responseString = "Duplicate"; + responseString = duplicateResponseString; }else{ responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceLocation.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 = successMessage; } } 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("{microServiceLocationDictionaryDatas: " + responseString + "}"); @@ -500,8 +508,8 @@ public class MicroServiceDictionaryController { return null; } }catch (Exception e){ - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); LOGGER.error(e); @@ -510,16 +518,16 @@ public class MicroServiceDictionaryController { } @RequestMapping(value={"/ms_dictionary/remove_msLocation"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removeMicroServiceLocationDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException { + public ModelAndView removeMicroServiceLocationDictionary(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()); MicroServiceLocation microServiceLocation = (MicroServiceLocation)mapper.readValue(root.get("data").toString(), MicroServiceLocation.class); commonClassDao.delete(microServiceLocation); - 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(); @@ -531,8 +539,8 @@ public class MicroServiceDictionaryController { } catch (Exception e){ LOGGER.error(e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -540,7 +548,7 @@ public class MicroServiceDictionaryController { } @RequestMapping(value={"/get_MicroServiceAttributeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getMicroServiceAttributeByNameDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getMicroServiceAttributeByNameDictionaryEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); @@ -555,31 +563,31 @@ public class MicroServiceDictionaryController { } @RequestMapping(value={"/get_MicroServiceAttributeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getMicroServiceAttributeDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getMicroServiceAttributeDictionaryEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("microServiceAttributeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(MicroServiceAttribute.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); - response.addHeader(SUCCESSKEY, SUCCESS); - response.addHeader(OPERATION, GETDICTIONARY); + response.addHeader(successMapKey, successMsg); + response.addHeader(operation, getDictionary); response.getWriter().write(j.toString()); } catch (Exception e){ response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - response.addHeader(ERROR, DICTIONARYDBQUERY); + response.addHeader(errorMsg, dictionaryDBQuery); LOGGER.error(e); } } @RequestMapping(value={"/ms_dictionary/save_modelAttribute"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView saveMicroServiceAttributeDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView saveMicroServiceAttributeDictionary(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; } @@ -589,10 +597,10 @@ public class MicroServiceDictionaryController { MicroServiceAttribute microServiceAttribute; if (fromAPI) { - microServiceAttribute = (MicroServiceAttribute)mapper.readValue(root.get("dictionaryFields").toString(), MicroServiceAttribute.class); + microServiceAttribute = (MicroServiceAttribute)mapper.readValue(root.get(dictionaryFields).toString(), MicroServiceAttribute.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))) { MicroServiceAttribute initialAttribute = (MicroServiceAttribute)mapper.readValue(root.get("initialFields").toString(), MicroServiceAttribute.class); String checkValue = initialAttribute.getName() + ":" + initialAttribute.getValue() + ":" + initialAttribute.getModelName(); @@ -622,22 +630,22 @@ public class MicroServiceDictionaryController { String responseString = ""; if(duplicateflag){ - responseString = "Duplicate"; + responseString = duplicateResponseString; }else{ responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceAttribute.class)); } if (fromAPI) { - if (responseString!=null && !responseString.equals("Duplicate")) { - responseString = "Success"; + if (responseString!=null && !(duplicateResponseString).equals(responseString)) { + responseString = successMessage; } 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("{microServiceAttributeDictionaryDatas: " + responseString + "}"); @@ -646,8 +654,8 @@ public class MicroServiceDictionaryController { } } catch (Exception e){ - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); LOGGER.error(e); @@ -656,16 +664,16 @@ public class MicroServiceDictionaryController { } @RequestMapping(value={"/ms_dictionary/remove_modelAttribute"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removeMicroServiceAttributeDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView removeMicroServiceAttributeDictionary(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()); MicroServiceAttribute microServiceAttribute = (MicroServiceAttribute)mapper.readValue(root.get("data").toString(), MicroServiceAttribute.class); commonClassDao.delete(microServiceAttribute); - 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(); @@ -677,8 +685,8 @@ public class MicroServiceDictionaryController { } catch (Exception e){ LOGGER.error(e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -687,11 +695,11 @@ public class MicroServiceDictionaryController { @RequestMapping(value={"/get_MicroServiceModelsDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getMicroServiceModelsDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getMicroServiceModelsDictionaryByNameEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); - model.put("microServiceModelsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataByColumn(MicroServiceModels.class, "modelName"))); + model.put(microServiceModelsDictionaryDatas, mapper.writeValueAsString(commonClassDao.getDataByColumn(MicroServiceModels.class, modelName))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.getWriter().write(j.toString()); @@ -708,13 +716,13 @@ public class MicroServiceDictionaryController { ObjectMapper mapper = new ObjectMapper(); JsonNode root = mapper.readTree(request.getReader()); String modelName = null; - if (root.get("microServiceModelsDictionaryData").has("modelName")){ - modelName = root.get("microServiceModelsDictionaryData").get("modelName").asText().replace("\"", ""); + if (root.get(microServiceModelsDictionaryData).has(modelName)){ + modelName = root.get(microServiceModelsDictionaryData).get(modelName).asText().replace("\"", ""); } if (modelName!=null){ - model.put("microServiceModelsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getDataById(MicroServiceModels.class, "modelName", modelName))); + model.put(microServiceModelsDictionaryDatas, mapper.writeValueAsString(commonClassDao.getDataById(MicroServiceModels.class, modelName, modelName))); } else{ - model.put(ERROR, "No model name given"); + model.put(errorMsg, "No model name given"); } JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); @@ -726,26 +734,26 @@ public class MicroServiceDictionaryController { } @RequestMapping(value={"/get_MicroServiceModelsData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getMicroServiceModelsDictionaryEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getMicroServiceModelsDictionaryEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); - model.put("microServiceModelsDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(MicroServiceModels.class))); + model.put(microServiceModelsDictionaryDatas, mapper.writeValueAsString(commonClassDao.getData(MicroServiceModels.class))); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); - response.addHeader(SUCCESSKEY, SUCCESS); - response.addHeader(OPERATION, GETDICTIONARY); + response.addHeader(successMapKey, successMsg); + response.addHeader(operation, getDictionary); response.getWriter().write(j.toString()); } catch (Exception e){ response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - response.addHeader(ERROR, DICTIONARYDBQUERY); + response.addHeader(errorMsg, dictionaryDBQuery); LOGGER.error(e); } } @RequestMapping(value={"/get_MicroServiceModelsDataServiceVersion"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getMicroServiceModelsDictionaryEntityDataServiceVersion(HttpServletRequest request, HttpServletResponse response){ + public void getMicroServiceModelsDictionaryEntityDataServiceVersion(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); @@ -757,7 +765,7 @@ public class MicroServiceDictionaryController { data.add(msmodel.getModelName() + "-v" + msmodel.getVersion()); } } - model.put("microServiceModelsDictionaryDatas", mapper.writeValueAsString(data)); + model.put(microServiceModelsDictionaryDatas, mapper.writeValueAsString(data)); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.addHeader("successMapKey", "success"); @@ -773,32 +781,32 @@ public class MicroServiceDictionaryController { } @RequestMapping(value={"/get_MicroServiceModelsDataByClass"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getMicroServiceModelsDictionaryClassEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getMicroServiceModelsDictionaryClassEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("microServiceModelsDictionaryClassDatas", mapper.writeValueAsString(modelList)); JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); - response.addHeader(SUCCESSKEY, SUCCESS); - response.addHeader(OPERATION, GETDICTIONARY); + response.addHeader(successMapKey, successMsg); + response.addHeader(operation, getDictionary); response.getWriter().write(j.toString()); } catch (Exception e){ response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - response.addHeader(ERROR, DICTIONARYDBQUERY); + response.addHeader(errorMsg, dictionaryDBQuery); LOGGER.error(e); } } @RequestMapping(value={"/ms_dictionary/save_model"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView saveMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView saveMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ try { boolean duplicateflag = false; boolean fromAPI = false; this.newModel = new MicroServiceModels(); - 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(); @@ -811,23 +819,22 @@ public class MicroServiceDictionaryController { JsonNode dataType = root.get("modelType"); String modelType= dataType.toString(); if(modelType.contains("yml")){ - if (root.has("microServiceModelsDictionaryData")){ - if (root.get("microServiceModelsDictionaryData").has("description")){ - microServiceModels.setDescription(root.get("microServiceModelsDictionaryData").get("description").asText().replace("\"", "")); + if (root.has(microServiceModelsDictionaryData)){ + if (root.get(microServiceModelsDictionaryData).has(description)){ + microServiceModels.setDescription(root.get(microServiceModelsDictionaryData).get(description).asText().replace("\"", "")); } - if (root.get("microServiceModelsDictionaryData").has("modelName")){ - microServiceModels.setModelName(root.get("microServiceModelsDictionaryData").get("modelName").asText().replace("\"", "")); + if (root.get(microServiceModelsDictionaryData).has(modelName)){ + microServiceModels.setModelName(root.get(microServiceModelsDictionaryData).get(modelName).asText().replace("\"", "")); this.newModel.setModelName(microServiceModels.getModelName()); } - if (root.get("microServiceModelsDictionaryData").has("version")){ - microServiceModels.setVersion(root.get("microServiceModelsDictionaryData").get("version").asText().replace("\"", "")); + if (root.get(microServiceModelsDictionaryData).has(version)){ + microServiceModels.setVersion(root.get(microServiceModelsDictionaryData).get(version).asText().replace("\"", "")); this.newModel.setVersion(microServiceModels.getVersion()); } } - MSAttributeObject mainClass = null; classMap = new HashMap<>(); - JsonNode data = root.get("classMap"); + JsonNode data = root.get(classMapData); ObjectMapper mapper1 = new ObjectMapper(); String data1 = data.toString().substring(1, data.toString().length()-1); data1 = data1.replace("\\", ""); @@ -842,7 +849,7 @@ public class MicroServiceDictionaryController { } userId = root.get("userid").textValue(); - mainClass = classMap.get(this.newModel.getModelName()); + MSAttributeObject mainClass = classMap.get(this.newModel.getModelName()); this.newModel.setDependency("[]"); String value = new Gson().toJson(mainClass.getSubClass()); this.newModel.setSub_attributes(value); @@ -859,11 +866,11 @@ public class MicroServiceDictionaryController { }else{ if (fromAPI) { - microServiceModels = (MicroServiceModels)mapper.readValue(root.get("dictionaryFields").toString(), MicroServiceModels.class); + microServiceModels = (MicroServiceModels)mapper.readValue(root.get(dictionaryFields).toString(), MicroServiceModels.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))) { String checkName = microServiceModels.getModelName() + ":" + microServiceModels.getVersion(); List<Object> duplicateData = commonClassDao.checkDuplicateEntry(checkName, "modelName:version", MicroServiceModels.class); int id = 0; @@ -876,22 +883,22 @@ public class MicroServiceDictionaryController { } } else { - if (root.has("microServiceModelsDictionaryData")){ - if (root.get("microServiceModelsDictionaryData").has("description")){ - microServiceModels.setDescription(root.get("microServiceModelsDictionaryData").get("description").asText().replace("\"", "")); + if (root.has(microServiceModelsDictionaryData)){ + if (root.get(microServiceModelsDictionaryData).has(description)){ + microServiceModels.setDescription(root.get(microServiceModelsDictionaryData).get(description).asText().replace("\"", "")); } - if (root.get("microServiceModelsDictionaryData").has("modelName")){ - microServiceModels.setModelName(root.get("microServiceModelsDictionaryData").get("modelName").asText().replace("\"", "")); + if (root.get(microServiceModelsDictionaryData).has(modelName)){ + microServiceModels.setModelName(root.get(microServiceModelsDictionaryData).get(modelName).asText().replace("\"", "")); this.newModel.setModelName(microServiceModels.getModelName()); } - if (root.get("microServiceModelsDictionaryData").has("version")){ - microServiceModels.setVersion(root.get("microServiceModelsDictionaryData").get("version").asText().replace("\"", "")); + if (root.get(microServiceModelsDictionaryData).has(version)){ + microServiceModels.setVersion(root.get(microServiceModelsDictionaryData).get(version).asText().replace("\"", "")); this.newModel.setVersion(microServiceModels.getVersion()); } } - if(root.has("classMap")){ + if(root.has(classMapData)){ classMap = new HashMap<>(); - JsonNode data = root.get("classMap"); + JsonNode data = root.get(classMapData); ObjectMapper mapper1 = new ObjectMapper(); String data1 = data.toString().substring(1, data.toString().length()-1); data1 = data1.replace("\\", ""); @@ -932,22 +939,22 @@ public class MicroServiceDictionaryController { } String responseString = ""; if(duplicateflag){ - responseString = "Duplicate"; + responseString = duplicateResponseString; }else{ responseString = mapper.writeValueAsString(commonClassDao.getData(MicroServiceModels.class)); } if (fromAPI) { - if (responseString!=null && !responseString.equals("Duplicate")) { - responseString = "Success"; + if (responseString!=null && !(duplicateResponseString).equals(responseString)) { + responseString = successMessage; } 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("{microServiceModelsDictionaryDatas: " + responseString + "}"); @@ -955,8 +962,8 @@ public class MicroServiceDictionaryController { return null; } }catch (Exception e){ - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); LOGGER.error(e); @@ -965,16 +972,16 @@ public class MicroServiceDictionaryController { } @RequestMapping(value={"/ms_dictionary/remove_msModel"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removeMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException { + public ModelAndView removeMicroServiceModelsDictionary(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()); MicroServiceModels microServiceModels = (MicroServiceModels)mapper.readValue(root.get("data").toString(), MicroServiceModels.class); commonClassDao.delete(microServiceModels); - 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,8 +993,8 @@ public class MicroServiceDictionaryController { } catch (Exception e){ LOGGER.error(e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -995,17 +1002,14 @@ public class MicroServiceDictionaryController { } private void addValuesToNewModel(HashMap<String,MSAttributeObject > classMap) { - new MicroServiceModels(); //Loop through the classmap and pull out the required info for the new file. - MSAttributeObject mainClass = null; - ArrayList<String> dependency = null; String subAttribute = null; - mainClass = classMap.get(this.newModel.getModelName()); + MSAttributeObject mainClass = classMap.get(this.newModel.getModelName()); if (mainClass !=null){ String dependTemp = StringUtils.replaceEach(mainClass.getDependency(), new String[]{"[", "]", " "}, new String[]{"", "", ""}); - dependency = new ArrayList<String>(Arrays.asList(dependTemp.split(","))); + ArrayList<String> dependency = new ArrayList<>(Arrays.asList(dependTemp.split(","))); dependency = getFullDependencyList(dependency); for (String element : dependency){ MSAttributeObject temp = new MSAttributeObject(); @@ -1042,7 +1046,7 @@ public class MicroServiceDictionaryController { if (classMap.containsKey(element)){ MSAttributeObject value = classMap.get(element); String rawValue = StringUtils.replaceEach(value.getDependency(), new String[]{"[", "]"}, new String[]{"", ""}); - workingList = new ArrayList<String>(Arrays.asList(rawValue.split(","))); + workingList = new ArrayList<>(Arrays.asList(rawValue.split(","))); for(String depend : workingList){ if (!returnList.contains(depend) && !depend.isEmpty()){ returnList.add(depend.trim()); diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PolicyScopeDictionaryController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PolicyScopeDictionaryController.java index 44ab4a3f6..2715d581b 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PolicyScopeDictionaryController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PolicyScopeDictionaryController.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.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -59,23 +58,39 @@ public class PolicyScopeDictionaryController { private static final Logger LOGGER = FlexLogger.getLogger(PolicyScopeDictionaryController.class); private static CommonClassDao commonClassDao; - + private static String successMapKey = "successMapKey"; + private static String exceptionOccured = "Exception Occured"; + 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 groupPolicyScopeListData1 = "groupPolicyScopeListData1"; + private static String policyScope= "PolicyScope"; + private static String update = "update"; + private static String duplicateResponseString = "Duplicate"; + private static String successMsg = "Success"; + private static String existsResponseString = "Exists"; + private static String utf8 = "UTF-8"; + private static String applicationJsonContentType = "application / json"; + /* + * This is an empty constructor + */ + public PolicyScopeDictionaryController(){} + @Autowired public PolicyScopeDictionaryController(CommonClassDao commonClassDao){ PolicyScopeDictionaryController.commonClassDao = commonClassDao; } - public PolicyScopeDictionaryController(){} - - private static String SUCCESSMAPKEY = "successMapKey"; - + 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_GroupPolicyScopeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getGroupPolicyScopeEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + public void getGroupPolicyScopeEntityDataByName(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); @@ -85,50 +100,49 @@ public class PolicyScopeDictionaryController { response.getWriter().write(j.toString()); } catch (Exception e){ - LOGGER.error("Exception Occured"+e); + LOGGER.error(exceptionOccured+e); } } @RequestMapping(value={"/get_GroupPolicyScopeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getGroupPolicyScopeEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getGroupPolicyScopeEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("groupPolicyScopeListDatas", mapper.writeValueAsString(commonClassDao.getData(GroupPolicyScopeList.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){ response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - response.addHeader("error", "dictionaryDBQuery"); + response.addHeader(errorMsg, dictionaryDBQuery); LOGGER.error(e); } } @RequestMapping(value={"/ps_dictionary/save_psGroupPolicyScope"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView savePSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView savePSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ try { boolean duplicateflag = false; boolean isFakeUpdate = false; boolean duplicateGroupFlag = 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(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); - //GroupPolicyScopeList gpdata = (GroupPolicyScopeList)mapper.readValue(root.get("groupPolicyScopeListData").toString(), GroupPolicyScopeList.class); GroupPolicyScopeList gpdata = null; GroupPolicyScope groupData = null; if (fromAPI) { gpdata = (GroupPolicyScopeList)mapper.readValue(root.get("dictionaryFields").toString(), GroupPolicyScopeList.class); try{ - groupData = (GroupPolicyScope)mapper.readValue(root.get("groupPolicyScopeListData1").toString(), GroupPolicyScope.class); + groupData = (GroupPolicyScope)mapper.readValue(root.get(groupPolicyScopeListData1).toString(), GroupPolicyScope.class); }catch(Exception e){ groupData = new GroupPolicyScope(); groupData.setResource(root.get("dictionaryFields").get("resource").toString().replace("\"", "")); @@ -138,13 +152,13 @@ public class PolicyScopeDictionaryController { LOGGER.error(e); } - if(!gpdata.getGroupName().startsWith("PolicyScope")){ + if(!gpdata.getGroupName().startsWith(policyScope)){ String name = "PolicyScope_" + gpdata.getGroupName(); gpdata.setGroupName(name); } //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<Object> duplicateData = commonClassDao.checkDuplicateEntry(gpdata.getGroupName(), "name", GroupPolicyScopeList.class); int id = 0; @@ -165,23 +179,22 @@ public class PolicyScopeDictionaryController { gpdata = (GroupPolicyScopeList)mapper.readValue(root.get("groupPolicyScopeListData").toString(), GroupPolicyScopeList.class); try{ - groupData = (GroupPolicyScope)mapper.readValue(root.get("groupPolicyScopeListData1").toString(), GroupPolicyScope.class); + groupData = (GroupPolicyScope)mapper.readValue(root.get(groupPolicyScopeListData1).toString(), GroupPolicyScope.class); }catch(Exception e){ LOGGER.error(e); groupData = new GroupPolicyScope(); - groupData.setResource(root.get("groupPolicyScopeListData1").get("resource").toString().replace("\"", "")); - groupData.setClosedloop(root.get("groupPolicyScopeListData1").get("closedloop").toString().replace("\"", "")); - groupData.setService(root.get("groupPolicyScopeListData1").get("service").toString().replace("\"", "")); - groupData.setType(root.get("groupPolicyScopeListData1").get("type").toString().replace("\"", "")); + groupData.setResource(root.get(groupPolicyScopeListData1).get("resource").toString().replace("\"", "")); + groupData.setClosedloop(root.get(groupPolicyScopeListData1).get("closedloop").toString().replace("\"", "")); + groupData.setService(root.get(groupPolicyScopeListData1).get("service").toString().replace("\"", "")); + groupData.setType(root.get(groupPolicyScopeListData1).get("type").toString().replace("\"", "")); } - if(!gpdata.getGroupName().startsWith("PolicyScope")){ + if(!gpdata.getGroupName().startsWith(policyScope)){ String name = "PolicyScope_" + gpdata.getGroupName(); gpdata.setGroupName(name); } } ArrayList<String> valueList = new ArrayList<>(); - String list = null; String resourceValue = groupData.getResource(); String typeValue = groupData.getType(); String serviceValue = groupData.getService(); @@ -190,9 +203,9 @@ public class PolicyScopeDictionaryController { valueList.add("service=" + serviceValue); valueList.add("type=" + typeValue); valueList.add("closedLoopControlName=" + closedLoopValue); - list = StringUtils.replaceEach(valueList.toString(), new String[]{"[", "]", " "}, new String[]{"", "", ""}); + String list = StringUtils.replaceEach(valueList.toString(), new String[]{"[", "]", " "}, new String[]{"", "", ""}); gpdata.setGroupList(list); - if(!gpdata.getGroupName().startsWith("PolicyScope")){ + if(!gpdata.getGroupName().startsWith(policyScope)){ String name = "PolicyScope_" + gpdata.getGroupName(); gpdata.setGroupName(name); } @@ -220,7 +233,7 @@ public class PolicyScopeDictionaryController { } String responseString = ""; if(duplicateflag){ - responseString = "Duplicate"; + responseString = duplicateResponseString; }else if(duplicateGroupFlag){ responseString = "DuplicateGroup"; }else{ @@ -228,11 +241,11 @@ public class PolicyScopeDictionaryController { } if (fromAPI) { - if (responseString!=null && !responseString.equals("Duplicate") && !responseString.equals("DuplicateGroup")) { + if (responseString!=null && !(duplicateResponseString).equals(responseString) && !("DuplicateGroup").equals(responseString)) { if(isFakeUpdate){ - responseString = "Exists"; + responseString = existsResponseString; } else { - responseString = "Success"; + responseString = successMsg; } } @@ -241,9 +254,9 @@ public class PolicyScopeDictionaryController { 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("{groupPolicyScopeListDatas: " + responseString + "}"); @@ -252,26 +265,25 @@ public class PolicyScopeDictionaryController { } }catch (Exception e){ LOGGER.error(e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); - } return null; } @RequestMapping(value={"/ps_dictionary/remove_GroupPolicyScope"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removePSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException { + public ModelAndView removePSGroupScopeDictionary(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()); GroupPolicyScopeList onapData = (GroupPolicyScopeList)mapper.readValue(root.get("data").toString(), GroupPolicyScopeList.class); commonClassDao.delete(onapData); - 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(); @@ -282,9 +294,9 @@ public class PolicyScopeDictionaryController { 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()); } @@ -292,7 +304,7 @@ public class PolicyScopeDictionaryController { } @RequestMapping(value={"/get_PSClosedLoopDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getPSClosedLoopEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + public void getPSClosedLoopEntityDataByName(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); @@ -302,36 +314,36 @@ public class PolicyScopeDictionaryController { response.getWriter().write(j.toString()); } catch (Exception e){ - LOGGER.error("Exception Occured"+e); + LOGGER.error(exceptionOccured+e); } } @RequestMapping(value={"/get_PSClosedLoopData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getPSClosedLoopEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getPSClosedLoopEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("psClosedLoopDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PolicyScopeClosedLoop.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){ response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - response.addHeader("error", "dictionaryDBQuery"); + response.addHeader(errorMsg, dictionaryDBQuery); LOGGER.error(e); } } @RequestMapping(value={"/ps_dictionary/save_psClosedLoop"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView savePSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView savePSClosedLoopDictionary(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(); @@ -342,7 +354,7 @@ public class PolicyScopeDictionaryController { onapData = (PolicyScopeClosedLoop)mapper.readValue(root.get("dictionaryFields").toString(), PolicyScopeClosedLoop.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<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeClosedLoop.class); int id = 0; for (int i =0; i< duplicateData.size(); i++){ @@ -375,26 +387,26 @@ public class PolicyScopeDictionaryController { } String responseString = ""; if(duplicateflag){ - responseString = "Duplicate"; + responseString = duplicateResponseString; }else{ responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeClosedLoop.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("{psClosedLoopDictionaryDatas: " + responseString + "}"); @@ -405,8 +417,8 @@ public class PolicyScopeDictionaryController { } }catch (Exception e){ - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); LOGGER.error(e); @@ -415,16 +427,16 @@ public class PolicyScopeDictionaryController { } @RequestMapping(value={"/ps_dictionary/remove_PSClosedLoop"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removePSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException { + public ModelAndView removePSClosedLoopDictionary(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()); PolicyScopeClosedLoop onapData = (PolicyScopeClosedLoop)mapper.readValue(root.get("data").toString(), PolicyScopeClosedLoop.class); commonClassDao.delete(onapData); - 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(); @@ -435,9 +447,9 @@ public class PolicyScopeDictionaryController { 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()); } @@ -445,7 +457,7 @@ public class PolicyScopeDictionaryController { } @RequestMapping(value={"/get_PSServiceDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getPSServiceEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + public void getPSServiceEntityDataByName(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); @@ -455,36 +467,36 @@ public class PolicyScopeDictionaryController { response.getWriter().write(j.toString()); } catch (Exception e){ - LOGGER.error("Exception Occured"+e); + LOGGER.error(exceptionOccured+e); } } @RequestMapping(value={"/get_PSServiceData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getPSServiceEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getPSServiceEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("psServiceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PolicyScopeService.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){ response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - response.addHeader("error", "dictionaryDBQuery"); + response.addHeader(errorMsg, dictionaryDBQuery); LOGGER.error(e); } } @RequestMapping(value={"/ps_dictionary/save_psService"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView savePSServiceDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView savePSServiceDictionary(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(); @@ -495,7 +507,7 @@ public class PolicyScopeDictionaryController { onapData = (PolicyScopeService)mapper.readValue(root.get("dictionaryFields").toString(), PolicyScopeService.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<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeService.class); int id = 0; for (int i =0; i< duplicateData.size(); i++){ @@ -527,17 +539,17 @@ public class PolicyScopeDictionaryController { String responseString = ""; if(duplicateflag){ - responseString = "Duplicate"; + responseString = duplicateResponseString; }else{ responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeService.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(); @@ -545,9 +557,9 @@ public class PolicyScopeDictionaryController { 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("{psServiceDictionaryDatas: " + responseString + "}"); @@ -555,8 +567,8 @@ public class PolicyScopeDictionaryController { return null; } }catch (Exception e){ - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); LOGGER.error(e); @@ -565,16 +577,16 @@ public class PolicyScopeDictionaryController { } @RequestMapping(value={"/ps_dictionary/remove_PSService"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removePSServiceDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView removePSServiceDictionary(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()); PolicyScopeService onapData = (PolicyScopeService)mapper.readValue(root.get("data").toString(), PolicyScopeService.class); commonClassDao.delete(onapData); - 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(); @@ -585,9 +597,9 @@ public class PolicyScopeDictionaryController { 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()); } @@ -595,7 +607,7 @@ public class PolicyScopeDictionaryController { } @RequestMapping(value={"/get_PSTypeDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getPSTypeEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + public void getPSTypeEntityDataByName(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); @@ -605,36 +617,36 @@ public class PolicyScopeDictionaryController { response.getWriter().write(j.toString()); } catch (Exception e){ - LOGGER.error("Exception Occured"+e); + LOGGER.error(exceptionOccured+e); } } @RequestMapping(value={"/get_PSTypeData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getPSTypeEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getPSTypeEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("psTypeDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PolicyScopeType.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){ response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - response.addHeader("error", "dictionaryDBQuery"); + response.addHeader(errorMsg, dictionaryDBQuery); LOGGER.error(e); } } @RequestMapping(value={"/ps_dictionary/save_psType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView savePSTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView savePSTypeDictionary(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(); @@ -645,7 +657,7 @@ public class PolicyScopeDictionaryController { onapData = (PolicyScopeType)mapper.readValue(root.get("dictionaryFields").toString(), PolicyScopeType.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<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeType.class); int id = 0; for (int i =0; i< duplicateData.size(); i++){ @@ -678,17 +690,17 @@ public class PolicyScopeDictionaryController { } String responseString = ""; if(duplicateflag){ - responseString = "Duplicate"; + responseString = duplicateResponseString; }else{ responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeType.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; } } @@ -698,9 +710,9 @@ public class PolicyScopeDictionaryController { } 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("{psTypeDictionaryDatas: " + responseString + "}"); @@ -711,8 +723,8 @@ public class PolicyScopeDictionaryController { } }catch (Exception e){ - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); LOGGER.error(e); @@ -721,16 +733,16 @@ public class PolicyScopeDictionaryController { } @RequestMapping(value={"/ps_dictionary/remove_PSType"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removePSTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException { + public ModelAndView removePSTypeDictionary(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()); PolicyScopeType onapData = (PolicyScopeType)mapper.readValue(root.get("data").toString(), PolicyScopeType.class); commonClassDao.delete(onapData); - 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(); @@ -741,9 +753,9 @@ public class PolicyScopeDictionaryController { 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()); } @@ -751,7 +763,7 @@ public class PolicyScopeDictionaryController { } @RequestMapping(value={"/get_PSResourceDataByName"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getPSResourceEntityDataByName(HttpServletRequest request, HttpServletResponse response){ + public void getPSResourceEntityDataByName(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); @@ -761,37 +773,37 @@ public class PolicyScopeDictionaryController { response.getWriter().write(j.toString()); } catch (Exception e){ - LOGGER.error("Exception Occured"+e); + LOGGER.error(exceptionOccured+e); } } @RequestMapping(value={"/get_PSResourceData"}, method={org.springframework.web.bind.annotation.RequestMethod.GET} , produces=MediaType.APPLICATION_JSON_VALUE) - public void getPSResourceEntityData(HttpServletRequest request, HttpServletResponse response){ + public void getPSResourceEntityData(HttpServletResponse response){ try{ Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); model.put("psResourceDictionaryDatas", mapper.writeValueAsString(commonClassDao.getData(PolicyScopeResource.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(e); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - response.addHeader("error", "dictionaryDBQuery"); - + response.addHeader(errorMsg, dictionaryDBQuery); + LOGGER.error(e); } } @RequestMapping(value={"/ps_dictionary/save_psResource"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView savePSResourceDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException{ + public ModelAndView savePSResourceDictionary(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(); @@ -802,11 +814,10 @@ public class PolicyScopeDictionaryController { onapData = (PolicyScopeResource)mapper.readValue(root.get("dictionaryFields").toString(), PolicyScopeResource.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<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeResource.class); - int id = 0; PolicyScopeResource data = (PolicyScopeResource) duplicateData.get(0); - id = data.getId(); + int id = data.getId(); if(id==0){ isFakeUpdate=true; @@ -832,17 +843,17 @@ public class PolicyScopeDictionaryController { } String responseString = ""; if(duplicateflag){ - responseString = "Duplicate"; + responseString = duplicateResponseString; }else{ responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeResource.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; } } @@ -852,9 +863,9 @@ public class PolicyScopeDictionaryController { } 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("{psResourceDictionaryDatas: " + responseString + "}"); @@ -866,26 +877,25 @@ public class PolicyScopeDictionaryController { }catch (Exception e){ LOGGER.error(e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); - } return null; } @RequestMapping(value={"/ps_dictionary/remove_PSResource"}, method={org.springframework.web.bind.annotation.RequestMethod.POST}) - public ModelAndView removePSResourceDictionary(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException, IOException { + public ModelAndView removePSResourceDictionary(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()); PolicyScopeResource onapData = (PolicyScopeResource)mapper.readValue(root.get("data").toString(), PolicyScopeResource.class); commonClassDao.delete(onapData); - 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(); @@ -896,9 +906,9 @@ public class PolicyScopeDictionaryController { 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()); } diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PushPolicyController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PushPolicyController.java index ace67a1e9..885a6117f 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PushPolicyController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/PushPolicyController.java @@ -58,12 +58,17 @@ public class PushPolicyController { private static final Logger LOGGER = FlexLogger.getLogger(PushPolicyController.class); private static CommonClassDao commonClassDao; - + private static String policyNames = "policyName"; + private static String errorMsg = "error"; + private static String operation = "operation"; + private static String messageContent = "message"; @Autowired public PushPolicyController(CommonClassDao commonClassDao){ PushPolicyController.commonClassDao = commonClassDao; } - + /* + * This is an empty constructor + */ public PushPolicyController(){} @RequestMapping(value="/pushPolicy", method=RequestMethod.POST) @@ -74,17 +79,17 @@ public class PushPolicyController { JsonNode root = mapper.readTree(request.getInputStream()); String policyScope = root.get("policyScope").asText(); String filePrefix = root.get("filePrefix").asText(); - String policyName = root.get("policyName").asText(); + String policyName = root.get(policyNames).asText(); String pdpGroup = root.get("pdpGroup").asText(); String requestID = request.getHeader("X-ECOMP-RequestID"); if(requestID==null){ requestID = UUID.randomUUID().toString(); - LOGGER.info("No request ID provided, sending generated ID: " + requestID.toString()); + LOGGER.info("No request ID provided, sending generated ID: " + requestID); } LOGGER.info("Push policy Request : " + root.asText()); String policyVersionName = policyScope.replace(".", File.separator) + File.separator + filePrefix + policyName; - List<?> policyVersionObject = commonClassDao.getDataById(PolicyVersion.class, "policyName", policyVersionName); + List<?> policyVersionObject = commonClassDao.getDataById(PolicyVersion.class, policyNames, policyVersionName); if(policyVersionObject!=null){ PolicyVersion policyVersion = (PolicyVersion) policyVersionObject.get(0); String policyID = policyVersionName.replace(File.separator, "."); // This is before adding version. @@ -93,18 +98,17 @@ public class PushPolicyController { }else{ String message = "Unknown Policy '" + policyName + "'"; PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message); - response.addHeader("error", "unknownPolicy"); - response.addHeader("operation", "push"); - response.addHeader("message", message); + response.addHeader(errorMsg, "unknownPolicy"); + response.addHeader(operation, "push"); + response.addHeader(messageContent, message); response.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } - //safetyChecker(policyName); } catch (NullPointerException | IOException e) { LOGGER.error(e); response.setStatus(HttpServletResponse.SC_NOT_FOUND); - response.addHeader("error", "unknown"); - response.addHeader("operation", "push"); + response.addHeader(errorMsg, "unknown"); + response.addHeader(operation, "push"); return; } } @@ -113,7 +117,6 @@ public class PushPolicyController { StdPDPGroup selectedPDPGroup = null; StdPDPPolicy selectedPolicy = null; //Get the current policies from the Group and Add the new one - //Set<PDPPolicy> currentPoliciesInGroup = null; try { selectedPDPGroup = (StdPDPGroup) XACMLPapServlet.getPAPEngine().getGroup(pdpGroup); } catch (PAPException e1) { @@ -122,9 +125,9 @@ public class PushPolicyController { if(selectedPDPGroup==null){ String message = "Unknown groupId '" + selectedPDPGroup + "'"; PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message); - response.addHeader("error", "unknownGroupId"); - response.addHeader("operation", "push"); - response.addHeader("message", message); + response.addHeader(errorMsg, "unknownGroupId"); + response.addHeader(operation, "push"); + response.addHeader(messageContent, message); response.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } @@ -132,18 +135,18 @@ public class PushPolicyController { EntityManager em = XACMLPapServlet.getEmf().createEntityManager(); Query createPolicyQuery = em.createQuery("SELECT p FROM PolicyEntity p WHERE p.scope=:scope AND p.policyName=:policyName"); createPolicyQuery.setParameter("scope", policyScope); - createPolicyQuery.setParameter("policyName", policyName.substring(policyScope.length()+1)); + createPolicyQuery.setParameter(policyNames, policyName.substring(policyScope.length()+1)); List<?> createPolicyQueryList = createPolicyQuery.getResultList(); PolicyEntity policyEntity = null; - if(createPolicyQueryList.size()>0){ + if(!createPolicyQueryList.isEmpty()){ policyEntity = (PolicyEntity)createPolicyQueryList.get(0); }else{ PolicyLogger.error("Somehow, more than one policy with the same scope, name, and deleted status were found in the database"); String message = "Unknown Policy '" + policyName + "'"; PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " " + message); - response.addHeader("error", "unknownPolicy"); - response.addHeader("operation", "push"); - response.addHeader("message", message); + response.addHeader(errorMsg, "unknownPolicy"); + response.addHeader(operation, "push"); + response.addHeader(messageContent, message); response.setStatus(HttpServletResponse.SC_NOT_FOUND); return; } @@ -162,68 +165,16 @@ public class PushPolicyController { new ObjectOutputStream(response.getOutputStream()).writeObject(selectedPolicy); } catch (IOException e) { LOGGER.error(e); - response.addHeader("error", "policyCopyError"); - response.addHeader("message", e.getMessage()); + response.addHeader(errorMsg, "policyCopyError"); + response.addHeader(messageContent, e.getMessage()); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); return; } response.addHeader("Content-Type","application/json"); response.setStatus(HttpServletResponse.SC_ACCEPTED); - response.addHeader("operation", "push"); + response.addHeader(operation, "push"); response.addHeader("policyId", policyName); return; // TODO : Check point to push policies within PAP. - /*PolicyDBDaoTransaction addPolicyToGroupTransaction = XACMLPapServlet.getDbDaoTransaction(); - try{ - if (selectedPolicy != null) { - // Add Current policies from container - currentPoliciesInGroup = selectedPDPGroup.getPolicies(); - // copy policy to PAP - addPolicyToGroupTransaction.addPolicyToGroup(selectedPDPGroup.getId(), policyName,"XACMLPapServlet.pushPolicyController"); - ((StdPDPGroup) selectedPDPGroup).copyPolicyToFile(policyName, policyID, new FileInputStream(temp)); - addPolicyToGroupTransaction.commitTransaction(); - } - }catch (Exception e) { - addPolicyToGroupTransaction.rollbackTransaction(); - String message = "Policy '" + policyName + "' not copied to group '" + pdpGroup +"': " + e; - PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW + " " + message); - PolicyLogger.audit("Transaction Failed - See Error.log"); - response.addHeader("error", "policyCopyError"); - response.addHeader("message", message); - response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); - return; - } - //If the selected policy is in the group we must remove it because the name is default - for (PDPPolicy existingPolicy : currentPoliciesInGroup) { - if (existingPolicy.getId().equals(selectedPolicy.getId())) { - selectedPDPGroup.removePolicyFromGroup(existingPolicy); - LOGGER.debug("Removing existing policy: " + existingPolicy); - break; - } - } - //Update the PDP Group after removing old version of policy - //Set<PDPPolicy> updatedPoliciesInGroup = selectedPDPGroup.getPolicies(); - //need to remove the policy with default name from group - for (PDPPolicy updatedPolicy : currentPoliciesInGroup) { - if (updatedPolicy.getName().equalsIgnoreCase("default")) { - selectedPDPGroup.removePolicyFromGroup(updatedPolicy); - } - } - Set<PDPPolicy> policies = selectedPDPGroup.getPolicies(); - policies.add(selectedPolicy); - selectedPDPGroup.setPolicies(policies); - // Update now. - try { - XACMLPapServlet.getPAPEngine().updateGroup(selectedPDPGroup); - } catch (PAPException e) { - // TODO Auto-generated catch block - logger.error("Exception Occured"+e); - } - // policy file copied ok and the Group was updated on the PDP - response.setStatus(HttpServletResponse.SC_NO_CONTENT); - response.addHeader("operation", "push"); - response.addHeader("policyId", policyName); - response.addHeader("groupId", pdpGroup); - return;*/ } } diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/SafePolicyController.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/SafePolicyController.java index f994cbacb..621d49869 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/SafePolicyController.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/controller/SafePolicyController.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.util.Date; import java.util.HashMap; import java.util.List; @@ -55,7 +54,12 @@ public class SafePolicyController { private static final Logger LOGGER = FlexLogger.getLogger(SafePolicyController.class); private static CommonClassDao commonClassDao; - + private static String duplicateResponseString = "Duplicate"; + private static String operation = "operation"; + private static String apiflag = "apiflag"; + private static String utf8 = "UTF-8"; + private static String applicationJsonContentType = "application / json"; + @Autowired public SafePolicyController(CommonClassDao commonClassDao){ SafePolicyController.commonClassDao = commonClassDao; @@ -64,15 +68,12 @@ public class SafePolicyController { public SafePolicyController(){} public UserInfo getUserInfo(String loginId){ - UserInfo name = (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId); - return name; + return (UserInfo) commonClassDao.getEntityItem(UserInfo.class, "userLoginId", loginId); } - private static String DUPLICATE = "Duplicate"; - @RequestMapping(value = { "/get_RiskTypeDataByName" }, method = { org.springframework.web.bind.annotation.RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_VALUE) - public void getRiskTypeDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response) { + public void getRiskTypeDictionaryByNameEntityData(HttpServletResponse response) { try { Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); @@ -87,7 +88,7 @@ public class SafePolicyController { @RequestMapping(value = { "/get_RiskTypeData" }, method = { org.springframework.web.bind.annotation.RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_VALUE) - public void getOnapNameDictionaryEntityData(HttpServletRequest request, HttpServletResponse response) { + public void getOnapNameDictionaryEntityData(HttpServletResponse response) { try { Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); @@ -95,7 +96,7 @@ public class SafePolicyController { JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.addHeader("successMapKey", "success"); - response.addHeader("operation", "getDictionary"); + response.addHeader(operation, "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e) { LOGGER.error(e); @@ -107,12 +108,12 @@ public class SafePolicyController { @RequestMapping(value = { "/sp_dictionary/save_riskType" }, method = { org.springframework.web.bind.annotation.RequestMethod.POST }) public ModelAndView saveRiskTypeDictionary(HttpServletRequest request, HttpServletResponse response) - throws UnsupportedEncodingException, IOException { + 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(); @@ -126,11 +127,10 @@ public class SafePolicyController { userId = "API"; //check if update operation or create, get id for data to be updated and update attributeData - if ("update".equalsIgnoreCase(request.getParameter("operation"))){ + if ("update".equalsIgnoreCase(request.getParameter(operation))){ List<Object> duplicateData = commonClassDao.checkDuplicateEntry(riskTypeData.getRiskName(), "name", RiskType.class); - int id = 0; RiskType data = (RiskType) duplicateData.get(0); - id = data.getId(); + int id = data.getId(); if(id==0){ isFakeUpdate=true; @@ -164,13 +164,13 @@ public class SafePolicyController { } String responseString = ""; if(duplicateflag){ - responseString = DUPLICATE; + responseString = duplicateResponseString; }else{ responseString = mapper.writeValueAsString(commonClassDao.getData(RiskType.class)); } if (fromAPI) { - if (responseString!=null && !responseString.equals(DUPLICATE)) { + if (responseString!=null && !responseString.equals(duplicateResponseString)) { if(isFakeUpdate){ responseString = "Exists"; } else { @@ -181,9 +181,9 @@ public class SafePolicyController { 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("{riskTypeDictionaryDatas: " + responseString + "}"); @@ -192,8 +192,8 @@ public class SafePolicyController { } }catch (Exception e) { LOGGER.error(e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -203,16 +203,16 @@ public class SafePolicyController { @RequestMapping(value = { "/sp_dictionary/remove_riskType" }, method = { org.springframework.web.bind.annotation.RequestMethod.POST }) public ModelAndView removeOnapDictionary(HttpServletRequest request, HttpServletResponse response) - throws UnsupportedEncodingException, IOException{ + throws IOException{ try { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); RiskType onapData = (RiskType) mapper.readValue(root.get("data").toString(), RiskType.class); commonClassDao.delete(onapData); - 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(); @@ -223,8 +223,8 @@ public class SafePolicyController { return null; } catch (Exception e) { LOGGER.error(e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -233,7 +233,7 @@ public class SafePolicyController { @RequestMapping(value = { "/get_SafePolicyWarningDataByName" }, method = { org.springframework.web.bind.annotation.RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_VALUE) - public void getSafePolicyWarningEntityDataByName(HttpServletRequest request, HttpServletResponse response) { + public void getSafePolicyWarningEntityDataByName(HttpServletResponse response) { try { Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); @@ -249,7 +249,7 @@ public class SafePolicyController { @RequestMapping(value = { "/get_SafePolicyWarningData" }, method = { org.springframework.web.bind.annotation.RequestMethod.GET }, produces = MediaType.APPLICATION_JSON_VALUE) - public void getSafePolicyWarningeEntityData(HttpServletRequest request, HttpServletResponse response) { + public void getSafePolicyWarningeEntityData(HttpServletResponse response) { try { Map<String, Object> model = new HashMap<>(); ObjectMapper mapper = new ObjectMapper(); @@ -258,7 +258,7 @@ public class SafePolicyController { JsonMessage msg = new JsonMessage(mapper.writeValueAsString(model)); JSONObject j = new JSONObject(msg); response.addHeader("successMapKey", "success"); - response.addHeader("operation", "getDictionary"); + response.addHeader(operation, "getDictionary"); response.getWriter().write(j.toString()); } catch (Exception e) { LOGGER.error(e); @@ -270,12 +270,12 @@ public class SafePolicyController { @RequestMapping(value = { "/sp_dictionary/save_safePolicyWarning" }, method = { org.springframework.web.bind.annotation.RequestMethod.POST }) public ModelAndView saveSafePolicyWarningDictionary(HttpServletRequest request, HttpServletResponse response) - throws UnsupportedEncodingException, IOException { + 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(); @@ -287,11 +287,10 @@ public class SafePolicyController { .readValue(root.get("dictionaryFields").toString(), SafePolicyWarning.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<Object> duplicateData = commonClassDao.checkDuplicateEntry(safePolicyWarning.getName(), "name", SafePolicyWarning.class); - int id = 0; SafePolicyWarning data = (SafePolicyWarning) duplicateData.get(0); - id = data.getId(); + int id = data.getId(); if(id==0){ isFakeUpdate=true; @@ -318,13 +317,13 @@ public class SafePolicyController { } String responseString = ""; if(duplicateflag){ - responseString = DUPLICATE; + responseString = duplicateResponseString; }else{ responseString = mapper.writeValueAsString(commonClassDao.getData(SafePolicyWarning.class)); } if (fromAPI) { - if (responseString!=null && !responseString.equals(DUPLICATE)) { + if (responseString!=null && !responseString.equals(duplicateResponseString)) { if(isFakeUpdate){ responseString = "Exists"; } else { @@ -335,9 +334,9 @@ public class SafePolicyController { 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("{safePolicyWarningDatas: " + responseString + "}"); @@ -347,8 +346,8 @@ public class SafePolicyController { }catch (Exception e) { LOGGER.error(e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } @@ -358,7 +357,7 @@ public class SafePolicyController { @RequestMapping(value = { "/sp_dictionary/remove_SafePolicyWarning" }, method = { org.springframework.web.bind.annotation.RequestMethod.POST }) public ModelAndView removeSafePolicyWarningDictionary(HttpServletRequest request, HttpServletResponse response) - throws UnsupportedEncodingException, IOException { + throws IOException { try { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); @@ -366,9 +365,9 @@ public class SafePolicyController { SafePolicyWarning safePolicyWarningData = (SafePolicyWarning) mapper.readValue(root.get("data").toString(), SafePolicyWarning.class); commonClassDao.delete(safePolicyWarningData); - 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(); @@ -379,8 +378,8 @@ public class SafePolicyController { return null; } catch (Exception e) { System.out.println(e); - response.setCharacterEncoding("UTF-8"); - request.setCharacterEncoding("UTF-8"); + response.setCharacterEncoding(utf8); + request.setCharacterEncoding(utf8); PrintWriter out = response.getWriter(); out.write(e.getMessage()); } diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/APIRequestHandler.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/APIRequestHandler.java index 117fc04e3..3b254b005 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/APIRequestHandler.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/handler/APIRequestHandler.java @@ -54,7 +54,7 @@ public class APIRequestHandler { return; } if ("getMetrics".equalsIgnoreCase(apiflag)){ - MetricService.doGetPolicyMetrics(request, response); + MetricService.doGetPolicyMetrics(response); return; } } diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/service/DictionaryService.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/service/DictionaryService.java index c96f85dcf..25edb2668 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/service/DictionaryService.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/service/DictionaryService.java @@ -23,7 +23,6 @@ import java.io.IOException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - import org.onap.policy.pap.xacml.rest.controller.ActionPolicyDictionaryController; import org.onap.policy.pap.xacml.rest.controller.BRMSDictionaryController; import org.onap.policy.pap.xacml.rest.controller.ClosedLoopDictionaryController; @@ -48,200 +47,155 @@ public class DictionaryService { public String saveOnapDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { DictionaryController dictionary = new DictionaryController(); - String responseString = null; ModelAndView result = dictionary.saveOnapDictionary(request, response); - responseString = result.getViewName(); - return responseString; - + return result.getViewName(); } public String saveAttributeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ DictionaryController dictionary = new DictionaryController(); - String responseString = null; ModelAndView result = dictionary.saveAttributeDictionary(request, response); - responseString = result.getViewName(); - return responseString; - } + return result.getViewName(); + } public String saveActionPolicyDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { ActionPolicyDictionaryController action = new ActionPolicyDictionaryController(); - String responseString = null; ModelAndView result = action.saveActionPolicyDictionary(request, response); - responseString = result.getViewName(); - return responseString; + return result.getViewName(); } public String saveBRMSParamDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { BRMSDictionaryController dictionary = new BRMSDictionaryController(); - String responseString = null; ModelAndView result = dictionary.saveBRMSParamDictionary(request, response); - responseString = result.getViewName(); - return responseString; + return result.getViewName(); } public String saveVSCLAction(HttpServletRequest request, HttpServletResponse response) throws IOException{ ClosedLoopDictionaryController dictionary = new ClosedLoopDictionaryController(); - String responseString = null; ModelAndView result = dictionary.saveVSCLAction(request, response); - responseString = result.getViewName(); - return responseString; + return result.getViewName(); } public String saveVnfType(HttpServletRequest request, HttpServletResponse response) throws IOException{ ClosedLoopDictionaryController dictionary = new ClosedLoopDictionaryController(); - String responseString = null; ModelAndView result = dictionary.saveVnfType(request, response); - responseString = result.getViewName(); - return responseString; + return result.getViewName(); } public String savePEPOptions(HttpServletRequest request, HttpServletResponse response) throws IOException{ ClosedLoopDictionaryController dictionary = new ClosedLoopDictionaryController(); - String responseString = null; ModelAndView result = dictionary.savePEPOptions(request, response); - responseString = result.getViewName(); - return responseString; + return result.getViewName(); } public String saveVarbind(HttpServletRequest request, HttpServletResponse response) throws IOException{ ClosedLoopDictionaryController dictionary = new ClosedLoopDictionaryController(); - String responseString = null; ModelAndView result = dictionary.saveVarbind(request, response); - responseString = result.getViewName(); - return responseString; + return result.getViewName(); } public String saveServiceType(HttpServletRequest request, HttpServletResponse response) throws IOException{ ClosedLoopDictionaryController dictionary = new ClosedLoopDictionaryController(); - String responseString = null; ModelAndView result = dictionary.saveServiceType(request, response); - responseString = result.getViewName(); - return responseString; + return result.getViewName(); } public String saveSiteType(HttpServletRequest request, HttpServletResponse response) throws IOException{ ClosedLoopDictionaryController dictionary = new ClosedLoopDictionaryController(); - String responseString = null; ModelAndView result = dictionary.saveSiteType(request, response); - responseString = result.getViewName(); - return responseString; + return result.getViewName(); } public String saveSettingsDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ DecisionPolicyDictionaryController dictionary = new DecisionPolicyDictionaryController(); - String responseString = null; ModelAndView result = dictionary.saveSettingsDictionary(request, response); - responseString = result.getViewName(); - return responseString; + return result.getViewName(); } public String saveDescriptiveDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ DescriptiveDictionaryController dictionary = new DescriptiveDictionaryController(); - String responseString = null; ModelAndView result = dictionary.saveDescriptiveDictionary(request, response); - responseString = result.getViewName(); - return responseString; + return result.getViewName(); } public String saveEnforcerDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ EnforcerDictionaryController dictionary = new EnforcerDictionaryController(); - String responseString = null; ModelAndView result = dictionary.saveEnforcerDictionary(request, response); - responseString = result.getViewName(); - return responseString; + return result.getViewName(); } public String saveActionListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ FirewallDictionaryController dictionary = new FirewallDictionaryController(); - String responseString = null; ModelAndView result = dictionary.saveActionListDictionary(request, response); - responseString = result.getViewName(); - return responseString; + return result.getViewName(); } public String saveProtocolListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ FirewallDictionaryController dictionary = new FirewallDictionaryController(); - String responseString = null; ModelAndView result = dictionary.saveProtocolListDictionary(request, response); - responseString = result.getViewName(); - return responseString; + return result.getViewName(); } public String saveZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ FirewallDictionaryController dictionary = new FirewallDictionaryController(); - String responseString = null; ModelAndView result = dictionary.saveZoneDictionary(request, response); - responseString = result.getViewName(); - return responseString; + return result.getViewName(); } public String saveSecurityZoneDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ FirewallDictionaryController dictionary = new FirewallDictionaryController(); - String responseString = null; ModelAndView result = dictionary.saveSecurityZoneDictionary(request, response); - responseString = result.getViewName(); - return responseString; + return result.getViewName(); } public String savePrefixListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ FirewallDictionaryController dictionary = new FirewallDictionaryController(); - String responseString = null; ModelAndView result = dictionary.savePrefixListDictionary(request, response); - responseString = result.getViewName(); - return responseString; + return result.getViewName(); } public String saveAddressGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ FirewallDictionaryController dictionary = new FirewallDictionaryController(); - String responseString = null; ModelAndView result = dictionary.saveAddressGroupDictionary(request, response); - responseString = result.getViewName(); - return responseString; + return result.getViewName(); } public String saveServiceGroupDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ FirewallDictionaryController dictionary = new FirewallDictionaryController(); - String responseString = null; ModelAndView result = dictionary.saveServiceGroupDictionary(request, response); - responseString = result.getViewName(); - return responseString; + return result.getViewName(); } public String saveServiceListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ FirewallDictionaryController dictionary = new FirewallDictionaryController(); - String responseString = null; ModelAndView result = dictionary.saveServiceListDictionary(request, response); - responseString = result.getViewName(); - return responseString; + return result.getViewName(); } public String saveTermListDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ FirewallDictionaryController dictionary = new FirewallDictionaryController(); - String responseString = null; ModelAndView result = dictionary.saveTermListDictionary(request, response); - responseString = result.getViewName(); - return responseString; + return result.getViewName(); } @@ -250,108 +204,84 @@ public class DictionaryService { public String saveMicroServiceLocationDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ MicroServiceDictionaryController dictionary = new MicroServiceDictionaryController(); - String responseString = null; ModelAndView result = dictionary.saveMicroServiceLocationDictionary(request, response); - responseString = result.getViewName(); - return responseString; + return result.getViewName(); } public String saveMicroServiceConfigNameDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ MicroServiceDictionaryController dictionary = new MicroServiceDictionaryController(); - String responseString = null; ModelAndView result = dictionary.saveMicroServiceConfigNameDictionary(request, response); - responseString = result.getViewName(); - return responseString; + return result.getViewName(); } public String saveDCAEUUIDDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ MicroServiceDictionaryController dictionary = new MicroServiceDictionaryController(); - String responseString = null; ModelAndView result = dictionary.saveDCAEUUIDDictionary(request, response); - responseString = result.getViewName(); - return responseString; + return result.getViewName(); } public String saveMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ MicroServiceDictionaryController dictionary = new MicroServiceDictionaryController(); - String responseString = null; ModelAndView result = dictionary.saveMicroServiceModelsDictionary(request, response); - responseString = result.getViewName(); - return responseString; + return result.getViewName(); } public String saveMicroServiceDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ MicroServiceDictionaryController dictionary = new MicroServiceDictionaryController(); - String responseString = null; ModelAndView result = dictionary.saveMicroServiceAttributeDictionary(request, response); - responseString = result.getViewName(); - return responseString; + return result.getViewName(); } public String savePSServiceDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ PolicyScopeDictionaryController dictionary = new PolicyScopeDictionaryController(); - String responseString = null; ModelAndView result = dictionary.savePSServiceDictionary(request, response); - responseString = result.getViewName(); - return responseString; + return result.getViewName(); } public String savePSResourceDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ PolicyScopeDictionaryController dictionary = new PolicyScopeDictionaryController(); - String responseString = null; ModelAndView result = dictionary.savePSResourceDictionary(request, response); - responseString = result.getViewName(); - return responseString; + return result.getViewName(); } public String savePSTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ PolicyScopeDictionaryController dictionary = new PolicyScopeDictionaryController(); - String responseString = null; ModelAndView result = dictionary.savePSTypeDictionary(request, response); - responseString = result.getViewName(); - return responseString; + return result.getViewName(); } public String savePSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ PolicyScopeDictionaryController dictionary = new PolicyScopeDictionaryController(); - String responseString = null; ModelAndView result = dictionary.savePSClosedLoopDictionary(request, response); - responseString = result.getViewName(); - return responseString; + return result.getViewName(); } public String savePSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ PolicyScopeDictionaryController dictionary = new PolicyScopeDictionaryController(); - String responseString = null; ModelAndView result = dictionary.savePSGroupScopeDictionary(request, response); - responseString = result.getViewName(); - return responseString; + return result.getViewName(); } public String saveRiskTypeDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ SafePolicyController dictionary = new SafePolicyController(); - String responseString = null; ModelAndView result = dictionary.saveRiskTypeDictionary(request, response); - responseString = result.getViewName(); - return responseString; + return result.getViewName(); } public String saveSafePolicyWarningDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException{ SafePolicyController dictionary = new SafePolicyController(); - String responseString = null; ModelAndView result = dictionary.saveSafePolicyWarningDictionary(request, response); - responseString = result.getViewName(); - return responseString; + return result.getViewName(); } @@ -360,172 +290,172 @@ public class DictionaryService { */ public void getOnapDictionary(HttpServletRequest request, HttpServletResponse response){ DictionaryController dictionary = new DictionaryController(); - dictionary.getOnapNameDictionaryEntityData(request, response); + dictionary.getOnapNameDictionaryEntityData(response); } public void getAttributeDictionary(HttpServletRequest request, HttpServletResponse response){ DictionaryController dictionary = new DictionaryController(); - dictionary.getAttributeDictionaryEntityData(request, response); + dictionary.getAttributeDictionaryEntityData(response); } public void getActionPolicyDictionary(HttpServletRequest request, HttpServletResponse response){ ActionPolicyDictionaryController action = new ActionPolicyDictionaryController(); - action.getActionPolicyDictionaryEntityData(request, response); + action.getActionPolicyDictionaryEntityData(response); } public void getBRMSParamDictionary(HttpServletRequest request, HttpServletResponse response){ BRMSDictionaryController dictionary = new BRMSDictionaryController(); - dictionary.getBRMSParamDictionaryEntityData(request, response); + dictionary.getBRMSParamDictionaryEntityData(response); } public void getVSCLAction(HttpServletRequest request, HttpServletResponse response){ ClosedLoopDictionaryController dictionary = new ClosedLoopDictionaryController(); - dictionary.getVSCLActionDictionaryEntityData(request, response); + dictionary.getVSCLActionDictionaryEntityData(response); } public void getVnfType(HttpServletRequest request, HttpServletResponse response){ ClosedLoopDictionaryController dictionary = new ClosedLoopDictionaryController(); - dictionary.getVNFTypeDictionaryEntityData(request, response); + dictionary.getVNFTypeDictionaryEntityData(response); } public void getPEPOptions(HttpServletRequest request, HttpServletResponse response){ ClosedLoopDictionaryController dictionary = new ClosedLoopDictionaryController(); - dictionary.getPEPOptionsDictionaryEntityData(request, response); + dictionary.getPEPOptionsDictionaryEntityData(response); } public void getVarbind(HttpServletRequest request, HttpServletResponse response){ ClosedLoopDictionaryController dictionary = new ClosedLoopDictionaryController(); - dictionary.getVarbindDictionaryEntityData(request, response); + dictionary.getVarbindDictionaryEntityData(response); } public void getServiceType(HttpServletRequest request, HttpServletResponse response){ ClosedLoopDictionaryController dictionary = new ClosedLoopDictionaryController(); - dictionary.getClosedLoopServiceDictionaryEntityData(request, response); + dictionary.getClosedLoopServiceDictionaryEntityData(response); } public void getSiteType(HttpServletRequest request, HttpServletResponse response){ ClosedLoopDictionaryController dictionary = new ClosedLoopDictionaryController(); - dictionary.getClosedLoopSiteDictionaryEntityData(request, response); + dictionary.getClosedLoopSiteDictionaryEntityData(response); } public void getSettingsDictionary(HttpServletRequest request, HttpServletResponse response){ DecisionPolicyDictionaryController dictionary = new DecisionPolicyDictionaryController(); - dictionary.getSettingsDictionaryEntityData(request, response); + dictionary.getSettingsDictionaryEntityData(response); } public void getDescriptiveDictionary(HttpServletRequest request, HttpServletResponse response){ DescriptiveDictionaryController dictionary = new DescriptiveDictionaryController(); - dictionary.getDescriptiveDictionaryEntityData(request, response); + dictionary.getDescriptiveDictionaryEntityData(response); } public void getEnforcerDictionary(HttpServletRequest request, HttpServletResponse response){ EnforcerDictionaryController dictionary = new EnforcerDictionaryController(); - dictionary.getEnforcerDictionaryEntityData(request, response); + dictionary.getEnforcerDictionaryEntityData(response); } public void getActionListDictionary(HttpServletRequest request, HttpServletResponse response){ FirewallDictionaryController dictionary = new FirewallDictionaryController(); - dictionary.getActionListDictionaryEntityData(request, response); + dictionary.getActionListDictionaryEntityData(response); } public void getProtocolListDictionary(HttpServletRequest request, HttpServletResponse response){ FirewallDictionaryController dictionary = new FirewallDictionaryController(); - dictionary.getProtocolListDictionaryEntityData(request, response); + dictionary.getProtocolListDictionaryEntityData(response); } public void getZoneDictionary(HttpServletRequest request, HttpServletResponse response){ FirewallDictionaryController dictionary = new FirewallDictionaryController(); - dictionary.getZoneDictionaryEntityData(request, response); + dictionary.getZoneDictionaryEntityData(response); } public void getSecurityZoneDictionary(HttpServletRequest request, HttpServletResponse response){ FirewallDictionaryController dictionary = new FirewallDictionaryController(); - dictionary.getSecurityZoneDictionaryEntityData(request, response); + dictionary.getSecurityZoneDictionaryEntityData(response); } public void getPrefixListDictionary(HttpServletRequest request, HttpServletResponse response){ FirewallDictionaryController dictionary = new FirewallDictionaryController(); - dictionary.getPrefixListDictionaryEntityData(request, response); + dictionary.getPrefixListDictionaryEntityData(response); } public void getAddressGroupDictionary(HttpServletRequest request, HttpServletResponse response){ FirewallDictionaryController dictionary = new FirewallDictionaryController(); - dictionary.getAddressGroupDictionaryEntityData(request, response); + dictionary.getAddressGroupDictionaryEntityData(response); } public void getServiceGroupDictionary(HttpServletRequest request, HttpServletResponse response){ FirewallDictionaryController dictionary = new FirewallDictionaryController(); - dictionary.getServiceGroupDictionaryEntityData(request, response); + dictionary.getServiceGroupDictionaryEntityData(response); } public void getServiceListDictionary(HttpServletRequest request, HttpServletResponse response){ FirewallDictionaryController dictionary = new FirewallDictionaryController(); - dictionary.getServiceListDictionaryEntityData(request, response); + dictionary.getServiceListDictionaryEntityData(response); } public void getTermListDictionary(HttpServletRequest request, HttpServletResponse response){ FirewallDictionaryController dictionary = new FirewallDictionaryController(); - dictionary.getTermListDictionaryEntityData(request, response); + dictionary.getTermListDictionaryEntityData(response); } public void getMicroServiceLocationDictionary(HttpServletRequest request, HttpServletResponse response){ MicroServiceDictionaryController dictionary = new MicroServiceDictionaryController(); - dictionary.getMicroServiceLocationDictionaryEntityData(request, response); + dictionary.getMicroServiceLocationDictionaryEntityData(response); } public void getMicroServiceConfigNameDictionary(HttpServletRequest request, HttpServletResponse response){ MicroServiceDictionaryController dictionary = new MicroServiceDictionaryController(); - dictionary.getMicroServiceConfigNameDictionaryEntityData(request, response); + dictionary.getMicroServiceConfigNameDictionaryEntityData(response); } public void getDCAEUUIDDictionary(HttpServletRequest request, HttpServletResponse response){ MicroServiceDictionaryController dictionary = new MicroServiceDictionaryController(); - dictionary.getDCAEUUIDDictionaryEntityData(request, response); + dictionary.getDCAEUUIDDictionaryEntityData(response); } public void getMicroServiceModelsDictionary(HttpServletRequest request, HttpServletResponse response){ MicroServiceDictionaryController dictionary = new MicroServiceDictionaryController(); - dictionary.getMicroServiceModelsDictionaryEntityData(request, response); + dictionary.getMicroServiceModelsDictionaryEntityData(response); } public void getMicroServiceDictionary(HttpServletRequest request, HttpServletResponse response){ MicroServiceDictionaryController dictionary = new MicroServiceDictionaryController(); - dictionary.getMicroServiceModelsDictionaryEntityData(request, response); + dictionary.getMicroServiceModelsDictionaryEntityData(response); } public void getPSServiceDictionary(HttpServletRequest request, HttpServletResponse response){ PolicyScopeDictionaryController dictionary = new PolicyScopeDictionaryController(); - dictionary.getPSServiceEntityData(request, response); + dictionary.getPSServiceEntityData(response); } public void getPSResourceDictionary(HttpServletRequest request, HttpServletResponse response){ PolicyScopeDictionaryController dictionary = new PolicyScopeDictionaryController(); - dictionary.getPSResourceEntityData(request, response); + dictionary.getPSResourceEntityData(response); } public void getPSTypeDictionary(HttpServletRequest request, HttpServletResponse response){ PolicyScopeDictionaryController dictionary = new PolicyScopeDictionaryController(); - dictionary.getPSTypeEntityData(request, response); + dictionary.getPSTypeEntityData(response); } public void getPSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response){ PolicyScopeDictionaryController dictionary = new PolicyScopeDictionaryController(); - dictionary.getPSClosedLoopEntityData(request, response); + dictionary.getPSClosedLoopEntityData(response); } public void getPSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response){ PolicyScopeDictionaryController dictionary = new PolicyScopeDictionaryController(); - dictionary.getGroupPolicyScopeEntityData(request, response); + dictionary.getGroupPolicyScopeEntityData(response); } public void getRiskTypeDictionary(HttpServletRequest request, HttpServletResponse response){ SafePolicyController dictionary = new SafePolicyController(); - dictionary.getOnapNameDictionaryEntityData(request, response); + dictionary.getOnapNameDictionaryEntityData(response); } public void getSafePolicyWarningDictionary(HttpServletRequest request, HttpServletResponse response) { SafePolicyController dictionary = new SafePolicyController(); - dictionary.getSafePolicyWarningeEntityData(request, response); + dictionary.getSafePolicyWarningeEntityData(response); } }
\ No newline at end of file diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/service/ImportService.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/service/ImportService.java index 8a9e8ffac..e942e6b3b 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/service/ImportService.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/service/ImportService.java @@ -41,6 +41,13 @@ import org.onap.policy.pap.xacml.rest.components.CreateNewMicroServiceModel; public class ImportService { private static final Logger logger = FlexLogger.getLogger(ImportService.class); + private static String errorMessage = "Error in reading in file from API call"; + private static String errorMsg = "error"; + private static String operation = "operation"; + private static String importHeader = "import"; + private static String service = "service"; + private static String extractDir = "ExtractDir"; + private static String successMessage = "success"; public void doImportMicroServicePut(HttpServletRequest request, HttpServletResponse response) { String importServiceCreation = request.getParameter("importService");; String fileName = request.getParameter("fileName"); @@ -48,8 +55,7 @@ public class ImportService { String serviceName = request.getParameter("serviceName"); String description = request.getParameter("description"); Map<String, String> successMap = new HashMap<>(); - switch(importServiceCreation){ - case "BRMSPARAM": + if(("BRMSPARAM").equals(importServiceCreation)){ StringBuilder builder = new StringBuilder(); int ch; try { @@ -58,20 +64,20 @@ public class ImportService { } } catch (IOException e) { logger.error(e); - PolicyLogger.error("Error in reading in file from API call"); + PolicyLogger.error(errorMessage); response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); - response.addHeader("error", "missing"); - response.addHeader("operation", "import"); - response.addHeader("service", serviceName); + response.addHeader(errorMsg, "missing"); + response.addHeader(operation, importHeader); + response.addHeader(service, serviceName); } CreateBRMSRuleTemplate brmsRuleTemplate = new CreateBRMSRuleTemplate(); successMap = brmsRuleTemplate.addRule(builder.toString(), serviceName, description, "API"); - break; - case "MICROSERVICE": + } + else if(("MICROSERVICE").equals(importServiceCreation)){ CreateNewMicroServiceModel newMS = null; String randomID = UUID.randomUUID().toString(); if ( fileName != null) { - File extracDir = new File("ExtractDir"); + File extracDir = new File(extractDir); if (!extracDir.exists()){ extracDir.mkdirs(); } @@ -86,21 +92,21 @@ public class ImportService { scanner.close(); } catch (IOException e1) { logger.error(e1); - PolicyLogger.error("Error in reading in file from API call"); + PolicyLogger.error(errorMessage); return; } PolicyLogger.info("XML request from API for import new Service"); try (Writer writer = new BufferedWriter(new OutputStreamWriter( - new FileOutputStream("ExtractDir" + File.separator + randomID+".xmi"), "utf-8"))) { + new FileOutputStream(extractDir + File.separator + randomID+".xmi"), "utf-8"))) { writer.write(xmi); } catch (IOException e) { logger.error(e); - PolicyLogger.error("Error in reading in file from API call"); + PolicyLogger.error(errorMessage); return; } }else{ InputStream inputStream = null; - try(FileOutputStream outputStream = new FileOutputStream("ExtractDir" + File.separator + randomID+".zip")) { + try(FileOutputStream outputStream = new FileOutputStream(extractDir + File.separator + randomID+".zip")) { inputStream = request.getInputStream(); byte[] buffer = new byte[4096]; int bytesRead = -1 ; @@ -122,40 +128,40 @@ public class ImportService { } newMS = new CreateNewMicroServiceModel(fileName, serviceName, "API", version, randomID); successMap = newMS.addValuesToNewModel(); - if (successMap.containsKey("success")) { + if (successMap.containsKey(successMessage)) { successMap.clear(); successMap = newMS.saveImportService(); } } - break; } + // return a response to the PAP - if (successMap.containsKey("success")) { + if (successMap.containsKey(successMessage)) { response.setStatus(HttpServletResponse.SC_OK); - response.addHeader("successMapKey", "success"); - response.addHeader("operation", "import"); - response.addHeader("service", serviceName); + response.addHeader("successMapKey", successMessage); + response.addHeader(operation, importHeader); + response.addHeader(service, serviceName); } else if (successMap.containsKey("DBError")) { if (successMap.get("DBError").contains("EXISTS")){ response.setStatus(HttpServletResponse.SC_CONFLICT); - response.addHeader("service", serviceName); - response.addHeader("error", "modelExistsDB"); + response.addHeader(service, serviceName); + response.addHeader(errorMsg, "modelExistsDB"); }else{ response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); - response.addHeader("error", "importDB"); + response.addHeader(errorMsg, "importDB"); } - response.addHeader("operation", "import"); - response.addHeader("service", serviceName); - }else if (successMap.get("error").contains("MISSING")){ + response.addHeader(operation, importHeader); + response.addHeader(service, serviceName); + }else if (successMap.get(errorMsg).contains("MISSING")){ response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); - response.addHeader("error", "missing"); - response.addHeader("operation", "import"); - response.addHeader("service", serviceName); - }else if (successMap.get("error").contains("VALIDATION")){ + response.addHeader(errorMsg, "missing"); + response.addHeader(operation, importHeader); + response.addHeader(service, serviceName); + }else if (successMap.get(errorMsg).contains("VALIDATION")){ response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); - response.addHeader("error", "validation"); - response.addHeader("operation", "import"); - response.addHeader("service", serviceName); + response.addHeader(errorMsg, "validation"); + response.addHeader(operation, importHeader); + response.addHeader(service, serviceName); } } diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/service/MetricService.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/service/MetricService.java index 416af4413..d239dfa1b 100644 --- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/service/MetricService.java +++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/service/MetricService.java @@ -36,8 +36,14 @@ import org.onap.policy.xacml.api.pap.OnapPDPGroup; import com.att.research.xacml.api.pap.PDPPolicy; public class MetricService { - - public static void doGetPolicyMetrics(HttpServletRequest request, HttpServletResponse response) { + private static String errorMsg = "error"; + /* + * This is a private constructor + * */ + public MetricService(){ + + } + public static void doGetPolicyMetrics(HttpServletResponse response) { Set<OnapPDPGroup> groups = new HashSet<>(); try { //get the count of policies on the PDP @@ -52,12 +58,12 @@ public class MetricService { //get the count of policies on the PAP EntityManager em = null; if(XACMLPapServlet.getEmf()!=null){ - em = (EntityManager) XACMLPapServlet.getEmf().createEntityManager(); + em = XACMLPapServlet.getEmf().createEntityManager(); } if (em==null){ PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE + " Error creating entity manager with persistence unit: " + XACMLPapServlet.getPersistenceUnit()); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - response.addHeader("error", "Error creating entity manager with persistence unit"); + response.addHeader(errorMsg, "Error creating entity manager with persistence unit"); return; } int papCount = ((Number) em.createNamedQuery("PolicyVersion.findAllCount").getSingleResult()).intValue(); @@ -78,14 +84,14 @@ public class MetricService { }else{ String message = "The policy count on the PAP and PDP is 0. Please check the database and file system to correct this error."; response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - response.addHeader("error", message); + response.addHeader(errorMsg, message); return; } } catch (Exception e) { String message = XACMLErrorConstants.ERROR_DATA_ISSUE + " Error Querying the Database: " + e.getMessage(); PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "XACMLPapServlet", " Error Querying the Database."); response.setStatus(HttpServletResponse.SC_BAD_REQUEST); - response.addHeader("error", message); + response.addHeader(errorMsg, message); return; } } |