List of usage examples for org.springframework.web.bind ServletRequestUtils getRequiredIntParameter
public static int getRequiredIntParameter(ServletRequest request, String name) throws ServletRequestBindingException
From source file:net.sourceforge.subsonic.controller.SetMusicFileInfoController.java
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { int id = ServletRequestUtils.getRequiredIntParameter(request, "id"); String action = request.getParameter("action"); MediaFile mediaFile = mediaFileService.getMediaFile(id); if ("comment".equals(action)) { mediaFile.setComment(StringUtil.toHtml(request.getParameter("comment"))); mediaFileService.updateMediaFile(mediaFile); }// w w w . j ava2s . c o m String url = "main.view?id=" + id; return new ModelAndView(new RedirectView(url)); }
From source file:net.sourceforge.subsonic.controller.SetRatingController.java
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { int id = ServletRequestUtils.getRequiredIntParameter(request, "id"); Integer rating = ServletRequestUtils.getIntParameter(request, "rating"); if (rating == 0) { rating = null;//from ww w.j a va2 s .c o m } MediaFile mediaFile = mediaFileService.getMediaFile(id); String username = securityService.getCurrentUsername(request); ratingService.setRatingForUser(username, mediaFile, rating); return new ModelAndView(new RedirectView("main.view?id=" + id)); }
From source file:net.sourceforge.subsonic.controller.PodcastChannelController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { Map<String, Object> map = new HashMap<String, Object>(); ModelAndView result = super.handleRequestInternal(request, response); result.addObject("model", map); int channelId = ServletRequestUtils.getRequiredIntParameter(request, "id"); map.put("user", securityService.getCurrentUser(request)); map.put("channel", podcastService.getChannel(channelId)); map.put("episodes", podcastService.getEpisodes(channelId)); return result; }
From source file:org.openmrs.module.patientalerts.web.controller.PatientAlertDashboardController.java
/** * Retrieves the Patient, and loads all his/her alerts. * // ww w . j a va2s . c o m * @see org.openmrs.web.controller.PortletController#populateModel(javax.servlet.http.HttpServletRequest, * java.util.Map) */ @Override protected void populateModel(HttpServletRequest request, Map<String, Object> model) { PatientService patService = Context.getPatientService(); PatientAlertsService patAlertService = Context.getService(PatientAlertsService.class); try { int patientId = ServletRequestUtils.getRequiredIntParameter(request, "patientId"); List<String> alertsMessagesForPatient = new ArrayList<String>(); Map<Integer, String> alerts = new HashMap<Integer, String>(); alertsMessagesForPatient .addAll(patAlertService.getAlertsForPatient(patService.getPatient(patientId), false)); int i = 0; for (String alert : alertsMessagesForPatient) { i += 1; alerts.put(i, alert); } model.put("alertsForPatient", alerts); } catch (ServletRequestBindingException e) { log.error("Error generated", e); } super.populateModel(request, model); }
From source file:org.sventon.web.ctrl.template.ListFilesController.java
@Override protected ModelAndView svnHandle(final SVNConnection connection, final BaseCommand command, final long headRevision, final UserRepositoryContext userRepositoryContext, final HttpServletRequest request, final HttpServletResponse response, final BindException exception) throws Exception { final ModelAndView modelAndView = super.svnHandle(connection, command, headRevision, userRepositoryContext, request, response, exception); final Map<String, Object> model = modelAndView.getModel(); final List<DirEntry> entries = (List<DirEntry>) model.get("dirEntries"); final DirEntryKindFilter entryFilter = new DirEntryKindFilter(DirEntry.Kind.FILE); final int rowNumber = ServletRequestUtils.getRequiredIntParameter(request, "rowNumber"); logger.debug("Adding data to model"); model.put("dirEntries", entryFilter.filter(entries)); model.put("rowNumber", rowNumber); modelAndView.setViewName(getViewName()); return modelAndView; }
From source file:net.sourceforge.subsonic.controller.RandomPlaylistController.java
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { int size = ServletRequestUtils.getRequiredIntParameter(request, "size"); String genre = request.getParameter("genre"); if (StringUtils.equalsIgnoreCase("any", genre)) { genre = null;/*w w w . jav a2 s . c om*/ } Integer fromYear = null; Integer toYear = null; String year = request.getParameter("year"); if (!StringUtils.equalsIgnoreCase("any", year)) { String[] tmp = StringUtils.split(year); fromYear = Integer.parseInt(tmp[0]); toYear = Integer.parseInt(tmp[1]); } Integer musicFolderId = ServletRequestUtils.getRequiredIntParameter(request, "musicFolderId"); if (musicFolderId == -1) { musicFolderId = null; } Player player = playerService.getPlayer(request, response); Playlist playlist = player.getPlaylist(); RandomSearchCriteria criteria = new RandomSearchCriteria(size, genre, fromYear, toYear, musicFolderId); playlist.addFiles(false, searchService.getRandomSongs(criteria)); if (request.getParameter("autoRandom") != null) { playlist.setRandomSearchCriteria(criteria); } Map<String, Object> map = new HashMap<String, Object>(); map.put("reloadFrames", reloadFrames); ModelAndView result = super.handleRequestInternal(request, response); result.addObject("model", map); return result; }
From source file:net.sourceforge.subsonic.controller.PlaylistController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { Map<String, Object> map = new HashMap<String, Object>(); int id = ServletRequestUtils.getRequiredIntParameter(request, "id"); User user = securityService.getCurrentUser(request); String username = user.getUsername(); UserSettings userSettings = settingsService.getUserSettings(username); Player player = playerService.getPlayer(request, response); Playlist playlist = playlistService.getPlaylist(id); if (playlist == null) { return new ModelAndView(new RedirectView("notFound.view")); }/*from w w w . j a v a 2s . c om*/ map.put("playlist", playlist); map.put("user", user); map.put("player", player); map.put("editAllowed", username.equals(playlist.getUsername()) || securityService.isAdmin(username)); map.put("partyMode", userSettings.isPartyModeEnabled()); ModelAndView result = super.handleRequestInternal(request, response); result.addObject("model", map); return result; }
From source file:org.openmrs.module.formentry.web.controller.EncounterTaskpaneController.java
/** * @see org.springframework.web.servlet.mvc.AbstractFormController#formBackingObject(javax.servlet.http.HttpServletRequest) *//* w w w . ja v a2 s. c o m*/ protected Object formBackingObject(HttpServletRequest request) throws ServletException { if (!Context.hasPrivilege(FormEntryConstants.PRIV_FORM_ENTRY)) throw new APIAuthenticationException("You must have FormEntry privileges to continue"); // find the relevant patient Integer patientId = ServletRequestUtils.getRequiredIntParameter(request, "patientId"); Patient patient = Context.getPatientService().getPatient(patientId); if (patient == null) throw new APIException("A valid patientId is required for this page. " + patientId + " not found"); // find the relevant encounter types int[] encounterTypeIds = ServletRequestUtils.getIntParameters(request, "encounterTypeId"); List<EncounterType> encounterTypes = new Vector<EncounterType>(); for (int encTypeId : encounterTypeIds) encounterTypes.add(new EncounterType(encTypeId)); // fetch the encounters for this patient EncounterService es = Context.getEncounterService(); List<Encounter> encounters = es.getEncounters(patient, null, null, null, null, encounterTypes, false); if (encounters == null) return Collections.emptyList(); else return encounters; }
From source file:gov.nih.nci.cabig.caaers.web.ae.AdditionalInformationDocumentZipDownloadController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws ServletRequestBindingException { Integer additionalInformationId = ServletRequestUtils.getRequiredIntParameter(request, "additionalInformationId"); List<AdditionalInformationDocument> additionalInformationDocuments = additionalInformationDocumentService .findByAdditionalInformationId(additionalInformationId); File tempFile = null;/*from w w w . j a v a 2s .c o m*/ ZipOutputStream zos = null; FileOutputStream fos = null; List<String> zipEntriesName = new ArrayList<String>(); try { tempFile = File.createTempFile( "additionalInformationFile" + System.currentTimeMillis() + RandomUtils.nextInt(1000), ".zip"); fos = new FileOutputStream(tempFile); zos = new ZipOutputStream(fos); for (AdditionalInformationDocument additionalInformationDocument : additionalInformationDocuments) { String name = getUniqueZipEntryName(additionalInformationDocument, zipEntriesName); zipEntriesName.add(name); ZipEntry zipEntry = new ZipEntry(name); zos.putNextEntry(zipEntry); IOUtils.copy(new FileInputStream(additionalInformationDocument.getFile()), zos); zos.closeEntry(); } zos.flush(); } catch (Exception e) { log.error("Unable to create temp file", e); return null; } finally { if (zos != null) IOUtils.closeQuietly(zos); if (fos != null) IOUtils.closeQuietly(fos); } if (tempFile != null) { FileInputStream fis = null; OutputStream out = null; try { fis = new FileInputStream(tempFile); out = response.getOutputStream(); response.setContentType("application/x-download"); response.setHeader("Content-Disposition", "attachment; filename=" + additionalInformationId + ".zip"); response.setHeader("Content-length", String.valueOf(tempFile.length())); response.setHeader("Pragma", "private"); response.setHeader("Cache-control", "private, must-revalidate"); IOUtils.copy(fis, out); out.flush(); } catch (Exception e) { log.error("Error while reading zip file ", e); } finally { IOUtils.closeQuietly(fis); IOUtils.closeQuietly(out); } FileUtils.deleteQuietly(tempFile); } return null; }