Search in sources :

Example 1 with SysSyncLogDto

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;
}
Also used : SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) SysSyncLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncLogFilter) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) SysSyncItemLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncItemLogFilter) SysSyncActionLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncActionLogFilter) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)

Example 2 with SysSyncLogDto

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());
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AutowireHelper(eu.bcvsolutions.idm.core.api.utils.AutowireHelper) Map(java.util.Map) SynchronizationMissingEntityActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationMissingEntityActionType) SynchronizationLinkedActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationLinkedActionType) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) SysSyncConfigService(eu.bcvsolutions.idm.acc.service.api.SysSyncConfigService) SynchronizationUnlinkedActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationUnlinkedActionType) SysSyncLogService(eu.bcvsolutions.idm.acc.service.api.SysSyncLogService) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) LongRunningTaskManager(eu.bcvsolutions.idm.core.scheduler.api.service.LongRunningTaskManager) Test(org.junit.Test) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) ReconciliationMissingAccountActionType(eu.bcvsolutions.idm.acc.domain.ReconciliationMissingAccountActionType) ZoneId(java.time.ZoneId) SysSyncIdentityConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncIdentityConfigDto) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) List(java.util.List) LocalDate(java.time.LocalDate) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSyncLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncLogFilter) TestHelper(eu.bcvsolutions.idm.acc.TestHelper) Assert(org.junit.Assert) SysSystemAttributeMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService) HashMap(java.util.HashMap) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) ZonedDateTime(java.time.ZonedDateTime) SysSyncLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncLogFilter) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 3 with SysSyncLogDto

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);
}
Also used : SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)

Example 4 with SysSyncLogDto

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);
    }
}
Also used : IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) FormableDto(eu.bcvsolutions.idm.core.api.dto.FormableDto) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) UUID(java.util.UUID) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)

Example 5 with SysSyncLogDto

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);
    }
}
Also used : SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)

Aggregations

SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)170 Test (org.junit.Test)141 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)129 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)129 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)98 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)83 SysSyncIdentityConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncIdentityConfigDto)55 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)54 SysSyncActionLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto)53 DefaultSynchronizationServiceTest (eu.bcvsolutions.idm.acc.service.impl.DefaultSynchronizationServiceTest)50 SysSyncLogFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncLogFilter)48 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)45 SysSyncItemLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto)44 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)40 SysSyncConfigFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter)40 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)39 IdmIdentityRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityRoleDto)36 SysSyncContractConfigDto (eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto)34 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)33 UUID (java.util.UUID)33