use of eu.bcvsolutions.idm.acc.event.AccountEvent in project CzechIdMng by bcvsolutions.
the class DefaultAccAccountService method delete.
@Override
@Transactional
public void delete(AccAccountDto account, BasePermission... permission) {
Assert.notNull(account, "Account is required.");
// delete all identity accounts (call event)
AccIdentityAccountFilter identityAccountFilter = new AccIdentityAccountFilter();
identityAccountFilter.setAccountId(account.getId());
List<AccIdentityAccountDto> identityAccounts = identityAccountService.find(identityAccountFilter, null).getContent();
identityAccounts.forEach(identityAccount -> {
identityAccountService.delete(identityAccount);
});
AccAccountDto potentialProtectedAccount = get(account);
// Account was already deleted during relations identity-accounts deletion
if (potentialProtectedAccount == null) {
return;
}
// rollback).
if (!account.isAccountProtectedAndValid() && potentialProtectedAccount.isAccountProtectedAndValid()) {
return;
}
this.publish(new AccountEvent(AccountEventType.DELETE, account, ImmutableMap.of(AccAccountService.DELETE_TARGET_ACCOUNT_PROPERTY, Boolean.TRUE)));
}
use of eu.bcvsolutions.idm.acc.event.AccountEvent in project CzechIdMng by bcvsolutions.
the class DefaultAccIdentityRoleAccountService method delete.
@Override
@Transactional
public void delete(AccIdentityRoleAccountDto entity, boolean deleteTargetAccount, BasePermission... permission) {
Assert.notNull(entity, "Entity is required.");
super.delete(entity, permission);
UUID account = entity.getAccount();
// We check if exists another (ownership) identityAccounts, if not
// then
// we will delete account
AccIdentityRoleAccountFilter filter = new AccIdentityRoleAccountFilter();
filter.setAccountId(account);
filter.setOwnership(Boolean.TRUE);
List<AccIdentityRoleAccountDto> entityAccounts = this.find(filter, null).getContent();
boolean moreEntityAccounts = entityAccounts.stream().filter(treeAccount -> {
return treeAccount.isOwnership() && !treeAccount.equals(entity);
}).findAny().isPresent();
if (!moreEntityAccounts && entity.isOwnership()) {
// We delete all entity accounts first
entityAccounts.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.event.AccountEvent in project CzechIdMng by bcvsolutions.
the class DefaultAccRoleAccountService method delete.
@Override
@Transactional
public void delete(AccRoleAccountDto entity, boolean deleteTargetAccount, BasePermission... permission) {
Assert.notNull(entity, "Entity is required.");
super.delete(entity, permission);
UUID account = entity.getAccount();
// We check if exists another (ownership) identityAccounts, if not
// then
// we will delete account
AccRoleAccountFilter filter = new AccRoleAccountFilter();
filter.setAccountId(account);
filter.setOwnership(Boolean.TRUE);
List<AccRoleAccountDto> entityAccounts = this.find(filter, null).getContent();
boolean moreEntityAccounts = entityAccounts.stream().filter(treeAccount -> {
return treeAccount.isOwnership() && !treeAccount.equals(entity);
}).findAny().isPresent();
if (!moreEntityAccounts && entity.isOwnership()) {
// We delete all tree accounts first
entityAccounts.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())));
}
}
Aggregations