use of eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto 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.dto.AbstractIdmAutomaticRoleDto in project CzechIdMng by bcvsolutions.
the class ProcessAutomaticRoleByAttributeTaskExecutor method process.
@Override
public Boolean process() {
UUID automaticRoleId = getAutomaticRoleId();
IdmAutomaticRoleAttributeDto automaticRolAttributeDto = automaticRoleAttributeService.get(automaticRoleId);
if (automaticRoleId == null || automaticRolAttributeDto == null) {
throw new ResultCodeException(CoreResultCode.AUTOMATIC_ROLE_TASK_EMPTY);
}
//
Set<AbstractIdmAutomaticRoleDto> setWithAutomaticRole = Sets.newHashSet(automaticRolAttributeDto);
//
List<String> failedEntitiesAdd = new ArrayList<>();
List<String> failedEntitiesRemove = new ArrayList<>();
//
// by contract
List<UUID> newPassedContracts = automaticRoleAttributeService.getContractsForAutomaticRole(automaticRoleId, true, null).getContent();
List<UUID> newNotPassedContracts = automaticRoleAttributeService.getContractsForAutomaticRole(automaticRoleId, false, null).getContent();
//
counter = 0L;
count = Long.valueOf(newPassedContracts.size() + newNotPassedContracts.size());
//
// assign new passed roles
boolean canContinue = true;
// process contracts
for (UUID contractId : newPassedContracts) {
IdmIdentityContractDto contract = identityContractService.get(contractId);
//
try {
if (async) {
automaticRoleAttributeService.addAutomaticRoles(contract, setWithAutomaticRole);
} else {
automaticRoleAttributeService.addAutomaticRolesInternal(contract, setWithAutomaticRole);
}
counter++;
} catch (Exception ex) {
LOG.error("Error while add new automatic role id [{}] to contract id [{}] and identity id [{}]", automaticRoleId, contractId, contract.getIdentity(), ex);
failedEntitiesAdd.add(contractId.toString());
} finally {
canContinue = updateState();
if (!canContinue) {
break;
}
}
}
//
if (canContinue) {
for (UUID contractId : newNotPassedContracts) {
try {
if (async) {
automaticRoleAttributeService.removeAutomaticRoles(contractId, setWithAutomaticRole);
} else {
automaticRoleAttributeService.removeAutomaticRolesInternal(contractId, setWithAutomaticRole);
}
counter++;
} catch (Exception ex) {
LOG.error("Error while remove automatic role id [{}] from contract id [{}].", automaticRoleId, contractId, ex);
failedEntitiesRemove.add(contractId.toString());
} finally {
canContinue = updateState();
if (!canContinue) {
break;
}
}
}
}
//
if (!failedEntitiesAdd.isEmpty() || !failedEntitiesRemove.isEmpty()) {
throw new ResultCodeException(CoreResultCode.AUTOMATIC_ROLE_PROCESS_TASK_NOT_COMPLETE, ImmutableMap.of("automaticRole", automaticRoleId, "failedAddEntities", StringUtils.join(failedEntitiesAdd, ","), "failedRemoveEntities", StringUtils.join(failedEntitiesRemove, ",")));
}
//
return Boolean.TRUE;
}
use of eu.bcvsolutions.idm.core.api.dto.AbstractIdmAutomaticRoleDto 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