@Test public void testSaveServiceType() { jsonString = "{\"userid\":\"demo\",\"closedLoopServiceDictionaryData\":{\"description\":\"test\",\"serviceName\":\"Test\",\"id\":1}}"; try (BufferedReader br = new BufferedReader(new StringReader(jsonString))) { when(request.getReader()).thenReturn(br); controller.saveServiceType(request, response); assertTrue(response.getContentAsString() != null && response.getContentAsString().contains("closedLoopServiceDictionaryData")); } catch (Exception e) { logger.error("Exception" + e); } }
@RequestMapping(value = {"/cl_dictionary/save_service"}, method = {RequestMethod.POST}) public ModelAndView saveServiceType(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()); ClosedLoopD2Services serviceData; String userId = null; if (fromAPI) { serviceData = mapper.readValue(root.get(dictionaryFields).toString(), ClosedLoopD2Services.class); userId = "API"; } else { serviceData = mapper.readValue(root.get("closedLoopServiceDictionaryData").toString(), ClosedLoopD2Services.class); userId = root.get(userid).textValue(); } UserInfo userInfo = utils.getUserInfo(userId); List<Object> duplicateData = commonClassDao.checkDuplicateEntry(serviceData.getServiceName(), serviceName, ClosedLoopD2Services.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { ClosedLoopD2Services data = (ClosedLoopD2Services) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { serviceData.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != serviceData.getId()))) { duplicateflag = true; } } String responseString = null; if (!duplicateflag) { serviceData.setUserModifiedBy(userInfo); if (serviceData.getId() == 0) { serviceData.setUserCreatedBy(userInfo); commonClassDao.save(serviceData); } else { serviceData.setModifiedDate(new Date()); commonClassDao.update(serviceData); } responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class)); } else { responseString = duplicateResponseString; } if (fromAPI) { return utils.getResultForApi(responseString); } else { utils.setResponseData(response, closedLoopDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; }
ClosedLoopDictionaryController { @RequestMapping(value = {"/cl_dictionary/save_service"}, method = {RequestMethod.POST}) public ModelAndView saveServiceType(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()); ClosedLoopD2Services serviceData; String userId = null; if (fromAPI) { serviceData = mapper.readValue(root.get(dictionaryFields).toString(), ClosedLoopD2Services.class); userId = "API"; } else { serviceData = mapper.readValue(root.get("closedLoopServiceDictionaryData").toString(), ClosedLoopD2Services.class); userId = root.get(userid).textValue(); } UserInfo userInfo = utils.getUserInfo(userId); List<Object> duplicateData = commonClassDao.checkDuplicateEntry(serviceData.getServiceName(), serviceName, ClosedLoopD2Services.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { ClosedLoopD2Services data = (ClosedLoopD2Services) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { serviceData.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != serviceData.getId()))) { duplicateflag = true; } } String responseString = null; if (!duplicateflag) { serviceData.setUserModifiedBy(userInfo); if (serviceData.getId() == 0) { serviceData.setUserCreatedBy(userInfo); commonClassDao.save(serviceData); } else { serviceData.setModifiedDate(new Date()); commonClassDao.update(serviceData); } responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class)); } else { responseString = duplicateResponseString; } if (fromAPI) { return utils.getResultForApi(responseString); } else { utils.setResponseData(response, closedLoopDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } }
ClosedLoopDictionaryController { @RequestMapping(value = {"/cl_dictionary/save_service"}, method = {RequestMethod.POST}) public ModelAndView saveServiceType(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()); ClosedLoopD2Services serviceData; String userId = null; if (fromAPI) { serviceData = mapper.readValue(root.get(dictionaryFields).toString(), ClosedLoopD2Services.class); userId = "API"; } else { serviceData = mapper.readValue(root.get("closedLoopServiceDictionaryData").toString(), ClosedLoopD2Services.class); userId = root.get(userid).textValue(); } UserInfo userInfo = utils.getUserInfo(userId); List<Object> duplicateData = commonClassDao.checkDuplicateEntry(serviceData.getServiceName(), serviceName, ClosedLoopD2Services.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { ClosedLoopD2Services data = (ClosedLoopD2Services) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { serviceData.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != serviceData.getId()))) { duplicateflag = true; } } String responseString = null; if (!duplicateflag) { serviceData.setUserModifiedBy(userInfo); if (serviceData.getId() == 0) { serviceData.setUserCreatedBy(userInfo); commonClassDao.save(serviceData); } else { serviceData.setModifiedDate(new Date()); commonClassDao.update(serviceData); } responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class)); } else { responseString = duplicateResponseString; } if (fromAPI) { return utils.getResultForApi(responseString); } else { utils.setResponseData(response, closedLoopDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } @Autowired  ClosedLoopDictionaryController(CommonClassDao commonClassDao);  ClosedLoopDictionaryController(); }
ClosedLoopDictionaryController { @RequestMapping(value = {"/cl_dictionary/save_service"}, method = {RequestMethod.POST}) public ModelAndView saveServiceType(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()); ClosedLoopD2Services serviceData; String userId = null; if (fromAPI) { serviceData = mapper.readValue(root.get(dictionaryFields).toString(), ClosedLoopD2Services.class); userId = "API"; } else { serviceData = mapper.readValue(root.get("closedLoopServiceDictionaryData").toString(), ClosedLoopD2Services.class); userId = root.get(userid).textValue(); } UserInfo userInfo = utils.getUserInfo(userId); List<Object> duplicateData = commonClassDao.checkDuplicateEntry(serviceData.getServiceName(), serviceName, ClosedLoopD2Services.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { ClosedLoopD2Services data = (ClosedLoopD2Services) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { serviceData.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != serviceData.getId()))) { duplicateflag = true; } } String responseString = null; if (!duplicateflag) { serviceData.setUserModifiedBy(userInfo); if (serviceData.getId() == 0) { serviceData.setUserCreatedBy(userInfo); commonClassDao.save(serviceData); } else { serviceData.setModifiedDate(new Date()); commonClassDao.update(serviceData); } responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class)); } else { responseString = duplicateResponseString; } if (fromAPI) { return utils.getResultForApi(responseString); } else { utils.setResponseData(response, closedLoopDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } @Autowired  ClosedLoopDictionaryController(CommonClassDao commonClassDao);  ClosedLoopDictionaryController(); void setCommonClassDao(CommonClassDao commonClassDao); static void setCommonClassDao(CommonClassDaoImpl commonClassDaoImpl); @RequestMapping( value = {"/get_VSCLActionDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getVSCLActionDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_VSCLActionData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getVSCLActionDictionaryEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_VNFTypeDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getVNFTypeDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_VNFTypeData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getVNFTypeDictionaryEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_PEPOptionsDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getPEPOptionsDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_PEPOptionsData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getPEPOptionsDictionaryEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_VarbindDictionaryDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getVarbindDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_VarbindDictionaryData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getVarbindDictionaryEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_ClosedLoopServicesDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getClosedLoopServiceDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_ClosedLoopServicesData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getClosedLoopServiceDictionaryEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_ClosedLoopSiteDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getClosedLoopSiteDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_ClosedLoopSiteData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getClosedLoopSiteDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/save_vsclAction"}, method = {RequestMethod.POST}) ModelAndView saveVSCLAction(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/remove_VsclAction"}, method = {RequestMethod.POST}) void removeVSCLAction(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/save_vnfType"}, method = {RequestMethod.POST}) ModelAndView saveVnfType(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/remove_vnfType"}, method = {RequestMethod.POST}) void removeVnfType(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/save_pepOptions"}, method = {RequestMethod.POST}) ModelAndView savePEPOptions(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/remove_pepOptions"}, method = {RequestMethod.POST}) void removePEPOptions(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/save_service"}, method = {RequestMethod.POST}) ModelAndView saveServiceType(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/remove_Service"}, method = {RequestMethod.POST}) void removeServiceType(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/save_siteName"}, method = {RequestMethod.POST}) ModelAndView saveSiteType(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/remove_site"}, method = {RequestMethod.POST}) void removeSiteType(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/save_varbind"}, method = {RequestMethod.POST}) ModelAndView saveVarbind(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/remove_varbindDict"}, method = {RequestMethod.POST}) void removeVarbind(HttpServletRequest request, HttpServletResponse response); }
ClosedLoopDictionaryController { @RequestMapping(value = {"/cl_dictionary/save_service"}, method = {RequestMethod.POST}) public ModelAndView saveServiceType(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()); ClosedLoopD2Services serviceData; String userId = null; if (fromAPI) { serviceData = mapper.readValue(root.get(dictionaryFields).toString(), ClosedLoopD2Services.class); userId = "API"; } else { serviceData = mapper.readValue(root.get("closedLoopServiceDictionaryData").toString(), ClosedLoopD2Services.class); userId = root.get(userid).textValue(); } UserInfo userInfo = utils.getUserInfo(userId); List<Object> duplicateData = commonClassDao.checkDuplicateEntry(serviceData.getServiceName(), serviceName, ClosedLoopD2Services.class); boolean duplicateflag = false; if (!duplicateData.isEmpty()) { ClosedLoopD2Services data = (ClosedLoopD2Services) duplicateData.get(0); if (request.getParameter(operation) != null && "update".equals(request.getParameter(operation))) { serviceData.setId(data.getId()); } else if ((request.getParameter(operation) != null && !"update".equals(request.getParameter(operation))) || (request.getParameter(operation) == null && (data.getId() != serviceData.getId()))) { duplicateflag = true; } } String responseString = null; if (!duplicateflag) { serviceData.setUserModifiedBy(userInfo); if (serviceData.getId() == 0) { serviceData.setUserCreatedBy(userInfo); commonClassDao.save(serviceData); } else { serviceData.setModifiedDate(new Date()); commonClassDao.update(serviceData); } responseString = mapper.writeValueAsString(commonClassDao.getData(ClosedLoopD2Services.class)); } else { responseString = duplicateResponseString; } if (fromAPI) { return utils.getResultForApi(responseString); } else { utils.setResponseData(response, closedLoopDatas, responseString); } } catch (Exception e) { utils.setErrorResponseData(response, e); } return null; } @Autowired  ClosedLoopDictionaryController(CommonClassDao commonClassDao);  ClosedLoopDictionaryController(); void setCommonClassDao(CommonClassDao commonClassDao); static void setCommonClassDao(CommonClassDaoImpl commonClassDaoImpl); @RequestMapping( value = {"/get_VSCLActionDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getVSCLActionDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_VSCLActionData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getVSCLActionDictionaryEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_VNFTypeDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getVNFTypeDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_VNFTypeData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getVNFTypeDictionaryEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_PEPOptionsDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getPEPOptionsDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_PEPOptionsData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getPEPOptionsDictionaryEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_VarbindDictionaryDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getVarbindDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_VarbindDictionaryData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getVarbindDictionaryEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_ClosedLoopServicesDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getClosedLoopServiceDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_ClosedLoopServicesData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getClosedLoopServiceDictionaryEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_ClosedLoopSiteDataByName"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getClosedLoopSiteDictionaryByNameEntityData(HttpServletResponse response); @RequestMapping( value = {"/get_ClosedLoopSiteData"}, method = {RequestMethod.GET}, produces = MediaType.APPLICATION_JSON_VALUE) void getClosedLoopSiteDictionaryEntityData(HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/save_vsclAction"}, method = {RequestMethod.POST}) ModelAndView saveVSCLAction(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/remove_VsclAction"}, method = {RequestMethod.POST}) void removeVSCLAction(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/save_vnfType"}, method = {RequestMethod.POST}) ModelAndView saveVnfType(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/remove_vnfType"}, method = {RequestMethod.POST}) void removeVnfType(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/save_pepOptions"}, method = {RequestMethod.POST}) ModelAndView savePEPOptions(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/remove_pepOptions"}, method = {RequestMethod.POST}) void removePEPOptions(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/save_service"}, method = {RequestMethod.POST}) ModelAndView saveServiceType(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/remove_Service"}, method = {RequestMethod.POST}) void removeServiceType(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/save_siteName"}, method = {RequestMethod.POST}) ModelAndView saveSiteType(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/remove_site"}, method = {RequestMethod.POST}) void removeSiteType(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/save_varbind"}, method = {RequestMethod.POST}) ModelAndView saveVarbind(HttpServletRequest request, HttpServletResponse response); @RequestMapping(value = {"/cl_dictionary/remove_varbindDict"}, method = {RequestMethod.POST}) void removeVarbind(HttpServletRequest request, HttpServletResponse response);  }