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:cz.muni.pa165.carparkapp.web.AdminController.java

@RequestMapping(value = "/users/delete/{id}", method = RequestMethod.POST)
public String deleteUser(@PathVariable int id, RedirectAttributes redirectAttributes, Locale locale,
        UriComponentsBuilder uriBuilder) {
    log.debug("deleteUser({})", id);
    EmployeeDTO user = employeeService.findEmployeeById(id);
    employeeService.deleteEmployee(user);
    /*redirectAttributes.addFlashAttribute(
        "message",// w w w.j  a  v  a2  s. co  m
        messageSource.getMessage("addCar.delete.mess", new Object[]
                {
                    car.getRegistrationNumber()
        }, locale)
    );*/
    return "redirect:" + uriBuilder.path("/admin/users/addUser").build();
}

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

@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
public String delete(@PathVariable long id, Model model, UriComponentsBuilder uriBuilder,
        RedirectAttributes redirectAttributes) {

    AlbumDTO foundAlbum = albumFacade.findById(id);
    ;//from   ww w. ja  va2 s.  c  om
    if (foundAlbum != null) {
        albumFacade.deleteAlbum(id);
        redirectAttributes.addFlashAttribute("alert_success",
                "Album with title: " + foundAlbum.getTitle() + " was deleted.");
        return "redirect:" + uriBuilder.path("/album/listAsAdmin").toUriString();
    }

    return "redirect:" + uriBuilder.path("/album/listAsAdmin").toUriString();
}

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

@RequestMapping(value = "/update", method = RequestMethod.POST)
@RolesAllowed("ADMIN")
public String updateDog(Model model, @Valid @ModelAttribute("dog") DogDTO dogDTO, BindingResult bindingResult,
        UriComponentsBuilder uriBuilder, RedirectAttributes redirectAttributes) {
    if (bindingResult.hasErrors()) {
        for (FieldError fe : bindingResult.getFieldErrors()) {
            model.addAttribute(fe.getField() + "_error", true);
        }//from  w  ww.  jav a 2 s.c  o m
        return "/dogs/edit";
    }

    Long id = dogDTO.getId();
    try {
        facade.updateDog(dogDTO);
        redirectAttributes.addFlashAttribute("alert_success", "Dog #" + id + " was updated.");
        return "redirect:" + uriBuilder.path("/dogs/view/{id}").buildAndExpand(id).encode().toUriString();
    } catch (Exception e) {
        log.warn("Exception wile updating: " + e.getMessage());
        redirectAttributes.addFlashAttribute("alert_danger", "Dog #" + id + " was not edited.");
        return "redirect:/";
    }

}

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

@RequestMapping(value = "/create", method = RequestMethod.POST)
@RolesAllowed("ADMIN")
public String createDog(Model model, @Valid @ModelAttribute("dog") DogDTO dogDTO, BindingResult bindingResult,
        UriComponentsBuilder uriBuilder, RedirectAttributes redirectAttributes) {
    if (bindingResult.hasErrors()) {
        for (FieldError fe : bindingResult.getFieldErrors()) {
            model.addAttribute(fe.getField() + "_error", true);
        }/*from   ww w .ja  va 2 s . co m*/
        return "dogs/create";
    }
    try {
        dogDTO = facade.createDog(dogDTO);
        Long id = dogDTO.getId();

        redirectAttributes.addFlashAttribute("alert_success", "Dog #" + id + " was created.");
        return "redirect:" + uriBuilder.path("/dogs/view/{id}").buildAndExpand(id).encode().toUriString();
    } catch (Exception e) {
        log.warn("Exception wile creating: " + e.getMessage());
        redirectAttributes.addFlashAttribute("alert_danger", "Dog was not created.");
        return "redirect:/";
    }
}

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

@RequestMapping(method = RequestMethod.GET, produces = MediaType.TEXT_HTML_VALUE)
public View showOpProfiles(@PathVariable("connectionId") final String connectionId,
        @PathVariable("databaseName") final String databaseName,
        final UriComponentsBuilder uriComponentsBuilder) throws ResourceNotFoundException {

    final String uri = uriComponentsBuilder.path("/connections/{connectionId}/databases/{databaseName}")
            .fragment("OpProfiles").buildAndExpand(connectionId, databaseName).toUriString();

    return new RedirectView(uri);
}

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

/**
 * POST method of create will submit the data, validate it, and create new
 * song//from  w ww.  jav a  2s .  co m
 *
 * @param formBean
 * @param bindingResult
 * @param model
 * @param redirectAttributes
 * @param uriBuilder
 * @return
 */
@RequestMapping(value = "/create", method = RequestMethod.POST)
public String create(@Valid @ModelAttribute("genreDTO") GenreDTO formBean, BindingResult bindingResult,
        Model model, RedirectAttributes redirectAttributes, UriComponentsBuilder uriBuilder) {

    if (bindingResult.hasErrors()) {
        return "/genre/create";
    }

    Long createdID = genreFacade.createGenre(formBean);

    redirectAttributes.addFlashAttribute("alert_success",
            "Succesfully created " + formBean.getTitle() + " with id " + createdID);
    redirectAttributes.addFlashAttribute("alert_success", "Genre " + createdID + " was created");
    return "redirect:" + uriBuilder.path("/genre/listAsAdmin").toUriString();
}

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

/**
 * Deletes a Steward//from w  ww.ja  v a  2  s.co m
 *
 * @param id Steward's id
 * @param model display data
 * @return jsp page
 */
@RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
public String delete(@PathVariable long id, Model model, UriComponentsBuilder uriBuilder,
        RedirectAttributes redirectAttributes) {

    StewardDTO steward;
    try {
        steward = stewardFacade.getStewardWithId(id);
        if (steward == null) {
            redirectAttributes.addFlashAttribute("alert_danger", "Steward with id: " + id + " does not exist.");
            return "redirect:" + uriBuilder.path("/steward").toUriString();
        }
        stewardFacade.removeSteward(id);
    } catch (Exception ex) {
        redirectAttributes.addFlashAttribute("alert_danger", "Steward with id: " + id + " cannot be deleted.");
        return "redirect:" + uriBuilder.path("/steward").toUriString();
    }

    redirectAttributes.addFlashAttribute("alert_info", "Steward with id: " + steward.getId() + " was deleted.");
    return "redirect:" + uriBuilder.path("/steward").toUriString();
}

From source file:za.ac.cput.project.universalhardwarestorev2.api.LoginApi.java

@RequestMapping(value = "/login/create", method = RequestMethod.POST)
public ResponseEntity<Void> createLogin(@RequestBody Login login, UriComponentsBuilder ucBuilder) {
    System.out.println("Creating Login " + login.getName());

    //USE THIS IF YOU WANT TO CHECK UNIQUE OBJECT
    //      if (LoginService.isLoginExist(login)) {
    //            System.out.println("A Login with name " + Login.getName() + " already exist");
    //            return new ResponseEntity<Void>(HttpStatus.CONFLICT);
    //        }//  www  .  jav a2s  .c  om

    service.save(login);

    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(ucBuilder.path("/login/{id}").buildAndExpand(login.getId()).toUri());
    return new ResponseEntity<Void>(headers, HttpStatus.CREATED);
}

From source file:com.playhaven.android.req.PlayHavenRequest.java

@SuppressWarnings("deprecation")
protected UriComponentsBuilder createUrl(Context context) throws PlayHavenException {
    try {//from   ww  w  .j a va 2s  .co  m
        SharedPreferences pref = PlayHaven.getPreferences(context);

        UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(getString(pref, APIServer));
        builder.path(context.getResources().getString(getApiPath(context)));
        builder.queryParam("app", getString(pref, AppPkg));
        builder.queryParam("opt_out", getString(pref, OptOut, "0"));
        builder.queryParam("app_version", getString(pref, AppVersion));
        builder.queryParam("os", getInt(pref, OSVersion, 0));
        WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        Display display = wm.getDefaultDisplay();
        builder.queryParam("orientation", display.getRotation());
        builder.queryParam("hardware", getString(pref, DeviceModel));
        PlayHaven.ConnectionType connectionType = getConnectionType(context);
        builder.queryParam("connection", connectionType.ordinal());
        builder.queryParam("idiom",
                context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK);

        /**
         * For height/width we will use getSize(Point) not getRealSize(Point) as this will allow us to automatically
         * account for rotation and screen decorations like the status bar. We only want to know available space.
         *
         * @playhaven.apihack for SDK_INT < 13, have to use getHeight and getWidth!
         */
        Point size = new Point();
        if (Build.VERSION.SDK_INT >= 13) {
            display.getSize(size);
        } else {
            size.x = display.getWidth();
            size.y = display.getHeight();
        }
        builder.queryParam("width", size.x);
        builder.queryParam("height", size.y);

        /**
         * SDK Version needs to be reported as a dotted numeric value
         * So, if it is a -SNAPSHOT build, we will replace -SNAPSHOT with the date of the build
         * IE: 2.0.0.20130201
         * as opposed to an actual released build, which would be like 2.0.0
         */
        String sdkVersion = getString(pref, SDKVersion);
        String[] date = Version.PLUGIN_BUILD_TIME.split("[\\s]");
        sdkVersion = sdkVersion.replace("-SNAPSHOT", "." + date[0].replaceAll("-", ""));
        builder.queryParam("sdk_version", sdkVersion);

        builder.queryParam("plugin", getString(pref, PluginIdentifer));

        Locale locale = context.getResources().getConfiguration().locale;
        builder.queryParam("languages", String.format("%s,%s", locale.toString(), locale.getLanguage()));
        builder.queryParam("token", getString(pref, Token));

        builder.queryParam("device", getString(pref, DeviceId));
        DisplayMetrics metrics = new DisplayMetrics();
        display.getMetrics(metrics);
        builder.queryParam("dpi", metrics.densityDpi);

        String uuid = UUID.randomUUID().toString();
        String nonce = base64Digest(uuid);
        builder.queryParam("nonce", nonce);

        ktsid = KontagentUtil.getSenderId(context);
        if (ktsid != null)
            builder.queryParam("sid", ktsid);

        addSignature(builder, pref, nonce);

        // Setup for signature verification
        String secret = getString(pref, Secret);
        SecretKeySpec key = new SecretKeySpec(secret.getBytes(UTF8), HMAC);
        sigMac = Mac.getInstance(HMAC);
        sigMac.init(key);
        sigMac.update(nonce.getBytes(UTF8));

        return builder;
    } catch (Exception e) {
        throw new PlayHavenException(e);
    }
}

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

/**
 * Updates steward/*  ww w.  j a  va  2  s .co m*/
 *
 * @param id, modelAttribute, bindingResult, model, redirectAttributes, uriBuilder
 * @return JSP page
 */
@RequestMapping(value = "/update/{id}", method = RequestMethod.POST)
public String updateSteward(@PathVariable("id") long id,
        @Valid @ModelAttribute("steward") UpdateStewardDTO updatedSteward, BindingResult bindingResult,
        Model model, RedirectAttributes redirectAttributes, UriComponentsBuilder uriBuilder) {

    try {
        StewardDTO steward = stewardFacade.getStewardWithId(id);
        stewardFacade.updateStewardName(updatedSteward);
    } catch (Exception ex) {
        redirectAttributes.addFlashAttribute("alert_danger",
                "Steward " + id + " wasn't updated because of some unknow error");
        return "redirect:" + uriBuilder.path("/steward/edit/{id}").buildAndExpand(id).encode().toUriString();
    }

    redirectAttributes.addFlashAttribute("alert_info", "Steward " + id + " was updated");
    return "redirect:" + uriBuilder.path("/steward/detail/{id}").buildAndExpand(id).encode().toUriString();
}