use of eu.bcvsolutions.idm.acc.dto.SysSyncLogDto in project CzechIdMng by bcvsolutions.
the class IdentityContractSyncTest method checkSyncLog.
private SysSyncLogDto checkSyncLog(AbstractSysSyncConfigDto config, SynchronizationActionType actionType, int count) {
SysSyncLogFilter logFilter = new SysSyncLogFilter();
logFilter.setSynchronizationConfigId(config.getId());
List<SysSyncLogDto> logs = syncLogService.find(logFilter, null).getContent();
Assert.assertEquals(1, logs.size());
SysSyncLogDto log = logs.get(0);
SysSyncActionLogFilter actionLogFilter = new SysSyncActionLogFilter();
actionLogFilter.setSynchronizationLogId(log.getId());
List<SysSyncActionLogDto> actions = syncActionLogService.find(actionLogFilter, null).getContent();
SysSyncActionLogDto actionLog = actions.stream().filter(action -> {
return actionType == action.getSyncAction();
}).findFirst().get();
SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter();
itemLogFilter.setSyncActionLogId(actionLog.getId());
List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent();
Assert.assertEquals(count, items.size());
return log;
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncLogDto in project CzechIdMng by bcvsolutions.
the class DeleteSynchronizationLogTaskExecutorIntegrationTest method testDeleteOldSynchronizationLogs.
@Test
public void testDeleteOldSynchronizationLogs() {
// prepare provisioning operations
SysSystemDto systemOne = getHelper().createTestResourceSystem(true);
AbstractSysSyncConfigDto syncConfigOne = createSyncConfig(systemOne);
SysSystemDto systemOther = getHelper().createTestResourceSystem(true);
AbstractSysSyncConfigDto syncConfigOther = createSyncConfig(systemOther);
//
ZonedDateTime createdOne = ZonedDateTime.now().minusDays(2);
SysSyncLogDto logOne = createDto(syncConfigOne, createdOne);
// all other variants for not removal
createDto(syncConfigOne, LocalDate.now().atStartOfDay(ZoneId.systemDefault()).plusMinutes(1));
createDto(syncConfigOne, LocalDate.now().atStartOfDay(ZoneId.systemDefault()).minusHours(22));
SysSyncLogDto logOther = createDto(syncConfigOther, ZonedDateTime.now().minusDays(2));
//
Assert.assertEquals(createdOne, logOne.getCreated());
SysSyncLogFilter filter = new SysSyncLogFilter();
filter.setSystemId(systemOne.getId());
List<SysSyncLogDto> logs = service.find(filter, null).getContent();
Assert.assertEquals(3, logs.size());
filter.setSystemId(systemOther.getId());
logs = service.find(filter, null).getContent();
Assert.assertEquals(1, logs.size());
//
DeleteSynchronizationLogTaskExecutor taskExecutor = new DeleteSynchronizationLogTaskExecutor();
Map<String, Object> properties = new HashMap<>();
properties.put(DeleteSynchronizationLogTaskExecutor.PARAMETER_NUMBER_OF_DAYS, 1);
properties.put(DeleteSynchronizationLogTaskExecutor.PARAMETER_SYSTEM, systemOne.getId());
AutowireHelper.autowire(taskExecutor);
taskExecutor.init(properties);
//
longRunningTaskManager.execute(taskExecutor);
//
filter.setSystemId(systemOne.getId());
logs = service.find(filter, null).getContent();
Assert.assertEquals(2, logs.size());
Assert.assertTrue(logs.stream().allMatch(a -> !a.getId().equals(logOne.getId())));
//
filter.setSystemId(systemOther.getId());
logs = service.find(filter, null).getContent();
Assert.assertEquals(1, logs.size());
Assert.assertTrue(logs.stream().allMatch(a -> a.getId().equals(logOther.getId())));
//
taskExecutor = new DeleteSynchronizationLogTaskExecutor();
properties = new HashMap<>();
properties.put(DeleteSynchronizationLogTaskExecutor.PARAMETER_NUMBER_OF_DAYS, 1);
properties.put(DeleteSynchronizationLogTaskExecutor.PARAMETER_SYSTEM, systemOther.getId());
AutowireHelper.autowire(taskExecutor);
taskExecutor.init(properties);
//
filter.setSystemId(systemOne.getId());
longRunningTaskManager.execute(taskExecutor);
logs = service.find(filter, null).getContent();
Assert.assertEquals(2, logs.size());
Assert.assertTrue(logs.stream().allMatch(a -> !a.getId().equals(logOne.getId())));
//
filter.setSystemId(systemOther.getId());
logs = service.find(filter, null).getContent();
Assert.assertTrue(logs.isEmpty());
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncLogDto in project CzechIdMng by bcvsolutions.
the class DeleteSynchronizationLogTaskExecutorIntegrationTest method createDto.
private SysSyncLogDto createDto(AbstractSysSyncConfigDto syncConfig, ZonedDateTime created) {
SysSyncLogDto dto = new SysSyncLogDto();
dto.setCreated(created);
dto.setSynchronizationConfig(syncConfig.getId());
//
return service.save(dto);
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncLogDto in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method doUpdateEntity.
/**
* Fill data from IC attributes to entity (EAV and confidential storage too)
*
* @param context
*/
protected void doUpdateEntity(SynchronizationContext context) {
String uid = context.getUid();
SysSyncLogDto log = context.getLog();
SysSyncItemLogDto logItem = context.getLogItem();
if (context.isSkipEntityUpdate()) {
addToItemLog(logItem, MessageFormat.format("Update of entity for account with uid [{0}] is skipped", uid));
return;
}
List<SysSyncActionLogDto> actionLogs = context.getActionLogs();
List<SysSystemAttributeMappingDto> mappedAttributes = context.getMappedAttributes();
AccAccountDto account = context.getAccount();
List<IcAttribute> icAttributes = context.getIcObject().getAttributes();
// Find entity ID, first try entity ID in the context then load by account
UUID entityId = context.getEntityId();
if (entityId == null && account != null) {
entityId = getEntityByAccount(account.getId());
}
DTO entity = null;
if (entityId != null) {
entity = this.getService().get(entityId);
}
if (entity != null) {
// Fill entity
entity = fillEntity(mappedAttributes, uid, icAttributes, entity, false, context);
// Fill extended attributes to the entity. EAV attributes will be saved within entity.
if (entity instanceof FormableDto) {
FormableDto formableDto = (FormableDto) entity;
formableDto.getEavs().clear();
IdmFormInstanceDto formInstanceDto = fillExtendedAttributes(mappedAttributes, uid, icAttributes, entity, false, context);
formableDto.getEavs().add(formInstanceDto);
}
// Update entity
if (context.isEntityDifferent()) {
entity = this.save(entity, true, context);
}
// Entity updated
addToItemLog(logItem, MessageFormat.format("Entity with id [{0}] was updated", entity.getId()));
if (logItem != null) {
logItem.setDisplayName(this.getDisplayNameForEntity(entity));
}
SystemEntityType entityType = context.getEntityType();
if (context.isEntityDifferent() && this.isProvisioningImplemented(entityType, logItem) && !context.isSkipProvisioning()) {
// Call provisioning for this entity
callProvisioningForEntity(entity, entityType, logItem);
}
// Add updated entity to the context
context.addEntityDto(entity);
} else {
addToItemLog(logItem, "Warning! - Entity-account relation (with ownership = true) was not found!");
initSyncActionLog(SynchronizationActionType.UPDATE_ENTITY, OperationResultType.WARNING, logItem, log, actionLogs);
}
}
use of eu.bcvsolutions.idm.acc.dto.SysSyncLogDto in project CzechIdMng by bcvsolutions.
the class AbstractSynchronizationExecutor method resolveMissingEntitySituation.
/**
* Method for resolve missing entity situation for one item.
*
* @param actionType
* @param context
*/
@Override
public void resolveMissingEntitySituation(SynchronizationMissingEntityActionType actionType, SynchronizationContext context) {
String uid = context.getUid();
SystemEntityType entityType = context.getEntityType();
SysSystemDto system = context.getSystem();
SysSyncLogDto log = context.getLog();
SysSyncItemLogDto logItem = context.getLogItem();
List<SysSyncActionLogDto> actionLogs = context.getActionLogs();
List<SysSystemAttributeMappingDto> mappedAttributes = context.getMappedAttributes();
List<IcAttribute> icAttributes = context.getIcObject().getAttributes();
addToItemLog(logItem, "Account and entity don't exist (missing entity).");
switch(actionType) {
case IGNORE:
// Ignore we will do nothing
addToItemLog(logItem, "Missing entity action is IGNORE, we will do nothing.");
initSyncActionLog(SynchronizationActionType.MISSING_ENTITY, OperationResultType.IGNORE, logItem, log, actionLogs);
return;
case CREATE_ENTITY:
// We don't want compute different in create entity situation.
context.setIsEntityDifferent(true);
// Generate UID value from mapped attribute marked as UID (Unique
// ID).
// UID mapped attribute must exist and returned value must be not
// null and must be String
String attributeUid = this.generateUID(context);
// Create idm account
AccAccountDto account = doCreateIdmAccount(attributeUid, system);
// Find and set SystemEntity (must exist)
account.setSystemEntity(this.findSystemEntity(uid, system, entityType).getId());
// Apply specific settings - check, if the account and the entity can be created
account = this.applySpecificSettingsBeforeLink(account, null, context);
if (account == null) {
return;
}
account = accountService.save(account);
// Create new entity
doCreateEntity(entityType, mappedAttributes, logItem, uid, icAttributes, account, context);
initSyncActionLog(SynchronizationActionType.CREATE_ENTITY, OperationResultType.SUCCESS, logItem, log, actionLogs);
}
}
Aggregations