@RequestMapping(value = "/deleteDrive", method = RequestMethod.GET) public @ResponseBody void deleteDrive(@RequestParam("rowId") Integer rowId) { try { Drive drive = driveService.getDrive(rowId); driveService.deleteDrive(drive); } catch (HelixServiceException e) { e.printStackTrace(); } }
@RequestMapping(value = "/saveOrUpdateDriveInfo", method = RequestMethod.GET) public @ResponseBody String saveOrUpdateDriveInfo( @RequestParam("description") String description, @RequestParam("month") Integer month, @RequestParam("year") Integer year, @RequestParam("totalAmount") String totalAmount, @RequestParam("totalCount") String totalCount, @RequestParam("totalCCAmount") String totalCCAmount, @RequestParam("averageAmount") String averageAmount, @RequestParam("Response") String Response, @RequestParam("inProcess") String inProcess, @RequestParam("userName") String userName, @RequestParam("driveId") Integer driveId, HttpServletResponse response) { // set encoding explicitly response.setCharacterEncoding("UTF-8"); try { User user = userService.getUser(userName); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = new Date(); Date currentDate = dateFormat.parse(dateFormat.format(date)); if (driveId != null) { // update drive info Drive drive = driveService.getDrive(driveId); drive.setDriveName(description); drive.setDriveMonth(month); drive.setDriveYear(year); drive.setFlInProcess(Boolean.valueOf(inProcess)); drive.setIdUserLastUpdated(user); drive.setDateUpdated(currentDate); driveService.updateDrive(drive); return driveId.toString(); } else { // add drive info Drive drive = new Drive(); drive.setDriveName(description); drive.setDriveMonth(month); drive.setDriveYear(year); drive.setFlInProcess(Boolean.valueOf(inProcess)); drive.setUser(user); drive.setDateCreated(currentDate); // set campaign drive.setCampaigns(buildCampaigns(drive)); driveService.saveDrive(drive); String driveIdStr = driveService.getLastDriveId(); return driveIdStr; } } catch (HelixServiceException e) { e.printStackTrace(); return null; } catch (Exception e) { e.printStackTrace(); return null; } }
@RequestMapping(value = "/load", method = RequestMethod.GET) public @ResponseBody void loadDriveDetails(HttpServletResponse response) { response.setContentType("text/xml"); response.setHeader("Cache-Control", "no-cache"); try { response.getWriter().write(buildDriveResponseXML().asXML()); } catch (HelixServiceException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
@RequestMapping(value = "/loadCampaignList", method = RequestMethod.GET) public @ResponseBody void loadCampaignDetails( HttpServletResponse response, @RequestParam("driveId") Integer driveId) { response.setContentType("text/xml"); response.setHeader("Cache-Control", "no-cache"); try { response.getWriter().write(buildCampaignListInfoResponseXML(driveId).asXML()); } catch (HelixServiceException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
private List<Campaign> buildCampaigns(Drive drive) { List<Campaign> campaigns = new ArrayList<Campaign>(); try { List<Client> clients = clientService.getClients(); for (Client client : clients) { Campaign campaign = new Campaign(); campaign.setDrive(drive); campaign.setClient(client); campaign.setCampaignYear(String.valueOf(drive.getDriveYear())); campaigns.add(campaign); } } catch (HelixServiceException e) { e.printStackTrace(); } return campaigns; }
@RequestMapping(value = "/print", method = RequestMethod.GET) public ModelAndView print(ModelAndView modelAndView) { List<DriveReport> driveReportList = new ArrayList<DriveReport>(); List<Drive> driveList = null; try { driveList = driveService.getDrives(); } catch (HelixServiceException e) { e.printStackTrace(); } for (Drive drive : driveList) { DriveReport driveReport = new DriveReport(); driveReport.setName(drive.getDriveName()); if (drive.getDriveMonth() != null) { driveReport.setMonth(drive.getDriveMonth().toString()); } if (drive.getDriveYear() != null) { driveReport.setYear(drive.getDriveYear().toString()); } driveReportList.add(driveReport); } JRDataSource ds = new JRBeanCollectionDataSource(driveReportList); // In order to use Spring's built-in Jasper support, // We are required to pass our datasource as a map parameter // parameterMap is the Model of our application Map<String, Object> parameterMap = new HashMap<String, Object>(); parameterMap.put("datasource", ds); // pdfReport is the View of our application // This is declared inside the /WEB-INF/jasper-views.xml modelAndView = new ModelAndView("pdfReportDrive", parameterMap); // Return the View and the Model combined return modelAndView; }