@Test public void testSaveBRMSDependencyDictionary() { logger.info("testSaveBRMSDependencyDictionary: Entering"); jsonString = "{\"brmsDependencyDictionaryData\": " + "{\"ruleName\": \"test\",\"rule\": \"test\"},\"userid\": \"testName\"}"; try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.saveBRMSDependencyDictionary(request, response); logger.info("response.getContentAsString(): " + response.getContentAsString()); assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("brmsDependencyDictionaryData")); } catch (Exception e) { fail("Exception: " + e); } logger.info("testSaveBRMSDependencyDictionary: exit"); }
@RequestMapping(value = {"/brms_dictionary/save_BRMSDependencyData"}, method = {RequestMethod.POST}) public ModelAndView saveBRMSDependencyDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { LOGGER.debug("DictionaryController: saveBRMSDependencyDictionary() is called"); boolean fromAPI = utils.isRequestFromAPI(request); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); BrmsDependency brmsDependency; String userId = null; if (fromAPI) { brmsDependency = mapper.readValue(root.get(dictionaryFields).toString(), BrmsDependency.class); userId = "API"; } else { brmsDependency = mapper.readValue(root.get("brmsDependencyDictionaryData").toString(), BrmsDependency.class); userId = root.get(userid).textValue(); } UserInfo userInfo = utils.getUserInfo(userId); List<Object> duplicateData = commonClassDao.checkDuplicateEntry(brmsDependency.getDependencyName(), dependencyName, BrmsDependency.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { BrmsDependency data = (BrmsDependency) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { brmsDependency.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != brmsDependency.getId()))) { duplicateflag = true; } } LOGGER.audit("the userId from the onap portal is: " + userId); String responseString = null; if (brmsDependency.getDependency() != null && !("").equals(brmsDependency.getDependency().trim())) { PEDependency dependency = null; try { dependency = PolicyUtils.jsonStringToObject(brmsDependency.getDependency(), PEDependency.class); } catch (Exception e) { LOGGER.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID + "wrong data given for BRMS PEDependency Dictionary : " + brmsDependency.getDependency(), e); } if (dependency == null) { responseString = errorMessage; } else { if (!duplicateflag) { brmsDependency.setUserModifiedBy(userInfo); if (brmsDependency.getId() == 0) { brmsDependency.setUserCreatedBy(userInfo); commonClassDao.save(brmsDependency); } else { brmsDependency.setModifiedDate(new Date()); commonClassDao.update(brmsDependency); } responseString = mapper.writeValueAsString(commonClassDao.getData(BrmsDependency.class)); } else { responseString = duplicateResponseString; } } } if (fromAPI) { if (responseString != null && !duplicateResponseString.equals(responseString) && !errorMessage.equals(responseString)) { responseString = successMsg; } ModelAndView result = new ModelAndView(); result.setViewName(responseString); return result; } else { utils.setResponseData(response, brmsDependencyDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; }
BRMSDictionaryController { @RequestMapping(value = {"/brms_dictionary/save_BRMSDependencyData"}, method = {RequestMethod.POST}) public ModelAndView saveBRMSDependencyDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { LOGGER.debug("DictionaryController: saveBRMSDependencyDictionary() is called"); boolean fromAPI = utils.isRequestFromAPI(request); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); BrmsDependency brmsDependency; String userId = null; if (fromAPI) { brmsDependency = mapper.readValue(root.get(dictionaryFields).toString(), BrmsDependency.class); userId = "API"; } else { brmsDependency = mapper.readValue(root.get("brmsDependencyDictionaryData").toString(), BrmsDependency.class); userId = root.get(userid).textValue(); } UserInfo userInfo = utils.getUserInfo(userId); List<Object> duplicateData = commonClassDao.checkDuplicateEntry(brmsDependency.getDependencyName(), dependencyName, BrmsDependency.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { BrmsDependency data = (BrmsDependency) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { brmsDependency.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != brmsDependency.getId()))) { duplicateflag = true; } } LOGGER.audit("the userId from the onap portal is: " + userId); String responseString = null; if (brmsDependency.getDependency() != null && !("").equals(brmsDependency.getDependency().trim())) { PEDependency dependency = null; try { dependency = PolicyUtils.jsonStringToObject(brmsDependency.getDependency(), PEDependency.class); } catch (Exception e) { LOGGER.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID + "wrong data given for BRMS PEDependency Dictionary : " + brmsDependency.getDependency(), e); } if (dependency == null) { responseString = errorMessage; } else { if (!duplicateflag) { brmsDependency.setUserModifiedBy(userInfo); if (brmsDependency.getId() == 0) { brmsDependency.setUserCreatedBy(userInfo); commonClassDao.save(brmsDependency); } else { brmsDependency.setModifiedDate(new Date()); commonClassDao.update(brmsDependency); } responseString = mapper.writeValueAsString(commonClassDao.getData(BrmsDependency.class)); } else { responseString = duplicateResponseString; } } } if (fromAPI) { if (responseString != null && !duplicateResponseString.equals(responseString) && !errorMessage.equals(responseString)) { responseString = successMsg; } ModelAndView result = new ModelAndView(); result.setViewName(responseString); return result; } else { utils.setResponseData(response, brmsDependencyDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } }
BRMSDictionaryController { @RequestMapping(value = {"/brms_dictionary/save_BRMSDependencyData"}, method = {RequestMethod.POST}) public ModelAndView saveBRMSDependencyDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { LOGGER.debug("DictionaryController: saveBRMSDependencyDictionary() is called"); boolean fromAPI = utils.isRequestFromAPI(request); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); BrmsDependency brmsDependency; String userId = null; if (fromAPI) { brmsDependency = mapper.readValue(root.get(dictionaryFields).toString(), BrmsDependency.class); userId = "API"; } else { brmsDependency = mapper.readValue(root.get("brmsDependencyDictionaryData").toString(), BrmsDependency.class); userId = root.get(userid).textValue(); } UserInfo userInfo = utils.getUserInfo(userId); List<Object> duplicateData = commonClassDao.checkDuplicateEntry(brmsDependency.getDependencyName(), dependencyName, BrmsDependency.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { BrmsDependency data = (BrmsDependency) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { brmsDependency.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != brmsDependency.getId()))) { duplicateflag = true; } } LOGGER.audit("the userId from the onap portal is: " + userId); String responseString = null; if (brmsDependency.getDependency() != null && !("").equals(brmsDependency.getDependency().trim())) { PEDependency dependency = null; try { dependency = PolicyUtils.jsonStringToObject(brmsDependency.getDependency(), PEDependency.class); } catch (Exception e) { LOGGER.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID + "wrong data given for BRMS PEDependency Dictionary : " + brmsDependency.getDependency(), e); } if (dependency == null) { responseString = errorMessage; } else { if (!duplicateflag) { brmsDependency.setUserModifiedBy(userInfo); if (brmsDependency.getId() == 0) { brmsDependency.setUserCreatedBy(userInfo); commonClassDao.save(brmsDependency); } else { brmsDependency.setModifiedDate(new Date()); commonClassDao.update(brmsDependency); } responseString = mapper.writeValueAsString(commonClassDao.getData(BrmsDependency.class)); } else { responseString = duplicateResponseString; } } } if (fromAPI) { if (responseString != null && !duplicateResponseString.equals(responseString) && !errorMessage.equals(responseString)) { responseString = successMsg; } ModelAndView result = new ModelAndView(); result.setViewName(responseString); return result; } else { utils.setResponseData(response, brmsDependencyDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } @Autowired  BRMSDictionaryController(CommonClassDao commonClassDao);  BRMSDictionaryController(); }
BRMSDictionaryController { @RequestMapping(value = {"/brms_dictionary/save_BRMSDependencyData"}, method = {RequestMethod.POST}) public ModelAndView saveBRMSDependencyDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { LOGGER.debug("DictionaryController: saveBRMSDependencyDictionary() is called"); boolean fromAPI = utils.isRequestFromAPI(request); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); BrmsDependency brmsDependency; String userId = null; if (fromAPI) { brmsDependency = mapper.readValue(root.get(dictionaryFields).toString(), BrmsDependency.class); userId = "API"; } else { brmsDependency = mapper.readValue(root.get("brmsDependencyDictionaryData").toString(), BrmsDependency.class); userId = root.get(userid).textValue(); } UserInfo userInfo = utils.getUserInfo(userId); List<Object> duplicateData = commonClassDao.checkDuplicateEntry(brmsDependency.getDependencyName(), dependencyName, BrmsDependency.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { BrmsDependency data = (BrmsDependency) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { brmsDependency.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != brmsDependency.getId()))) { duplicateflag = true; } } LOGGER.audit("the userId from the onap portal is: " + userId); String responseString = null; if (brmsDependency.getDependency() != null && !("").equals(brmsDependency.getDependency().trim())) { PEDependency dependency = null; try { dependency = PolicyUtils.jsonStringToObject(brmsDependency.getDependency(), PEDependency.class); } catch (Exception e) { LOGGER.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID + "wrong data given for BRMS PEDependency Dictionary : " + brmsDependency.getDependency(), e); } if (dependency == null) { responseString = errorMessage; } else { if (!duplicateflag) { brmsDependency.setUserModifiedBy(userInfo); if (brmsDependency.getId() == 0) { brmsDependency.setUserCreatedBy(userInfo); commonClassDao.save(brmsDependency); } else { brmsDependency.setModifiedDate(new Date()); commonClassDao.update(brmsDependency); } responseString = mapper.writeValueAsString(commonClassDao.getData(BrmsDependency.class)); } else { responseString = duplicateResponseString; } } } if (fromAPI) { if (responseString != null && !duplicateResponseString.equals(responseString) && !errorMessage.equals(responseString)) { responseString = successMsg; } ModelAndView result = new ModelAndView(); result.setViewName(responseString); return result; } else { utils.setResponseData(response, brmsDependencyDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } @Autowired  BRMSDictionaryController(CommonClassDao commonClassDao);  BRMSDictionaryController(); static void setCommonClassDao(CommonClassDao commonClassDao2); @RequestMapping( value = {"/get_BRMSParamDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getBRMSParamDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_BRMSParamData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getBRMSParamDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/brms_dictionary/set_BRMSParamData"}, method = {RequestMethod.POST}) static void setRuleData(HttpServletRequest request); @RequestMapping(value = {"/brms_dictionary/save_BRMSParam"}, method = {RequestMethod.POST}) ModelAndView saveBRMSParamDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/brms_dictionary/remove_brmsParam"}, method = {RequestMethod.POST}) void removeBRMSParamDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_BRMSDependencyDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getBRMSDependencyDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_BRMSDependencyData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getBRMSDependencyDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/brms_dictionary/save_BRMSDependencyData"}, method = {RequestMethod.POST}) ModelAndView saveBRMSDependencyDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/brms_dictionary/remove_brmsDependency"}, method = {RequestMethod.POST}) void removeBRMSDependencyDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_BRMSControllerDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getBRMSControllerDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_BRMSControllerData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getBRMSControllerDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/brms_dictionary/save_BRMSControllerData"}, method = {RequestMethod.POST}) ModelAndView saveBRMSControllerDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/brms_dictionary/remove_brmsController"}, method = {RequestMethod.POST}) void removeBRMSControllerDictionary(HttpServletRequest request, HttpServletResponse response); BrmsDependency getDependencyDataByID(String dependencyName); BrmsController getControllerDataByID(String controllerName); }
BRMSDictionaryController { @RequestMapping(value = {"/brms_dictionary/save_BRMSDependencyData"}, method = {RequestMethod.POST}) public ModelAndView saveBRMSDependencyDictionary(HttpServletRequest request, HttpServletResponse response) throws IOException { DictionaryUtils utils = getDictionaryUtilsInstance(); try { LOGGER.debug("DictionaryController: saveBRMSDependencyDictionary() is called"); boolean fromAPI = utils.isRequestFromAPI(request); ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); JsonNode root = mapper.readTree(request.getReader()); BrmsDependency brmsDependency; String userId = null; if (fromAPI) { brmsDependency = mapper.readValue(root.get(dictionaryFields).toString(), BrmsDependency.class); userId = "API"; } else { brmsDependency = mapper.readValue(root.get("brmsDependencyDictionaryData").toString(), BrmsDependency.class); userId = root.get(userid).textValue(); } UserInfo userInfo = utils.getUserInfo(userId); List<Object> duplicateData = commonClassDao.checkDuplicateEntry(brmsDependency.getDependencyName(), dependencyName, BrmsDependency.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { BrmsDependency data = (BrmsDependency) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { brmsDependency.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != brmsDependency.getId()))) { duplicateflag = true; } } LOGGER.audit("the userId from the onap portal is: " + userId); String responseString = null; if (brmsDependency.getDependency() != null && !("").equals(brmsDependency.getDependency().trim())) { PEDependency dependency = null; try { dependency = PolicyUtils.jsonStringToObject(brmsDependency.getDependency(), PEDependency.class); } catch (Exception e) { LOGGER.error(XACMLErrorConstants.ERROR_SCHEMA_INVALID + "wrong data given for BRMS PEDependency Dictionary : " + brmsDependency.getDependency(), e); } if (dependency == null) { responseString = errorMessage; } else { if (!duplicateflag) { brmsDependency.setUserModifiedBy(userInfo); if (brmsDependency.getId() == 0) { brmsDependency.setUserCreatedBy(userInfo); commonClassDao.save(brmsDependency); } else { brmsDependency.setModifiedDate(new Date()); commonClassDao.update(brmsDependency); } responseString = mapper.writeValueAsString(commonClassDao.getData(BrmsDependency.class)); } else { responseString = duplicateResponseString; } } } if (fromAPI) { if (responseString != null && !duplicateResponseString.equals(responseString) && !errorMessage.equals(responseString)) { responseString = successMsg; } ModelAndView result = new ModelAndView(); result.setViewName(responseString); return result; } else { utils.setResponseData(response, brmsDependencyDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } @Autowired  BRMSDictionaryController(CommonClassDao commonClassDao);  BRMSDictionaryController(); static void setCommonClassDao(CommonClassDao commonClassDao2); @RequestMapping( value = {"/get_BRMSParamDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getBRMSParamDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_BRMSParamData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getBRMSParamDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/brms_dictionary/set_BRMSParamData"}, method = {RequestMethod.POST}) static void setRuleData(HttpServletRequest request); @RequestMapping(value = {"/brms_dictionary/save_BRMSParam"}, method = {RequestMethod.POST}) ModelAndView saveBRMSParamDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/brms_dictionary/remove_brmsParam"}, method = {RequestMethod.POST}) void removeBRMSParamDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_BRMSDependencyDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getBRMSDependencyDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_BRMSDependencyData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getBRMSDependencyDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/brms_dictionary/save_BRMSDependencyData"}, method = {RequestMethod.POST}) ModelAndView saveBRMSDependencyDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/brms_dictionary/remove_brmsDependency"}, method = {RequestMethod.POST}) void removeBRMSDependencyDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_BRMSControllerDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getBRMSControllerDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_BRMSControllerData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getBRMSControllerDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/brms_dictionary/save_BRMSControllerData"}, method = {RequestMethod.POST}) ModelAndView saveBRMSControllerDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/brms_dictionary/remove_brmsController"}, method = {RequestMethod.POST}) void removeBRMSControllerDictionary(HttpServletRequest request, HttpServletResponse response); BrmsDependency getDependencyDataByID(String dependencyName); BrmsController getControllerDataByID(String controllerName);  }