Search in sources :

Example 1 with AccContractAccountDto

use of eu.bcvsolutions.idm.acc.dto.AccContractAccountDto in project CzechIdMng by bcvsolutions.

the class ContractSynchronizationExecutor method doUnlink.

/**
 * Operation remove IdentityContractAccount relations and linked roles
 *
 * @param account
 * @param removeIdentityContractIdentityContract
 * @param log
 * @param logItem
 * @param actionLogs
 */
protected void doUnlink(AccAccountDto account, boolean removeIdentityContractIdentityContract, SysSyncLogDto log, SysSyncItemLogDto logItem, List<SysSyncActionLogDto> actionLogs) {
    EntityAccountFilter entityAccountFilter = new AccContractAccountFilter();
    entityAccountFilter.setAccountId(account.getId());
    List<AccContractAccountDto> entityAccounts = contractAccoutnService.find((AccContractAccountFilter) entityAccountFilter, null).getContent();
    if (entityAccounts.isEmpty()) {
        addToItemLog(logItem, "Contract-account relation was not found!");
        initSyncActionLog(SynchronizationActionType.UPDATE_ENTITY, OperationResultType.WARNING, logItem, log, actionLogs);
        return;
    }
    addToItemLog(logItem, MessageFormat.format("Contract-account relations to delete {0}", entityAccounts));
    entityAccounts.stream().forEach(entityAccount -> {
        // We will remove contract account, but without delete connected
        // account
        contractAccoutnService.delete(entityAccount, false);
        addToItemLog(logItem, MessageFormat.format("Contract-account relation deleted (without call delete provisioning) (contract id: {0}, contract-account id: {1})", entityAccount.getContract(), entityAccount.getId()));
    });
    return;
}
Also used : EntityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.EntityAccountFilter) AccContractAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccContractAccountFilter) AccContractAccountDto(eu.bcvsolutions.idm.acc.dto.AccContractAccountDto)

Example 2 with AccContractAccountDto

use of eu.bcvsolutions.idm.acc.dto.AccContractAccountDto 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 3 with AccContractAccountDto

use of eu.bcvsolutions.idm.acc.dto.AccContractAccountDto in project CzechIdMng by bcvsolutions.

the class IdentityContractSyncTest method deleteContractAccountTest.

@Test
public void deleteContractAccountTest() {
    SysSystemDto system = initData();
    Assert.assertNotNull(system);
    AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
    Assert.assertTrue(config instanceof SysSyncContractConfigDto);
    helper.createIdentity(CONTRACT_OWNER_ONE);
    helper.createIdentity(CONTRACT_OWNER_TWO);
    helper.createIdentity(CONTRACT_LEADER_ONE);
    IdmIdentityContractFilter contractFilter = new IdmIdentityContractFilter();
    contractFilter.setProperty(IdmIdentityContract_.position.getName());
    contractFilter.setValue("1");
    Assert.assertEquals(0, contractService.find(contractFilter, null).getTotalElements());
    contractFilter.setValue("2");
    Assert.assertEquals(0, contractService.find(contractFilter, null).getTotalElements());
    helper.startSynchronization(config);
    SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 3);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    contractFilter.setValue("1");
    List<IdmIdentityContractDto> contracts = contractService.find(contractFilter, null).getContent();
    Assert.assertEquals(1, contracts.size());
    // Find the account for this contract
    IdmIdentityContractDto contract = contracts.get(0);
    AccContractAccountFilter contractAccountFilter = new AccContractAccountFilter();
    contractAccountFilter.setContractId(contract.getId());
    contractAccountFilter.setSystemId(system.getId());
    List<AccContractAccountDto> contractAccounts = contractAccountService.find(contractAccountFilter, null).getContent();
    Assert.assertEquals(1, contractAccounts.size());
    AccContractAccountDto contractAccount = contractAccounts.get(0);
    AccAccountDto account = accountService.get(contractAccount.getAccount());
    Assert.assertNotNull(account);
    // Delete this account directly test
    accountService.delete(account);
    account = accountService.get(contractAccount.getAccount());
    Assert.assertNull(account);
    // Delete log
    syncLogService.delete(log);
}
Also used : AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSyncContractConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) AccContractAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccContractAccountFilter) AccContractAccountDto(eu.bcvsolutions.idm.acc.dto.AccContractAccountDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 4 with AccContractAccountDto

use of eu.bcvsolutions.idm.acc.dto.AccContractAccountDto 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);
    });
    // delete all contract slice accounts
    AccContractSliceAccountFilter contractSliceAccountFilter = new AccContractSliceAccountFilter();
    contractSliceAccountFilter.setAccountId(account.getId());
    contractAccountSliceService.find(contractSliceAccountFilter, null).forEach(contractAccount -> {
        contractAccountSliceService.delete(contractAccount);
    });
    // 
    AccAccountDto refreshAccount = accountService.get(account.getId());
    // directly now
    if (refreshAccount != null) {
        accountService.deleteInternal(refreshAccount);
    }
    if (deleteTargetAccount && account.getEntityType() != null) {
        SystemEntityType entityType = account.getEntityType();
        if (!entityType.isSupportsProvisioning()) {
            LOG.warn(MessageFormat.format("Provisioning is not supported for [{1}] now [{0}]!", account.getUid(), entityType));
            return new DefaultEventResult<>(event, this);
        }
        LOG.debug(MessageFormat.format("Call delete provisioning for account with UID [{0}] and entity ID [{1}].", account.getUid(), entityId));
        // Create context for systemEntity in account DTO and set ID of role-request to it.
        UUID roleRequestId = this.getRoleRequestIdProperty(event.getProperties());
        this.initContext(account, roleRequestId);
        this.provisioningService.doDeleteProvisioning(account, account.getEntityType(), entityId);
    }
    return new DefaultEventResult<>(event, this);
}
Also used : AccRoleAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccRoleAccountFilter) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) AccIdentityAccountDto(eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto) AccContractAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccContractAccountFilter) AccContractAccountDto(eu.bcvsolutions.idm.acc.dto.AccContractAccountDto) AccContractSliceAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccContractSliceAccountFilter) AccTreeAccountDto(eu.bcvsolutions.idm.acc.dto.AccTreeAccountDto) AccRoleAccountDto(eu.bcvsolutions.idm.acc.dto.AccRoleAccountDto) AccTreeAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccTreeAccountFilter) AccIdentityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter) DefaultEventResult(eu.bcvsolutions.idm.core.api.event.DefaultEventResult) AccRoleCatalogueAccountDto(eu.bcvsolutions.idm.acc.dto.AccRoleCatalogueAccountDto) UUID(java.util.UUID) AccRoleCatalogueAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccRoleCatalogueAccountFilter)

Aggregations

AccContractAccountDto (eu.bcvsolutions.idm.acc.dto.AccContractAccountDto)4 AccContractAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccContractAccountFilter)4 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)2 UUID (java.util.UUID)2 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)1 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)1 AccIdentityAccountDto (eu.bcvsolutions.idm.acc.dto.AccIdentityAccountDto)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 SysSyncContractConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto)1 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)1 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)1 AccContractSliceAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccContractSliceAccountFilter)1 AccIdentityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccIdentityAccountFilter)1 AccRoleAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccRoleAccountFilter)1 AccRoleCatalogueAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccRoleCatalogueAccountFilter)1 AccTreeAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.AccTreeAccountFilter)1 EntityAccountFilter (eu.bcvsolutions.idm.acc.dto.filter.EntityAccountFilter)1 AccountEvent (eu.bcvsolutions.idm.acc.event.AccountEvent)1