use of eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto in project CzechIdMng by bcvsolutions.
the class DefaultProvisioningExecutorIntegrationTest method testClearProvisioningBatchOnReadonlySystem.
@Test
public void testClearProvisioningBatchOnReadonlySystem() {
SysSystemDto system = getHelper().createTestResourceSystem(true);
system.setReadonly(true);
system = systemService.save(system);
String firstname = "firstname";
SysProvisioningOperationDto provisioningOperation = createProvisioningOperation(system, firstname);
Map<ProvisioningAttributeDto, Object> accoutObject = provisioningOperation.getProvisioningContext().getAccountObject();
String uid = (String) accoutObject.get(getProvisioningAttribute(TestHelper.ATTRIBUTE_MAPPING_NAME));
//
// publish event
// 1 - create
provisioningExecutor.execute(provisioningOperation);
// is necessary to get again operation from service
SysProvisioningOperationFilter filter = new SysProvisioningOperationFilter();
filter.setSystemEntity(provisioningOperation.getSystemEntity());
filter.setSystemId(system.getId());
SysProvisioningOperationDto readOnlyOperation = provisioningOperationService.find(filter, null).getContent().get(0);
assertEquals(OperationState.NOT_EXECUTED, readOnlyOperation.getResultState());
assertEquals(AccResultCode.PROVISIONING_SYSTEM_READONLY.name(), readOnlyOperation.getResult().getModel().getStatusEnum());
SysSystemEntityDto systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, uid);
// 2 - update
provisioningExecutor.execute(updateProvisioningOperation(systemEntity, firstname + 2));
//
// FIXME: how to order operations created in the same milis?
getHelper().waitForResult(null, 1, 1);
//
// 3 - update
provisioningExecutor.execute(updateProvisioningOperation(systemEntity, firstname + 3));
//
systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, uid);
assertTrue(systemEntity.isWish());
assertNull(getHelper().findResource(uid));
//
// check batch
SysProvisioningBatchDto batch = provisioningBatchService.findBatch(systemEntity.getId());
Assert.assertNotNull(batch);
//
// check provisioning operation requests
List<SysProvisioningOperationDto> requests = provisioningOperationService.findByBatchId(batch.getId(), null).getContent();
Assert.assertEquals(3, requests.size());
//
// execute first operation - create
system.setReadonly(false);
system = systemService.save(system);
provisioningExecutor.execute(readOnlyOperation);
Assert.assertNull(provisioningOperationService.get(readOnlyOperation.getId()));
//
systemEntity = systemEntityService.getBySystemAndEntityTypeAndUid(system, SystemEntityType.IDENTITY, uid);
assertFalse(systemEntity.isWish());
TestResource resource = getHelper().findResource(uid);
assertNotNull(resource);
Assert.assertEquals(firstname, resource.getFirstname());
Assert.assertEquals(2, provisioningOperationService.findByBatchId(batch.getId(), null).getContent().size());
//
// execute whole batch
provisioningExecutor.execute(batch);
//
resource = getHelper().findResource(uid);
Assert.assertEquals(firstname + 3, resource.getFirstname());
Assert.assertEquals(0, provisioningOperationService.findByBatchId(batch.getId(), null).getTotalElements());
Assert.assertNull(provisioningOperationService.get(readOnlyOperation.getId()));
batch = provisioningBatchService.get(batch.getId());
Assert.assertNull(batch.getNextAttempt());
}
use of eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto in project CzechIdMng by bcvsolutions.
the class DefaultSysSystemServiceTest method testReferentialIntegrityProvisioningOperationExists.
@Test(expected = ResultCodeException.class)
public void testReferentialIntegrityProvisioningOperationExists() {
SysSystemDto system = new SysSystemDto();
String systemName = "t_s_" + System.currentTimeMillis();
system.setName(systemName);
system = systemService.save(system);
// system entity
SysSystemEntityDto systemEntity = new SysSystemEntityDto();
systemEntity.setUid("test");
systemEntity.setSystem(system.getId());
systemEntity.setEntityType(SystemEntityType.IDENTITY);
systemEntity = systemEntityService.save(systemEntity);
SysProvisioningOperationDto provisioningOperation = new SysProvisioningOperationDto();
provisioningOperation.setSystem(system.getId());
provisioningOperation.setEntityType(SystemEntityType.IDENTITY);
provisioningOperation.setOperationType(ProvisioningEventType.CREATE);
provisioningOperation.setSystemEntity(systemEntity.getId());
provisioningOperation.setEntityIdentifier(UUID.randomUUID());
provisioningOperation.setProvisioningContext(new ProvisioningContext());
provisioningOperation.setResult(new OperationResult());
provisioningOperationService.save(provisioningOperation);
//
systemService.delete(system);
}
use of eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto 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.dto.SysSystemEntityDto in project CzechIdMng by bcvsolutions.
the class DefaultSynchronizationService method resolveUnlinkedSituation.
@Override
public SysSyncItemLogDto resolveUnlinkedSituation(String uid, SystemEntityType entityType, UUID entityId, UUID configId, String actionType) {
Assert.notNull(uid);
Assert.notNull(entityType);
Assert.notNull(configId);
Assert.notNull(actionType);
Assert.notNull(entityId);
AbstractSysSyncConfigDto config = synchronizationConfigService.get(configId);
SysSystemMappingDto mapping = systemMappingService.get(config.getSystemMapping());
SysSchemaObjectClassDto sysSchemaObjectClassDto = schemaObjectClassService.get(mapping.getObjectClass());
SysSystemDto system = DtoUtils.getEmbedded(sysSchemaObjectClassDto, SysSchemaObjectClass_.system, SysSystemDto.class);
SysSystemEntityDto systemEntity = findSystemEntity(uid, system, entityType);
SysSyncItemLogDto itemLog = new SysSyncItemLogDto();
SynchronizationContext context = new SynchronizationContext();
context.addUid(uid).addSystem(system).addConfig(config).addEntityType(entityType).addEntityId(entityId).addSystemEntity(systemEntity);
getSyncExecutor(entityType).resolveUnlinkedSituation(SynchronizationUnlinkedActionType.valueOf(actionType), context);
return itemLog;
}
use of eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto in project CzechIdMng by bcvsolutions.
the class BasicVirtualConnector method updateSystemEntity.
/**
* We have to change system entity directly from VS module (request can be
* started/executed async => standard process update UID in system entity (ACC
* module) will not works!)
*
* @param uidValue
* @param attributeUidValue
* @param systemEntityMustExists
*/
private void updateSystemEntity(String uidValue, Object attributeUidValue, boolean systemEntityMustExists) {
SysSystemEntityFilter systemEntityFilter = new SysSystemEntityFilter();
systemEntityFilter.setUid(uidValue);
systemEntityFilter.setSystemId(systemId);
List<SysSystemEntityDto> systemEntities = systemEntityService.find(systemEntityFilter, null).getContent();
if (systemEntities.isEmpty() && !systemEntityMustExists) {
return;
}
if (systemEntities.isEmpty()) {
throw new IcException(MessageFormat.format("System entity was not found for UID [{0}] and system ID [{1}]! Change UID attribute (new [{2}]) cannot be executed!", uidValue, systemId, attributeUidValue));
}
if (systemEntities.size() > 1) {
throw new IcException(MessageFormat.format("For UID [{0}] and system ID [{1}] was found too many items [{2}]! Change UID attribute (new [{3}]) cannot be executed!", uidValue, systemId, systemEntities.size(), attributeUidValue));
}
SysSystemEntityDto systemEntity = systemEntities.get(0);
systemEntity.setUid((String) attributeUidValue);
systemEntity.setWish(false);
// Save changed system entity
systemEntityService.save(systemEntity);
LOG.info("Update account - UID was changed (old: {} new: {}). System entity was updated.", uidValue, attributeUidValue);
}
Aggregations