@Test public void testSaveSettingsDictionary() { logger.info("testSaveSettingsDictionary: Entering"); MockHttpServletResponse response = new MockHttpServletResponse(); request = mock(HttpServletRequest.class); try { jsonString = "{\"settingsDictionaryData\":{\"xacmlId\":\"testMMRestAPI1\"," + "\"datatypeBean\": {\"shortName\":\"string\"},\"description\":\"test\"," + "\"priority\":\"High\"}, \"userid\":\"test\"}"; BufferedReader br = new BufferedReader(new StringReader(jsonString)); when(request.getReader()).thenReturn(br); controller.saveSettingsDictionary(request, response); logger.info("response.getContentAsString(): " + response.getContentAsString()); assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("settingsDictionaryDatas")); } catch (Exception e) { logger.error("Exception Occured" + e); fail("Exception: " + e); } logger.info("testSaveSettingsDictionary: exit"); }
@RequestMapping(value = {"/decision_dictionary/save_Settings"}, method = {RequestMethod.POST}) public ModelAndView saveSettingsDictionary(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()); DecisionSettings decisionSettings; String userId = null; if (fromAPI) { decisionSettings = mapper.readValue(root.get(dictionaryFields).toString(), DecisionSettings.class); userId = "API"; } else { decisionSettings = mapper.readValue(root.get("settingsDictionaryData").toString(), DecisionSettings.class); userId = root.get("userid").textValue(); } UserInfo userInfo = utils.getUserInfo(userId); List<Object> duplicateData = commonClassDao.checkDuplicateEntry(decisionSettings.getXacmlId(), xacmlId, DecisionSettings.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { DecisionSettings data = (DecisionSettings) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { decisionSettings.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != decisionSettings.getId()))) { duplicateflag = true; } } if (decisionSettings.getDatatypeBean().getShortName() != null) { String datatype = decisionSettings.getDatatypeBean().getShortName(); decisionSettings.setDatatypeBean(utils.getDataType(datatype)); } String responseString = null; if (!duplicateflag) { decisionSettings.setUserModifiedBy(userInfo); if (decisionSettings.getId() == 0) { decisionSettings.setUserCreatedBy(userInfo); commonClassDao.save(decisionSettings); } else { decisionSettings.setModifiedDate(new Date()); commonClassDao.update(decisionSettings); } responseString = mapper.writeValueAsString(commonClassDao.getData(DecisionSettings.class)); } else { responseString = duplicateResponseString; } if (fromAPI) { return utils.getResultForApi(responseString); } else { utils.setResponseData(response, settingDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; }
DecisionPolicyDictionaryController { @RequestMapping(value = {"/decision_dictionary/save_Settings"}, method = {RequestMethod.POST}) public ModelAndView saveSettingsDictionary(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()); DecisionSettings decisionSettings; String userId = null; if (fromAPI) { decisionSettings = mapper.readValue(root.get(dictionaryFields).toString(), DecisionSettings.class); userId = "API"; } else { decisionSettings = mapper.readValue(root.get("settingsDictionaryData").toString(), DecisionSettings.class); userId = root.get("userid").textValue(); } UserInfo userInfo = utils.getUserInfo(userId); List<Object> duplicateData = commonClassDao.checkDuplicateEntry(decisionSettings.getXacmlId(), xacmlId, DecisionSettings.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { DecisionSettings data = (DecisionSettings) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { decisionSettings.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != decisionSettings.getId()))) { duplicateflag = true; } } if (decisionSettings.getDatatypeBean().getShortName() != null) { String datatype = decisionSettings.getDatatypeBean().getShortName(); decisionSettings.setDatatypeBean(utils.getDataType(datatype)); } String responseString = null; if (!duplicateflag) { decisionSettings.setUserModifiedBy(userInfo); if (decisionSettings.getId() == 0) { decisionSettings.setUserCreatedBy(userInfo); commonClassDao.save(decisionSettings); } else { decisionSettings.setModifiedDate(new Date()); commonClassDao.update(decisionSettings); } responseString = mapper.writeValueAsString(commonClassDao.getData(DecisionSettings.class)); } else { responseString = duplicateResponseString; } if (fromAPI) { return utils.getResultForApi(responseString); } else { utils.setResponseData(response, settingDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } }
DecisionPolicyDictionaryController { @RequestMapping(value = {"/decision_dictionary/save_Settings"}, method = {RequestMethod.POST}) public ModelAndView saveSettingsDictionary(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()); DecisionSettings decisionSettings; String userId = null; if (fromAPI) { decisionSettings = mapper.readValue(root.get(dictionaryFields).toString(), DecisionSettings.class); userId = "API"; } else { decisionSettings = mapper.readValue(root.get("settingsDictionaryData").toString(), DecisionSettings.class); userId = root.get("userid").textValue(); } UserInfo userInfo = utils.getUserInfo(userId); List<Object> duplicateData = commonClassDao.checkDuplicateEntry(decisionSettings.getXacmlId(), xacmlId, DecisionSettings.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { DecisionSettings data = (DecisionSettings) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { decisionSettings.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != decisionSettings.getId()))) { duplicateflag = true; } } if (decisionSettings.getDatatypeBean().getShortName() != null) { String datatype = decisionSettings.getDatatypeBean().getShortName(); decisionSettings.setDatatypeBean(utils.getDataType(datatype)); } String responseString = null; if (!duplicateflag) { decisionSettings.setUserModifiedBy(userInfo); if (decisionSettings.getId() == 0) { decisionSettings.setUserCreatedBy(userInfo); commonClassDao.save(decisionSettings); } else { decisionSettings.setModifiedDate(new Date()); commonClassDao.update(decisionSettings); } responseString = mapper.writeValueAsString(commonClassDao.getData(DecisionSettings.class)); } else { responseString = duplicateResponseString; } if (fromAPI) { return utils.getResultForApi(responseString); } else { utils.setResponseData(response, settingDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } @Autowired  DecisionPolicyDictionaryController(CommonClassDao commonClassDao);  DecisionPolicyDictionaryController(); }
DecisionPolicyDictionaryController { @RequestMapping(value = {"/decision_dictionary/save_Settings"}, method = {RequestMethod.POST}) public ModelAndView saveSettingsDictionary(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()); DecisionSettings decisionSettings; String userId = null; if (fromAPI) { decisionSettings = mapper.readValue(root.get(dictionaryFields).toString(), DecisionSettings.class); userId = "API"; } else { decisionSettings = mapper.readValue(root.get("settingsDictionaryData").toString(), DecisionSettings.class); userId = root.get("userid").textValue(); } UserInfo userInfo = utils.getUserInfo(userId); List<Object> duplicateData = commonClassDao.checkDuplicateEntry(decisionSettings.getXacmlId(), xacmlId, DecisionSettings.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { DecisionSettings data = (DecisionSettings) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { decisionSettings.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != decisionSettings.getId()))) { duplicateflag = true; } } if (decisionSettings.getDatatypeBean().getShortName() != null) { String datatype = decisionSettings.getDatatypeBean().getShortName(); decisionSettings.setDatatypeBean(utils.getDataType(datatype)); } String responseString = null; if (!duplicateflag) { decisionSettings.setUserModifiedBy(userInfo); if (decisionSettings.getId() == 0) { decisionSettings.setUserCreatedBy(userInfo); commonClassDao.save(decisionSettings); } else { decisionSettings.setModifiedDate(new Date()); commonClassDao.update(decisionSettings); } responseString = mapper.writeValueAsString(commonClassDao.getData(DecisionSettings.class)); } else { responseString = duplicateResponseString; } if (fromAPI) { return utils.getResultForApi(responseString); } else { utils.setResponseData(response, settingDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } @Autowired  DecisionPolicyDictionaryController(CommonClassDao commonClassDao);  DecisionPolicyDictionaryController(); @RequestMapping( value = {"/get_SettingsDictionaryDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getSettingsDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_SettingsDictionaryData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getSettingsDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/decision_dictionary/save_Settings"}, method = {RequestMethod.POST}) ModelAndView saveSettingsDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/settings_dictionary/remove_settings"}, method = {RequestMethod.POST}) void removeSettingsDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_RainyDayDictionaryDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getRainyDayDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_RainyDayDictionaryData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getRainyDayDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/decision_dictionary/save_RainyDay"}, method = {RequestMethod.POST}) ModelAndView saveRainyDayDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/decision_dictionary/remove_rainyDay"}, method = {RequestMethod.POST}) void removeRainyDayDictionary(HttpServletRequest request, HttpServletResponse response); }
DecisionPolicyDictionaryController { @RequestMapping(value = {"/decision_dictionary/save_Settings"}, method = {RequestMethod.POST}) public ModelAndView saveSettingsDictionary(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()); DecisionSettings decisionSettings; String userId = null; if (fromAPI) { decisionSettings = mapper.readValue(root.get(dictionaryFields).toString(), DecisionSettings.class); userId = "API"; } else { decisionSettings = mapper.readValue(root.get("settingsDictionaryData").toString(), DecisionSettings.class); userId = root.get("userid").textValue(); } UserInfo userInfo = utils.getUserInfo(userId); List<Object> duplicateData = commonClassDao.checkDuplicateEntry(decisionSettings.getXacmlId(), xacmlId, DecisionSettings.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { DecisionSettings data = (DecisionSettings) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { decisionSettings.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != decisionSettings.getId()))) { duplicateflag = true; } } if (decisionSettings.getDatatypeBean().getShortName() != null) { String datatype = decisionSettings.getDatatypeBean().getShortName(); decisionSettings.setDatatypeBean(utils.getDataType(datatype)); } String responseString = null; if (!duplicateflag) { decisionSettings.setUserModifiedBy(userInfo); if (decisionSettings.getId() == 0) { decisionSettings.setUserCreatedBy(userInfo); commonClassDao.save(decisionSettings); } else { decisionSettings.setModifiedDate(new Date()); commonClassDao.update(decisionSettings); } responseString = mapper.writeValueAsString(commonClassDao.getData(DecisionSettings.class)); } else { responseString = duplicateResponseString; } if (fromAPI) { return utils.getResultForApi(responseString); } else { utils.setResponseData(response, settingDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } @Autowired  DecisionPolicyDictionaryController(CommonClassDao commonClassDao);  DecisionPolicyDictionaryController(); @RequestMapping( value = {"/get_SettingsDictionaryDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getSettingsDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_SettingsDictionaryData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getSettingsDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/decision_dictionary/save_Settings"}, method = {RequestMethod.POST}) ModelAndView saveSettingsDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/settings_dictionary/remove_settings"}, method = {RequestMethod.POST}) void removeSettingsDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_RainyDayDictionaryDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getRainyDayDictionaryByNameEntityData(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_RainyDayDictionaryData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getRainyDayDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/decision_dictionary/save_RainyDay"}, method = {RequestMethod.POST}) ModelAndView saveRainyDayDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/decision_dictionary/remove_rainyDay"}, method = {RequestMethod.POST}) void removeRainyDayDictionary(HttpServletRequest request, HttpServletResponse response);  }