use of eu.bcvsolutions.idm.acc.dto.AccTreeAccountDto in project CzechIdMng by bcvsolutions.
the class TreeSynchronizationExecutor method getValueByMappedAttribute.
@Override
protected Object getValueByMappedAttribute(AttributeMapping attribute, List<IcAttribute> icAttributes, SynchronizationContext context) {
Object transformedValue = super.getValueByMappedAttribute(attribute, icAttributes, context);
if (transformedValue != null && PARENT_FIELD.equals(attribute.getIdmPropertyName())) {
String parentUid = transformedValue.toString();
SysSystemMappingDto systemMapping = systemMappingService.get(((SysSystemAttributeMappingDto) attribute).getSystemMapping());
SysSchemaObjectClassDto schemaObjectClass = schemaObjectClassService.get(systemMapping.getObjectClass());
UUID systemId = schemaObjectClass.getSystem();
// Find account by UID from parent field
AccAccountFilter accountFilter = new AccAccountFilter();
accountFilter.setUid(parentUid);
accountFilter.setSystemId(systemId);
transformedValue = null;
List<AccAccountDto> parentAccounts = accountService.find(accountFilter, null).getContent();
if (!parentAccounts.isEmpty()) {
UUID parentAccount = parentAccounts.get(0).getId();
// Find relation between tree and account
AccTreeAccountFilter treeAccountFilter = new AccTreeAccountFilter();
treeAccountFilter.setAccountId(parentAccount);
List<AccTreeAccountDto> treeAccounts = treeAccountService.find(treeAccountFilter, null).getContent();
if (!treeAccounts.isEmpty()) {
// Find parent tree node by ID
// TODO: resolve more treeAccounts situations
// parent uuid - we are working with dtos
transformedValue = treeAccounts.get(0).getTreeNode();
} else {
LOG.warn("For parent UID: [{}] on system ID [{}] and acc account: [{}], was not found tree accounts! Return null value in parent!!", parentUid, systemId, parentAccount);
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_TREE_PARENT_TREE_ACCOUNT_NOT_FOUND, ImmutableMap.of("parentUid", parentUid, "systemId", systemId, "parentAccount", parentAccount));
}
} else {
LOG.warn("For parent UID: [{}] on system ID [{}], was not found parents account! Return null value in parent!!", parentUid, systemId);
throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_TREE_PARENT_ACCOUNT_NOT_FOUND, ImmutableMap.of("parentUid", parentUid, "systemId", systemId));
}
}
return transformedValue;
}
use of eu.bcvsolutions.idm.acc.dto.AccTreeAccountDto in project CzechIdMng by bcvsolutions.
the class DefaultAccTreeAccountService method delete.
@Override
@Transactional
public void delete(AccTreeAccountDto entity, boolean deleteTargetAccount, BasePermission... permission) {
Assert.notNull(entity);
super.delete(entity, permission);
UUID account = entity.getAccount();
// We check if exists another (ownership) identityAccounts, if not
// then
// we will delete account
AccTreeAccountFilter filter = new AccTreeAccountFilter();
filter.setAccountId(account);
filter.setOwnership(Boolean.TRUE);
List<AccTreeAccountDto> treeAccounts = this.find(filter, null).getContent();
boolean moreTreeAccounts = treeAccounts.stream().filter(treeAccount -> {
return treeAccount.isOwnership() && !treeAccount.equals(entity);
}).findAny().isPresent();
if (!moreTreeAccounts && entity.isOwnership()) {
// We delete all tree accounts first
treeAccounts.forEach(identityAccount -> {
super.delete(identityAccount);
});
// Finally we can delete account
accountService.publish(new AccountEvent(AccountEventType.DELETE, accountService.get(account), ImmutableMap.of(AccAccountService.DELETE_TARGET_ACCOUNT_PROPERTY, deleteTargetAccount, AccAccountService.ENTITY_ID_PROPERTY, entity.getEntity())));
}
}
use of eu.bcvsolutions.idm.acc.dto.AccTreeAccountDto in project CzechIdMng by bcvsolutions.
the class AccountDeleteProcessor method process.
@Override
public EventResult<AccAccountDto> process(EntityEvent<AccAccountDto> event) {
AccAccountDto account = event.getContent();
UUID entityId = null;
Object entityIdObj = event.getProperties().get(AccAccountService.ENTITY_ID_PROPERTY);
if (entityIdObj instanceof UUID) {
entityId = (UUID) entityIdObj;
}
boolean deleteTargetAccount = false;
Object deleteTargetAccountObj = event.getProperties().get(AccAccountService.DELETE_TARGET_ACCOUNT_PROPERTY);
if (deleteTargetAccountObj instanceof Boolean) {
deleteTargetAccount = (boolean) deleteTargetAccountObj;
}
Assert.notNull(account, "Account cannot be null!");
// We do not allow delete account in protection
if (account.isAccountProtectedAndValid()) {
throw new ResultCodeException(AccResultCode.ACCOUNT_CANNOT_BE_DELETED_IS_PROTECTED, ImmutableMap.of("uid", account.getUid()));
}
// delete all identity accounts
AccIdentityAccountFilter identityAccountFilter = new AccIdentityAccountFilter();
identityAccountFilter.setAccountId(account.getId());
List<AccIdentityAccountDto> identityAccounts = identityAccountService.find(identityAccountFilter, null).getContent();
identityAccounts.forEach(identityAccount -> {
identityAccountService.delete(identityAccount);
});
// delete all role accounts
AccRoleAccountFilter roleAccountFilter = new AccRoleAccountFilter();
roleAccountFilter.setAccountId(account.getId());
List<AccRoleAccountDto> roleAccounts = roleAccountService.find(roleAccountFilter, null).getContent();
roleAccounts.forEach(roleAccount -> {
roleAccountService.delete(roleAccount);
});
// delete all roleCatalogue accounts
AccRoleCatalogueAccountFilter roleCatalogueAccountFilter = new AccRoleCatalogueAccountFilter();
roleCatalogueAccountFilter.setAccountId(account.getId());
List<AccRoleCatalogueAccountDto> roleCatalogueAccounts = roleCatalogueAccountService.find(roleCatalogueAccountFilter, null).getContent();
roleCatalogueAccounts.forEach(roleCatalogueAccount -> {
roleCatalogueAccountService.delete(roleCatalogueAccount);
});
// delete all tree accounts
AccTreeAccountFilter treeAccountFilter = new AccTreeAccountFilter();
treeAccountFilter.setAccountId(account.getId());
List<AccTreeAccountDto> treeAccounts = treeAccountService.find(treeAccountFilter, null).getContent();
treeAccounts.forEach(treeAccount -> {
treeAccountService.delete(treeAccount);
});
// delete all contract accounts
AccContractAccountFilter contractAccountFilter = new AccContractAccountFilter();
contractAccountFilter.setAccountId(account.getId());
List<AccContractAccountDto> contractAccounts = contractAccountService.find(contractAccountFilter, null).getContent();
contractAccounts.forEach(contractAccount -> {
contractAccountService.delete(contractAccount);
});
//
AccAccountDto refreshAccount = accountService.get(account.getId());
// If account still exists (was not deleted by entity-account), we delete him directly now
if (refreshAccount != null) {
accountService.deleteInternal(refreshAccount);
}
if (deleteTargetAccount) {
if (SystemEntityType.CONTRACT == account.getEntityType()) {
LOG.warn(MessageFormat.format("Provisioning is not supported for contract now [{0}]!", account.getUid()));
return new DefaultEventResult<>(event, this);
}
this.provisioningService.doDeleteProvisioning(account, account.getEntityType(), entityId);
}
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.acc.dto.AccTreeAccountDto in project CzechIdMng by bcvsolutions.
the class TreeProvisioningExecutor method getAttributeValue.
@Override
protected Object getAttributeValue(String uid, IdmTreeNodeDto entity, AttributeMapping attribute) {
Object idmValue = super.getAttributeValue(uid, entity, attribute);
if (attribute.isEntityAttribute() && TreeSynchronizationExecutor.PARENT_FIELD.equals(attribute.getIdmPropertyName())) {
// parent format (UID of parent)
if (idmValue instanceof UUID) {
// Generally we expect IdmTreeNode as parent (we will do
// transform)
AccTreeAccountFilter treeAccountFilter = new AccTreeAccountFilter();
treeAccountFilter.setSystemId(this.getSytemFromSchemaAttribute(attribute.getSchemaAttribute()).getId());
treeAccountFilter.setTreeNodeId(((UUID) idmValue));
List<AccTreeAccountDto> treeAccounts = treeAccountService.find(treeAccountFilter, null).getContent();
if (treeAccounts.isEmpty()) {
throw new ProvisioningException(AccResultCode.PROVISIONING_TREE_PARENT_ACCOUNT_NOT_FOUND, ImmutableMap.of("parentNode", idmValue));
}
if (treeAccounts.size() != 1) {
throw new ProvisioningException(AccResultCode.PROVISIONING_TREE_TOO_MANY_PARENT_ACCOUNTS, ImmutableMap.of("parentNode", idmValue));
}
AccTreeAccountDto treeAccount = treeAccounts.get(0);
String parentUid = accountService.get(treeAccount.getAccount()).getUid();
return parentUid;
} else {
// without any transform
return idmValue;
}
}
return idmValue;
}
use of eu.bcvsolutions.idm.acc.dto.AccTreeAccountDto in project CzechIdMng by bcvsolutions.
the class TreeSynchronizationExecutor method doUnlink.
/**
* Operation remove EntityAccount relations and linked roles
*
* @param account
* @param removeIdentityRole
* @param log
* @param logItem
* @param actionLogs
*/
@Override
protected void doUnlink(AccAccountDto account, boolean removeIdentityRole, SysSyncLogDto log, SysSyncItemLogDto logItem, List<SysSyncActionLogDto> actionLogs) {
AccTreeAccountFilter treeAccountFilter = new AccTreeAccountFilter();
treeAccountFilter.setAccountId(account.getId());
List<AccTreeAccountDto> treeAccounts = treeAccountService.find(treeAccountFilter, null).getContent();
if (treeAccounts.isEmpty()) {
addToItemLog(logItem, "Tree account relation was not found!");
initSyncActionLog(SynchronizationActionType.UPDATE_ENTITY, OperationResultType.WARNING, logItem, log, actionLogs);
return;
}
addToItemLog(logItem, MessageFormat.format("Tree-account relations to delete {0}", treeAccounts));
treeAccounts.stream().forEach(treeAccount -> {
// We will remove tree account, but without delete connected
// account
treeAccountService.delete(treeAccount, false);
addToItemLog(logItem, MessageFormat.format("Tree-account relation deleted (without call delete provisioning) (treeNode: {0}, id: {1})", treeAccount.getTreeNode(), treeAccount.getId()));
});
return;
}
Aggregations