use of eu.bcvsolutions.idm.acc.event.AccountEvent in project CzechIdMng by bcvsolutions.
the class DefaultAccRoleCatalogueAccountService method delete.
@Override
@Transactional
public void delete(AccRoleCatalogueAccountDto 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
AccRoleCatalogueAccountFilter filter = new AccRoleCatalogueAccountFilter();
filter.setAccountId(account);
filter.setOwnership(Boolean.TRUE);
List<AccRoleCatalogueAccountDto> 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())));
}
}
use of eu.bcvsolutions.idm.acc.event.AccountEvent in project CzechIdMng by bcvsolutions.
the class DefaultAccTreeAccountService method delete.
@Override
@Transactional
public void delete(AccTreeAccountDto 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
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.event.AccountEvent in project CzechIdMng by bcvsolutions.
the class ContractSliceAccountDeleteProcessor method process.
@Override
public EventResult<AccContractSliceAccountDto> process(EntityEvent<AccContractSliceAccountDto> event) {
AccContractSliceAccountDto entity = event.getContent();
UUID account = entity.getAccount();
AccAccountDto accountDto = accountService.get(account);
Assert.notNull(accountDto, "Account cannot be null!");
boolean deleteTargetAccount = (boolean) event.getProperties().get(AccIdentityAccountService.DELETE_TARGET_ACCOUNT_KEY);
// We check if exists another (ownership) identityAccounts, if not
// then
// we will delete account
AccContractSliceAccountFilter filter = new AccContractSliceAccountFilter();
filter.setAccountId(account);
filter.setOwnership(Boolean.TRUE);
List<AccContractSliceAccountDto> entityAccounts = service.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 -> {
service.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())));
}
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.acc.event.AccountEvent in project CzechIdMng by bcvsolutions.
the class DefaultAccContractAccountService method delete.
@Override
@Transactional
public void delete(AccContractAccountDto 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
AccContractAccountFilter filter = new AccContractAccountFilter();
filter.setAccountId(account);
filter.setOwnership(Boolean.TRUE);
List<AccContractAccountDto> 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 IdentityAccountDeleteProcessor method process.
@Override
public EventResult<AccIdentityAccountDto> process(EntityEvent<AccIdentityAccountDto> event) {
AccIdentityAccountDto entity = event.getContent();
UUID account = entity.getAccount();
AccAccountDto accountDto = accountService.get(account);
Assert.notNull(accountDto, "Account cannot be null!");
// We check if exists another (ownership) identity-accounts, if not
// then we will delete account
AccIdentityAccountFilter identityAccountFilter = new AccIdentityAccountFilter();
identityAccountFilter.setAccountId(account);
identityAccountFilter.setOwnership(Boolean.TRUE);
identityAccountFilter.setNotIdentityAccount(entity.getId());
boolean moreIdentityAccounts = service.find(identityAccountFilter, PageRequest.of(0, 1)).getTotalElements() > 0;
boolean deleteTargetAccount = (boolean) event.getProperties().get(AccIdentityAccountService.DELETE_TARGET_ACCOUNT_KEY);
boolean deleteAccAccount = true;
// If is account in protection, then we will not delete
// identity-account
// But is here exception from this. When is presented
// attribute FORCE_DELETE_OF_IDENTITY_ACCOUNT_KEY, then
// we will do delete of identity-account (it is important
// for integrity ... for example during delete of whole
// identity).
boolean forceDeleteIdentityAccount = isForceDeleteAttributePresent(event.getProperties());
if (!moreIdentityAccounts && entity.isOwnership()) {
if (accountDto.isAccountProtectedAndValid()) {
if (forceDeleteIdentityAccount) {
// Target account and AccAccount will NOT be deleted!
deleteAccAccount = false;
} else {
throw new ResultCodeException(AccResultCode.ACCOUNT_CANNOT_BE_DELETED_IS_PROTECTED, ImmutableMap.of("uid", accountDto.getUid()));
}
// Is account protection activated on system mapping?
// Set account as protected we can only on account without protection (event has already invalid protection)!
} else if (!accountDto.isInProtection() && systemMappingService.isEnabledProtection(accountDto)) {
// This identity account is last ... protection will be
// activated
activateProtection(accountDto);
accountDto = accountService.save(accountDto);
entity.setRoleSystem(null);
entity.setIdentityRole(null);
service.save(entity);
doProvisioningSkipAccountProtection(accountDto, entity.getEntity());
// identity-account
if (forceDeleteIdentityAccount) {
// Target account and AccAccount will NOT be deleted!
deleteAccAccount = false;
} else {
return new DefaultEventResult<>(event, this);
}
}
}
service.deleteInternal(entity);
// Finally we can delete AccAccount
if (!moreIdentityAccounts && entity.isOwnership() && deleteAccAccount) {
// We delete all NOT ownership identity accounts first
AccIdentityAccountFilter filter = new AccIdentityAccountFilter();
filter.setAccountId(account);
filter.setOwnership(Boolean.FALSE);
// Find NOT ownership identity accounts
service.find(filter, null).getContent().stream().filter(identityAccount -> !identityAccount.isOwnership() && !identityAccount.equals(entity)).forEach(identityAccount -> {
service.delete(identityAccount);
});
UUID roleRequestId = this.getRoleRequestIdProperty(event.getProperties());
Map<String, Serializable> properties = new HashMap<String, Serializable>();
properties.put(AccAccountService.DELETE_TARGET_ACCOUNT_PROPERTY, deleteTargetAccount);
properties.put(AccAccountService.ENTITY_ID_PROPERTY, entity.getEntity());
if (roleRequestId != null) {
properties.put(IdmRoleRequestService.ROLE_REQUEST_ID_KEY, roleRequestId);
}
accountService.publish(new AccountEvent(AccountEventType.DELETE, accountDto, properties));
}
return new DefaultEventResult<>(event, this);
}
Aggregations