Search in sources :

Example 1 with FilterOperation

use of com.evolveum.midpoint.repo.sqlbase.filtering.item.FilterOperation in project midpoint by Evolveum.

the class ExtensionItemFilterProcessor method process.

@Override
public Predicate process(ValueFilter<?, ?> filter) throws RepositoryException {
    ItemDefinition<?> definition = filter.getDefinition();
    Objects.requireNonNull(definition, "Item '" + filter.getPath() + "' without definition used in query.");
    MExtItem extItem = new ExtensionProcessor((SqaleRepoContext) context.repositoryContext()).resolveExtensionItem(definition, holderType);
    assert definition != null;
    if (extItem == null) {
        throw new QueryException("Extension item " + definition.getItemName() + " is not indexed, filter: " + filter);
    }
    if (definition instanceof PrismReferenceDefinition) {
        return processReference(extItem, (RefFilter) filter);
    }
    PropertyValueFilter<?> propertyValueFilter = (PropertyValueFilter<?>) filter;
    ValueFilterValues<?, ?> values = ValueFilterValues.from(propertyValueFilter);
    FilterOperation operation = operation(filter);
    List<?> filterValues = filter.getValues();
    if (filterValues == null || filterValues.isEmpty()) {
        if (operation.isAnyEqualOperation()) {
            return extItemIsNull(extItem);
        } else {
            throw new QueryException("Null value for other than EQUAL filter: " + filter);
        }
    }
    if (extItem.valueType.equals(STRING_TYPE)) {
        return processString(extItem, values, operation, filter);
    }
    // TODO for anything lower we don't support multi-value filter yet, but the solution from string can be adapted.
    if (filterValues.size() > 1) {
        throw new QueryException("Multiple values in filter are not supported for extension items: " + filter);
    }
    if (ExtUtils.isEnumDefinition((PrismPropertyDefinition<?>) definition)) {
        return processEnum(extItem, values, operation, filter);
    } else if (extItem.valueType.equals(INT_TYPE) || extItem.valueType.equals(INTEGER_TYPE) || extItem.valueType.equals(LONG_TYPE) || extItem.valueType.equals(SHORT_TYPE) || extItem.valueType.equals(DOUBLE_TYPE) || extItem.valueType.equals(FLOAT_TYPE) || extItem.valueType.equals(DECIMAL_TYPE)) {
        return processNumeric(extItem, values, operation, filter);
    } else if (extItem.valueType.equals(BOOLEAN_TYPE)) {
        return processBoolean(extItem, values, operation, filter);
    } else if (extItem.valueType.equals(DATETIME_TYPE)) {
        // noinspection unchecked
        PropertyValueFilter<XMLGregorianCalendar> dateTimeFilter = (PropertyValueFilter<XMLGregorianCalendar>) filter;
        return processString(extItem, ValueFilterValues.from(dateTimeFilter, ExtUtils::extensionDateTime), operation, filter);
    } else if (extItem.valueType.equals(POLY_STRING_TYPE)) {
        return processPolyString(extItem, values, operation, propertyValueFilter);
    }
    throw new QueryException("Unsupported filter for extension item: " + filter);
}
Also used : ExtUtils(com.evolveum.midpoint.repo.sqale.ExtUtils) SqaleRepoContext(com.evolveum.midpoint.repo.sqale.SqaleRepoContext) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) MExtItem(com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem) FilterOperation(com.evolveum.midpoint.repo.sqlbase.filtering.item.FilterOperation) ExtensionProcessor(com.evolveum.midpoint.repo.sqale.ExtensionProcessor) PropertyValueFilter(com.evolveum.midpoint.prism.query.PropertyValueFilter)

Example 2 with FilterOperation

use of com.evolveum.midpoint.repo.sqlbase.filtering.item.FilterOperation in project midpoint by Evolveum.

the class AuditCustomColumnItemFilterProcessor method createPredicate.

private Predicate createPredicate(PropertyValueFilter<AuditEventRecordCustomColumnPropertyType> filter, AuditEventRecordCustomColumnPropertyType customColumnPropertyType) throws QueryException {
    FilterOperation operation = operation(filter);
    Path<?> path = context.path().getPath(customColumnPropertyType.getName());
    if (customColumnPropertyType.getValue() == null) {
        if (operation.isAnyEqualOperation()) {
            return ExpressionUtils.predicate(Ops.IS_NULL, path);
        } else {
            throw new QueryException("Null value for other than EQUAL filter: " + filter);
        }
    }
    return singleValuePredicate(path, operation, customColumnPropertyType.getValue());
}
Also used : QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) FilterOperation(com.evolveum.midpoint.repo.sqlbase.filtering.item.FilterOperation)

Example 3 with FilterOperation

use of com.evolveum.midpoint.repo.sqlbase.filtering.item.FilterOperation in project midpoint by Evolveum.

the class AuditCustomColumnItemFilterProcessor method createPredicate.

private Predicate createPredicate(PropertyValueFilter<AuditEventRecordCustomColumnPropertyType> filter, AuditEventRecordCustomColumnPropertyType customColumnPropertyType) throws QueryException {
    FilterOperation operation = operation(filter);
    Path<?> path = context.path().getPath(customColumnPropertyType.getName());
    if (customColumnPropertyType.getValue() == null) {
        if (operation.isAnyEqualOperation()) {
            return ExpressionUtils.predicate(Ops.IS_NULL, path);
        } else {
            throw new QueryException("Null value for other than EQUAL filter: " + filter);
        }
    }
    return singleValuePredicate(path, operation, customColumnPropertyType.getValue());
}
Also used : QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) FilterOperation(com.evolveum.midpoint.repo.sqlbase.filtering.item.FilterOperation)

Example 4 with FilterOperation

use of com.evolveum.midpoint.repo.sqlbase.filtering.item.FilterOperation in project midpoint by Evolveum.

the class UuidItemFilterProcessor method process.

@Override
public Predicate process(PropertyValueFilter<Object> filter) throws RepositoryException {
    // This is adapted version of ItemValueFilterProcessor#createBinaryCondition.
    // Because conversion is different for various operations, we don't use ValueFilterValues.
    FilterOperation operation = operation(filter);
    if (filter.getValues() == null || filter.getValues().isEmpty()) {
        if (operation.isAnyEqualOperation()) {
            return ExpressionUtils.predicate(Ops.IS_NULL, path);
        } else {
            throw new QueryException("Null value for other than EQUAL filter: " + filter);
        }
    }
    if (filter.getValues().size() > 1) {
        if (operation.isAnyEqualOperation()) {
            List<UUID> oids = filter.getValues().stream().map(s -> UUID.fromString(uuidString(s.getValue()))).collect(Collectors.toList());
            return ExpressionUtils.predicate(Ops.IN, operation.treatPathForIn(path), ConstantImpl.create(oids));
        } else {
            throw new QueryException("Multi-value for other than EQUAL filter: " + filter);
        }
    }
    // noinspection ConstantConditions
    String oid = uuidString(filter.getSingleValue().getValue());
    if (oid.length() < OID_MIN.length()) {
        // operator is enough, ignore case doesn't play any role for UUID type
        return processIncompleteOid(oid, operation.operator, filter);
    } else {
        // singleValuePredicate() treatment is not necessary, let's just create the predicate
        return ExpressionUtils.predicate(operation.operator, path, ConstantImpl.create(UUID.fromString(oid)));
    }
}
Also used : FlexibleRelationalPathBase(com.evolveum.midpoint.repo.sqlbase.querydsl.FlexibleRelationalPathBase) SqlQueryContext(com.evolveum.midpoint.repo.sqlbase.SqlQueryContext) ExpressionUtils(com.querydsl.core.types.ExpressionUtils) FilterOperation(com.evolveum.midpoint.repo.sqlbase.filtering.item.FilterOperation) Ops(com.querydsl.core.types.Ops) QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) UUID(java.util.UUID) UuidPath(com.evolveum.midpoint.repo.sqlbase.querydsl.UuidPath) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) PropertyValueFilter(com.evolveum.midpoint.prism.query.PropertyValueFilter) List(java.util.List) SinglePathItemFilterProcessor(com.evolveum.midpoint.repo.sqlbase.filtering.item.SinglePathItemFilterProcessor) ConstantImpl(com.querydsl.core.types.ConstantImpl) Predicate(com.querydsl.core.types.Predicate) RepositoryException(com.evolveum.midpoint.repo.sqlbase.RepositoryException) SimpleItemFilterProcessor(com.evolveum.midpoint.repo.sqlbase.filtering.item.SimpleItemFilterProcessor) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) FilterOperation(com.evolveum.midpoint.repo.sqlbase.filtering.item.FilterOperation) UUID(java.util.UUID)

Aggregations

QueryException (com.evolveum.midpoint.repo.sqlbase.QueryException)4 FilterOperation (com.evolveum.midpoint.repo.sqlbase.filtering.item.FilterOperation)4 PropertyValueFilter (com.evolveum.midpoint.prism.query.PropertyValueFilter)2 ExtUtils (com.evolveum.midpoint.repo.sqale.ExtUtils)1 ExtensionProcessor (com.evolveum.midpoint.repo.sqale.ExtensionProcessor)1 SqaleRepoContext (com.evolveum.midpoint.repo.sqale.SqaleRepoContext)1 MExtItem (com.evolveum.midpoint.repo.sqale.qmodel.ext.MExtItem)1 RepositoryException (com.evolveum.midpoint.repo.sqlbase.RepositoryException)1 SqlQueryContext (com.evolveum.midpoint.repo.sqlbase.SqlQueryContext)1 SimpleItemFilterProcessor (com.evolveum.midpoint.repo.sqlbase.filtering.item.SimpleItemFilterProcessor)1 SinglePathItemFilterProcessor (com.evolveum.midpoint.repo.sqlbase.filtering.item.SinglePathItemFilterProcessor)1 FlexibleRelationalPathBase (com.evolveum.midpoint.repo.sqlbase.querydsl.FlexibleRelationalPathBase)1 UuidPath (com.evolveum.midpoint.repo.sqlbase.querydsl.UuidPath)1 RawType (com.evolveum.prism.xml.ns._public.types_3.RawType)1 ConstantImpl (com.querydsl.core.types.ConstantImpl)1 ExpressionUtils (com.querydsl.core.types.ExpressionUtils)1 Ops (com.querydsl.core.types.Ops)1 Predicate (com.querydsl.core.types.Predicate)1 List (java.util.List)1 UUID (java.util.UUID)1