Search in sources :

Example 26 with IdmRequestItemDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto 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)

Example 27 with IdmRequestItemDto

use of eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto in project CzechIdMng by bcvsolutions.

the class IdmRequestController method getChanges.

@ResponseBody
@RequestMapping(value = "/{backendId}/entity/{entityId}/changes", method = RequestMethod.GET)
@PreAuthorize("hasAuthority('" + CoreGroupPermission.REQUEST_READ + "')")
@ApiOperation(value = "Request changes of entity", nickname = "getRequestEntityChange", response = IdmRequestItemDto.class, tags = { IdmRequestItemController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = CoreGroupPermission.REQUEST_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = CoreGroupPermission.REQUEST_READ, description = "") }) })
public ResponseEntity<?> getChanges(@ApiParam(value = "Item's uuid identifier.", required = true) @PathVariable @NotNull String backendId, @ApiParam(value = "Entity's uuid identifier.", required = true) @PathVariable @NotNull String entityId) {
    IdmRequestDto dto = this.getDto(backendId);
    // Find item by entity ID and request ID
    IdmRequestItemFilter itemFilter = new IdmRequestItemFilter();
    itemFilter.setRequestId(dto.getId());
    itemFilter.setOwnerId(UUID.fromString(entityId));
    List<IdmRequestItemDto> items = requestItemService.find(itemFilter, null, IdmBasePermission.READ).getContent();
    if (items.isEmpty()) {
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }
    IdmRequestItemChangesDto result = requestManager.getChanges(items.get(0));
    if (result == null) {
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }
    // 
    return new ResponseEntity<>(result, HttpStatus.OK);
}
Also used : IdmRequestItemDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto) ResponseEntity(org.springframework.http.ResponseEntity) IdmRequestItemFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestItemFilter) IdmRequestDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestDto) IdmRequestItemChangesDto(eu.bcvsolutions.idm.core.api.dto.IdmRequestItemChangesDto) 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

IdmRequestItemDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestItemDto)27 IdmRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestDto)21 Requestable (eu.bcvsolutions.idm.core.api.domain.Requestable)14 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)12 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)10 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)9 Test (org.junit.Test)9 AbstractDto (eu.bcvsolutions.idm.core.api.dto.AbstractDto)8 IdmRequestItemFilter (eu.bcvsolutions.idm.core.api.dto.filter.IdmRequestItemFilter)7 IOException (java.io.IOException)7 OperationResultDto (eu.bcvsolutions.idm.core.api.dto.OperationResultDto)6 IdmRequestItemService (eu.bcvsolutions.idm.core.api.service.IdmRequestItemService)6 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)6 RequestOperationType (eu.bcvsolutions.idm.core.api.domain.RequestOperationType)5 RequestState (eu.bcvsolutions.idm.core.api.domain.RequestState)5 IdmRequestItemChangesDto (eu.bcvsolutions.idm.core.api.dto.IdmRequestItemChangesDto)5 RequestManager (eu.bcvsolutions.idm.core.api.service.RequestManager)5 IdmFormInstanceDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto)5 WorkflowProcessInstanceService (eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService)5 ArrayList (java.util.ArrayList)5