Search in sources :

Example 31 with ProvisioningException

use of eu.bcvsolutions.idm.acc.exception.ProvisioningException in project CzechIdMng by bcvsolutions.

the class ContractSynchronizationExecutor method getValueByMappedAttribute.

@Override
protected Object getValueByMappedAttribute(AttributeMapping attribute, List<IcAttribute> icAttributes, SynchronizationContext context) {
    Object transformedValue = super.getValueByMappedAttribute(attribute, icAttributes, context);
    // Transform contract state enumeration from string
    if (CONTRACT_STATE_FIELD.equals(attribute.getIdmPropertyName()) && transformedValue instanceof String && attribute.isEntityAttribute()) {
        return ContractState.valueOf((String) transformedValue);
    }
    // Transform contract guarantees
    if (CONTRACT_GUARANTEES_FIELD.equals(attribute.getIdmPropertyName()) && attribute.isEntityAttribute()) {
        return transformGuarantees(context, transformedValue);
    }
    // Transform work position (tree node)
    if (CONTRACT_WORK_POSITION_FIELD.equals(attribute.getIdmPropertyName()) && attribute.isEntityAttribute()) {
        if (transformedValue != null) {
            IdmTreeNodeDto workposition = this.findTreeNode(transformedValue, context);
            if (workposition != null) {
                return workposition.getId();
            }
            return null;
        } else {
            if (getConfig(context).getDefaultTreeNode() != null) {
                UUID defaultNode = ((SysSyncContractConfigDto) context.getConfig()).getDefaultTreeNode();
                IdmTreeNodeDto node = (IdmTreeNodeDto) lookupService.lookupDto(IdmTreeNodeDto.class, defaultNode);
                if (node != null) {
                    context.getLogItem().addToLog(MessageFormat.format("Warning! - None workposition was defined for this realtion, we use default workposition [{0}]!", node.getCode()));
                    return node.getId();
                }
            }
        }
    }
    // Transform contract owner
    if (transformedValue != null && CONTRACT_IDENTITY_FIELD.equals(attribute.getIdmPropertyName()) && attribute.isEntityAttribute()) {
        context.getLogItem().addToLog(MessageFormat.format("Finding contract owner [{0}].", transformedValue));
        IdmIdentityDto identity = this.findIdentity(transformedValue, context);
        if (identity == null) {
            throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_IDM_FIELD_CANNOT_BE_NULL, ImmutableMap.of("property", CONTRACT_IDENTITY_FIELD));
        }
        return identity.getId();
    }
    return transformedValue;
}
Also used : SysSyncContractConfigDto(eu.bcvsolutions.idm.acc.dto.SysSyncContractConfigDto) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) IdmTreeNodeDto(eu.bcvsolutions.idm.core.api.dto.IdmTreeNodeDto) UUID(java.util.UUID) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)

Example 32 with ProvisioningException

use of eu.bcvsolutions.idm.acc.exception.ProvisioningException in project CzechIdMng by bcvsolutions.

the class ContractSynchronizationExecutor method findByAttribute.

@Override
protected IdmIdentityContractDto findByAttribute(String idmAttributeName, String value) {
    CorrelationFilter filter = getEntityFilter();
    filter.setProperty(idmAttributeName);
    filter.setValue(value);
    List<IdmIdentityContractDto> entities = contractService.find((IdmIdentityContractFilter) filter, null).getContent();
    if (CollectionUtils.isEmpty(entities)) {
        return null;
    }
    if (entities.size() > 1) {
        throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_CORRELATION_TO_MANY_RESULTS, ImmutableMap.of("correlationAttribute", idmAttributeName, "value", value));
    }
    if (entities.size() == 1) {
        return entities.get(0);
    }
    return null;
}
Also used : CorrelationFilter(eu.bcvsolutions.idm.core.api.dto.filter.CorrelationFilter) IdmIdentityContractFilter(eu.bcvsolutions.idm.core.api.dto.filter.IdmIdentityContractFilter) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) IdmIdentityContractDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)

Example 33 with ProvisioningException

use of eu.bcvsolutions.idm.acc.exception.ProvisioningException in project CzechIdMng by bcvsolutions.

the class TreeProvisioningExecutor method getAttributeValue.

@Override
protected Object getAttributeValue(String uid, IdmTreeNodeDto entity, AttributeMapping attribute) {
    Object idmValue = super.getAttributeValue(uid, entity, attribute);
    if (attribute.isEntityAttribute() && TreeSynchronizationExecutor.PARENT_FIELD.equals(attribute.getIdmPropertyName())) {
        // parent format (UID of parent)
        if (idmValue instanceof UUID) {
            // Generally we expect IdmTreeNode as parent (we will do
            // transform)
            AccTreeAccountFilter treeAccountFilter = new AccTreeAccountFilter();
            treeAccountFilter.setSystemId(this.getSytemFromSchemaAttribute(attribute.getSchemaAttribute()).getId());
            treeAccountFilter.setTreeNodeId(((UUID) idmValue));
            List<AccTreeAccountDto> treeAccounts = treeAccountService.find(treeAccountFilter, null).getContent();
            if (treeAccounts.isEmpty()) {
                throw new ProvisioningException(AccResultCode.PROVISIONING_TREE_PARENT_ACCOUNT_NOT_FOUND, ImmutableMap.of("parentNode", idmValue));
            }
            if (treeAccounts.size() != 1) {
                throw new ProvisioningException(AccResultCode.PROVISIONING_TREE_TOO_MANY_PARENT_ACCOUNTS, ImmutableMap.of("parentNode", idmValue));
            }
            AccTreeAccountDto treeAccount = treeAccounts.get(0);
            String parentUid = accountService.get(treeAccount.getAccount()).getUid();
            return parentUid;
        } else {
            // without any transform
            return idmValue;
        }
    }
    return idmValue;
}
Also used : AccTreeAccountDto(eu.bcvsolutions.idm.acc.dto.AccTreeAccountDto) AccTreeAccountFilter(eu.bcvsolutions.idm.acc.dto.filter.AccTreeAccountFilter) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) UUID(java.util.UUID)

Example 34 with ProvisioningException

use of eu.bcvsolutions.idm.acc.exception.ProvisioningException in project CzechIdMng by bcvsolutions.

the class TreeSynchronizationExecutor method process.

@Override
public AbstractSysSyncConfigDto process(UUID synchronizationConfigId) {
    // Clear cache
    this.clearCache();
    // Validate and create basic context
    SynchronizationContext context = this.validate(synchronizationConfigId);
    AbstractSysSyncConfigDto config = context.getConfig();
    SystemEntityType entityType = context.getEntityType();
    SysSystemDto system = context.getSystem();
    IcConnectorConfiguration connectorConfig = context.getConnectorConfig();
    List<SysSystemAttributeMappingDto> mappedAttributes = context.getMappedAttributes();
    SysSystemMappingDto systemMapping = systemMappingService.get(context.getConfig().getSystemMapping());
    SysSchemaObjectClassDto schemaObjectClassDto = schemaObjectClassService.get(systemMapping.getObjectClass());
    IcObjectClass objectClass = new IcObjectClassImpl(schemaObjectClassDto.getObjectClassName());
    // Load last token
    Object lastToken = config.isReconciliation() ? null : config.getToken();
    // Create basic synchronization log
    SysSyncLogDto log = new SysSyncLogDto();
    log.setSynchronizationConfig(config.getId());
    log.setStarted(LocalDateTime.now());
    log.setRunning(true);
    log.setToken(lastToken != null ? lastToken.toString() : null);
    log.addToLog(MessageFormat.format("Synchronization was started in {0}.", log.getStarted()));
    // List of all accounts with full IC object (used in tree sync)
    Map<String, IcConnectorObject> accountsMap = new HashMap<>();
    longRunningTaskExecutor.setCounter(0L);
    try {
        log = synchronizationLogService.save(log);
        List<SysSyncActionLogDto> actionsLog = new ArrayList<>();
        // Add logs to context
        context.addLog(log).addActionLogs(actionsLog);
        boolean export = false;
        if (export) {
            // Start exporting entities to resource
            log.addToLog("Exporting entities to resource started...");
            this.startExport(entityType, config, mappedAttributes, log, actionsLog);
        } else {
            if (config.getTokenAttribute() == null && !config.isReconciliation()) {
                throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_TOKEN_ATTRIBUTE_NOT_FOUND);
            }
            TreeResultsHandler resultHandler = new TreeResultsHandler(accountsMap);
            // We have to search all data for tree
            IcFilter filter = null;
            log.addToLog(MessageFormat.format("Start search with filter {0}.", "NONE"));
            log = synchronizationLogService.save(log);
            connectorFacade.search(system.getConnectorInstance(), connectorConfig, objectClass, filter, resultHandler);
            // Execute sync for this tree and searched accounts
            processTreeSync(context, accountsMap);
            log = context.getLog();
        }
        // 
        log.addToLog(MessageFormat.format("Synchronization was correctly ended in {0}.", LocalDateTime.now()));
        synchronizationConfigService.save(config);
    } catch (Exception e) {
        String message = "Error during synchronization";
        log.addToLog(message);
        log.setContainsError(true);
        log.addToLog(Throwables.getStackTraceAsString(e));
        LOG.error(message, e);
    } finally {
        log.setRunning(false);
        log.setEnded(LocalDateTime.now());
        log = synchronizationLogService.save(log);
        // 
        longRunningTaskExecutor.setCount(longRunningTaskExecutor.getCounter());
        longRunningTaskExecutor.updateState();
        // Clear cache
        this.clearCache();
    }
    return config;
}
Also used : IcConnectorConfiguration(eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration) IcObjectClassImpl(eu.bcvsolutions.idm.ic.impl.IcObjectClassImpl) HashMap(java.util.HashMap) SystemEntityType(eu.bcvsolutions.idm.acc.domain.SystemEntityType) ArrayList(java.util.ArrayList) SynchronizationContext(eu.bcvsolutions.idm.acc.domain.SynchronizationContext) IcObjectClass(eu.bcvsolutions.idm.ic.api.IcObjectClass) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto) SysSystemAttributeMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto) SysSystemMappingDto(eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto) SysSystemDto(eu.bcvsolutions.idm.acc.dto.SysSystemDto) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) SysSyncActionLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncActionLogDto) AbstractSysSyncConfigDto(eu.bcvsolutions.idm.acc.dto.AbstractSysSyncConfigDto) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) SysSchemaObjectClassDto(eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto) IcFilter(eu.bcvsolutions.idm.ic.filter.api.IcFilter)

Example 35 with ProvisioningException

use of eu.bcvsolutions.idm.acc.exception.ProvisioningException in project CzechIdMng by bcvsolutions.

the class DefaultSynchronizationService method stopSynchronization.

@Override
public AbstractSysSyncConfigDto stopSynchronization(AbstractSysSyncConfigDto config) {
    Assert.notNull(config);
    // Synchronization must be running
    SysSyncLogFilter logFilter = new SysSyncLogFilter();
    logFilter.setSynchronizationConfigId(config.getId());
    logFilter.setRunning(Boolean.TRUE);
    List<SysSyncLogDto> logs = synchronizationLogService.find(logFilter, null).getContent();
    if (logs.isEmpty()) {
        throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_IS_NOT_RUNNING, ImmutableMap.of("name", config.getName()));
    }
    logs.forEach(log -> {
        log.setRunning(false);
        log.setEnded(LocalDateTime.now());
    });
    synchronizationLogService.saveAll(logs);
    return config;
}
Also used : SysSyncLogFilter(eu.bcvsolutions.idm.acc.dto.filter.SysSyncLogFilter) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) SysSyncLogDto(eu.bcvsolutions.idm.acc.dto.SysSyncLogDto)

Aggregations

ProvisioningException (eu.bcvsolutions.idm.acc.exception.ProvisioningException)41 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)20 SysSystemMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemMappingDto)19 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)17 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)16 SysSchemaObjectClassDto (eu.bcvsolutions.idm.acc.dto.SysSchemaObjectClassDto)15 SysSystemAttributeMappingDto (eu.bcvsolutions.idm.acc.dto.SysSystemAttributeMappingDto)14 IcConnectorConfiguration (eu.bcvsolutions.idm.ic.api.IcConnectorConfiguration)14 List (java.util.List)13 UUID (java.util.UUID)13 ImmutableMap (com.google.common.collect.ImmutableMap)12 AccResultCode (eu.bcvsolutions.idm.acc.domain.AccResultCode)12 SysSystemEntityDto (eu.bcvsolutions.idm.acc.dto.SysSystemEntityDto)12 SysSchemaObjectClassService (eu.bcvsolutions.idm.acc.service.api.SysSchemaObjectClassService)12 SysSystemAttributeMappingService (eu.bcvsolutions.idm.acc.service.api.SysSystemAttributeMappingService)12 SysSystemMappingService (eu.bcvsolutions.idm.acc.service.api.SysSystemMappingService)12 ArrayList (java.util.ArrayList)12 AccAccountDto (eu.bcvsolutions.idm.acc.dto.AccAccountDto)11 SysSystemAttributeMappingFilter (eu.bcvsolutions.idm.acc.dto.filter.SysSystemAttributeMappingFilter)11 SysSchemaAttributeService (eu.bcvsolutions.idm.acc.service.api.SysSchemaAttributeService)11