Example usage for org.springframework.web.bind.annotation RequestMethod PUT

List of usage examples for org.springframework.web.bind.annotation RequestMethod PUT

Introduction

In this page you can find the example usage for org.springframework.web.bind.annotation RequestMethod PUT.

Prototype

RequestMethod PUT

To view the source code for org.springframework.web.bind.annotation RequestMethod PUT.

Click Source Link

Usage

From source file:net.eusashead.hateoas.springhalbuilder.controller.OrderController.java

/**
 * Modify a {@link Order}/*  w  ww. j  a v  a2s  .c o m*/
 * 
 * @param order {@link Order} to update
 * @param builder {@link PutResponseBuilder} to build response
 * @return {@link ResponseEntity} with null body and HTTP status 204 
 */
@RequestMapping(method = RequestMethod.PUT)
public ResponseEntity<Void> put(@RequestBody Order order, PutResponseBuilder<Order> builder) {
    Order saved = orderRepository.save(order);
    return builder.etag(saved.getVersion()).lastModified(saved.getUpdated()).build();
}

From source file:de.zib.vold.userInterface.RESTController.java

/**
 * Handles Put requests./* www  . j  a v a  2 s.co m*/
 *
 * This method is used by clients to submit new keys.
 *
 * @param clientIpAddress The ip of the sending client, it's extracted from the request itself.
 * @param args The URL arguments of the request.
 //* @param argsbody The PUT body arguments of the request.
 * @param request Request informations
 * @return A map of keys with its lifetime, whereas the livetime is zero if an error for that key occured.
 */
@RequestMapping(method = RequestMethod.PUT)
public ResponseEntity<Map<String, String>> insert(@ModelAttribute("clientIpAddress") String clientIpAddress,
        @RequestParam MultiValueMap<String, String> args,
        //@RequestBody MultiValueMap< String, String > argsbody,
        @RequestHeader(value = "TIMESTAMP", defaultValue = "unset") String timeStampHeader,
        HttpServletRequest request) throws IOException {

    MultiValueMap<String, String> argsbody = getBody();
    final long timeStamp;
    if (timeStampHeader.equals("unset"))
        timeStamp = DateTime.now().getMillis();
    else
        timeStamp = Long.parseLong(timeStampHeader);

    // guard
    {
        if (argsbody != null)
            logger.debug("PUT: " + args.toString() + " AND " + argsbody.toString());
        else
            logger.debug("PUT: " + args.toString());

        checkState();
    }

    Map<String, String> invalidKeys = new HashMap<String, String>();

    // get actual scope
    String scope;
    {
        scope = request.getRequestURI();
        String removepath = removePrefix + request.getContextPath() + request.getServletPath();

        scope = scope.substring(removepath.length(), scope.length());
    }

    // merge args to argsbody
    {
        if (null == argsbody) {
            if (null == args) {
                logger.warn("Got a totally empty request from " + clientIpAddress + ".");
                return new ResponseEntity<Map<String, String>>(invalidKeys, HttpStatus.OK);
            }

            argsbody = args;
        } else if (null != args) {
            argsbody.putAll(args);
        }
    }

    // process each key
    {
        for (Map.Entry<String, List<String>> entry : argsbody.entrySet()) {
            URIKey urikey;
            String source;
            Key k;

            // build key
            {
                urikey = URIKey.fromURIString(entry.getKey(), enc);

                File path_correction = new File(scope + "/" + urikey.getKey().get_scope());

                k = new Key(path_correction.getPath(), urikey.getKey().get_type(),
                        urikey.getKey().get_keyname());

                if (null == urikey.getSource()) {
                    source = clientIpAddress;
                } else {
                    source = urikey.getSource();
                }
            }

            // handle write request for that key
            {
                try {
                    logger.debug(
                            "Inserting " + entry.getValue().size() + " values for key " + urikey.toURIString());
                    frontend.insert(source, k, new HashSet<String>(entry.getValue()), timeStamp);
                } catch (VoldException e) {
                    logger.error("Could not handle write request for key " + entry.getKey() + ". ", e);
                    invalidKeys.put(entry.getKey(), "ERROR: " + e.getMessage());
                }
            }
        }
    }

    return new ResponseEntity<Map<String, String>>(invalidKeys, HttpStatus.OK);
}

From source file:com.wavemaker.tools.apidocs.tools.spring.controller2.VacationController.java

@RequestMapping(value = "/{id:.+}", method = RequestMethod.PUT)
@ApiOperation(value = "Updates the Vacation instance associated with the given id.")
public Vacation editVacation(@PathVariable("id") Integer id, @RequestBody Vacation instance)
        throws EntityNotFoundException {
    return null;/*  w  w  w  .  j a  v a  2 s  . co m*/
}

From source file:miage.ecom.web.admin.controller.CategoryController.java

@RequestMapping(value = "/category/{idCategory}", method = RequestMethod.PUT)
public @ResponseBody Map<String, ? extends Object> update(@PathVariable Integer idCategory,
        @RequestBody Category category) {

    Map<String, Object> output = null;

    try {//  w ww .j ava  2  s  .com

        if (categoryFacade.find(idCategory) != null && category.getIdCategory() == idCategory) {

            categoryFacade.edit(category);
            output = ExtJsUtil.getEditSuccessResponse(category, "Catgorie " + idCategory + " mise  jour");

        } else {

            output = ExtJsUtil.getErrorResponse("Cette catgorie n'existe pas");

        }

    } catch (Exception e) {

        output = ExtJsUtil.getErrorResponse("Impossible de sauvegarder la catgorie");
    }

    return output;
}

From source file:org.openlmis.fulfillment.web.OrderFileTemplateController.java

/**
 * Allows updating order file templates.
 *
 * @param orderFileTemplateDto An order file template bound to the request body
 * @return ResponseEntity containing saved orderFileTemplate
 *//*  w  w w  . j  a  va 2  s  .  c  om*/
@RequestMapping(value = "/orderFileTemplates", method = RequestMethod.PUT)
@ResponseBody
public OrderFileTemplateDto savedOrderFileTemplate(
        @RequestBody @Valid OrderFileTemplateDto orderFileTemplateDto, BindingResult bindingResult) {
    LOGGER.debug("Checking right to update order file template");
    permissionService.canManageSystemSettings();

    if (bindingResult.hasErrors()) {
        throw new ValidationException(bindingResult.getAllErrors().get(0).getDefaultMessage());
    }

    OrderFileTemplate template = orderFileTemplateService.getOrderFileTemplate();
    if (!template.getId().equals(orderFileTemplateDto.getId())) {
        throw new ValidationException(ERROR_ORDER_FILE_TEMPLATE_CREATION);
    }

    LOGGER.debug("Saving Order File Template");
    template.importDto(orderFileTemplateDto);
    template = orderFileTemplateRepository.save(template);

    LOGGER.debug("Saved Order File Template with id: " + template.getId());
    return OrderFileTemplateDto.newInstance(template);
}

From source file:es.fdi.reservas.users.web.UserRestController.java

@RequestMapping(value = "/admin/administrar/usuarios/editar/{idUser}/{user}/{admin}/{gestor}", method = RequestMethod.PUT)
public void editarUsuario(@PathVariable("idUser") long idUser, @PathVariable("user") String user,
        @PathVariable("admin") String admin, @PathVariable("gestor") String gestor,
        @RequestBody UserDTO userActualizado) {

    Attachment attachment = new Attachment("");

    if (userActualizado.getFacultad() == null) {
        userActualizado.setFacultad(user_service.getUser(userActualizado.getId()).getFacultad().getId());
    }//from w ww. j a va 2s.c om
    if (userActualizado.getImagen().equals("")) {
        attachment = user_service.getUser(userActualizado.getId()).getImagen();
    } else if (userActualizado.getImagen().contains("fakepath")) {
        String img = userActualizado.getImagen();
        String[] barras = img.split("fakepath");
        String fin = barras[1];
        fin = fin.substring(1);

        if (user_service.getAttachmentByName(fin).isEmpty()) {
            int pos = fin.lastIndexOf(".");
            String punto = fin.substring(0, pos);
            String end = fin.substring(pos + 1, fin.length());
            String nom = punto + "-" + userActualizado.getId() + "." + end;
            nom = nom.replace(nom, "/img/" + nom);

            attachment.setAttachmentUrl("/img/" + fin);
            attachment.setStorageKey(nom);
            user_service.addImagen(attachment);
        } else {
            attachment = user_service.getAttachmentByName(fin).get(0);
        }
    } else {

        if (user_service.getAttachmentByName(userActualizado.getImagen()).isEmpty()) {

            //si no esta, lo aado
            String img = userActualizado.getImagen();
            int pos = img.lastIndexOf(".");
            String punto = img.substring(0, pos);
            String fin = img.substring(pos + 1, img.length());
            String nom = punto + "-" + idUser + "." + fin;
            nom = nom.replace(nom, "/img/" + nom);

            attachment.setAttachmentUrl("/img/" + userActualizado.getImagen());
            attachment.setStorageKey(nom);
        } else {
            attachment = user_service.getAttachmentByName(userActualizado.getImagen()).get(0);
        }
    }
    user_service.editaUsuario(userActualizado, user, admin, gestor, attachment);
    //System.out.println(imagen + " Existe");
    //      }else{
    //         System.out.println(imagen + " No existe");
    //      }

}

From source file:cn.cdwx.jpa.web.account.TaskRestController.java

@RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaTypes.JSON)
public ResponseEntity<?> update(@RequestBody Task task) {
    // JSR303 Bean Validator, RestExceptionHandler?.
    BeanValidators.validateWithException(validator, task);
    // ?/*from ww  w.  j a va 2s . c o m*/
    taskService.saveTask(task);

    // Restful204??, . ?200??.
    return new ResponseEntity(HttpStatus.NO_CONTENT);
}

From source file:net.skhome.roborace.web.controller.UserController.java

@RequestMapping(method = RequestMethod.PUT)
public void updateUserAccount(@RequestBody @Valid final UserAccount account,
        final HttpServletResponse response) {

    try {//from   www.j  av  a  2  s .co  m
        service.updateUserAccount(account);
        response.setStatus(HttpServletResponse.SC_OK);
    } catch (DataAccessException ex) {
        throw new ResourceNotFoundException(account.getId());
    }

}

From source file:org.oncoblocks.centromere.web.controller.ReadOnlyApiController.java

/**
 * {@code PUT /{id}}/*  w  w  w.ja v  a2  s.  co m*/
 * Attempts to update an existing entity record, replacing it with the submitted entity. Throws
 *   an exception if the target entity does not exist.
 *
 * @return updated representation of the submitted entity.
 */
@RequestMapping(value = "/{id}", method = RequestMethod.PUT, produces = { MediaType.APPLICATION_JSON_VALUE,
        ApiMediaTypes.APPLICATION_HAL_JSON_VALUE, ApiMediaTypes.APPLICATION_HAL_XML_VALUE,
        MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_PLAIN_VALUE })
public HttpEntity<?> update(@RequestBody T entity, @PathVariable ID id, HttpServletRequest request) {
    throw new MethodNotAllowedException();
}

From source file:dk.matzon.echelog.interfaces.rest.NetworkController.java

@Override
@RequestMapping(path = "/networks", method = { RequestMethod.POST, RequestMethod.PUT })
public NetworkDTO save(@RequestBody NetworkDTO _networkDTO) {
    Network network = NetworkAssembler.fromDTO(_networkDTO);
    network = echelog.addNetwork(network);
    return NetworkAssembler.toDTO(network);
}