Search in sources :

Example 11 with SysSyncItemLogDto

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

the class AbstractSynchronizationExecutor method initSyncActionLog.

/**
 * Init sync action log
 *
 * @param actionType
 * @param resultType
 * @param logItem
 * @param log
 * @param actionLogs
 * @param interateCount
 */
protected void initSyncActionLog(SynchronizationActionType actionType, OperationResultType resultType, SysSyncItemLogDto logItem, SysSyncLogDto log, List<SysSyncActionLogDto> actionLogs, boolean interateCount) {
    if (logItem == null || actionLogs == null) {
        // maybe)
        return;
    }
    // WARNING, then have priority
    if (this.existItemLogInActions(actionLogs, logItem)) {
        if (OperationResultType.ERROR != resultType && OperationResultType.WARNING != resultType) {
            return;
        }
        Pair<SysSyncActionLogDto, SysSyncItemLogDto> actionWithItemLog = getActionLogThatContains(actionLogs, logItem);
        if (OperationResultType.ERROR == resultType && OperationResultType.ERROR == actionWithItemLog.getLeft().getOperationResult()) {
            return;
        }
        if (OperationResultType.WARNING == resultType && OperationResultType.WARNING == actionWithItemLog.getLeft().getOperationResult()) {
            return;
        }
    }
    SysSyncActionLogDto actionLog;
    Optional<SysSyncActionLogDto> optionalActionLog = actionLogs.stream().filter(al -> {
        return actionType == al.getSyncAction() && resultType == al.getOperationResult();
    }).findFirst();
    if (optionalActionLog.isPresent()) {
        actionLog = optionalActionLog.get();
    } else {
        actionLog = new SysSyncActionLogDto();
        actionLog.setOperationResult(resultType);
        actionLog.setSyncAction(actionType);
        actionLog.setSyncLog(log.getId());
        actionLogs.add(actionLog);
    }
    actionLog.addLogItems(logItem);
    if (interateCount) {
        actionLog.setOperationCount(actionLog.getOperationCount() + 1);
        addToItemLog(logItem, MessageFormat.format("Operation count for [{0}] is [{1}]", actionLog.getSyncAction(), actionLog.getOperationCount()));
    }
}
Also used : SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) DtoUtils(eu.bcvsolutions.idm.core.api.utils.DtoUtils) IcNotFilter(eu.bcvsolutions.idm.ic.filter.impl.IcNotFilter) IdmFormAttributeDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormAttributeDto) ZonedDateTime(java.time.ZonedDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) AttributeValueWrapperDto(eu.bcvsolutions.idm.acc.dto.AttributeValueWrapperDto) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) EntityAccountDto(eu.bcvsolutions.idm.acc.dto.EntityAccountDto) ConfigurationService(eu.bcvsolutions.idm.core.api.service.ConfigurationService) FormService(eu.bcvsolutions.idm.core.eav.api.service.FormService) SysSystemAttributeMapping_(eu.bcvsolutions.idm.acc.entity.SysSystemAttributeMapping_) GroovyScriptService(eu.bcvsolutions.idm.core.api.service.GroovyScriptService) CoreEvent(eu.bcvsolutions.idm.core.api.event.CoreEvent) Pair(org.apache.commons.lang3.tuple.Pair) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) EntityAccountService(eu.bcvsolutions.idm.acc.service.api.EntityAccountService) Map(java.util.Map) SynchronizationUnlinkedActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationUnlinkedActionType) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) IcSyncTokenImpl(eu.bcvsolutions.idm.ic.impl.IcSyncTokenImpl) Loggable(eu.bcvsolutions.idm.core.api.domain.Loggable) IcFilter(eu.bcvsolutions.idm.ic.filter.api.IcFilter) Set(java.util.Set) PageRequest(org.springframework.data.domain.PageRequest) ReconciliationMissingAccountActionType(eu.bcvsolutions.idm.acc.domain.ReconciliationMissingAccountActionType) IntrospectionException(java.beans.IntrospectionException) Serializable(java.io.Serializable) InvocationTargetException(java.lang.reflect.InvocationTargetException) AttributeMapping(eu.bcvsolutions.idm.acc.domain.AttributeMapping) SynchronizationSituationType(eu.bcvsolutions.idm.acc.domain.SynchronizationSituationType) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) Lazy(org.springframework.context.annotation.Lazy) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AccResultCode(eu.bcvsolutions.idm.acc.domain.AccResultCode) FormableDto(eu.bcvsolutions.idm.core.api.dto.FormableDto) IcConnectorFacade(eu.bcvsolutions.idm.ic.service.api.IcConnectorFacade) IcSyncResultsHandler(eu.bcvsolutions.idm.ic.api.IcSyncResultsHandler) SynchronizationEventType(eu.bcvsolutions.idm.acc.event.SynchronizationEventType) SysSystemEntityService(eu.bcvsolutions.idm.acc.service.api.SysSystemEntityService) Session(org.hibernate.Session) ValueWrapper(eu.bcvsolutions.idm.core.api.config.cache.domain.ValueWrapper) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) AbstractDto(eu.bcvsolutions.idm.core.api.dto.AbstractDto) Lists(com.google.common.collect.Lists) SysSyncConfig(eu.bcvsolutions.idm.acc.entity.SysSyncConfig) IcResultsHandler(eu.bcvsolutions.idm.ic.filter.api.IcResultsHandler) WorkflowProcessInstanceService(eu.bcvsolutions.idm.core.workflow.service.WorkflowProcessInstanceService) SynchronizationLinkedActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationLinkedActionType) SysSystemEntityFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemEntityFilter) IcObjectClass(eu.bcvsolutions.idm.ic.api.IcObjectClass) IcOrFilter(eu.bcvsolutions.idm.ic.filter.impl.IcOrFilter) EventResult(eu.bcvsolutions.idm.core.api.event.EventResult) IdmFormInstanceDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormInstanceDto) AccModuleDescriptor(eu.bcvsolutions.idm.acc.AccModuleDescriptor) SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) SysSchemaObjectClass_(eu.bcvsolutions.idm.acc.entity.SysSchemaObjectClass_) IcFilterBuilder(eu.bcvsolutions.idm.ic.filter.impl.IcFilterBuilder) CoreException(eu.bcvsolutions.idm.core.api.exception.CoreException) IcConnectorKey(eu.bcvsolutions.idm.ic.api.IcConnectorKey) IdmCacheManager(eu.bcvsolutions.idm.core.api.service.IdmCacheManager) Throwables(com.google.common.base.Throwables) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) EntityManager(javax.persistence.EntityManager) VariableScope(org.activiti.engine.delegate.VariableScope) BaseFilter(eu.bcvsolutions.idm.core.api.dto.filter.BaseFilter) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) SynchronizationContext(eu.bcvsolutions.idm.acc.domain.SynchronizationContext) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SynchronizationEntityExecutor(eu.bcvsolutions.idm.acc.service.api.SynchronizationEntityExecutor) SysSyncLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncLogFilter) BaseDto(eu.bcvsolutions.idm.core.api.dto.BaseDto) SysSyncActionLogService(eu.bcvsolutions.idm.acc.service.api.SysSyncActionLogService) EntityEventManager(eu.bcvsolutions.idm.core.api.service.EntityEventManager) OperationResultType(eu.bcvsolutions.idm.acc.domain.OperationResultType) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) IcSyncDeltaTypeEnum(eu.bcvsolutions.idm.ic.impl.IcSyncDeltaTypeEnum) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) AbstractSchedulableTaskExecutor(eu.bcvsolutions.idm.core.scheduler.api.service.AbstractSchedulableTaskExecutor) SynchronizationMissingEntityActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationMissingEntityActionType) ProvisioningConfiguration(eu.bcvsolutions.idm.acc.config.domain.ProvisioningConfiguration) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) SysSyncConfigService(eu.bcvsolutions.idm.acc.service.api.SysSyncConfigService) Pageable(org.springframework.data.domain.Pageable) SysSyncLogService(eu.bcvsolutions.idm.acc.service.api.SysSyncLogService) ImmutableMap(com.google.common.collect.ImmutableMap) ReadWriteDtoService(eu.bcvsolutions.idm.core.api.service.ReadWriteDtoService) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) EntityAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.EntityAccountFilter) AccAccountService(eu.bcvsolutions.idm.acc.service.api.AccAccountService) ExceptionUtils(eu.bcvsolutions.idm.core.api.utils.ExceptionUtils) AccountType(eu.bcvsolutions.idm.acc.domain.AccountType) Optional(java.util.Optional) AccAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccAccountFilter) SysSchemaObjectClassService(eu.bcvsolutions.idm.acc.service.api.SysSchemaObjectClassService) IcConnectorConfiguration(eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration) HashMap(java.util.HashMap) IcObjectClassImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) MessageFormat(java.text.MessageFormat) HashSet(java.util.HashSet) ProcessEngine(org.activiti.engine.ProcessEngine) SysSystemMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemMappingService) ConfidentialStorage(eu.bcvsolutions.idm.core.api.service.ConfidentialStorage) SynchronizationActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationActionType) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) CollectionUtils(org.apache.commons.collections.CollectionUtils) EntityUtils(eu.bcvsolutions.idm.core.api.utils.EntityUtils) CorrelationFilter(eu.bcvsolutions.idm.core.api.dto.filter.CorrelationFilter) IcSyncDelta(eu.bcvsolutions.idm.ic.api.IcSyncDelta) IcAndFilter(eu.bcvsolutions.idm.ic.filter.impl.IcAndFilter) IcAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcAttributeImpl) Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) SysSystemService(eu.bcvsolutions.idm.acc.service.api.SysSystemService) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) SysSchemaAttributeService(eu.bcvsolutions.idm.acc.service.api.SysSchemaAttributeService) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) SysSyncActionLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncActionLogFilter) SynchronizationService(eu.bcvsolutions.idm.acc.service.api.SynchronizationService) DateTimeFormatter(java.time.format.DateTimeFormatter) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) ProvisioningService(eu.bcvsolutions.idm.acc.service.api.ProvisioningService) IcFilterOperationType(eu.bcvsolutions.idm.ic.domain.IcFilterOperationType) SysSyncItemLogService(eu.bcvsolutions.idm.acc.service.api.SysSyncItemLogService) IcSyncToken(eu.bcvsolutions.idm.ic.api.IcSyncToken) SysSystemAttributeMappingService(eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) Assert(org.springframework.util.Assert) StringUtils(org.springframework.util.StringUtils) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto)

Example 12 with SysSyncItemLogDto

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

the class AbstractSynchronizationExecutor method doCreateLink.

/**
 * Create account and relation on him
 *
 * @param callProvisioning
 * @param dto
 * @param context
 */
protected void doCreateLink(DTO dto, boolean callProvisioning, SynchronizationContext context) {
    String uid = context.getUid();
    SystemEntityType entityType = context.getEntityType();
    SysSystemDto system = context.getSystem();
    SysSyncItemLogDto logItem = context.getLogItem();
    SysSystemEntityDto systemEntity = context.getSystemEntity();
    String entityIdentification = dto.getId().toString();
    if (dto instanceof Codeable) {
        entityIdentification = ((Codeable) dto).getCode();
    }
    logItem.setDisplayName(entityIdentification);
    // 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);
    AccAccountDto account = doCreateIdmAccount(attributeUid, system);
    if (systemEntity != null) {
        // If SystemEntity for this account already exist, then we linked
        // him to new account
        account.setSystemEntity(systemEntity.getId());
    }
    account = this.applySpecificSettingsBeforeLink(account, dto, context);
    if (account == null) {
        // Identity account won't be created
        addToItemLog(logItem, MessageFormat.format("Link between uid [{0}] and entity [{1}] will not be created due to specific settings of synchronization. " + "Processing of this item is finished.", uid, entityIdentification));
        return;
    }
    account = accountService.save(account);
    addToItemLog(logItem, MessageFormat.format("Account with uid [{0}] and id [{1}] was created", uid, account.getId()));
    // Create new entity account relation
    EntityAccountDto entityAccount = this.createEntityAccount(account, dto, context);
    entityAccount = (EntityAccountDto) getEntityAccountService().save(entityAccount);
    context.addAccount(account);
    // Identity account Created
    addToItemLog(logItem, MessageFormat.format("Entity account relation  with id [{0}], between account [{1}] and entity [{2}] was created", entityAccount.getId(), uid, entityIdentification));
    logItem.setType(entityAccount.getClass().getSimpleName());
    logItem.setIdentification(entityAccount.getId().toString());
    if (callProvisioning) {
        if (this.isProvisioningImplemented(entityType, logItem)) {
            // Call provisioning for this entity
            callProvisioningForEntity(dto, entityType, logItem);
        }
    }
}
Also used : Codeable(eu.bcvsolutions.idm.core.api.domain.Codeable) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) EntityAccountDto(eu.bcvsolutions.idm.acc.dto.EntityAccountDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) AccAccountDto(eu.bcvsolutions.idm.acc.dto.AccAccountDto) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

Example 13 with SysSyncItemLogDto

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

the class AbstractSynchronizationExecutor method doItemSynchronization.

@Override
public boolean doItemSynchronization(SynchronizationContext context) {
    Assert.notNull(context, "Context is required.");
    String uid = context.getUid();
    IcConnectorObject icObject = context.getIcObject();
    IcSyncDeltaTypeEnum type = context.getType();
    AbstractSysSyncConfigDto config = context.getConfig();
    SysSystemDto system = context.getSystem();
    SystemEntityType entityType = context.getEntityType();
    AccAccountDto account = context.getAccount();
    SysSyncLogDto log = context.getLog();
    SysSyncItemLogDto logItem = context.getLogItem();
    List<SysSyncActionLogDto> actionLogs = context.getActionLogs();
    // Set default unknown action type
    context.addActionType(SynchronizationActionType.UNKNOWN);
    // If differential sync is disabled, then is every entity marks as different.
    context.setIsEntityDifferent(!config.isDifferentialSync());
    try {
        // Find system entity for uid
        SysSystemEntityDto systemEntity = findSystemEntity(uid, system, entityType);
        context.addSystemEntity(systemEntity);
        // Find acc account for uid or system entity
        if (account == null) {
            account = findAccount(context);
            if (systemEntity == null) {
                addToItemLog(logItem, "SystemEntity for this uid doesn't exist. We will create it.");
                systemEntity = createSystemEntity(uid, entityType, system);
            }
        }
        context.addSystemEntity(systemEntity).addAccount(account);
        if (IcSyncDeltaTypeEnum.CREATE == type || IcSyncDeltaTypeEnum.UPDATE == type || IcSyncDeltaTypeEnum.CREATE_OR_UPDATE == type) {
            // Update or create
            Assert.notNull(icObject, "Connector object is required.");
            List<IcAttribute> icAttributes = icObject.getAttributes();
            if (account == null) {
                // Account doesn't exist in IDM
                systemEntity = removeSystemEntityWishIfPossible(systemEntity, false, context);
                context.addSystemEntity(systemEntity);
                resolveAccountNotExistSituation(context, systemEntity, icAttributes);
            } else {
                // Account exist in IdM (LINKED)
                SynchronizationLinkedActionType linkedAction = config.getLinkedAction();
                SynchronizationActionType action = linkedAction.getAction();
                context.addActionType(action);
                SynchronizationSituationType situation = SynchronizationSituationType.LINKED;
                // configured
                if (linkedAction == SynchronizationLinkedActionType.UPDATE_ENTITY || linkedAction == SynchronizationLinkedActionType.UPDATE_ACCOUNT) {
                    systemEntity = removeSystemEntityWishIfPossible(systemEntity, true, context);
                    context.addSystemEntity(systemEntity);
                }
                if (StringUtils.hasLength(config.getLinkedActionWfKey())) {
                    // We will start specific workflow
                    startWorkflow(config.getLinkedActionWfKey(), situation, action, null, context);
                } else {
                    resolveLinkedSituation(config.getLinkedAction(), context);
                }
                addToItemLog(logItem, "Account exist in IdM (LINKED) - ended");
            }
        } else if (IcSyncDeltaTypeEnum.DELETE == type) {
            // Missing account situation, can be call from connector
            // (support delete account event) and from reconciliation
            context.addActionType(config.getMissingAccountAction().getAction());
            SynchronizationSituationType situation = SynchronizationSituationType.MISSING_ACCOUNT;
            if (StringUtils.hasLength(config.getMissingAccountActionWfKey())) {
                ReconciliationMissingAccountActionType missingAccountActionType = config.getMissingAccountAction();
                SynchronizationActionType action = missingAccountActionType.getAction();
                // We will start specific workflow
                startWorkflow(config.getMissingAccountActionWfKey(), situation, action, null, context);
            } else {
                // Resolve missing account situation for one item
                this.resolveMissingAccountSituation(config.getMissingAccountAction(), context);
            }
        } else if (context.isExportAction()) {
            // Export situation - create account to system
            this.resolveUnlinkedSituation(SynchronizationUnlinkedActionType.LINK_AND_UPDATE_ACCOUNT, context);
        }
        // Call hard hibernate session flush and clear
        if (getHibernateSession().isOpen()) {
            getHibernateSession().flush();
            getHibernateSession().clear();
        }
        return true;
    } catch (Exception e) {
        loggingException(context.getActionType(), log, logItem, actionLogs, uid, e);
        throw e;
    }
}
Also used : SynchronizationSituationType(eu.bcvsolutions.idm.acc.domain.SynchronizationSituationType) SynchronizationLinkedActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationLinkedActionType) 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) ReconciliationMissingAccountActionType(eu.bcvsolutions.idm.acc.domain.ReconciliationMissingAccountActionType) 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) SynchronizationActionType(eu.bcvsolutions.idm.acc.domain.SynchronizationActionType) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) IcSyncDeltaTypeEnum(eu.bcvsolutions.idm.ic.impl.IcSyncDeltaTypeEnum) IcAttribute(eu.bcvsolutions.idm.ic.api.IcAttribute) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) SysSystemEntityDto(eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)

Example 14 with SysSyncItemLogDto

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

the class AbstractSynchronizationExecutor method exportEntity.

/**
 * Start export item (entity) to target resource
 *
 * @param context
 * @param uidAttribute
 * @param entity
 */
protected void exportEntity(SynchronizationContext context, SysSystemAttributeMappingDto uidAttribute, AbstractDto entity) {
    SystemEntityType entityType = context.getEntityType();
    AbstractSysSyncConfigDto config = context.getConfig();
    SysSyncLogDto log = context.getLog();
    List<SysSyncActionLogDto> actionsLog = context.getActionLogs();
    SysSystemDto system = context.getSystem();
    SysSyncItemLogDto itemLog = new SysSyncItemLogDto();
    try {
        // Default setting for log item
        itemLog.setIdentification(entity.getId().toString());
        itemLog.setDisplayName(this.getDisplayNameForEntity(entity));
        itemLog.setType(entityType.getEntityType().getSimpleName());
        itemLog.addToLog(MessageFormat.format("Start export for entity [{0}].", this.getDisplayNameForEntity(entity)));
        UUID accountId = this.getAccountByEntity(entity.getId(), system.getId());
        if (accountId != null) {
            initSyncActionLog(SynchronizationActionType.CREATE_ACCOUNT, OperationResultType.IGNORE, itemLog, log, actionsLog);
            itemLog.addToLog(MessageFormat.format("For entity [{0}] AccAccount [{1}] was found. Export for this entity ends (only entity without AccAccount can be exported)!", this.getDisplayNameForEntity(entity), accountId));
            return;
        }
        String uid = systemAttributeMappingService.generateUid(entity, uidAttribute);
        // Do export for one item (produces event)
        // Start in new Transaction
        // 
        context.addUid(uid).addConfig(// 
        config).addSystem(// 
        system).addEntityType(// 
        entityType).addEntityId(entity.getId()).addLog(// 
        log).addLogItem(// 
        itemLog).addActionLogs(// 
        actionsLog).addExportAction(true);
        CoreEvent<SysSyncItemLogDto> event = new CoreEvent<>(SynchronizationEventType.START_ITEM, itemLog);
        event.getProperties().put(SynchronizationService.WRAPPER_SYNC_ITEM, context);
        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);
        }
        // Update (increased counter) and check state of sync (maybe was cancelled from
        // sync or LRT)
        updateAndCheckState(result, log);
    } catch (Exception ex) {
        String message = MessageFormat.format("Export - error for entity [{0}]", entity.getId());
        log.addToLog(message);
        log.addToLog(Throwables.getStackTraceAsString(ex));
        LOG.error(message, ex);
    } finally {
        synchronizationConfigService.save(config);
        boolean existingItemLog = existItemLogInActions(actionsLog, itemLog);
        actionsLog = (List<SysSyncActionLogDto>) syncActionLogService.saveAll(actionsLog);
        // 
        if (!existingItemLog) {
            addToItemLog(itemLog, MessageFormat.format("Missing action log for entity [{0}]!", entity.getId()));
            initSyncActionLog(SynchronizationActionType.UNKNOWN, OperationResultType.ERROR, itemLog, log, actionsLog);
            syncItemLogService.save(itemLog);
        }
    }
}
Also used : SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) 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) UUID(java.util.UUID) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)

Example 15 with SysSyncItemLogDto

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

the class DefaultSynchronizationService method resolveMissingEntitySituation.

@Override
public SysSyncItemLogDto resolveMissingEntitySituation(String uid, SystemEntityType entityType, List<IcAttribute> icAttributes, UUID configId, String actionType) {
    Assert.notNull(uid, "Uid is required.");
    Assert.notNull(entityType, "Entity type is required.");
    Assert.notNull(icAttributes, "Connector attribues are required.");
    Assert.notNull(configId, "Configuration identifier is required.");
    Assert.notNull(actionType, "Action type is required.");
    AbstractSysSyncConfigDto config = synchronizationConfigService.get(configId);
    SysSystemMappingDto mapping = systemMappingService.get(config.getSystemMapping());
    SysSchemaObjectClassDto sysSchemaObjectClassDto = schemaObjectClassService.get(mapping.getObjectClass());
    SysSystemDto system = DtoUtils.getEmbedded(sysSchemaObjectClassDto, SysSchemaObjectClass_.system);
    SysSystemAttributeMappingFilter attributeHandlingFilter = new SysSystemAttributeMappingFilter();
    attributeHandlingFilter.setSystemMappingId(mapping.getId());
    List<SysSystemAttributeMappingDto> mappedAttributes = attributeHandlingService.find(attributeHandlingFilter, null).getContent();
    SysSyncItemLogDto itemLog = new SysSyncItemLogDto();
    // Little workaround, we have only IcAttributes ... we create IcObject manually
    IcConnectorObjectImpl icObject = new IcConnectorObjectImpl();
    icObject.setAttributes(icAttributes);
    icObject.setUidValue(uid);
    SynchronizationContext context = new SynchronizationContext();
    // 
    context.addUid(uid).addSystem(// 
    system).addConfig(// 
    config).addEntityType(// 
    entityType).addLogItem(// 
    itemLog).addMappedAttributes(// 
    mappedAttributes).addIcObject(// 
    icObject);
    getSyncExecutor(entityType, configId).resolveMissingEntitySituation(SynchronizationMissingEntityActionType.valueOf(actionType), context);
    return itemLog;
}
Also used : AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) SysSystemAttributeMappingFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter) SynchronizationContext(eu.bcvsolutions.idm.acc.domain.SynchronizationContext) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSyncItemLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncItemLogDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) IcConnectorObjectImpl(eu.bcvsolutions.idm.ic.impl.IcConnectorObjectImpl) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto)

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