Java Code Examples for org.springframework.web.bind.annotation.RequestMethod#PATCH

The following examples show how to use org.springframework.web.bind.annotation.RequestMethod#PATCH . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataObjectModelController.java    From entando-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{dataModelId}", method = RequestMethod.PATCH, produces = MediaType.APPLICATION_JSON_VALUE, consumes="application/json-patch+json")
public ResponseEntity<SimpleRestResponse<DataModelDto>> patchDataObjectModel(@PathVariable Long dataModelId,
                                                                             @RequestBody JsonNode jsonPatch,
                                                                             BindingResult bindingResult) throws JsonProcessingException {
    logger.debug("Patching data object model -> {}", dataModelId);

    this.getDataObjectModelValidator().validateDataObjectModelJsonPatch(jsonPatch, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }

    DataModelDto patchedDataModelDto = this.getDataObjectModelService().getPatchedDataObjectModel(dataModelId, jsonPatch);
    DataObjectModelRequest dataObjectModelRequest = this.dataModelDtoToRequestConverter.convert(patchedDataModelDto);

    return this.updateDataObjectModel(Long.toString(dataModelId), dataObjectModelRequest, bindingResult);

}
 
Example 2
Source File: InstancesProxyController.java    From Moss with Apache License 2.0 6 votes vote down vote up
@RequestMapping(path = REQUEST_MAPPING_PATH, method = {RequestMethod.GET, RequestMethod.HEAD, RequestMethod.POST, RequestMethod.PUT, RequestMethod.PATCH, RequestMethod.DELETE, RequestMethod.OPTIONS})
public Mono<Void> endpointProxy(@PathVariable("instanceId") String instanceId,
                                ServerHttpRequest request,
                                ServerHttpResponse response) {
    String endpointLocalPath = getEndpointLocalPath(request.getPath().pathWithinApplication().value());
    URI uri = UriComponentsBuilder.fromPath(endpointLocalPath)
                                  .query(request.getURI().getRawQuery())
                                  .build(true)
                                  .toUri();

    return super.forward(instanceId, uri, request.getMethod(), request.getHeaders(),
        () -> BodyInserters.fromDataBuffers(request.getBody())).flatMap(clientResponse -> {
        response.setStatusCode(clientResponse.statusCode());
        response.getHeaders().addAll(filterHeaders(clientResponse.headers().asHttpHeaders()));
        return response.writeAndFlushWith(clientResponse.body(BodyExtractors.toDataBuffers()).window(1));
    });
}
 
Example 3
Source File: AnotherFakeApi.java    From openapi-generator with Apache License 2.0 6 votes vote down vote up
/**
 * PATCH /another-fake/dummy : To test special tags
 * To test special tags and operation ID starting with number
 *
 * @param body client model (required)
 * @return successful operation (status code 200)
 */
@ApiOperation(value = "To test special tags", nickname = "call123testSpecialTags", notes = "To test special tags and operation ID starting with number", response = Client.class, tags={ "$another-fake?", })
@ApiResponses(value = { 
    @ApiResponse(code = 200, message = "successful operation", response = Client.class) })
@RequestMapping(value = "/another-fake/dummy",
    produces = { "application/json" }, 
    consumes = { "application/json" },
    method = RequestMethod.PATCH)
default ResponseEntity<Client> call123testSpecialTags(@ApiParam(value = "client model" ,required=true )  @Valid @RequestBody Client body) {
    getRequest().ifPresent(request -> {
        for (MediaType mediaType: MediaType.parseMediaTypes(request.getHeader("Accept"))) {
            if (mediaType.isCompatibleWith(MediaType.valueOf("application/json"))) {
                String exampleString = "{ \"client\" : \"client\" }";
                ApiUtil.setExampleResponse(request, "application/json", exampleString);
                break;
            }
        }
    });
    return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);

}
 
Example 4
Source File: RoleController.java    From entando-core with GNU Lesser General Public License v3.0 5 votes vote down vote up
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{roleCode}", method = RequestMethod.PATCH, produces = MediaType.APPLICATION_JSON_VALUE, consumes="application/json-patch+json")
public ResponseEntity<SimpleRestResponse<RoleDto>> updateRole(@PathVariable String roleCode, @RequestBody JsonNode patchRequest, BindingResult bindingResult) {
    logger.debug("update role {} with jsonpatch-request {}", roleCode, patchRequest);

    this.getRoleValidator().validateJsonPatch(patchRequest, bindingResult);
    if (bindingResult.hasErrors()) {
        throw new ValidationGenericException(bindingResult);
    }

    RoleDto patchedRoleDto = this.getRoleService().getPatchedRole(roleCode, patchRequest);
    RoleRequest patchedRoleRequest = this.roleDtotoRoleRequestConverter.convert(patchedRoleDto);

    return this.updateRole(roleCode, patchedRoleRequest, bindingResult);
}
 
Example 5
Source File: FakeApi.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * PATCH /fake : To test \&quot;client\&quot; model
 * To test \&quot;client\&quot; model
 *
 * @param body client model (required)
 * @return successful operation (status code 200)
 */
@ApiOperation(value = "To test \"client\" model", nickname = "testClientModel", notes = "To test \"client\" model", response = Client.class, tags={ "fake", })
@ApiResponses(value = { 
    @ApiResponse(code = 200, message = "successful operation", response = Client.class) })
@RequestMapping(value = "/fake",
    produces = { "application/json" }, 
    consumes = { "application/json" },
    method = RequestMethod.PATCH)
ResponseEntity<Client> testClientModel(@ApiParam(value = "client model" ,required=true )  @Valid @RequestBody Client body);
 
Example 6
Source File: AuthorBlogRestController.java    From JiwhizBlogWeb with Apache License 2.0 5 votes vote down vote up
@RequestMapping(method = RequestMethod.PATCH, value = ApiUrls.URL_AUTHOR_BLOGS_BLOG)
public HttpEntity<AuthorBlogResource> patchBlogPost(
        @PathVariable("blogId") String blogId, 
        @RequestBody Map<String, String> updateMap) throws ResourceNotFoundException {
    BlogPost blogPost = getBlogByIdAndCheckAuthor(blogId);
    String content = updateMap.get("content");
    if (content != null) {
        blogPost.setContent(content);
    }
    String title = updateMap.get("title");
    if (title != null) {
        blogPost.setTitle(title);
    }
    String tagString = updateMap.get("tagString");
    if (tagString != null) {
        blogPost.parseAndSetTags(tagString);
    }
    String published = updateMap.get("published");
    if (published != null) {
        blogPost.setPublished(published.equals("true"));
    }
    
    blogPost = blogPostRepository.save(blogPost);

    AuthorBlogResource resource = authorBlogResourceAssembler.toResource(blogPost);
    return new ResponseEntity<>(resource, HttpStatus.OK);

}
 
Example 7
Source File: NotesController.java    From restdocs-raml with MIT License 5 votes vote down vote up
@RequestMapping(value = "/{id}", method = RequestMethod.PATCH)
@ResponseStatus(HttpStatus.NO_CONTENT)
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);
}
 
Example 8
Source File: FakeApi.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * PATCH /fake : To test \&quot;client\&quot; model
 * To test \&quot;client\&quot; model
 *
 * @param body client model (required)
 * @return successful operation (status code 200)
 */
@ApiOperation(value = "To test \"client\" model", nickname = "testClientModel", notes = "To test \"client\" model", response = Client.class, tags={ "fake", })
@ApiResponses(value = { 
    @ApiResponse(code = 200, message = "successful operation", response = Client.class) })
@RequestMapping(value = "/fake",
    produces = { "application/json" }, 
    consumes = { "application/json" },
    method = RequestMethod.PATCH)
ResponseEntity<Client> testClientModel(@ApiParam(value = "client model" ,required=true )  @Valid @RequestBody Client body);
 
Example 9
Source File: FakeClassnameTestApi.java    From openapi-generator with Apache License 2.0 5 votes vote down vote up
/**
 * PATCH /fake_classname_test : To test class name in snake case
 * To test class name in snake case
 *
 * @param body client model (required)
 * @return successful operation (status code 200)
 */
@ApiOperation(value = "To test class name in snake case", nickname = "testClassname", notes = "To test class name in snake case", response = Client.class, authorizations = {
    @Authorization(value = "api_key_query")
}, tags={ "fake_classname_tags 123#$%^", })
@ApiResponses(value = { 
    @ApiResponse(code = 200, message = "successful operation", response = Client.class) })
@RequestMapping(value = "/fake_classname_test",
    produces = { "application/json" }, 
    consumes = { "application/json" },
    method = RequestMethod.PATCH)
default ResponseEntity<Client> testClassname(@ApiParam(value = "client model" ,required=true )  @Valid @RequestBody Client body) {
    return getDelegate().testClassname(body);
}
 
Example 10
Source File: UpdateController.java    From metron with Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "Update a document with a patch")
@ApiResponse(message = "Returns the complete patched document.", code = 200)
@RequestMapping(value = "/patch", method = RequestMethod.PATCH)
ResponseEntity<Document> patch(
        final @ApiParam(name = "request", value = "Patch request", required = true)
              @RequestBody
        PatchRequest request
) throws RestException {
  try {
    return new ResponseEntity<>(service.patch(request), HttpStatus.OK);
  } catch (OriginalNotFoundException e) {
    return new ResponseEntity<>(HttpStatus.NOT_FOUND);
  }
}
 
Example 11
Source File: SafeSpringCsrfRequestMappingController.java    From Android_Code_Arbiter with GNU Lesser General Public License v3.0 4 votes vote down vote up
@RequestMapping(value = "/request-mapping-patch", method = RequestMethod.PATCH)
public void requestMappingPatch() {
}
 
Example 12
Source File: ServletAnnotationControllerHandlerMethodTests.java    From java-technology-stack with MIT License 4 votes vote down vote up
@RequestMapping(value = "/something", method = RequestMethod.PATCH)
@ResponseBody
public String handlePartialUpdate(@RequestBody String content) throws IOException {
	return content;
}
 
Example 13
Source File: ContextModelController.java    From SO with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * response for request "/cm, HTTP-method:PATCH(update)".<BR/>
 * @param cm ContextModelForMQ
 * @return updated ContextModelForMQ id
 */
@RequestMapping(method=RequestMethod.PATCH)
public String updateContextModel(ContextModelForDB cm) {
    //implements...
    return null;
}
 
Example 14
Source File: HeavyResourceController.java    From tutorials with MIT License 4 votes vote down vote up
@RequestMapping(value = "/heavyresource2/{id}", method = RequestMethod.PATCH, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> partialUpdateGeneric(@RequestBody Map<String, Object> updates,
                                              @PathVariable("id") String id) {
    heavyResourceRepository.save(updates, id);
    return ResponseEntity.ok("resource updated");
}
 
Example 15
Source File: OrchestrationServiceController.java    From SO with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * response for request "/os, HTTP-method:PATCH(update)".<BR/>
 * @param os OrchestrationServiceForDB
 * @return updated OrchestrationServiceForDB id
 */
@RequestMapping(method=RequestMethod.PATCH)
public String updateOrchestrationService(OrchestrationServiceForDB os) {
    //implements...
    return null;
}
 
Example 16
Source File: CompositeVirtualObjectController.java    From SO with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * response for request "/cvo, HTTP-method:PATCH(update)".<BR/>
 * @param cvo CompositeVirtualObjectForDB
 * @return updated profile id
 */
@RequestMapping(method=RequestMethod.PATCH)
public String updateCompositeVirtualObject(CompositeVirtualObjectForDB cvo) {
    //implements...
    return null;
}
 
Example 17
Source File: ChartFacadeController.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@RequestMapping( value = "/{uid}", method = RequestMethod.PATCH )
@ResponseStatus( value = HttpStatus.NO_CONTENT )
public void partialUpdateObject(
    @PathVariable( "uid" ) String pvUid, @RequestParam Map<String, String> rpParameters,
    HttpServletRequest request, HttpServletResponse response ) throws Exception
{
    WebOptions options = new WebOptions( rpParameters );
    List<Visualization> entities = getEntity( pvUid, options );

    if ( entities.isEmpty() )
    {
        throw new WebMessageException( WebMessageUtils.notFound( Chart.class, pvUid ) );
    }

    Visualization persistedObject = entities.get( 0 );

    User user = currentUserService.getCurrentUser();

    if ( !aclService.canUpdate( user, persistedObject ) )
    {
        throw new UpdateAccessDeniedException( "You don't have the proper permissions to update this object." );
    }

    Patch patch = null;

    if ( isJson( request ) )
    {
        patch = patchService.diff(
            new PatchParams( jsonMapper.readTree( request.getInputStream() ) )
        );
    }
    else if ( isXml( request ) )
    {
        patch = patchService.diff(
            new PatchParams( xmlMapper.readTree( request.getInputStream() ) )
        );
    }

    patchService.apply( patch, persistedObject );
    manager.update( persistedObject );
}
 
Example 18
Source File: FixedDeviceController.java    From SO with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * response for request "/fd, HTTP-method:PATCH(update)".<BR/>
 * @param fd FixedDeviceForDB
 * @return updated FixedDeviceForDB id
 */
@RequestMapping(method=RequestMethod.PATCH)
public String updateFixedDevice(FixedDeviceForDB fd) {
    //implements...
    return null;
}
 
Example 19
Source File: CodeFirstSpringmvc.java    From servicecomb-java-chassis with Apache License 2.0 4 votes vote down vote up
@ResponseHeaders({@ResponseHeader(name = "h1", response = String.class),
    @ResponseHeader(name = "h2", response = String.class)})
@RequestMapping(path = "/responseEntity", method = RequestMethod.PATCH)
public ResponseEntity<Date> responseEntityPATCH(InvocationContext c1, @RequestAttribute("date") Date date) {
  return responseEntity(c1, date);
}
 
Example 20
Source File: UnsafeSpringCsrfRequestMappingController.java    From Android_Code_Arbiter with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Mapping to several HTTP request methods is not OK if it's a mix of unprotected and protected HTTP request methods.
 */
@RequestMapping(value = "/request-mapping-all-unprotected-methods-and-one-protected-method",
        method = {RequestMethod.GET, RequestMethod.HEAD, RequestMethod.TRACE, RequestMethod.OPTIONS, RequestMethod.PATCH})
public void requestMappingAllUnprotectedMethodsAndOneProtectedMethod() {
}