use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleTreeNodeFilter in project CzechIdMng by bcvsolutions.
the class RoleDuplicateBulkActionIntegrationTest method findAutomaticRolesByTree.
private List<IdmRoleTreeNodeDto> findAutomaticRolesByTree(IdmRoleDto role) {
IdmRoleTreeNodeFilter filter = new IdmRoleTreeNodeFilter();
filter.setRoleId(role.getId());
//
return roleTreeNodeService.find(filter, null).getContent();
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleTreeNodeFilter in project CzechIdMng by bcvsolutions.
the class RoleDeleteProcessor method checkWithoutForceDelete.
/**
* Check role can be deleted without force delete.
*
* @param role deleted role
* @throws ResultCodeException if not
*/
private void checkWithoutForceDelete(IdmRoleDto role) {
UUID roleId = role.getId();
// check assigned roles
IdmIdentityRoleFilter identityRoleFilter = new IdmIdentityRoleFilter();
identityRoleFilter.setRoleId(roleId);
if (identityRoleService.count(identityRoleFilter) > 0) {
throw new ResultCodeException(CoreResultCode.ROLE_DELETE_FAILED_IDENTITY_ASSIGNED, ImmutableMap.of("role", role.getCode()));
}
//
// automatic roles by tree structure
IdmRoleTreeNodeFilter filter = new IdmRoleTreeNodeFilter();
filter.setRoleId(roleId);
if (roleTreeNodeService.count(filter) > 0) {
throw new ResultCodeException(CoreResultCode.ROLE_DELETE_FAILED_HAS_TREE_NODE, ImmutableMap.of("role", role.getCode()));
}
//
// related automatic roles by attribute
IdmAutomaticRoleFilter automaticRoleFilter = new IdmAutomaticRoleFilter();
automaticRoleFilter.setRoleId(roleId);
if (automaticRoleAttributeService.count(automaticRoleFilter) > 0) {
// some automatic role attribute has assigned this role
throw new ResultCodeException(CoreResultCode.ROLE_DELETE_FAILED_AUTOMATIC_ROLE_ASSIGNED, ImmutableMap.of("role", role.getCode()));
}
//
// business roles
IdmRoleCompositionFilter compositionFilter = new IdmRoleCompositionFilter();
compositionFilter.setSubId(roleId);
if (roleCompositionService.count(compositionFilter) > 0) {
throw new ResultCodeException(CoreResultCode.ROLE_DELETE_FAILED_HAS_COMPOSITION, ImmutableMap.of("role", role.getCode()));
}
compositionFilter = new IdmRoleCompositionFilter();
compositionFilter.setSuperiorId(roleId);
if (roleCompositionService.count(compositionFilter) > 0) {
throw new ResultCodeException(CoreResultCode.ROLE_DELETE_FAILED_HAS_COMPOSITION, ImmutableMap.of("role", role.getCode()));
}
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleTreeNodeFilter in project CzechIdMng by bcvsolutions.
the class TreeNodeDeleteProcessor method process.
@Override
public EventResult<IdmTreeNodeDto> process(EntityEvent<IdmTreeNodeDto> event) {
IdmTreeNodeDto treeNode = event.getContent();
Assert.notNull(treeNode, "Tree node is required.");
UUID treeNodeId = treeNode.getId();
Assert.notNull(treeNodeId, "Tree node identifier is required.");
boolean forceDelete = getBooleanProperty(PROPERTY_FORCE_DELETE, event.getProperties());
// check role can be removed without force
if (!forceDelete) {
checkWithoutForceDelete(treeNode);
}
//
// check automatic role request
IdmAutomaticRoleRequestFilter roleRequestFilter = new IdmAutomaticRoleRequestFilter();
roleRequestFilter.setTreeNodeId(treeNodeId);
List<IdmAutomaticRoleRequestDto> roleRequestDtos = roleRequestService.find(roleRequestFilter, null).getContent();
for (IdmAutomaticRoleRequestDto request : roleRequestDtos) {
if (!request.getState().isTerminatedState()) {
roleRequestService.cancel(request);
}
request.setTreeNode(null);
roleRequestService.save(request);
}
if (forceDelete) {
// delete all tree node children
service.findChildrenByParent(treeNodeId, null).forEach(child -> {
TreeNodeEvent treeNodeEvent = new TreeNodeEvent(TreeNodeEventType.DELETE, child);
//
service.publish(treeNodeEvent, event);
clearSession();
});
//
// update contract slices
IdmContractSliceFilter sliceFilter = new IdmContractSliceFilter();
sliceFilter.setTreeNode(treeNodeId);
sliceFilter.setRecursionType(RecursionType.NO);
contractSliceService.find(sliceFilter, null).forEach(slice -> {
slice.setWorkPosition(null);
contractSliceService.save(slice);
clearSession();
});
//
// update related contracts
IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
contractFilter.setWorkPosition(treeNodeId);
contractFilter.setRecursionType(RecursionType.NO);
identityContractService.find(contractFilter, null).forEach(identityContract -> {
// prepare event
identityContract.setWorkPosition(null);
IdentityContractEvent contractEvent = new IdentityContractEvent(IdentityContractEventType.UPDATE, identityContract);
//
identityContractService.publish(contractEvent, event);
clearSession();
});
//
// update related contract positions
IdmContractPositionFilter positionFilter = new IdmContractPositionFilter();
positionFilter.setWorkPosition(treeNodeId);
contractPositionService.find(positionFilter, null).forEach(contractPosition -> {
// prepare event
contractPosition.setWorkPosition(null);
ContractPositionEvent contractPositionEvent = new ContractPositionEvent(ContractPositionEventType.UPDATE, contractPosition);
//
contractPositionService.publish(contractPositionEvent, event);
clearSession();
});
//
// related automatic roles by tree structure
IdmRoleTreeNodeFilter roleTreeNodefilter = new IdmRoleTreeNodeFilter();
roleTreeNodefilter.setTreeNodeId(treeNodeId);
roleTreeNodeService.findIds(roleTreeNodefilter, null).stream().forEach(roleTreeNodeId -> {
// sync => all asynchronous requests have to be prepared in event queue
RemoveAutomaticRoleTaskExecutor automaticRoleTask = AutowireHelper.createBean(RemoveAutomaticRoleTaskExecutor.class);
automaticRoleTask.setAutomaticRoleId(roleTreeNodeId);
longRunningTaskManager.executeSync(automaticRoleTask);
clearSession();
});
}
//
if (forceDelete) {
LOG.debug("Tree node [{}] should be deleted by caller after all asynchronus processes are completed.", treeNode.getCode());
//
// dirty flag only - will be processed after asynchronous events ends
IdmEntityStateDto stateDeleted = new IdmEntityStateDto();
stateDeleted.setEvent(event.getId());
stateDeleted.setResult(new OperationResultDto.Builder(OperationState.RUNNING).setModel(new DefaultResultModel(CoreResultCode.DELETED)).build());
entityStateManager.saveState(treeNode, stateDeleted);
//
// set disabled
treeNode.setDisabled(true);
service.saveInternal(treeNode);
} else {
service.deleteInternal(treeNode);
}
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleTreeNodeFilter in project CzechIdMng by bcvsolutions.
the class DuplicateRoleAutomaticByTreeProcessor method process.
@Override
public EventResult<IdmRoleDto> process(EntityEvent<IdmRoleDto> event) {
IdmRoleDto cloned = event.getContent();
IdmRoleDto originalSource = event.getOriginalSource();
IdmRoleTreeNodeFilter filter = new IdmRoleTreeNodeFilter();
filter.setRoleId(cloned.getId());
Set<UUID> usedAutomaticRoles = new HashSet<>();
List<IdmRoleTreeNodeDto> currentAutomaticRoles = roleTreeNodeService.find(filter, null).getContent();
//
filter.setRoleId(originalSource.getId());
roleTreeNodeService.find(filter, null).forEach(automaticRole -> {
UUID exists = exists(currentAutomaticRoles, automaticRole);
if (exists != null) {
usedAutomaticRoles.add(exists);
} else {
IdmRoleTreeNodeDto clonedAutomaticRole = new IdmRoleTreeNodeDto();
clonedAutomaticRole.setName(automaticRole.getName());
clonedAutomaticRole.setRole(cloned.getId());
clonedAutomaticRole.setTreeNode(automaticRole.getTreeNode());
clonedAutomaticRole.setRecursionType(automaticRole.getRecursionType());
//
RoleTreeNodeEvent automaticRoleEvent = new RoleTreeNodeEvent(RoleTreeNodeEventType.CREATE, clonedAutomaticRole);
// execute sync
automaticRoleEvent.setPriority(PriorityType.IMMEDIATE);
roleTreeNodeService.publish(automaticRoleEvent, event);
}
});
//
// remove not used originals
currentAutomaticRoles.stream().filter(automaticRole -> {
return !usedAutomaticRoles.contains(automaticRole.getId());
}).forEach(automaticRole -> {
// dirty flag automatic role only - will be processed after parent action ends
IdmEntityStateDto stateDeleted = new IdmEntityStateDto();
stateDeleted.setEvent(event.getId());
stateDeleted.setSuperOwnerId(cloned.getId());
stateDeleted.setResult(new OperationResultDto.Builder(OperationState.RUNNING).setModel(new DefaultResultModel(CoreResultCode.DELETED)).build());
entityStateManager.saveState(automaticRole, stateDeleted);
});
//
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.core.api.dto.filter.IdmRoleTreeNodeFilter in project CzechIdMng by bcvsolutions.
the class DefaultAccTestHelper method cleaner.
/**
* Manual delete of all automatic roles, sync, mappings. Because previous tests didn't make a delete well.
*/
@Override
public void cleaner() {
// Delete all automatic roles.
roleTreeNodeService.deleteAll(roleTreeNodeService.find(new IdmRoleTreeNodeFilter(), null).getContent());
automaticRoleAttributeService.deleteAll(automaticRoleAttributeService.find(new IdmRoleTreeNodeFilter(), null).getContent());
// Delete all syncs.
syncConfigService.deleteAll(syncConfigService.find(new SysSyncConfigFilter(), null).getContent());
// Delete all groups.
systemGroupService.deleteAll(systemGroupService.find(new SysSystemGroupFilter(), null));
// Delete all mappings.
systemMappingService.deleteAll(systemMappingService.find(new SysSystemMappingFilter(), null).getContent());
// Delete all uniform password definitions.
uniformPasswordService.deleteAll(uniformPasswordService.find(new AccUniformPasswordFilter(), null).getContent());
}
Aggregations