Search in sources :

Example 1 with ResourceSupport

use of org.springframework.hateoas.ResourceSupport in project spring-boot by spring-projects.

the class LinksEnhancerTests method useNameAsRelIfAvailable.

@Test
public void useNameAsRelIfAvailable() throws Exception {
    TestMvcEndpoint endpoint = new TestMvcEndpoint(new TestEndpoint("a"));
    endpoint.setPath("something-else");
    LinksEnhancer enhancer = getLinksEnhancer(Collections.singletonList((MvcEndpoint) endpoint));
    ResourceSupport support = new ResourceSupport();
    enhancer.addEndpointLinks(support, "");
    assertThat(support.getLink("a").getHref()).contains("/something-else");
}
Also used : AbstractMvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.AbstractMvcEndpoint) MvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint) ResourceSupport(org.springframework.hateoas.ResourceSupport) Test(org.junit.Test)

Example 2 with ResourceSupport

use of org.springframework.hateoas.ResourceSupport in project spring-boot by spring-projects.

the class LinksEnhancerTests method usePathAsRelIfNameNotAvailable.

@Test
public void usePathAsRelIfNameNotAvailable() throws Exception {
    MvcEndpoint endpoint = new NoNameTestMvcEndpoint("/a", false);
    LinksEnhancer enhancer = getLinksEnhancer(Collections.singletonList(endpoint));
    ResourceSupport support = new ResourceSupport();
    enhancer.addEndpointLinks(support, "");
    assertThat(support.getLink("a").getHref()).contains("/a");
}
Also used : AbstractMvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.AbstractMvcEndpoint) MvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint) ResourceSupport(org.springframework.hateoas.ResourceSupport) Test(org.junit.Test)

Example 3 with ResourceSupport

use of org.springframework.hateoas.ResourceSupport in project spring-boot by spring-projects.

the class LinksEnhancerTests method multipleHrefsForSameRelWhenPathIsDifferent.

@Test
public void multipleHrefsForSameRelWhenPathIsDifferent() throws Exception {
    TestMvcEndpoint endpoint = new TestMvcEndpoint(new TestEndpoint("a"));
    endpoint.setPath("endpoint");
    TestMvcEndpoint otherEndpoint = new TestMvcEndpoint(new TestEndpoint("a"));
    otherEndpoint.setPath("other-endpoint");
    LinksEnhancer enhancer = getLinksEnhancer(Arrays.asList((MvcEndpoint) endpoint, otherEndpoint));
    ResourceSupport support = new ResourceSupport();
    enhancer.addEndpointLinks(support, "");
    assertThat(support.getLinks()).haveExactly(1, getCondition("a", "endpoint"));
    assertThat(support.getLinks()).haveExactly(1, getCondition("a", "other-endpoint"));
}
Also used : AbstractMvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.AbstractMvcEndpoint) MvcEndpoint(org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint) ResourceSupport(org.springframework.hateoas.ResourceSupport) Test(org.junit.Test)

Example 4 with ResourceSupport

use of org.springframework.hateoas.ResourceSupport in project tutorials by eugenp.

the class IndexController method index.

@GetMapping
public ResourceSupport index() {
    ResourceSupport index = new ResourceSupport();
    index.add(linkTo(CRUDController.class).withRel("crud"));
    return index;
}
Also used : ResourceSupport(org.springframework.hateoas.ResourceSupport) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Example 5 with ResourceSupport

use of org.springframework.hateoas.ResourceSupport in project CzechIdMng by bcvsolutions.

the class AbstractReadDtoController method get.

/**
 * Returns response DTO by given backendId
 *
 * @param backendId
 * @return
 */
@ApiOperation(value = "Read record", authorizations = { @Authorization(SwaggerConfig.AUTHENTICATION_BASIC), @Authorization(SwaggerConfig.AUTHENTICATION_CIDMST) })
public ResponseEntity<?> get(@ApiParam(value = "Record's uuid identifier or unique code, if record supports Codeable interface.", required = true) @PathVariable @NotNull String backendId) {
    DTO dto = getDto(backendId);
    if (dto == null) {
        throw new EntityNotFoundException(getService().getEntityClass(), backendId);
    }
    ResourceSupport resource = toResource(dto);
    if (resource == null) {
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }
    // 
    return new ResponseEntity<>(resource, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) ResourceSupport(org.springframework.hateoas.ResourceSupport) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

ResourceSupport (org.springframework.hateoas.ResourceSupport)18 ApiOperation (io.swagger.annotations.ApiOperation)11 ResponseEntity (org.springframework.http.ResponseEntity)9 EntityNotFoundException (eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException)7 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 Test (org.junit.Test)4 AbstractMvcEndpoint (org.springframework.boot.actuate.endpoint.mvc.AbstractMvcEndpoint)4 MvcEndpoint (org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)4 Requestable (eu.bcvsolutions.idm.core.api.domain.Requestable)3 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)3 IdmRoleRequestFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter)2 HiddenResourceSupport (org.opentosca.toscana.api.docs.HiddenResourceSupport)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)1 IdmIdentityProjectionDto (eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto)1 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)1 RoleRequestEvent (eu.bcvsolutions.idm.core.model.event.RoleRequestEvent)1 VsRequestDto (eu.bcvsolutions.idm.vs.dto.VsRequestDto)1