use of eu.bcvsolutions.idm.acc.dto.filter.AccContractSliceAccountFilter 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.dto.filter.AccContractSliceAccountFilter in project CzechIdMng by bcvsolutions.
the class ContractSliceDeleteProcessor method process.
@Override
public EventResult<IdmContractSliceDto> process(EntityEvent<IdmContractSliceDto> event) {
// delete relations on account (includes delete of account )
AccContractSliceAccountFilter filter = new AccContractSliceAccountFilter();
filter.setEntityId(event.getContent().getId());
entityAccountService.find(filter, null).forEach(entityAccount -> {
LOG.debug("Remove contract-account for account [{}]", entityAccount.getId());
entityAccountService.delete(entityAccount);
});
return new DefaultEventResult<>(event, this);
}
use of eu.bcvsolutions.idm.acc.dto.filter.AccContractSliceAccountFilter 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);
}
use of eu.bcvsolutions.idm.acc.dto.filter.AccContractSliceAccountFilter in project CzechIdMng by bcvsolutions.
the class ContractSliceSyncTest method unlinkAccountTest.
@Test
public void unlinkAccountTest() {
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);
IdmContractSliceFilter contractFilter = new IdmContractSliceFilter();
contractFilter.setProperty(IdmIdentityContract_.position.getName());
contractFilter.setValue("1");
Assert.assertEquals(0, contractSliceService.find(contractFilter, null).getTotalElements());
contractFilter.setValue("2");
Assert.assertEquals(0, contractSliceService.find(contractFilter, null).getTotalElements());
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 4);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
contractFilter.setValue("1");
List<IdmContractSliceDto> contractSlices = contractSliceService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractSlices.size());
// Find the account for this contract slice
IdmContractSliceDto slice = contractSlices.get(0);
AccContractSliceAccountFilter contractAccountFilter = new AccContractSliceAccountFilter();
contractAccountFilter.setSliceId(slice.getId());
contractAccountFilter.setSystemId(system.getId());
List<AccContractSliceAccountDto> contractAccounts = contractSliceAccountService.find(contractAccountFilter, null).getContent();
Assert.assertEquals(1, contractAccounts.size());
AccContractSliceAccountDto contractAccount = contractAccounts.get(0);
AccAccountDto account = accountService.get(contractAccount.getAccount());
Assert.assertNotNull(account);
// Delete log
syncLogService.delete(log);
// Change settings of sync and run
config.setLinkedAction(SynchronizationLinkedActionType.UNLINK);
config.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE);
config.setMissingEntityAction(SynchronizationMissingEntityActionType.IGNORE);
config.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE);
config = syncConfigService.save(config);
helper.startSynchronization(config);
log = checkSyncLog(config, SynchronizationActionType.UNLINK, 4);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
// Find the account for this contract slice ... unlink operation was executed,
// none relation can be found
contractAccountFilter = new AccContractSliceAccountFilter();
contractAccountFilter.setSliceId(slice.getId());
contractAccountFilter.setSystemId(system.getId());
contractAccounts = contractSliceAccountService.find(contractAccountFilter, null).getContent();
Assert.assertEquals(0, contractAccounts.size());
account = accountService.get(account.getId());
Assert.assertNull(account);
// Delete log
syncLogService.delete(log);
}
use of eu.bcvsolutions.idm.acc.dto.filter.AccContractSliceAccountFilter in project CzechIdMng by bcvsolutions.
the class ContractSliceSyncTest method updateAccountTest.
@Test
public void updateAccountTest() {
SysSystemDto system = initData();
Assert.assertNotNull(system);
AbstractSysSyncConfigDto config = doCreateSyncConfig(system);
Assert.assertTrue(config instanceof SysSyncContractConfigDto);
config = syncConfigService.save(config);
helper.createIdentity(CONTRACT_OWNER_ONE);
helper.createIdentity(CONTRACT_OWNER_TWO);
helper.createIdentity(CONTRACT_LEADER_ONE);
IdmContractSliceFilter contractFilter = new IdmContractSliceFilter();
contractFilter.setProperty(IdmIdentityContract_.position.getName());
contractFilter.setValue("1");
Assert.assertEquals(0, contractSliceService.find(contractFilter, null).getTotalElements());
contractFilter.setValue("2");
Assert.assertEquals(0, contractSliceService.find(contractFilter, null).getTotalElements());
helper.startSynchronization(config);
SysSyncLogDto log = checkSyncLog(config, SynchronizationActionType.CREATE_ENTITY, 4);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
contractFilter.setValue("1");
List<IdmContractSliceDto> contractSlices = contractSliceService.find(contractFilter, null).getContent();
Assert.assertEquals(1, contractSlices.size());
// Find the account for this contract slice
IdmContractSliceDto slice = contractSlices.get(0);
AccContractSliceAccountFilter contractAccountFilter = new AccContractSliceAccountFilter();
contractAccountFilter.setSliceId(slice.getId());
contractAccountFilter.setSystemId(system.getId());
List<AccContractSliceAccountDto> contractAccounts = contractSliceAccountService.find(contractAccountFilter, null).getContent();
Assert.assertEquals(1, contractAccounts.size());
AccContractSliceAccountDto contractAccount = contractAccounts.get(0);
AccAccountDto account = accountService.get(contractAccount.getAccount());
Assert.assertNotNull(account);
// Delete log
syncLogService.delete(log);
TestContractSliceResource accountOnTargetSystem = this.getBean().findSliceOnTargetSystem("1");
Assert.assertNull(accountOnTargetSystem.getState());
// Set slice to disabled
slice.setState(ContractState.DISABLED);
// Change settings of sync and run
config.setLinkedAction(SynchronizationLinkedActionType.UPDATE_ACCOUNT);
config.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE);
config.setMissingEntityAction(SynchronizationMissingEntityActionType.IGNORE);
config.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE);
config = syncConfigService.save(config);
helper.startSynchronization(config);
log = checkSyncLog(config, SynchronizationActionType.UPDATE_ACCOUNT, 4);
Assert.assertFalse(log.isRunning());
Assert.assertFalse(log.isContainsError());
// Sync of slice does not supports provisioning now (account was not changed)!
accountOnTargetSystem = this.getBean().findSliceOnTargetSystem("1");
Assert.assertEquals(null, accountOnTargetSystem.getState());
// Delete log
syncLogService.delete(log);
}
Aggregations