Search in sources :

Example 6 with AccountEvent

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)));
}
Also used : AccountEvent(eu.bcvsolutions.idm.acc.event.AccountEvent) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with AccountEvent

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())));
    }
}
Also used : AccountEvent(eu.bcvsolutions.idm.acc.event.AccountEvent) UUID(java.util.UUID) AccIdentityRoleAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityRoleAccountFilter) AccIdentityRoleAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityRoleAccountDto) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with AccountEvent

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())));
    }
}
Also used : AccRoleAccountDto(eu.bcvsolutions.idm.acc.dto.AccRoleAccountDto) AccRoleAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccRoleAccountFilter) AccountEvent(eu.bcvsolutions.idm.acc.event.AccountEvent) UUID(java.util.UUID) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

AccountEvent (eu.bcvsolutions.idm.acc.event.AccountEvent)8 UUID (java.util.UUID)7 Transactional (org.springframework.transaction.annotation.Transactional)6 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)3 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)2 AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)2 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 AccResultCode (eu.bcvsolutions.idm.acc.domain.AccResultCode)1 AccContractAccountDto (eu.bcvsolutions.idm.acc.dto.AccContractAccountDto)1 AccContractSliceAccountDto (eu.bcvsolutions.idm.acc.dto.AccContractSliceAccountDto)1 AccIdentityRoleAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityRoleAccountDto)1 AccRoleAccountDto (eu.bcvsolutions.idm.acc.dto.AccRoleAccountDto)1 AccRoleCatalogueAccountDto (eu.bcvsolutions.idm.acc.dto.AccRoleCatalogueAccountDto)1 AccTreeAccountDto (eu.bcvsolutions.idm.acc.dto.AccTreeAccountDto)1 AccContractAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccContractAccountFilter)1 AccContractSliceAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccContractSliceAccountFilter)1 AccIdentityRoleAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityRoleAccountFilter)1 AccRoleAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccRoleAccountFilter)1 AccRoleCatalogueAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccRoleCatalogueAccountFilter)1