Search in sources :

Example 1 with IcFilterOperationType

use of eu.bcvsolutions.idm.ic.domain.IcFilterOperationType in project CzechIdMng by bcvsolutions.

the class AbstractSynchronizationExecutor method resolveSynchronizationFilter.

/**
 * Compile filter for search from filter attribute and filter script
 *
 * @param config
 * @return
 */
protected IcFilter resolveSynchronizationFilter(AbstractSysSyncConfigDto config) {
    // If is reconciliation, then is filter null
    if (config.isReconciliation()) {
        return null;
    }
    IcFilter filter = null;
    AttributeMapping filterAttributeMapping = null;
    if (config.getFilterAttribute() != null) {
        filterAttributeMapping = systemAttributeMappingService.get(config.getFilterAttribute());
    }
    String configToken = config.getToken();
    String filterScript = config.getCustomFilterScript();
    if (filterAttributeMapping == null && configToken == null && StringUtils.isEmpty(filterScript)) {
        return null;
    }
    if (filterAttributeMapping != null) {
        Object transformedValue = systemAttributeMappingService.transformValueToResource(null, configToken, filterAttributeMapping, config);
        if (transformedValue != null) {
            SysSchemaAttributeDto schemaAttributeDto = schemaAttributeService.get(filterAttributeMapping.getSchemaAttribute());
            IcAttributeImpl filterAttribute = new IcAttributeImpl(schemaAttributeDto.getName(), transformedValue);
            switch(config.getFilterOperation()) {
                case GREATER_THAN:
                    filter = IcFilterBuilder.greaterThan(filterAttribute);
                    break;
                case LESS_THAN:
                    filter = IcFilterBuilder.lessThan(filterAttribute);
                    break;
                case EQUAL_TO:
                    filter = IcFilterBuilder.equalTo(filterAttribute);
                    break;
                case CONTAINS:
                    filter = IcFilterBuilder.contains(filterAttribute);
                    break;
                case ENDS_WITH:
                    filter = IcFilterBuilder.endsWith(filterAttribute);
                    break;
                case STARTS_WITH:
                    filter = IcFilterBuilder.startsWith(filterAttribute);
                    break;
            }
        }
    }
    if (StringUtils.hasLength(filterScript)) {
        Map<String, Object> variables = new HashMap<>();
        variables.put("filter", filter);
        variables.put("token", configToken);
        List<Class<?>> allowTypes = new ArrayList<>();
        // Allow all IC filter operator
        for (IcFilterOperationType operation : IcFilterOperationType.values()) {
            allowTypes.add(operation.getImplementation());
        }
        allowTypes.add(IcAndFilter.class);
        allowTypes.add(IcOrFilter.class);
        allowTypes.add(IcFilterBuilder.class);
        allowTypes.add(IcAttributeImpl.class);
        allowTypes.add(IcAttribute.class);
        Object filterObj = groovyScriptService.evaluate(filterScript, variables, allowTypes);
        if (filterObj != null && !(filterObj instanceof IcFilter)) {
            throw new ProvisioningException(AccResultCode.SYNCHRONIZATION_FILTER_VALUE_WRONG_TYPE, ImmutableMap.of("type", filterObj.getClass().getName()));
        }
        filter = (IcFilter) filterObj;
    }
    return filter;
}
Also used : HashMap(java.util.HashMap) SysSchemaAttributeDto(eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto) ArrayList(java.util.ArrayList) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IcAttributeImpl(eu.bcvsolutions.idm.ic.impl.IcAttributeImpl) AttributeMapping(eu.bcvsolutions.idm.acc.domain.AttributeMapping) ProvisioningException(eu.bcvsolutions.idm.acc.exception.ProvisioningException) IcConnectorObject(eu.bcvsolutions.idm.ic.api.IcConnectorObject) IcObjectClass(eu.bcvsolutions.idm.ic.api.IcObjectClass) IcFilterOperationType(eu.bcvsolutions.idm.ic.domain.IcFilterOperationType) IcFilter(eu.bcvsolutions.idm.ic.filter.api.IcFilter)

Aggregations

AttributeMapping (eu.bcvsolutions.idm.acc.domain.AttributeMapping)1 SysSchemaAttributeDto (eu.bcvsolutions.idm.acc.dto.SysSchemaAttributeDto)1 ProvisioningException (eu.bcvsolutions.idm.acc.exception.ProvisioningException)1 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)1 IcConnectorObject (eu.bcvsolutions.idm.ic.api.IcConnectorObject)1 IcObjectClass (eu.bcvsolutions.idm.ic.api.IcObjectClass)1 IcFilterOperationType (eu.bcvsolutions.idm.ic.domain.IcFilterOperationType)1 IcFilter (eu.bcvsolutions.idm.ic.filter.api.IcFilter)1 IcAttributeImpl (eu.bcvsolutions.idm.ic.impl.IcAttributeImpl)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1