use of eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto in project CzechIdMng by bcvsolutions.
the class DefaultAutomaticRoleManager method deleteAutomaticRole.
@Override
public void deleteAutomaticRole(AbstractIdmAutomaticRoleDto automaticRole, boolean executeImmediately) {
Assert.notNull(automaticRole, "Automatic role is required.");
Assert.notNull(automaticRole.getId(), "Automatic role must exists!");
IdmAutomaticRoleRequestDto request = new IdmAutomaticRoleRequestDto();
if (automaticRole instanceof IdmRoleTreeNodeDto) {
request.setRequestType(AutomaticRoleRequestType.TREE);
request.setTreeNode(((IdmRoleTreeNodeDto) automaticRole).getTreeNode());
} else {
request.setRequestType(AutomaticRoleRequestType.ATTRIBUTE);
}
request.setOperation(RequestOperationType.REMOVE);
request.setExecuteImmediately(executeImmediately);
request.setAutomaticRole(automaticRole.getId());
request.setName(automaticRole.getName());
request.setRole(automaticRole.getRole());
request = roleRequestService.save(request);
request = roleRequestService.startRequestInternal(request.getId(), true);
if (RequestState.EXECUTED == request.getState()) {
return;
}
if (RequestState.IN_PROGRESS == request.getState()) {
throw new AcceptedException(request.getId().toString());
}
if (RequestState.EXCEPTION == request.getState()) {
throw new CoreException(request.getResult().getCause());
}
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto in project CzechIdMng by bcvsolutions.
the class ProcessSkippedAutomaticRoleByTreeTaskExecutor method processItem.
@Override
public Optional<OperationResult> processItem(IdmEntityStateDto state) {
// check state is already processed by ProcessAutomaticRoleByTreeTaskExecutor
// => automatic role recount can be skipped multiple times for the same automatic role.
UUID ownerId = state.getOwnerId();
state = entityStateService.get(state);
if (state == null) {
LOG.debug("Automatic roles for owner [{}] was already processed.", ownerId);
// we need some result - counter / count will match.
return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
}
//
if (processedOwnerIds.contains(ownerId)) {
LOG.debug("Automatic roles for owner [{}] was already processed, delete state only.", ownerId);
//
entityStateManager.deleteState(state);
// Item will be deleted only - we need some result - counter / count will match.
return Optional.of(new OperationResult.Builder(OperationState.EXECUTED).build());
}
//
// process automatic role on state owner
LOG.debug("Process automatic roles for contract [{}].", ownerId);
//
IdmRoleTreeNodeDto automaticRole = lookupService.lookupDto(IdmRoleTreeNodeDto.class, ownerId);
if (automaticRole == null) {
getItemService().createLogItem(state, new OperationResult.Builder(OperationState.NOT_EXECUTED).setModel(new DefaultResultModel(CoreResultCode.CONTENT_DELETED, ImmutableMap.of("ownerId", ownerId, "ownerType", entityEventManager.getOwnerType(IdmRoleTreeNodeDto.class)))).build(), this.getLongRunningTaskId());
// delete state only
entityStateManager.deleteState(state);
} else {
ProcessAutomaticRoleByTreeTaskExecutor automaticRoleTask = AutowireHelper.createBean(ProcessAutomaticRoleByTreeTaskExecutor.class);
automaticRoleTask.setAutomaticRoles(Lists.newArrayList(automaticRole.getId()));
// invalid roles will be removed, after LRT end (prevent drop and create target account)
automaticRoleTask.setRemoveNotProcessedIdentityRoles(false);
automaticRoleTask.setRequireNewTransaction(true);
// exception is thrown and logged otherwise
longRunningTaskManager.executeSync(automaticRoleTask);
processedRoleRequests.addAll(automaticRoleTask.getProcessedRoleRequests());
processedAutomaticRoles.add(ownerId);
//
getItemService().createLogItem(automaticRole, new OperationResult.Builder(OperationState.EXECUTED).build(), this.getLongRunningTaskId());
}
//
processedOwnerIds.add(ownerId);
// Log added manually above - log processed contract / position instead of deleted entity state.
return Optional.empty();
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto in project CzechIdMng by bcvsolutions.
the class ProcessAutomaticRoleByTreeTaskExecutor method getFormInstance.
@Override
public IdmFormInstanceDto getFormInstance(ConfigurationMap properties) {
IdmFormInstanceDto formInstance = new IdmFormInstanceDto(getFormDefinition());
//
List<UUID> automaticRoles = getAutomaticRoles(properties);
if (CollectionUtils.isEmpty(automaticRoles)) {
return null;
}
automaticRoles.forEach(automaticRoleId -> {
IdmFormValueDto value = new IdmFormValueDto(formInstance.getMappedAttributeByCode(AbstractAutomaticRoleTaskExecutor.PARAMETER_ROLE_TREE_NODE));
value.setUuidValue(automaticRoleId);
IdmRoleTreeNodeDto automaticRole = roleTreeNodeService.get(automaticRoleId);
if (automaticRole == null) {
// id only => prevent to load on UI
// TODO: load from audit => #978 required
automaticRole = new IdmRoleTreeNodeDto(automaticRoleId);
}
value.getEmbedded().put(IdmFormValueDto.PROPERTY_UUID_VALUE, automaticRole);
formInstance.getValues().add(value);
});
//
return formInstance;
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto in project CzechIdMng by bcvsolutions.
the class ProcessAutomaticRoleByTreeTaskExecutorIntegrationTest method testFormInstance.
@Test
public void testFormInstance() {
ConfigurationMap properties = new ConfigurationMap();
//
Assert.assertNull(executor.getFormInstance(properties));
//
UUID automaticRoleId = UUID.randomUUID();
properties.put(AbstractAutomaticRoleTaskExecutor.PARAMETER_ROLE_TREE_NODE, automaticRoleId);
//
IdmFormInstanceDto formInstance = executor.getFormInstance(properties);
Assert.assertNotNull(formInstance);
Assert.assertNotNull(formInstance.getValues().stream().anyMatch(v -> v.getUuidValue().equals(automaticRoleId) && v.getEmbedded().get(IdmFormValueDto.PROPERTY_UUID_VALUE) != null));
//
IdmRoleTreeNodeDto automaticRole = getHelper().createRoleTreeNode(getHelper().createRole(), getHelper().createTreeNode(), true);
properties.put(AbstractAutomaticRoleTaskExecutor.PARAMETER_ROLE_TREE_NODE, automaticRole.getId());
//
formInstance = executor.getFormInstance(properties);
Assert.assertNotNull(formInstance);
Assert.assertNotNull(formInstance.getValues().stream().anyMatch(v -> v.getUuidValue().equals(automaticRole.getId()) && v.getEmbedded().get(IdmFormValueDto.PROPERTY_UUID_VALUE) != null));
}
use of eu.bcvsolutions.idm.core.api.dto.IdmRoleTreeNodeDto in project CzechIdMng by bcvsolutions.
the class IdmRoleTreeNodeControllerRestTest method prepareDto.
@Override
protected IdmRoleTreeNodeDto prepareDto() {
IdmRoleTreeNodeDto dto = new IdmRoleTreeNodeDto();
dto.setName(getHelper().createName());
dto.setRole(getHelper().createRole().getId());
dto.setTreeNode(getHelper().createTreeNode().getId());
dto.setRecursionType(RecursionType.NO);
//
return dto;
}
Aggregations