Search in sources :

Example 1 with PropertyValueFilter

use of com.evolveum.midpoint.prism.query.PropertyValueFilter in project midpoint by Evolveum.

the class DefinitionsHelper method applyDefinition.

void applyDefinition(ProvisioningContext ctx, ObjectQuery query) throws SchemaException {
    if (query == null) {
        return;
    }
    ObjectFilter filter = query.getFilter();
    if (filter == null) {
        return;
    }
    com.evolveum.midpoint.prism.query.Visitor visitor = subFilter -> {
        if (subFilter instanceof PropertyValueFilter) {
            PropertyValueFilter<?> valueFilter = (PropertyValueFilter<?>) subFilter;
            ItemDefinition<?> definition = valueFilter.getDefinition();
            if (definition instanceof ResourceAttributeDefinition) {
                // already has a resource-related definition
                return;
            }
            if (!ShadowType.F_ATTRIBUTES.equivalent(valueFilter.getParentPath())) {
                return;
            }
            QName attributeName = valueFilter.getElementName();
            ResourceAttributeDefinition<?> attributeDefinition = ctx.getObjectDefinitionRequired().findAttributeDefinition(attributeName);
            if (attributeDefinition == null) {
                throw new TunnelException(new SchemaException("No definition for attribute " + attributeName + " in query " + query));
            }
            // noinspection unchecked,rawtypes
            valueFilter.setDefinition((ResourceAttributeDefinition) attributeDefinition);
        }
    };
    try {
        filter.accept(visitor);
    } catch (TunnelException te) {
        throw (SchemaException) te.getCause();
    }
}
Also used : ProvisioningContextFactory(com.evolveum.midpoint.provisioning.impl.ProvisioningContextFactory) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) com.evolveum.midpoint.util.exception(com.evolveum.midpoint.util.exception) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) ProvisioningContext(com.evolveum.midpoint.provisioning.impl.ProvisioningContext) Qualifier(org.springframework.beans.factory.annotation.Qualifier) RepositoryService(com.evolveum.midpoint.repo.api.RepositoryService) ObjectQueryUtil(com.evolveum.midpoint.schema.util.ObjectQueryUtil) Experimental(com.evolveum.midpoint.util.annotation.Experimental) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ShadowCaretaker(com.evolveum.midpoint.provisioning.impl.ShadowCaretaker) PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) Nullable(org.jetbrains.annotations.Nullable) PropertyValueFilter(com.evolveum.midpoint.prism.query.PropertyValueFilter) Component(org.springframework.stereotype.Component) ResourceShadowCoordinates(com.evolveum.midpoint.schema.ResourceShadowCoordinates) MiscUtil.stateCheck(com.evolveum.midpoint.util.MiscUtil.stateCheck) QName(javax.xml.namespace.QName) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) ShadowCoordinatesQualifiedObjectDelta(com.evolveum.midpoint.schema.processor.ShadowCoordinatesQualifiedObjectDelta) ShadowManager(com.evolveum.midpoint.provisioning.impl.shadows.manager.ShadowManager) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ResourceAttributeDefinition(com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition) QName(javax.xml.namespace.QName) ItemDefinition(com.evolveum.midpoint.prism.ItemDefinition) ObjectFilter(com.evolveum.midpoint.prism.query.ObjectFilter) PropertyValueFilter(com.evolveum.midpoint.prism.query.PropertyValueFilter)

Example 2 with PropertyValueFilter

use of com.evolveum.midpoint.prism.query.PropertyValueFilter in project midpoint by Evolveum.

the class PropertyRestriction method getValueFromFilter.

private Object getValueFromFilter(ValueFilter filter) throws QueryException {
    JpaPropertyDefinition def = linkDefinition.getTargetDefinition();
    Object value;
    if (filter instanceof PropertyValueFilter) {
        value = getValue((PropertyValueFilter) filter);
    } else {
        throw new QueryException("Unknown filter '" + filter + "', can't get value from it.");
    }
    Object adaptedValue = adaptValueType(value, filter);
    if (def.isEnumerated()) {
        return getRepoEnumValue((Enum) adaptedValue, def.getJpaClass());
    } else {
        return adaptedValue;
    }
}
Also used : QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) JpaPropertyDefinition(com.evolveum.midpoint.repo.sql.query.definition.JpaPropertyDefinition) PropertyValueFilter(com.evolveum.midpoint.prism.query.PropertyValueFilter)

Example 3 with PropertyValueFilter

use of com.evolveum.midpoint.prism.query.PropertyValueFilter 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 4 with PropertyValueFilter

use of com.evolveum.midpoint.prism.query.PropertyValueFilter in project midpoint by Evolveum.

the class PropertyRestriction method getValueFromFilter.

protected Object getValueFromFilter(ValueFilter filter) throws QueryException {
    JpaPropertyDefinition def = linkDefinition.getTargetDefinition();
    Object value;
    if (filter instanceof PropertyValueFilter) {
        value = getValue((PropertyValueFilter) filter);
    } else {
        throw new QueryException("Unknown filter '" + filter + "', can't get value from it.");
    }
    value = checkValueType(value, filter);
    if (def.isEnumerated()) {
        value = getRepoEnumValue((Enum) value, def.getJpaClass());
    }
    return value;
}
Also used : SchemaEnum(com.evolveum.midpoint.repo.sql.data.common.enums.SchemaEnum) QueryException(com.evolveum.midpoint.repo.sql.query.QueryException) JpaPropertyDefinition(com.evolveum.midpoint.repo.sql.query2.definition.JpaPropertyDefinition) PropertyValueFilter(com.evolveum.midpoint.prism.query.PropertyValueFilter)

Example 5 with PropertyValueFilter

use of com.evolveum.midpoint.prism.query.PropertyValueFilter in project midpoint by Evolveum.

the class DetailTableItemFilterProcessor method process.

@Override
public Predicate process(PropertyValueFilter<String> filter) throws RepositoryException {
    SqlQueryContext<?, DQ, DR> subcontext = context.subquery(detailQueryType);
    SQLQuery<?> subquery = subcontext.sqlQuery();
    subquery.where(joinOnPredicate.apply(context.path(), subcontext.path()));
    FilterProcessor<ValueFilter<?, ?>> filterProcessor = nestedItemMapper.createFilterProcessor(subcontext);
    if (filterProcessor == null) {
        throw new QueryException("Filtering on " + filter.getPath() + " is not supported.");
    // this should not even happen, we can't even create a Query that would cause this
    }
    Predicate predicate = filterProcessor.process(filter);
    if (predicate instanceof Operation && ((Operation<?>) predicate).getOperator().equals(Ops.IS_NULL)) {
        return subquery.notExists();
    } else {
        return subquery.where(predicate).exists();
    }
}
Also used : QueryException(com.evolveum.midpoint.repo.sqlbase.QueryException) ValueFilter(com.evolveum.midpoint.prism.query.ValueFilter) PropertyValueFilter(com.evolveum.midpoint.prism.query.PropertyValueFilter) Operation(com.querydsl.core.types.Operation) Predicate(com.querydsl.core.types.Predicate)

Aggregations

PropertyValueFilter (com.evolveum.midpoint.prism.query.PropertyValueFilter)7 QueryException (com.evolveum.midpoint.repo.sqlbase.QueryException)5 Predicate (com.querydsl.core.types.Predicate)3 RepositoryException (com.evolveum.midpoint.repo.sqlbase.RepositoryException)2 SqlQueryContext (com.evolveum.midpoint.repo.sqlbase.SqlQueryContext)2 FilterOperation (com.evolveum.midpoint.repo.sqlbase.filtering.item.FilterOperation)2 SinglePathItemFilterProcessor (com.evolveum.midpoint.repo.sqlbase.filtering.item.SinglePathItemFilterProcessor)2 FlexibleRelationalPathBase (com.evolveum.midpoint.repo.sqlbase.querydsl.FlexibleRelationalPathBase)2 List (java.util.List)2 Function (java.util.function.Function)2 ItemDefinition (com.evolveum.midpoint.prism.ItemDefinition)1 PrismObject (com.evolveum.midpoint.prism.PrismObject)1 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)1 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)1 EqualFilter (com.evolveum.midpoint.prism.query.EqualFilter)1 ObjectFilter (com.evolveum.midpoint.prism.query.ObjectFilter)1 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)1 ValueFilter (com.evolveum.midpoint.prism.query.ValueFilter)1 ProvisioningContext (com.evolveum.midpoint.provisioning.impl.ProvisioningContext)1 ProvisioningContextFactory (com.evolveum.midpoint.provisioning.impl.ProvisioningContextFactory)1