Search in sources :

Example 26 with EntityNotFoundException

use of eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException 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 27 with EntityNotFoundException

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

Example 28 with EntityNotFoundException

use of eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException in project CzechIdMng by bcvsolutions.

the class RemoveAutomaticRoleTaskExecutor method validate.

/**
 * Automatic role removal can be start, if previously LRT ended.
 */
@Override
public void validate(IdmLongRunningTaskDto task) {
    super.validate(task);
    // 
    UUID automaticRoleId = getAutomaticRoleId();
    boolean byTree = true;
    AbstractIdmAutomaticRoleDto automaticRole = roleTreeNodeService.get(automaticRoleId);
    if (automaticRole == null) {
        // get from automatic role attribute service
        byTree = false;
        automaticRole = automaticRoleAttributeService.get(automaticRoleId);
    }
    if (automaticRole == null) {
        throw new EntityNotFoundException(AbstractIdmAutomaticRoleDto.class, automaticRoleId);
    }
    // 
    IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
    filter.setTaskType(AutowireHelper.getTargetType(this));
    filter.setOperationState(OperationState.RUNNING);
    // ignore waiting tasks
    filter.setRunning(Boolean.TRUE);
    // 
    if (byTree) {
        for (UUID longRunningTaskId : getLongRunningTaskService().findIds(filter, PageRequest.of(0, 1))) {
            if (longRunningTaskId.equals(getLongRunningTaskId())) {
                continue;
            }
            throw new AcceptedException(CoreResultCode.AUTOMATIC_ROLE_TASK_RUNNING, ImmutableMap.of("taskId", longRunningTaskId.toString()));
        }
        // 
        filter.setTaskType(AutowireHelper.getTargetType(ProcessAutomaticRoleByTreeTaskExecutor.class));
        for (UUID longRunningTaskId : getLongRunningTaskService().findIds(filter, PageRequest.of(0, 1))) {
            if (longRunningTaskId.equals(getLongRunningTaskId())) {
                continue;
            }
            throw new AcceptedException(CoreResultCode.AUTOMATIC_ROLE_TASK_RUNNING, ImmutableMap.of("taskId", longRunningTaskId.toString()));
        }
    } else {
        // by attribute - prevent currently removed role only
        for (IdmLongRunningTaskDto longRunningTask : getLongRunningTaskService().find(filter, null)) {
            if (longRunningTask.getId().equals(getLongRunningTaskId())) {
                continue;
            }
            if (longRunningTask.getTaskProperties().get(AbstractAutomaticRoleTaskExecutor.PARAMETER_ROLE_TREE_NODE).equals(automaticRole.getId())) {
                throw new ResultCodeException(CoreResultCode.AUTOMATIC_ROLE_REMOVE_TASK_RUN_CONCURRENTLY, ImmutableMap.of("roleTreeNode", automaticRole.getId().toString(), "taskId", longRunningTask.getId().toString()));
            }
        }
        // 
        filter.setTaskType(AutowireHelper.getTargetType(ProcessAutomaticRoleByAttributeTaskExecutor.class));
        for (IdmLongRunningTaskDto longRunningTask : getLongRunningTaskService().find(filter, null)) {
            if (longRunningTask.getId().equals(getLongRunningTaskId())) {
                continue;
            }
            if (longRunningTask.getTaskProperties().get(AbstractAutomaticRoleTaskExecutor.PARAMETER_ROLE_TREE_NODE).equals(automaticRole.getId())) {
                throw new ResultCodeException(CoreResultCode.AUTOMATIC_ROLE_REMOVE_TASK_ADD_RUNNING, ImmutableMap.of("automaticRoleId", automaticRole.getId().toString(), "taskId", longRunningTask.getId().toString()));
            }
        }
    }
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AbstractIdmAutomaticRoleDto(eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) UUID(java.util.UUID)

Example 29 with EntityNotFoundException

use of eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException in project CzechIdMng by bcvsolutions.

the class RemoveRoleCompositionTaskExecutor method validate.

/**
 * Automatic role removal can be start, if previously LRT ended.
 */
@Override
public void validate(IdmLongRunningTaskDto task) {
    super.validate(task);
    // 
    // composition is already deleted
    IdmRoleCompositionDto roleComposition = roleCompositionService.get(roleCompositionId);
    if (roleComposition == null) {
        throw new EntityNotFoundException(IdmRoleComposition.class, roleCompositionId);
    }
    // 
    IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
    filter.setOperationState(OperationState.RUNNING);
    // ignore waiting tasks
    filter.setRunning(Boolean.TRUE);
    filter.setTaskType(AddNewRoleCompositionTaskExecutor.class.getCanonicalName());
    for (UUID longRunningTaskId : getLongRunningTaskService().findIds(filter, PageRequest.of(0, 1))) {
        throw new AcceptedException(CoreResultCode.ROLE_COMPOSITION_RUN_CONCURRENTLY, ImmutableMap.of("taskId", longRunningTaskId.toString(), "roleCompositionId", roleCompositionId.toString()));
    }
}
Also used : IdmRoleCompositionDto(eu.bcvsolutions.idm.core.api.dto.IdmRoleCompositionDto) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) UUID(java.util.UUID)

Example 30 with EntityNotFoundException

use of eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException in project CzechIdMng by bcvsolutions.

the class ProcessAutomaticRoleByAttributeTaskExecutor method validate.

/**
 * Automatic role removal can be start, if previously LRT ended.
 */
@Override
public void validate(IdmLongRunningTaskDto task) {
    super.validate(task);
    // 
    UUID automaticRoleId = getAutomaticRoleId();
    AbstractIdmAutomaticRoleDto automaticRole = automaticRoleAttributeService.get(automaticRoleId);
    if (automaticRole == null) {
        throw new EntityNotFoundException(AbstractIdmAutomaticRoleDto.class, automaticRoleId);
    }
    // 
    IdmLongRunningTaskFilter filter = new IdmLongRunningTaskFilter();
    filter.setTaskType(AutowireHelper.getTargetType(this));
    filter.setOperationState(OperationState.RUNNING);
    // by attribute - prevent currently processed role only
    for (IdmLongRunningTaskDto longRunningTask : getLongRunningTaskService().find(filter, null)) {
        if (longRunningTask.getId().equals(getLongRunningTaskId())) {
            continue;
        }
        if (longRunningTask.getTaskProperties().get(AbstractAutomaticRoleTaskExecutor.PARAMETER_ROLE_TREE_NODE).equals(automaticRole.getId())) {
            throw new AcceptedException(CoreResultCode.AUTOMATIC_ROLE_TASK_RUNNING, ImmutableMap.of("taskId", longRunningTask.getId().toString()));
        }
    }
    // 
    filter.setTaskType(AutowireHelper.getTargetType(RemoveAutomaticRoleTaskExecutor.class));
    for (IdmLongRunningTaskDto longRunningTask : getLongRunningTaskService().find(filter, null)) {
        if (longRunningTask.getId().equals(getLongRunningTaskId())) {
            continue;
        }
        if (longRunningTask.getTaskProperties().get(AbstractAutomaticRoleTaskExecutor.PARAMETER_ROLE_TREE_NODE).equals(automaticRole.getId())) {
            throw new AcceptedException(CoreResultCode.AUTOMATIC_ROLE_TASK_RUNNING, ImmutableMap.of("taskId", longRunningTask.getId().toString()));
        }
    }
}
Also used : IdmLongRunningTaskDto(eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto) AbstractIdmAutomaticRoleDto(eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto) IdmLongRunningTaskFilter(eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter) EntityNotFoundException(eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException) AcceptedException(eu.bcvsolutions.idm.core.api.exception.AcceptedException) UUID(java.util.UUID)

Aggregations

EntityNotFoundException (eu.bcvsolutions.idm.core.api.exception.EntityNotFoundException)30 ApiOperation (io.swagger.annotations.ApiOperation)15 ResponseEntity (org.springframework.http.ResponseEntity)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)10 UUID (java.util.UUID)10 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)9 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)9 IdmLongRunningTaskDto (eu.bcvsolutions.idm.core.scheduler.api.dto.IdmLongRunningTaskDto)7 ResourceSupport (org.springframework.hateoas.ResourceSupport)7 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)6 Transactional (org.springframework.transaction.annotation.Transactional)5 IdmAttachmentDto (eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto)4 IOException (java.io.IOException)4 IdmPasswordDto (eu.bcvsolutions.idm.core.api.dto.IdmPasswordDto)3 IdmProfileDto (eu.bcvsolutions.idm.core.api.dto.IdmProfileDto)3 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)3 IdmTokenDto (eu.bcvsolutions.idm.core.api.dto.IdmTokenDto)3 AcceptedException (eu.bcvsolutions.idm.core.api.exception.AcceptedException)3 IdmLongRunningTaskFilter (eu.bcvsolutions.idm.core.scheduler.api.dto.filter.IdmLongRunningTaskFilter)3