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);
}
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);
}
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()));
}
}
}
}
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()));
}
}
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()));
}
}
}
Aggregations