use of eu.bcvsolutions.idm.acc.domain.SystemEntityType 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.domain.SystemEntityType in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningArchiveServiceIntegrationTest method resultStateFilterTest.
@Test
@Transactional
public void resultStateFilterTest() {
SystemEntityType entityType = SystemEntityType.IDENTITY;
SysSystemDto system = createSystem();
OperationResult resultState = new OperationResult();
resultState.setState(OperationState.CREATED);
SysProvisioningArchiveDto provisioningArchive1 = createProvisioningArchive(entityType, system);
SysProvisioningArchiveDto provisioningArchive2 = createProvisioningArchive(entityType, system);
provisioningArchive2.setResult(resultState);
service.save(provisioningArchive2);
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setSystemId(system.getId());
filter.setResultState(OperationState.CREATED);
Page<SysProvisioningArchiveDto> result = service.find(filter, null);
assertEquals(1, result.getTotalElements());
assertFalse(result.getContent().contains(provisioningArchive1));
assertTrue(result.getContent().contains(provisioningArchive2));
}
use of eu.bcvsolutions.idm.acc.domain.SystemEntityType in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningArchiveServiceIntegrationTest method entityIdentifierFilterTest.
@Test
@Transactional
public void entityIdentifierFilterTest() {
SystemEntityType entityType = SystemEntityType.IDENTITY;
SysSystemDto system = createSystem();
createProvisioningArchive(entityType, system);
SysProvisioningArchiveDto provisioningArchive1 = createProvisioningArchive(entityType, system);
provisioningArchive1.setEntityIdentifier(UUID.randomUUID());
provisioningArchive1 = service.save(provisioningArchive1);
SysProvisioningArchiveDto provisioningArchive2 = createProvisioningArchive(entityType, system);
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setEntityIdentifier(provisioningArchive1.getEntityIdentifier());
Page<SysProvisioningArchiveDto> result = service.find(filter, null);
assertEquals(1, result.getTotalElements());
assertTrue(result.getContent().contains(provisioningArchive1));
assertFalse(result.getContent().contains(provisioningArchive2));
}
use of eu.bcvsolutions.idm.acc.domain.SystemEntityType in project CzechIdMng by bcvsolutions.
the class AbstractProvisioningExecutor method doInternalProvisioning.
@Override
public void doInternalProvisioning(AccAccountDto account, DTO dto) {
Assert.notNull(account);
Assert.notNull(dto);
//
ProvisioningOperationType operationType;
SysSystemDto system = DtoUtils.getEmbedded(account, AccAccount_.system, SysSystemDto.class);
SysSystemEntityDto systemEntity = getSystemEntity(account);
SystemEntityType entityType = SystemEntityType.getByClass(dto.getClass());
String uid = account.getUid();
//
if (systemEntity == null) {
// prepare system entity - uid could be changed by provisioning, but
// we need to link her with account
// First we try find system entity with same uid.
systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, entityType, uid);
if (systemEntity == null) {
systemEntity = new SysSystemEntityDto();
systemEntity.setEntityType(entityType);
systemEntity.setSystem(system.getId());
systemEntity.setUid(uid);
systemEntity.setWish(true);
systemEntity = systemEntityService.save(systemEntity);
}
account.setSystemEntity(systemEntity.getId());
account = accountService.save(account);
// we wont create account, but after target system call can be
// switched to UPDATE
operationType = ProvisioningOperationType.CREATE;
} else {
// we wont update account, but after target system call can be
// switched to CREATE
operationType = ProvisioningOperationType.UPDATE;
}
List<AttributeMapping> finalAttributes = resolveMappedAttributes(account, dto, system, systemEntity.getEntityType());
if (CollectionUtils.isEmpty(finalAttributes)) {
// nothing to do - mapping is empty
return;
}
doProvisioning(systemEntity, dto, dto.getId(), operationType, finalAttributes);
}
use of eu.bcvsolutions.idm.acc.domain.SystemEntityType in project CzechIdMng by bcvsolutions.
the class DefaultSysProvisioningArchiveServiceTest method entityIdentifierFilterTest.
@Test
public void entityIdentifierFilterTest() {
IdmBasePermission permission = IdmBasePermission.ADMIN;
SystemEntityType entityType = SystemEntityType.IDENTITY;
SysSystemDto system = createRoleSystem();
createProvisioningArchive(entityType, system);
SysProvisioningArchiveDto provisioningArchive1 = createProvisioningArchive(entityType, system);
provisioningArchive1.setEntityIdentifier(UUID.randomUUID());
provisioningArchive1 = archiveService.save(provisioningArchive1);
SysProvisioningArchiveDto provisioningArchive2 = createProvisioningArchive(entityType, system);
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setEntityIdentifier(provisioningArchive1.getEntityIdentifier());
Page<SysProvisioningArchiveDto> result = archiveService.find(filter, null, permission);
assertEquals(1, result.getTotalElements());
assertTrue(result.getContent().contains(provisioningArchive1));
assertFalse(result.getContent().contains(provisioningArchive2));
}
Aggregations