@Test public void testUpdatePSServiceDictionary() { jsonString = "{\"userid\":\"demo\",\"psServiceDictionaryData\":{\"description\":\"test\",\"name\":\"Test\"}}"; try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.savePSServiceDictionary(request, response); assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("psServiceDictionaryDatas")); } catch (Exception e) { logger.error("Exception" + e); } }
@RequestMapping(value = {"/ps_dictionary/save_psService"}, method = {RequestMethod.POST}) public ModelAndView savePSServiceDictionary(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()); PolicyScopeService onapData; if (fromAPI) { onapData = mapper.readValue(root.get(dictionaryFields).toString(), PolicyScopeService.class); } else { onapData = mapper.readValue(root.get("psServiceDictionaryData").toString(), PolicyScopeService.class); } List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeService.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { PolicyScopeService data = (PolicyScopeService) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { onapData.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != onapData.getId()))) { duplicateflag = true; } } String responseString = null; if (!duplicateflag) { if (onapData.getId() == 0) { commonClassDao.save(onapData); } else { commonClassDao.update(onapData); } responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeService.class)); } else { responseString = duplicateResponseString; } if (fromAPI) { return utils.getResultForApi(responseString); } else { utils.setResponseData(response, psServiceDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; }
PolicyScopeDictionaryController { @RequestMapping(value = {"/ps_dictionary/save_psService"}, method = {RequestMethod.POST}) public ModelAndView savePSServiceDictionary(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()); PolicyScopeService onapData; if (fromAPI) { onapData = mapper.readValue(root.get(dictionaryFields).toString(), PolicyScopeService.class); } else { onapData = mapper.readValue(root.get("psServiceDictionaryData").toString(), PolicyScopeService.class); } List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeService.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { PolicyScopeService data = (PolicyScopeService) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { onapData.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != onapData.getId()))) { duplicateflag = true; } } String responseString = null; if (!duplicateflag) { if (onapData.getId() == 0) { commonClassDao.save(onapData); } else { commonClassDao.update(onapData); } responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeService.class)); } else { responseString = duplicateResponseString; } if (fromAPI) { return utils.getResultForApi(responseString); } else { utils.setResponseData(response, psServiceDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } }
PolicyScopeDictionaryController { @RequestMapping(value = {"/ps_dictionary/save_psService"}, method = {RequestMethod.POST}) public ModelAndView savePSServiceDictionary(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()); PolicyScopeService onapData; if (fromAPI) { onapData = mapper.readValue(root.get(dictionaryFields).toString(), PolicyScopeService.class); } else { onapData = mapper.readValue(root.get("psServiceDictionaryData").toString(), PolicyScopeService.class); } List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeService.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { PolicyScopeService data = (PolicyScopeService) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { onapData.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != onapData.getId()))) { duplicateflag = true; } } String responseString = null; if (!duplicateflag) { if (onapData.getId() == 0) { commonClassDao.save(onapData); } else { commonClassDao.update(onapData); } responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeService.class)); } else { responseString = duplicateResponseString; } if (fromAPI) { return utils.getResultForApi(responseString); } else { utils.setResponseData(response, psServiceDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } PolicyScopeDictionaryController(); @Autowired  PolicyScopeDictionaryController(CommonClassDao commonClassDao); }
PolicyScopeDictionaryController { @RequestMapping(value = {"/ps_dictionary/save_psService"}, method = {RequestMethod.POST}) public ModelAndView savePSServiceDictionary(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()); PolicyScopeService onapData; if (fromAPI) { onapData = mapper.readValue(root.get(dictionaryFields).toString(), PolicyScopeService.class); } else { onapData = mapper.readValue(root.get("psServiceDictionaryData").toString(), PolicyScopeService.class); } List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeService.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { PolicyScopeService data = (PolicyScopeService) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { onapData.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != onapData.getId()))) { duplicateflag = true; } } String responseString = null; if (!duplicateflag) { if (onapData.getId() == 0) { commonClassDao.save(onapData); } else { commonClassDao.update(onapData); } responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeService.class)); } else { responseString = duplicateResponseString; } if (fromAPI) { return utils.getResultForApi(responseString); } else { utils.setResponseData(response, psServiceDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } PolicyScopeDictionaryController(); @Autowired  PolicyScopeDictionaryController(CommonClassDao commonClassDao); void setCommonClassDao(CommonClassDao commonClassDao); @RequestMapping( value = {"/get_GroupPolicyScopeDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getGroupPolicyScopeEntityDataByName(HttpServletResponse response); @RequestMapping( value = {"/get_GroupPolicyScopeData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getGroupPolicyScopeEntityData(HttpServletResponse response); @RequestMapping(value = {"/ps_dictionary/save_psGroupPolicyScope"}, method = {RequestMethod.POST}) ModelAndView savePSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ps_dictionary/remove_GroupPolicyScope"}, method = {RequestMethod.POST}) void removePSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_PSClosedLoopDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getPSClosedLoopEntityDataByName(HttpServletResponse response); @RequestMapping( value = {"/get_PSClosedLoopData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getPSClosedLoopEntityData(HttpServletResponse response); @RequestMapping(value = {"/ps_dictionary/save_psClosedLoop"}, method = {RequestMethod.POST}) ModelAndView savePSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ps_dictionary/remove_PSClosedLoop"}, method = {RequestMethod.POST}) void removePSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_PSServiceDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getPSServiceEntityDataByName(HttpServletResponse response); @RequestMapping( value = {"/get_PSServiceData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getPSServiceEntityData(HttpServletResponse response); @RequestMapping(value = {"/ps_dictionary/save_psService"}, method = {RequestMethod.POST}) ModelAndView savePSServiceDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ps_dictionary/remove_PSService"}, method = {RequestMethod.POST}) void removePSServiceDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_PSTypeDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getPSTypeEntityDataByName(HttpServletResponse response); @RequestMapping( value = {"/get_PSTypeData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getPSTypeEntityData(HttpServletResponse response); @RequestMapping(value = {"/ps_dictionary/save_psType"}, method = {RequestMethod.POST}) ModelAndView savePSTypeDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ps_dictionary/remove_PSType"}, method = {RequestMethod.POST}) void removePSTypeDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_PSResourceDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getPSResourceEntityDataByName(HttpServletResponse response); @RequestMapping( value = {"/get_PSResourceData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getPSResourceEntityData(HttpServletResponse response); @RequestMapping(value = {"/ps_dictionary/save_psResource"}, method = {RequestMethod.POST}) ModelAndView savePSResourceDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ps_dictionary/remove_PSResource"}, method = {RequestMethod.POST}) void removePSResourceDictionary(HttpServletRequest request, HttpServletResponse response); }
PolicyScopeDictionaryController { @RequestMapping(value = {"/ps_dictionary/save_psService"}, method = {RequestMethod.POST}) public ModelAndView savePSServiceDictionary(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()); PolicyScopeService onapData; if (fromAPI) { onapData = mapper.readValue(root.get(dictionaryFields).toString(), PolicyScopeService.class); } else { onapData = mapper.readValue(root.get("psServiceDictionaryData").toString(), PolicyScopeService.class); } List<Object> duplicateData = commonClassDao.checkDuplicateEntry(onapData.getName(), "name", PolicyScopeService.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { PolicyScopeService data = (PolicyScopeService) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { onapData.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != onapData.getId()))) { duplicateflag = true; } } String responseString = null; if (!duplicateflag) { if (onapData.getId() == 0) { commonClassDao.save(onapData); } else { commonClassDao.update(onapData); } responseString = mapper.writeValueAsString(commonClassDao.getData(PolicyScopeService.class)); } else { responseString = duplicateResponseString; } if (fromAPI) { return utils.getResultForApi(responseString); } else { utils.setResponseData(response, psServiceDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } PolicyScopeDictionaryController(); @Autowired  PolicyScopeDictionaryController(CommonClassDao commonClassDao); void setCommonClassDao(CommonClassDao commonClassDao); @RequestMapping( value = {"/get_GroupPolicyScopeDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getGroupPolicyScopeEntityDataByName(HttpServletResponse response); @RequestMapping( value = {"/get_GroupPolicyScopeData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getGroupPolicyScopeEntityData(HttpServletResponse response); @RequestMapping(value = {"/ps_dictionary/save_psGroupPolicyScope"}, method = {RequestMethod.POST}) ModelAndView savePSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ps_dictionary/remove_GroupPolicyScope"}, method = {RequestMethod.POST}) void removePSGroupScopeDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_PSClosedLoopDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getPSClosedLoopEntityDataByName(HttpServletResponse response); @RequestMapping( value = {"/get_PSClosedLoopData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getPSClosedLoopEntityData(HttpServletResponse response); @RequestMapping(value = {"/ps_dictionary/save_psClosedLoop"}, method = {RequestMethod.POST}) ModelAndView savePSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ps_dictionary/remove_PSClosedLoop"}, method = {RequestMethod.POST}) void removePSClosedLoopDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_PSServiceDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getPSServiceEntityDataByName(HttpServletResponse response); @RequestMapping( value = {"/get_PSServiceData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getPSServiceEntityData(HttpServletResponse response); @RequestMapping(value = {"/ps_dictionary/save_psService"}, method = {RequestMethod.POST}) ModelAndView savePSServiceDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ps_dictionary/remove_PSService"}, method = {RequestMethod.POST}) void removePSServiceDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_PSTypeDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getPSTypeEntityDataByName(HttpServletResponse response); @RequestMapping( value = {"/get_PSTypeData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getPSTypeEntityData(HttpServletResponse response); @RequestMapping(value = {"/ps_dictionary/save_psType"}, method = {RequestMethod.POST}) ModelAndView savePSTypeDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ps_dictionary/remove_PSType"}, method = {RequestMethod.POST}) void removePSTypeDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping( value = {"/get_PSResourceDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getPSResourceEntityDataByName(HttpServletResponse response); @RequestMapping( value = {"/get_PSResourceData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getPSResourceEntityData(HttpServletResponse response); @RequestMapping(value = {"/ps_dictionary/save_psResource"}, method = {RequestMethod.POST}) ModelAndView savePSResourceDictionary(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/ps_dictionary/remove_PSResource"}, method = {RequestMethod.POST}) void removePSResourceDictionary(HttpServletRequest request, HttpServletResponse response);  }