Search in sources :

Example 46 with SysSyncItemLogDto

use of eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto in project CzechIdMng by bcvsolutions.

the class AbstractSynchronizationExecutor method startWorkflow.

/**
 * Start workflow process by wfDefinitionKey. Create input variables and put
 * them to the process. If log variable is present after the process started,
 * then add the log to the synchronization log.
 *
 * @param wfDefinitionKey
 * @param situation
 * @param action
 * @param dto
 */
private void startWorkflow(String wfDefinitionKey, SynchronizationSituationType situation, SynchronizationActionType action, DTO dto, SynchronizationContext context) {
    SystemEntityType entityType = context.getEntityType();
    SysSyncLogDto log = context.getLog();
    SysSyncItemLogDto logItem = context.getLogItem();
    List<SysSyncActionLogDto> actionLogs = context.getActionLogs();
    AccAccountDto account = context.getAccount();
    String uid = context.getUid();
    AbstractSysSyncConfigDto config = context.getConfig();
    addToItemLog(logItem, MessageFormat.format("Workflow for [{0}] situation was found. We will start it.", situation));
    Map<String, Object> variables = new HashMap<>();
    variables.put(SynchronizationService.WF_VARIABLE_KEY_UID, uid);
    variables.put(SynchronizationService.WF_VARIABLE_KEY_ENTITY_TYPE, entityType);
    variables.put(SynchronizationService.WF_VARIABLE_KEY_SYNC_SITUATION, situation.name());
    variables.put(SynchronizationService.WF_VARIABLE_KEY_IC_ATTRIBUTES, context.getIcObject() != null ? context.getIcObject().getAttributes() : null);
    variables.put(SynchronizationService.WF_VARIABLE_KEY_ACTION_TYPE, action.name());
    variables.put(SynchronizationService.WF_VARIABLE_KEY_ENTITY_ID, dto != null ? dto.getId() : null);
    variables.put(SynchronizationService.WF_VARIABLE_KEY_ACC_ACCOUNT_ID, account != null ? account.getId() : null);
    variables.put(SynchronizationService.WF_VARIABLE_KEY_SYNC_CONFIG_ID, config.getId());
    variables.put(SynchronizationService.WF_VARIABLE_KEY_SYNC_CONFIG_ID, config.getId());
    variables.put(SynchronizationService.WF_VARIABLE_KEY_SYSTEM_ID, context.getSystem().getId());
    ProcessInstance processInstance = workflowProcessInstanceService.startProcess(wfDefinitionKey, SysSyncConfig.class.getSimpleName(), uid, config.getId().toString(), variables);
    if (processInstance instanceof VariableScope) {
        Object logItemObj = ((VariableScope) processInstance).getVariable(SynchronizationService.WF_VARIABLE_KEY_LOG_ITEM);
        if (logItemObj instanceof String) {
            addToItemLog(logItem, (String) logItemObj);
        }
    }
    if (processInstance != null && processInstance.isEnded()) {
        addToItemLog(logItem, MessageFormat.format("Workflow (with id [{0}]) for missing entity situation ended.", processInstance.getId()));
        initSyncActionLog(situation.getAction(), OperationResultType.WF, logItem, log, actionLogs);
        // We don't wont history for workflow executed in synchronization!
        processEngine.getHistoryService().deleteHistoricProcessInstance(processInstance.getId());
        addToItemLog(logItem, MessageFormat.format("Workflow history for process instance [{0}] was deleted.", processInstance.getId()));
    } else {
        // If workflow not ended, then the history will be not deleted!
        addToItemLog(logItem, MessageFormat.format("Workflow (with id [{0}]) for missing entity situation not ended (will be ended asynchronously).", processInstance != null ? processInstance.getId() : null));
        initSyncActionLog(situation.getAction(), OperationResultType.WF, logItem, log, actionLogs);
    }
}
Also used : HashMap(java.util.HashMap) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) SysSyncConfig(eu.bcvsolutions.idm.acc.entity.SysSyncConfig) SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) VariableScope(org.activiti.engine.delegate.VariableScope)

Example 47 with SysSyncItemLogDto

use of eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto in project CzechIdMng by bcvsolutions.

the class AbstractSynchronizationExecutor method resolveMissingAccountSituation.

/**
 * Method for resolve missing account situation for one item.
 *
 * @param action
 * @param context
 */
@Override
public void resolveMissingAccountSituation(ReconciliationMissingAccountActionType action, SynchronizationContext context) {
    SystemEntityType entityType = context.getEntityType();
    SysSyncLogDto log = context.getLog();
    SysSyncItemLogDto logItem = context.getLogItem();
    List<SysSyncActionLogDto> actionLogs = context.getActionLogs();
    AccAccountDto account = context.getAccount();
    addToItemLog(logItem, "Account doesn't exist on target system, but account in IdM was found (missing account).");
    addToItemLog(logItem, MessageFormat.format("Missing account action is [{0}]", action));
    switch(action) {
        case IGNORE:
            // Ignore we will do nothing
            initSyncActionLog(SynchronizationActionType.MISSING_ACCOUNT, OperationResultType.IGNORE, logItem, log, actionLogs);
            return;
        case CREATE_ACCOUNT:
            doUpdateAccount(account, entityType, log, logItem, actionLogs);
            initSyncActionLog(SynchronizationActionType.CREATE_ACCOUNT, OperationResultType.SUCCESS, logItem, log, actionLogs);
            return;
        case DELETE_ENTITY:
            doDeleteEntity(account, entityType, log, logItem, actionLogs);
            initSyncActionLog(SynchronizationActionType.DELETE_ENTITY, OperationResultType.SUCCESS, logItem, log, actionLogs);
            return;
        case UNLINK:
            doUnlink(account, false, log, logItem, actionLogs);
            initSyncActionLog(SynchronizationActionType.UNLINK, OperationResultType.SUCCESS, logItem, log, actionLogs);
            return;
        case UNLINK_AND_REMOVE_ROLE:
            doUnlink(account, true, log, logItem, actionLogs);
            initSyncActionLog(SynchronizationActionType.UNLINK_AND_REMOVE_ROLE, OperationResultType.SUCCESS, logItem, log, actionLogs);
    }
}
Also used : SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)

Example 48 with SysSyncItemLogDto

use of eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto in project CzechIdMng by bcvsolutions.

the class AbstractSynchronizationExecutor method resolveUnlinkedSituation.

/**
 * Method for resolve unlinked situation for one item.
 *
 * @param action
 * @param context
 */
@SuppressWarnings("unchecked")
@Override
public void resolveUnlinkedSituation(SynchronizationUnlinkedActionType action, SynchronizationContext context) {
    UUID entityId = context.getEntityId();
    SysSyncLogDto log = context.getLog();
    SysSyncItemLogDto logItem = context.getLogItem();
    List<SysSyncActionLogDto> actionLogs = context.getActionLogs();
    addToItemLog(logItem, MessageFormat.format("Account does not exist, but an entity [{0}] was found by correlation (entity unlinked).", entityId));
    addToItemLog(logItem, MessageFormat.format("Unlinked action is [{0}]", action));
    DTO entity = findById(entityId);
    switch(action) {
        case IGNORE:
            // Ignore we will do nothing
            initSyncActionLog(SynchronizationActionType.UNLINKED, OperationResultType.IGNORE, logItem, log, actionLogs);
            return;
        case LINK:
            // Create IdM account
            doCreateLink(entity, false, context);
            initSyncActionLog(SynchronizationActionType.LINK, OperationResultType.SUCCESS, logItem, log, actionLogs);
            return;
        case LINK_AND_UPDATE_ACCOUNT:
            // Create IdM account
            doCreateLink(entity, true, context);
            initSyncActionLog(SynchronizationActionType.LINK_AND_UPDATE_ACCOUNT, OperationResultType.SUCCESS, logItem, log, actionLogs);
            return;
        case LINK_AND_UPDATE_ENTITY:
            // Could be update of entity skipped?
            context.addSkipEntityUpdate(skipEntityUpdate(entity, context));
            // Update entity without provisioning
            context.addSkipProvisioning(true);
            doUpdateEntity(context);
            context.addSkipProvisioning(false);
            // Get updated entity from context
            if (context.getEntityDto() != null) {
                entity = (DTO) context.getEntityDto();
            }
            // Create IdM account
            doCreateLink(entity, true, context);
            initSyncActionLog(SynchronizationActionType.LINK_AND_UPDATE_ENTITY, OperationResultType.SUCCESS, logItem, log, actionLogs);
    }
}
Also used : SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) UUID(java.util.UUID) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)

Example 49 with SysSyncItemLogDto

use of eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto in project CzechIdMng by bcvsolutions.

the class AbstractSynchronizationExecutor method startItemSynchronization.

/**
 * Main method for synchronization item. This method is call form "custom
 * filter" and "connector sync" mode.
 *
 * @param itemContext
 * @return
 */
protected boolean startItemSynchronization(SynchronizationContext itemContext) {
    String uid = itemContext.getUid();
    AbstractSysSyncConfigDto config = itemContext.getConfig();
    SystemEntityType entityType = itemContext.getEntityType();
    SysSyncLogDto log = itemContext.getLog();
    SysSyncItemLogDto itemLog = itemContext.getLogItem();
    List<SysSyncActionLogDto> actionsLog = new ArrayList<>();
    try {
        SysSyncActionLogFilter actionFilter = new SysSyncActionLogFilter();
        actionFilter.setSynchronizationLogId(log.getId());
        actionsLog.addAll(syncActionLogService.find(actionFilter, null).getContent());
        itemContext.addActionLogs(actionsLog);
        // Default setting for log item
        itemLog.setIdentification(uid);
        itemLog.setDisplayName(uid);
        itemLog.setType(entityType.getEntityType().getSimpleName());
        // Do synchronization for one item (produces item)
        // Start in new Transaction
        CoreEvent<SysSyncItemLogDto> event = new CoreEvent<>(SynchronizationEventType.START_ITEM, itemLog);
        event.getProperties().put(SynchronizationService.WRAPPER_SYNC_ITEM, itemContext);
        EventResult<SysSyncItemLogDto> lastResult = entityEventManager.process(event).getLastResult();
        boolean result = false;
        if (lastResult != null && lastResult.getEvent().getProperties().containsKey(SynchronizationService.RESULT_SYNC_ITEM)) {
            result = (boolean) lastResult.getEvent().getProperties().get(SynchronizationService.RESULT_SYNC_ITEM);
        }
        return result;
    } catch (Exception ex) {
        Pair<SysSyncActionLogDto, SysSyncItemLogDto> actionWithItemLog = getActionLogThatContains(actionsLog, itemLog);
        if (actionWithItemLog != null) {
            // We have to decrement count and log as error
            itemLog = actionWithItemLog.getRight();
            SysSyncActionLogDto actionLogDto = actionWithItemLog.getLeft();
            actionLogDto.setOperationCount(actionLogDto.getOperationCount() - 1);
            actionLogDto.getLogItems().remove(itemLog);
            loggingException(actionLogDto.getSyncAction(), log, itemLog, actionsLog, uid, ex);
        } else {
            loggingException(SynchronizationActionType.UNKNOWN, log, itemLog, actionsLog, uid, ex);
        }
        return true;
    } finally {
        synchronizationConfigService.save(config);
        boolean existingItemLog = existItemLogInActions(actionsLog, itemLog);
        actionsLog = saveActionLogs(actionsLog, log.getId());
        // 
        if (!existingItemLog) {
            addToItemLog(itemLog, MessageFormat.format("Missing action log for UID [{0}]!", uid));
            initSyncActionLog(SynchronizationActionType.UNKNOWN, OperationResultType.ERROR, itemLog, log, actionsLog);
            syncItemLogService.save(itemLog);
        }
    }
}
Also used : SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) ArrayList(java.util.ArrayList) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) SysSyncActionLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncActionLogFilter) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) Pair(org.apache.commons.lang3.tuple.Pair) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair)

Example 50 with SysSyncItemLogDto

use of eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto in project CzechIdMng by bcvsolutions.

the class DefaultSynchronizationServiceTest method doStartSyncB_Linked_doEntityUpdate_Filtered.

@Test
public /**
 * We will do synchronize with use inner connector synch function.
 */
void doStartSyncB_Linked_doEntityUpdate_Filtered() {
    SysSyncConfigFilter configFilter = new SysSyncConfigFilter();
    configFilter.setName(SYNC_CONFIG_NAME);
    List<AbstractSysSyncConfigDto> syncConfigs = syncConfigService.find(configFilter, null).getContent();
    this.getBean().changeResourceData();
    Assert.assertEquals(1, syncConfigs.size());
    AbstractSysSyncConfigDto syncConfigCustom = syncConfigs.get(0);
    Assert.assertFalse(syncConfigService.isRunning(syncConfigCustom));
    SysSystemMappingDto systemMapping = systemMappingService.get(syncConfigCustom.getSystemMapping());
    SysSystemDto system = systemService.get(schemaObjectClassService.get(systemMapping.getObjectClass()).getSystem());
    IdmFormDefinitionDto savedFormDefinition = systemService.getConnectorFormDefinition(system);
    IdmFormAttributeDto changeLogColumn = savedFormDefinition.getMappedAttributeByCode("changeLogColumn");
    formService.saveValues(system, changeLogColumn, ImmutableList.of("modified"));
    // Set sync config
    syncConfigCustom.setLinkedAction(SynchronizationLinkedActionType.UPDATE_ENTITY);
    syncConfigCustom.setUnlinkedAction(SynchronizationUnlinkedActionType.IGNORE);
    syncConfigCustom.setMissingEntityAction(SynchronizationMissingEntityActionType.IGNORE);
    syncConfigCustom.setMissingAccountAction(ReconciliationMissingAccountActionType.IGNORE);
    syncConfigCustom.setCustomFilter(false);
    syncConfigCustom.setReconciliation(false);
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    // We want do sync for account changed in future
    syncConfigCustom.setToken(ZonedDateTime.now().format(formatter));
    // We don`t use custom filter. This option will be not used.
    syncConfigCustom.setFilterOperation(IcFilterOperationType.ENDS_WITH);
    syncConfigService.save(syncConfigCustom);
    helper.startSynchronization(syncConfigCustom);
    // 
    SysSyncLogFilter logFilter = new SysSyncLogFilter();
    logFilter.setSynchronizationConfigId(syncConfigCustom.getId());
    List<SysSyncLogDto> logs = syncLogService.find(logFilter, null).getContent();
    Assert.assertEquals(1, logs.size());
    SysSyncLogDto log = logs.get(0);
    Assert.assertFalse(log.isRunning());
    Assert.assertFalse(log.isContainsError());
    SysSyncActionLogFilter actionLogFilter = new SysSyncActionLogFilter();
    actionLogFilter.setSynchronizationLogId(log.getId());
    List<SysSyncActionLogDto> actions = syncActionLogService.find(actionLogFilter, null).getContent();
    Assert.assertEquals(1, actions.size());
    SysSyncActionLogDto actionLog = actions.stream().filter(action -> {
        return SynchronizationActionType.UPDATE_ENTITY == action.getSyncAction();
    }).findFirst().get();
    SysSyncItemLogFilter itemLogFilter = new SysSyncItemLogFilter();
    itemLogFilter.setSyncActionLogId(actionLog.getId());
    List<SysSyncItemLogDto> items = syncItemLogService.find(itemLogFilter, null).getContent();
    Assert.assertEquals(1, items.size());
    Assert.assertEquals("x" + IDENTITY_USERNAME_TWO, items.get(0).getIdentification());
    // Delete log
    syncLogService.delete(log);
    // We have to change property of connector configuration "changeLogColumn" from "modified" on empty string.
    // When is this property set, then custom filter not working. Bug in Table connector !!!
    formService.saveValues(system, changeLogColumn, ImmutableList.of(""));
}
Also used : SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) 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) SysSyncConfigFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter) DateTimeFormatter(java.time.format.DateTimeFormatter) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Aggregations

SysSyncItemLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto)60 SysSyncActionLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto)43 SysSyncLogDto (eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)43 AbstractSysSyncConfigDto (eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto)38 SysSyncActionLogFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncActionLogFilter)29 SysSyncItemLogFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncItemLogFilter)27 SysSyncLogFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncLogFilter)26 SysSyncConfigFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSyncConfigFilter)24 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)24 Test (org.junit.Test)24 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)20 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)19 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)17 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)16 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)13 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)12 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)11 UUID (java.util.UUID)11 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)10 SysSystemAttributeMappingFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter)10