Search in sources :

Example 1 with AccountEvent

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

Example 2 with AccountEvent

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

Example 3 with AccountEvent

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);
}
Also used : AccountEvent(eu.bcvsolutions.idm.acc.event.AccountEvent) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) AccContractSliceAccountDto(eu.bcvsolutions.idm.acc.dto.AccContractSliceAccountDto) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) UUID(java.util.UUID) AccContractSliceAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccContractSliceAccountFilter)

Example 4 with AccountEvent

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

Example 5 with AccountEvent

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);
}
Also used : AccountEvent(eu.bcvsolutions.idm.acc.event.AccountEvent) ProvisioningEvent(eu.bcvsolutions.idm.acc.event.ProvisioningEvent) ZonedDateTime(java.time.ZonedDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) CoreEventProcessor(eu.bcvsolutions.idm.core.api.event.CoreEventProcessor) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) IdmRoleRequestService(eu.bcvsolutions.idm.core.api.service.IdmRoleRequestService) SysSystemMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemMappingService) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) Map(java.util.Map) IdentityAccountEventType(eu.bcvsolutions.idm.acc.event.IdentityAccountEvent.IdentityAccountEventType) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) AccountEventType(eu.bcvsolutions.idm.acc.event.AccountEvent.AccountEventType) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) EntityEvent(eu.bcvsolutions.idm.core.api.event.EntityEvent) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) Description(org.springframework.context.annotation.Description) ImmutableMap(com.google.common.collect.ImmutableMap) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) PageRequest(org.springframework.data.domain.PageRequest) UUID(java.util.UUID) Serializable(java.io.Serializable) ProvisioningEventType(eu.bcvsolutions.idm.acc.event.ProvisioningEvent.ProvisioningEventType) Component(org.springframework.stereotype.Component) AccAccountService(eu.bcvsolutions.idm.acc.service.api.AccAccountService) ProvisioningService(eu.bcvsolutions.idm.acc.service.api.ProvisioningService) AccIdentityAccountService(eu.bcvsolutions.idm.acc.service.api.AccIdentityAccountService) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) AccResultCode(eu.bcvsolutions.idm.acc.domain.AccResultCode) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) Assert(org.springframework.util.Assert) Serializable(java.io.Serializable) HashMap(java.util.HashMap) AccountEvent(eu.bcvsolutions.idm.acc.event.AccountEvent) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) UUID(java.util.UUID)

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