Search in sources :

Example 1 with IdmRequestItemService

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

the class IdmRequestItemController method delete.

@Override
@ResponseBody
@RequestMapping(value = "/{backendId}", method = RequestMethod.DELETE)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.REQUEST_ITEM_DELETE + "')")
@ApiOperation(value = "Delete request item", nickname = "deleteRequestItem", tags = { IdmRequestItemController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.REQUEST_ITEM_DELETE, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.REQUEST_ITEM_DELETE, description = "") }) })
public ResponseEntity<?> delete(@ApiParam(value = "Item's uuid identifier.", required = true) @PathVariable @NotNull String backendId) {
    IdmRequestItemService service = ((IdmRequestItemService) this.getService());
    IdmRequestItemDto dto = service.get(backendId);
    IdmRequestDto request = DtoUtils.getEmbedded(dto, IdmRequestItem_.request, IdmRequestDto.class);
    // 
    checkAccess(dto, IdmBasePermission.DELETE);
    // Request item where his request is in the Executed state can not be delete or change
    if (RequestState.EXECUTED == request.getState()) {
        throw new ResultCodeException(CoreResultCode.REQUEST_EXECUTED_CANNOT_DELETE, ImmutableMap.of("request", dto));
    }
    // In others states, will be request item set to Canceled result and save.
    if (RequestState.CONCEPT == request.getState()) {
        service.delete(dto);
    } else {
        dto.setState(RequestState.CANCELED);
        dto.setResult(new OperationResultDto(OperationState.CANCELED));
        service.save(dto);
    }
    return new ResponseEntity<Object>(HttpStatus.NO_CONTENT);
}
Also used : IdmRequestItemDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto) ResponseEntity(org.springframework.http.ResponseEntity) IdmRequestItemService(eu.bcvsolutions.idm.core.api.service.IdmRequestItemService) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) OperationResultDto(eu.bcvsolutions.idm.core.api.dto.OperationResultDto) 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 IdmRequestItemDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto)1 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1 IdmRequestItemService (eu.bcvsolutions.idm.core.api.service.IdmRequestItemService)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