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;
}
Aggregations