Search in sources :

Example 6 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)

Example 7 with ResourceSupport

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

the class IdmRoleRequestController method startRequest.

@ResponseBody
@RequestMapping(value = "/{backendId}/start", method = RequestMethod.PUT)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.ROLE_REQUEST_UPDATE + "')")
@ApiOperation(value = "Start role request. Returns request doesn't contains concepts (from version 9.7.0!).", nickname = "startRoleRequest", response = IdmRoleRequestDto.class, tags = { IdmRoleRequestController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.ROLE_REQUEST_UPDATE, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.ROLE_REQUEST_UPDATE, description = "") }) })
public ResponseEntity<?> startRequest(@ApiParam(value = "Role request's uuid identifier.", required = true) @PathVariable @NotNull String backendId) {
    IdmRoleRequestDto requestDto = service.get(backendId, new IdmRoleRequestFilter(true), IdmBasePermission.READ);
    // Validate
    service.validate(requestDto);
    // Start request
    Map<String, Serializable> variables = new HashMap<>();
    variables.put(RoleRequestApprovalProcessor.CHECK_RIGHT_PROPERTY, Boolean.TRUE);
    RoleRequestEvent event = new RoleRequestEvent(RoleRequestEventType.EXCECUTE, requestDto, variables);
    event.setPriority(PriorityType.HIGH);
    // 
    requestDto = service.startRequest(event);
    if (!requestDto.getState().isTerminatedState()) {
        throw new AcceptedException();
    }
    ResourceSupport resource = toResource(requestDto);
    ResponseEntity<ResourceSupport> response = new ResponseEntity<>(resource, HttpStatus.OK);
    return response;
}
Also used : Serializable(java.io.Serializable) ResponseEntity(org.springframework.http.ResponseEntity) HashMap(java.util.HashMap) IdmRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter) RoleRequestEvent(eu.bcvsolutions.idm.core.model.event.RoleRequestEvent) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) ResourceSupport(org.springframework.hateoas.ResourceSupport) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) 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 8 with ResourceSupport

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

the class IdmRoleRequestController method get.

@Override
@ResponseBody
@RequestMapping(value = "/{backendId}", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.ROLE_REQUEST_READ + "')")
@ApiOperation(value = "Role request detail. Returns request doesn't contains concepts (from version 9.7.0!).", nickname = "getRoleRequest", response = IdmRoleRequestDto.class, tags = { IdmRoleRequestController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.ROLE_REQUEST_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.ROLE_REQUEST_READ, description = "") }) })
public ResponseEntity<?> get(@ApiParam(value = "Role request's uuid identifier.", required = true) @PathVariable @NotNull String backendId) {
    // 
    IdmRoleRequestFilter filter = new IdmRoleRequestFilter();
    filter.setIncludeApprovers(true);
    IdmRoleRequestDto requestDto = getService().get(backendId, filter, IdmBasePermission.READ);
    if (requestDto == null) {
        throw new EntityNotFoundException(getService().getEntityClass(), backendId);
    }
    ResourceSupport resource = toResource(requestDto);
    if (resource == null) {
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }
    return new ResponseEntity<>(resource, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) IdmRoleRequestFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleRequestFilter) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) ResourceSupport(org.springframework.hateoas.ResourceSupport) IdmRoleRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto) 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 9 with ResourceSupport

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

the class AbstractRequestDtoController method post.

/**
 * Post DTO and convert to response
 *
 * @param dto
 * @param requestId
 * @return
 */
@ApiOperation(value = "Create / update record", authorizations = { // 
@Authorization(SwaggerConfig.AUTHENTICATION_BASIC), // 
@Authorization(SwaggerConfig.AUTHENTICATION_CIDMST) })
public // 
ResponseEntity<?> post(// 
@ApiParam(value = "Request ID", required = true) String requestId, @ApiParam(value = "Record (dto).", required = true) DTO dto) {
    // 
    Requestable resultDto = requestManager.post(requestId, dto, IdmBasePermission.CREATE);
    @SuppressWarnings("unchecked") ResourceSupport resource = toResource(requestId, (DTO) resultDto);
    if (resource == null) {
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }
    return new ResponseEntity<>(resource, HttpStatus.CREATED);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) Requestable(eu.bcvsolutions.idm.core.api.domain.Requestable) ResourceSupport(org.springframework.hateoas.ResourceSupport) ApiOperation(io.swagger.annotations.ApiOperation)

Example 10 with ResourceSupport

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

the class AbstractRequestDtoController method delete.

/**
 * Deletes DTO by given id
 *
 * @param requestId
 * @param backendId
 * @return
 */
@ApiOperation(value = "Delete record", authorizations = { @Authorization(SwaggerConfig.AUTHENTICATION_BASIC), @Authorization(SwaggerConfig.AUTHENTICATION_CIDMST) })
public // 
ResponseEntity<?> delete(// 
@ApiParam(value = "Request ID", required = true) String requestId, @ApiParam(value = "Record's uuid identifier or unique code.", required = true) String backendId) {
    // 
    DTO dto = getDto(requestId, backendId);
    if (dto == null) {
        throw new EntityNotFoundException(getService().getEntityClass(), backendId);
    }
    Requestable resultDto = requestManager.delete(requestId, dto, IdmBasePermission.DELETE);
    @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