Search in sources :

Example 1 with IdmRequestService

use of eu.bcvsolutions.idm.core.api.service.IdmRequestService in project CzechIdMng by bcvsolutions.

the class IdmRequestController method delete.

@Override
@ResponseBody
@RequestMapping(value = "/{backendId}", method = RequestMethod.DELETE)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.REQUEST_DELETE + "')")
@ApiOperation(value = "Delete request", nickname = "deleteRequest", tags = { IdmRequestController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.REQUEST_DELETE, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.REQUEST_DELETE, description = "") }) })
public ResponseEntity<?> delete(@ApiParam(value = "Request's uuid identifier.", required = true) @PathVariable @NotNull String backendId) {
    IdmRequestService service = ((IdmRequestService) this.getService());
    IdmRequestDto dto = service.get(backendId);
    // 
    checkAccess(dto, IdmBasePermission.DELETE);
    // Request in Executed state can not be delete or change
    if (RequestState.EXECUTED == dto.getState()) {
        throw new ResultCodeException(CoreResultCode.REQUEST_EXECUTED_CANNOT_DELETE, ImmutableMap.of("request", dto));
    }
    // Only request in Concept state, can be deleted. In others states, will be request set to Canceled state and save.
    if (RequestState.CONCEPT == dto.getState()) {
        service.delete(dto);
    } else {
        requestManager.cancel(dto);
    }
    return new ResponseEntity<Object>(HttpStatus.NO_CONTENT);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) IdmRequestService(eu.bcvsolutions.idm.core.api.service.IdmRequestService) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) 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)

Aggregations

IdmRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestDto)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1 IdmRequestService (eu.bcvsolutions.idm.core.api.service.IdmRequestService)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ResponseEntity (org.springframework.http.ResponseEntity)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)1