Example usage for org.springframework.web.util UriComponentsBuilder path

List of usage examples for org.springframework.web.util UriComponentsBuilder path

Introduction

In this page you can find the example usage for org.springframework.web.util UriComponentsBuilder path.

Prototype

@Override
public UriComponentsBuilder path(String path) 

Source Link

Document

Append the given path to the existing path of this builder.

Usage

From source file:de.otto.mongodb.profiler.web.OpProfileController.java

@RequestMapping(value = "/control", method = RequestMethod.POST, params = "action=reset", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public View resetProfiles(@PathVariable("connectionId") final String connectionId,
        @PathVariable("databaseName") final String databaseName,
        final UriComponentsBuilder uriComponentsBuilder) throws ResourceNotFoundException {

    getProfilerService().getOpProfiler(requireDatabase(connectionId, databaseName)).reset();

    return new RedirectView(uriComponentsBuilder.path("/connections/{connectionId}/databases/{databaseName}")
            .fragment("OpProfiles").buildAndExpand(connectionId, databaseName).toUriString());
}

From source file:de.otto.mongodb.profiler.web.OpProfileController.java

@RequestMapping(value = "/control", method = RequestMethod.POST, params = "action=stopProfiling", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public View stopProfiling(@PathVariable("connectionId") final String connectionId,
        @PathVariable("databaseName") final String databaseName,
        final UriComponentsBuilder uriComponentsBuilder) throws ResourceNotFoundException {

    getProfilerService().getOpProfiler(requireDatabase(connectionId, databaseName)).stopProfiling();

    return new RedirectView(uriComponentsBuilder.path("/connections/{connectionId}/databases/{databaseName}")
            .fragment("OpProfiles").buildAndExpand(connectionId, databaseName).toUriString());
}

From source file:de.otto.mongodb.profiler.web.OpProfileController.java

@RequestMapping(value = "/control", method = RequestMethod.POST, params = "action=startProfiling", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public View startProfiling(@PathVariable("connectionId") final String connectionId,
        @PathVariable("databaseName") final String databaseName,
        final UriComponentsBuilder uriComponentsBuilder) throws ResourceNotFoundException {

    getProfilerService().getOpProfiler(requireDatabase(connectionId, databaseName)).continueProfiling();

    return new RedirectView(uriComponentsBuilder.path("/connections/{connectionId}/databases/{databaseName}")
            .fragment("OpProfiles").buildAndExpand(connectionId, databaseName).toUriString());
}

From source file:de.otto.mongodb.profiler.web.OpProfileController.java

@RequestMapping(value = "/{id:.+}/issues", method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public View dismissIssue(@PathVariable("connectionId") final String connectionId,
        @PathVariable("databaseName") final String databaseName, @PathVariable("id") final String id,
        @RequestParam("dismiss") final String issueCode, final UriComponentsBuilder uriComponentsBuilder)
        throws Exception {

    requireProfile(requireDatabase(connectionId, databaseName), id).dismissIssue(issueCode);

    return new RedirectView(
            uriComponentsBuilder.path("/connections/{connectionId}/databases/{databaseName}/ops/{id}")
                    .buildAndExpand(connectionId, databaseName, id).toUriString());
}

From source file:cz.muni.pa165.carparkapp.web.AdminController.java

@RequestMapping(value = "/car/update", method = RequestMethod.POST)
public String updateCar(@Valid @ModelAttribute CarDTO car, BindingResult bindingResult,
        RedirectAttributes redirectAttributes, UriComponentsBuilder uriBuilder, Locale locale) {
    log.debug("update(locale={}, book={})", locale, car);

    if (car.getId() < 1) {
        carService.addCar(car);// ww  w  .j av  a  2 s . co m
        redirectAttributes.addFlashAttribute("message", messageSource.getMessage("car.add.message",
                new Object[] { car.getRegistrationNumber() }, locale));
    } else {
        carService.updateCar(car);
        redirectAttributes.addFlashAttribute("message", messageSource.getMessage("car.updated.message",
                new Object[] { car.getRegistrationNumber() }, locale));
    }
    return "redirect:" + uriBuilder.path("/admin/car/addCar").build();
}

From source file:cz.muni.pa165.carparkapp.web.AdminController.java

@RequestMapping(value = "branch/update", method = RequestMethod.POST)
public String update(@Valid @ModelAttribute BranchDTO branch, BindingResult bindingResult,
        RedirectAttributes redirectAttributes, UriComponentsBuilder uriBuilder, Locale locale) {
    log.debug("update(locale={}, branch={})", locale, branch);
    if (branch.getId() < 1) {
        branchService.addBranch(branch);
        redirectAttributes.addFlashAttribute("message", messageSource.getMessage("branch.add.message",
                new Object[] { branch.getCompanyNumber() }, locale));
    } else {/*from   w w w  .jav a 2s  .  c  om*/
        branchService.updateBranch(branch);
        redirectAttributes.addFlashAttribute("message", messageSource.getMessage("branch.updated.message",
                new Object[] { branch.getCompanyNumber() }, locale));
    }
    return "redirect:" + uriBuilder.path("/admin/branch/addBranch").build();
}

From source file:org.woofenterprise.dogs.web.controllers.AppointmentsController.java

@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
@RolesAllowed("ADMIN")
public String deleteAppointment(@PathVariable("id") long id, UriComponentsBuilder uriBuilder,
        RedirectAttributes redirectAttributes) {
    try {//w  w w .j av  a2 s .  c  o  m
        AppointmentDTO appointment = facade.findAppointmentById(id);
        if (appointment == null) {
            throw new ResourceNotFoundException();
        }
        facade.cancelAppointment(appointment);
        redirectAttributes.addFlashAttribute("alert_success", "Appointment #" + id + " was deleted.");
    } catch (Exception ex) {
        redirectAttributes.addFlashAttribute("alert_danger",
                "Appointment #" + id + " was not deleted. " + ex.getLocalizedMessage());
    }

    return "redirect:" + uriBuilder.path("/appointments/").build().encode().toUriString();
}

From source file:cz.muni.fi.mvc.controllers.DestinationController.java

/**
 * Updates destination/*from ww  w . j av a  2s  .c  o  m*/
 *
 * @param id, modelAttribute, bindingResult, model, redirectAttributes, uriBuilder
 * @return JSP page
 */
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
public String updateDestination(@PathVariable("id") long id,
        @Valid @ModelAttribute("destination") UpdateDestinationLocationDTO updatedDestination,
        BindingResult bindingResult, Model model, RedirectAttributes redirectAttributes,
        UriComponentsBuilder uriBuilder) {

    if (bindingResult.hasErrors()) {
        for (FieldError fe : bindingResult.getFieldErrors()) {
            model.addAttribute(fe.getField() + "_error", true);
            log.trace("FieldError: {}", fe);
        }
        for (ObjectError ge : bindingResult.getGlobalErrors()) {
            log.trace("ObjectError: {}", ge);
        }
        return "destination/edit";
    }

    if ((updatedDestination.getLocation()).equals("")) {
        redirectAttributes.addFlashAttribute("alert_danger", "Location of destination is empty");
        return "redirect:"
                + uriBuilder.path("/destination/edit/{id}").buildAndExpand(id).encode().toUriString();
    }

    try {
        destinationFacade.updateDestinationLocation(updatedDestination);
    } catch (Exception ex) {
        redirectAttributes.addFlashAttribute("alert_danger",
                "Destination " + id + " wasn't updated because location already exists");
        return "redirect:"
                + uriBuilder.path("/destination/edit/{id}").buildAndExpand(id).encode().toUriString();
    }
    redirectAttributes.addFlashAttribute("alert_success", "Destination " + id + " was updated");
    return "redirect:" + uriBuilder.path("/destination").toUriString();
}

From source file:com.sothawo.taboo2.Taboo2Service.java

/**
 * creates a new bookmark in the repository.
 *
 * @param bookmark/*  w w w .j ava2 s  . c  o m*/
 *         new bookmark to be created
 * @param ucb
 *         uri component builder to build the created uri
 * @return the created bookmark
 * @throws IllegalArgumentException
 *         when bookmark is null or has it's id set or one of the tags is an empty string
 */
@RequestMapping(value = MAPPING_BOOKMARKS, method = RequestMethod.POST)
public final ResponseEntity<Bookmark> createBookmark(@RequestBody final Bookmark bookmark,
        final UriComponentsBuilder ucb) {
    if (null == bookmark) {
        throw new IllegalArgumentException("bookmark must not be null");
    }
    if (null != bookmark.getId()) {
        throw new IllegalArgumentException("id must not be set");
    }
    if (bookmark.getTags().stream().filter(String::isEmpty).findFirst().isPresent()) {
        throw new IllegalArgumentException("tags must not be empty");
    }

    Bookmark createdBookmark = repository.createBookmark(bookmark);
    HttpHeaders headers = new HttpHeaders();
    URI locationUri = ucb.path(MAPPING_TABOO2 + MAPPING_BOOKMARKS + '/')
            .path(String.valueOf(createdBookmark.getId())).build().toUri();
    headers.setLocation(locationUri);
    LOG.info("created bookmark {}", createdBookmark);
    return new ResponseEntity<>(createdBookmark, headers, HttpStatus.CREATED);
}

From source file:cz.fi.muni.pa165.presentation.layer.mvc.controllers.AlbumController.java

/**
 * POST method of create will submit the data, validate it, and create new
 * song//from  ww w. ja v a2  s.  c om
 *
 * @param formBean
 * @param bindingResult
 * @param model
 * @param redirectAttributes
 * @param uriBuilder
 * @return
 */
@RequestMapping(value = "/create", method = RequestMethod.POST)
public String create(@Valid @ModelAttribute("albumDTO") AlbumCreateDTO formBean, BindingResult bindingResult,
        Model model, RedirectAttributes redirectAttributes, UriComponentsBuilder uriBuilder) {

    if (bindingResult.hasErrors()) {
        model.addAttribute("albums", albumFacade.findAll());
        model.addAttribute("musicians", musicianFacade.findAll());
        model.addAttribute("genres", genreFacade.findAll());
        return "/album/create";
    }

    Long createdAlbumID = albumFacade.createAlbum(formBean);

    redirectAttributes.addFlashAttribute("alert_success",
            "Succesfully created " + formBean.getTitle() + " with id " + createdAlbumID);

    redirectAttributes.addFlashAttribute("alert_success", "Album " + createdAlbumID + " was created");
    return "redirect:" + uriBuilder.path("/album/listAsAdmin").toUriString();
}