Search in sources :

Example 16 with ResourceSupport

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

the class IdmIdentityProjectionController method get.

@ResponseBody
@RequestMapping(value = "/{backendId}", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.IDENTITY_READ + "')")
@ApiOperation(value = "Identity projection detail", nickname = "getIdentityProjection", response = IdmIdentityProjectionDto.class, tags = { IdmIdentityProjectionController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.IDENTITY_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.IDENTITY_READ, description = "") }) })
public ResponseEntity<?> get(@ApiParam(value = "Identity's uuid identifier or username.", required = true) @PathVariable @NotNull String backendId) {
    IdmIdentityProjectionDto dto = getDto(backendId);
    if (dto == null) {
        throw new EntityNotFoundException(identityService.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) IdmIdentityProjectionDto(eu.bcvsolutions.idm.core.api.dto.projection.IdmIdentityProjectionDto) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with ResourceSupport

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

the class AbstractRequestDtoController method get.

/**
 * Returns response DTO by given backendId
 *
 * @param backendId
 * @param requestId
 * @return
 */
@ApiOperation(value = "Read record", authorizations = { // 
@Authorization(SwaggerConfig.AUTHENTICATION_BASIC), // 
@Authorization(SwaggerConfig.AUTHENTICATION_CIDMST) })
public ResponseEntity<?> get(@PathVariable @NotNull String requestId, // 
@ApiParam(value = "Record's uuid identifier or unique code, if record supports Codeable interface.", required = true) @PathVariable @NotNull String backendId) {
    // 
    DTO dto = getDto(requestId, backendId);
    if (dto == null) {
        throw new EntityNotFoundException(getService().getEntityClass(), backendId);
    }
    ResourceSupport resource = toResource(requestId, 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)

Example 18 with ResourceSupport

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

the class AbstractRequestDtoController method put.

/**
 * Update DTO by given backendId and convert to response
 *
 * @param requestId
 * @param backendId
 * @param dto
 * @return
 */
@ApiOperation(value = "Update record", authorizations = { @Authorization(SwaggerConfig.AUTHENTICATION_BASIC), @Authorization(SwaggerConfig.AUTHENTICATION_CIDMST) })
public // 
ResponseEntity<?> put(// 
@ApiParam(value = "Request ID", required = true) String requestId, // 
@ApiParam(value = "Record's uuid identifier or unique code", required = true) String backendId, @ApiParam(value = "Record (dto).", required = true) DTO dto) {
    // 
    DTO updatedDto = getDto(requestId, backendId);
    if (updatedDto == null) {
        throw new EntityNotFoundException(getService().getEntityClass(), backendId);
    }
    Requestable resultDto = requestManager.post(requestId, dto, IdmBasePermission.UPDATE);
    @SuppressWarnings("unchecked") ResourceSupport resource = toResource(requestId, (DTO) resultDto);
    if (resource == null) {
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }
    return new ResponseEntity<>(resource, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) 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