@Test public void testSaveSafePolicyWarningDictionary() { jsonString = "{\"userid\":\"demo\",\"safePolicyWarningData\":{\"id\":1,\"description\":\"test\",\"name\":\"Test\"}}"; try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.saveSafePolicyWarningDictionary(request, response); assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("safePolicyWarningDatas")); } catch (Exception e) { logger.error("Exception" + e); } }
@RequestMapping(value = {"/sp_dictionary/save_safePolicyWarning"}, method = {RequestMethod.POST}) public ModelAndView saveSafePolicyWarningDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); SafePolicyWarning safePolicyWarning; if (fromAPI) { safePolicyWarning = mapper.readValue(root.get("dictionaryFields").toString(), SafePolicyWarning.class); } else { safePolicyWarning = mapper.readValue(root.get("safePolicyWarningData").toString(), SafePolicyWarning.class); } List<Object> duplicateData = commonClassDao.checkDuplicateEntry(safePolicyWarning.getName(), "name", SafePolicyWarning.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { SafePolicyWarning data = (SafePolicyWarning) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { safePolicyWarning.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != safePolicyWarning.getId()))) { duplicateflag = true; } } String responseString = null; if (!duplicateflag) { if (safePolicyWarning.getId() == 0) { commonClassDao.save(safePolicyWarning); } else { commonClassDao.update(safePolicyWarning); } responseString = mapper.writeValueAsString(commonClassDao.getData(SafePolicyWarning.class)); } else { responseString = duplicateResponseString; } if (fromAPI) { return utils.getResultForApi(responseString); } else { utils.setResponseData(response, safePolicyWarningDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; }
SafePolicyController { @RequestMapping(value = {"/sp_dictionary/save_safePolicyWarning"}, method = {RequestMethod.POST}) public ModelAndView saveSafePolicyWarningDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); SafePolicyWarning safePolicyWarning; if (fromAPI) { safePolicyWarning = mapper.readValue(root.get("dictionaryFields").toString(), SafePolicyWarning.class); } else { safePolicyWarning = mapper.readValue(root.get("safePolicyWarningData").toString(), SafePolicyWarning.class); } List<Object> duplicateData = commonClassDao.checkDuplicateEntry(safePolicyWarning.getName(), "name", SafePolicyWarning.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { SafePolicyWarning data = (SafePolicyWarning) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { safePolicyWarning.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != safePolicyWarning.getId()))) { duplicateflag = true; } } String responseString = null; if (!duplicateflag) { if (safePolicyWarning.getId() == 0) { commonClassDao.save(safePolicyWarning); } else { commonClassDao.update(safePolicyWarning); } responseString = mapper.writeValueAsString(commonClassDao.getData(SafePolicyWarning.class)); } else { responseString = duplicateResponseString; } if (fromAPI) { return utils.getResultForApi(responseString); } else { utils.setResponseData(response, safePolicyWarningDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } }
SafePolicyController { @RequestMapping(value = {"/sp_dictionary/save_safePolicyWarning"}, method = {RequestMethod.POST}) public ModelAndView saveSafePolicyWarningDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); SafePolicyWarning safePolicyWarning; if (fromAPI) { safePolicyWarning = mapper.readValue(root.get("dictionaryFields").toString(), SafePolicyWarning.class); } else { safePolicyWarning = mapper.readValue(root.get("safePolicyWarningData").toString(), SafePolicyWarning.class); } List<Object> duplicateData = commonClassDao.checkDuplicateEntry(safePolicyWarning.getName(), "name", SafePolicyWarning.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { SafePolicyWarning data = (SafePolicyWarning) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { safePolicyWarning.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != safePolicyWarning.getId()))) { duplicateflag = true; } } String responseString = null; if (!duplicateflag) { if (safePolicyWarning.getId() == 0) { commonClassDao.save(safePolicyWarning); } else { commonClassDao.update(safePolicyWarning); } responseString = mapper.writeValueAsString(commonClassDao.getData(SafePolicyWarning.class)); } else { responseString = duplicateResponseString; } if (fromAPI) { return utils.getResultForApi(responseString); } else { utils.setResponseData(response, safePolicyWarningDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } @Autowired  SafePolicyController(CommonClassDao commonClassDao);  SafePolicyController(); }
SafePolicyController { @RequestMapping(value = {"/sp_dictionary/save_safePolicyWarning"}, method = {RequestMethod.POST}) public ModelAndView saveSafePolicyWarningDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); SafePolicyWarning safePolicyWarning; if (fromAPI) { safePolicyWarning = mapper.readValue(root.get("dictionaryFields").toString(), SafePolicyWarning.class); } else { safePolicyWarning = mapper.readValue(root.get("safePolicyWarningData").toString(), SafePolicyWarning.class); } List<Object> duplicateData = commonClassDao.checkDuplicateEntry(safePolicyWarning.getName(), "name", SafePolicyWarning.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { SafePolicyWarning data = (SafePolicyWarning) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { safePolicyWarning.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != safePolicyWarning.getId()))) { duplicateflag = true; } } String responseString = null; if (!duplicateflag) { if (safePolicyWarning.getId() == 0) { commonClassDao.save(safePolicyWarning); } else { commonClassDao.update(safePolicyWarning); } responseString = mapper.writeValueAsString(commonClassDao.getData(SafePolicyWarning.class)); } else { responseString = duplicateResponseString; } if (fromAPI) { return utils.getResultForApi(responseString); } else { utils.setResponseData(response, safePolicyWarningDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } @Autowired  SafePolicyController(CommonClassDao commonClassDao);  SafePolicyController(); void setCommonClassDao(CommonClassDao commonClassDao); @RequestMapping( value = {"/get_RiskTypeDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getRiskTypeDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_RiskTypeData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getRiskTypeDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/sp_dictionary/save_riskType"}, method = {RequestMethod.POST}) ModelAndView saveRiskTypeDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/sp_dictionary/remove_riskType"}, method = {RequestMethod.POST}) void removeRiskTypeDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_SafePolicyWarningDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getSafePolicyWarningEntityDataByName(HttpServletResponse response); @RequestMapping( value = {"/get_SafePolicyWarningData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getSafePolicyWarningeEntityData(HttpServletResponse response); @RequestMapping(value = {"/sp_dictionary/save_safePolicyWarning"}, method = {RequestMethod.POST}) ModelAndView saveSafePolicyWarningDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/sp_dictionary/remove_SafePolicyWarning"}, method = {RequestMethod.POST}) void removeSafePolicyWarningDictionary(HttpServletRequest request, HttpServletResponse response); }
SafePolicyController { @RequestMapping(value = {"/sp_dictionary/save_safePolicyWarning"}, method = {RequestMethod.POST}) public ModelAndView saveSafePolicyWarningDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { boolean fromAPI = utils.isRequestFromAPI(request); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); SafePolicyWarning safePolicyWarning; if (fromAPI) { safePolicyWarning = mapper.readValue(root.get("dictionaryFields").toString(), SafePolicyWarning.class); } else { safePolicyWarning = mapper.readValue(root.get("safePolicyWarningData").toString(), SafePolicyWarning.class); } List<Object> duplicateData = commonClassDao.checkDuplicateEntry(safePolicyWarning.getName(), "name", SafePolicyWarning.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { SafePolicyWarning data = (SafePolicyWarning) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { safePolicyWarning.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != safePolicyWarning.getId()))) { duplicateflag = true; } } String responseString = null; if (!duplicateflag) { if (safePolicyWarning.getId() == 0) { commonClassDao.save(safePolicyWarning); } else { commonClassDao.update(safePolicyWarning); } responseString = mapper.writeValueAsString(commonClassDao.getData(SafePolicyWarning.class)); } else { responseString = duplicateResponseString; } if (fromAPI) { return utils.getResultForApi(responseString); } else { utils.setResponseData(response, safePolicyWarningDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } @Autowired  SafePolicyController(CommonClassDao commonClassDao);  SafePolicyController(); void setCommonClassDao(CommonClassDao commonClassDao); @RequestMapping( value = {"/get_RiskTypeDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getRiskTypeDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_RiskTypeData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getRiskTypeDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/sp_dictionary/save_riskType"}, method = {RequestMethod.POST}) ModelAndView saveRiskTypeDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/sp_dictionary/remove_riskType"}, method = {RequestMethod.POST}) void removeRiskTypeDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_SafePolicyWarningDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getSafePolicyWarningEntityDataByName(HttpServletResponse response); @RequestMapping( value = {"/get_SafePolicyWarningData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getSafePolicyWarningeEntityData(HttpServletResponse response); @RequestMapping(value = {"/sp_dictionary/save_safePolicyWarning"}, method = {RequestMethod.POST}) ModelAndView saveSafePolicyWarningDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/sp_dictionary/remove_SafePolicyWarning"}, method = {RequestMethod.POST}) void removeSafePolicyWarningDictionary(HttpServletRequest request, HttpServletResponse response);  }