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

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

Introduction

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

Prototype

RequestMethod PATCH

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

Click Source Link

Usage

From source file:com.wordnik.springmvc.UserResource.java

@RequestMapping(value = "/{username}", method = { RequestMethod.PUT, RequestMethod.PATCH })
@ApiOperation(value = "Updated user", notes = "This can only be done by the logged in user.", position = 4)
@ApiResponses(value = { @ApiResponse(code = 400, message = "Invalid user supplied"),
        @ApiResponse(code = 404, message = "User not found") })
public ResponseEntity updateUser(
        @ApiParam(value = "name that need to be deleted", required = true) @PathVariable("username") String username,
        @ApiParam(value = "Updated user object", required = true) User user) {
    userData.addUser(user);//  w  ww . j a v a  2 s  .  c o  m
    return new ResponseEntity(HttpStatus.OK);
}

From source file:com.okta.scim.SingleUserController.java

/**
 * Update via Patch {@link User} attributes
 *
 * @param payload Payload from HTTP request
 * @param id {@link User#id}/*from   w w  w. j av  a2 s .co  m*/
 *
 * @return {@link #scimError(String, Optional)} / JSON {@link Map} of {@link User}
 */
@RequestMapping(method = RequestMethod.PATCH)
public @ResponseBody Map singleUserPatch(@RequestBody Map<String, Object> payload, @PathVariable String id) {
    List schema = (List) payload.get("schemas");
    List<Map> operations = (List) payload.get("Operations");

    if (schema == null) {
        return scimError("Payload must contain schema attribute.", Optional.of(400));
    }
    if (operations == null) {
        return scimError("Payload must contain operations attribute.", Optional.of(400));
    }

    //Verify schema
    String schemaPatchOp = "urn:ietf:params:scim:api:messages:2.0:PatchOp";
    if (!schema.contains(schemaPatchOp)) {
        return scimError("The 'schemas' type in this request is not supported.", Optional.of(501));
    }

    //Find user for update
    User user = db.findById(id).get(0);

    for (Map map : operations) {
        if (map.get("op") == null && !map.get("op").equals("replace")) {
            continue;
        }
        Map<String, Object> value = (Map) map.get("value");

        // Use Java reflection to find and set User attribute
        if (value != null) {
            for (Map.Entry key : value.entrySet()) {
                try {
                    Field field = user.getClass().getDeclaredField(key.getKey().toString());
                    field.set(user, key.getValue());
                } catch (NoSuchFieldException | IllegalAccessException e) {
                    // Error - Do not update field
                }
            }
        }
    }
    return user.toScimResource();
}

From source file:com.swcguild.vendingmachinemvc.controller.UserController.java

@RequestMapping(value = "/money", method = RequestMethod.PATCH)
@ResponseBody
public int dispenseMoney() {
    return dao.updateMoney(-dao.getMoney());

}

From source file:com.swcguild.capstoneproject.controller.AdminController.java

@RequestMapping(value = "/post/{id}", method = RequestMethod.PATCH)
@ResponseBody//from www  .j a  v a  2  s  .  c o  m
public void publishPost(@PathVariable("id") int id, @Valid @RequestBody Post data) {

    dao.publishPost(id, data);

}

From source file:de.metas.ui.web.pattribute.ASIRestController.java

@RequestMapping(value = "/{asiDocId}", method = RequestMethod.PATCH)
public List<JSONDocument> processChanges(@PathVariable("asiDocId") final int asiDocId //
        , @RequestBody final List<JSONDocumentChangedEvent> events //
) {/* w  w  w. j  a v  a2  s  . c o m*/
    userSession.assertLoggedIn();

    return Execution.callInNewExecution("processChanges", () -> {
        asiRepo.processASIDocumentChanges(asiDocId, events);
        return JSONDocument.ofEvents(Execution.getCurrentDocumentChangesCollector(), newJsonOpts());
    });
}

From source file:com.example.notes.TagsController.java

@RequestMapping(value = "/{id}", method = RequestMethod.PATCH)
@ResponseStatus(HttpStatus.NO_CONTENT)/*from w ww  . j a  va  2  s  .c  o  m*/
void updateTag(@PathVariable("id") long id, @RequestBody TagPatchInput tagInput) {
    Tag tag = findTagById(id);
    if (tagInput.getName() != null) {
        tag.setName(tagInput.getName());
    }
    this.repository.save(tag);
}

From source file:com.jiwhiz.rest.admin.CommentRestController.java

@RequestMapping(method = RequestMethod.PATCH, value = URL_ADMIN_COMMENTS_COMMENT)
@Transactional//from w ww  .j  a v  a  2s.co m
public HttpEntity<Void> updateCommentPost(@PathVariable("commentId") String commentId,
        @RequestBody Map<String, String> updateMap) throws ResourceNotFoundException {
    CommentPost commentPost = getCommentById(commentId);

    String content = updateMap.get("content");
    if (content != null) {
        commentPost.update(content);
    }
    String statusString = updateMap.get("status");
    if (statusString != null) {
        CommentStatusType status = CommentStatusType.valueOf(statusString);
        if (status != null) {
            commentPost.setStatus(status);
        } else {
            //TODO throw exception for invalid status
        }
    }
    commentPostRepository.save(commentPost);

    return new ResponseEntity<Void>(HttpStatus.NO_CONTENT);
}

From source file:de.metas.ui.web.address.AddressRestController.java

@RequestMapping(value = "/{docId}", method = RequestMethod.PATCH)
public List<JSONDocument> processChanges(@PathVariable("docId") final int docId //
        , @RequestBody final List<JSONDocumentChangedEvent> events //
) {/* w  ww .java2  s  .co  m*/
    userSession.assertLoggedIn();

    return Execution.callInNewExecution("processChanges", () -> {
        addressRepo.processAddressDocumentChanges(docId, events);
        return JSONDocument.ofEvents(Execution.getCurrentDocumentChangesCollector(), newJsonOpts());
    });
}

From source file:it.smartcommunitylab.aac.apimanager.wso2.WSO2Controller.java

@RequestMapping(value = "/wso2/client/validity/{clientId}/{validity}", method = RequestMethod.PATCH)
public @ResponseBody void updateTokenValidity(HttpServletResponse response,
        @PathVariable("clientId") String clientId, @PathVariable("validity") Integer validity)
        throws Exception {
    try {/*w  w  w . j  a v  a  2 s.  co  m*/
        ObjectMapper mapper = new ObjectMapper();
        mapper.configure(Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);

        wso2Manager.updateValidity(clientId, validity);

    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
    }
}

From source file:com.example.notes.NotesController.java

@RequestMapping(value = "/{id}", method = RequestMethod.PATCH)
@ResponseStatus(HttpStatus.NO_CONTENT)//  w w w . ja  v a  2  s.  c o  m
void updateNote(@PathVariable("id") long id, @RequestBody NotePatchInput noteInput) {
    Note note = findNoteById(id);
    if (noteInput.getTagUris() != null) {
        note.setTags(getTags(noteInput.getTagUris()));
    }
    if (noteInput.getTitle() != null) {
        note.setTitle(noteInput.getTitle());
    }
    if (noteInput.getBody() != null) {
        note.setBody(noteInput.getBody());
    }
    this.noteRepository.save(note);
}