org.alfresco.repo.search.impl.querymodel.impl.functions.PropertyAccessor Java Examples

The following examples show how to use org.alfresco.repo.search.impl.querymodel.impl.functions.PropertyAccessor. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DBQueryModelFactory.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public DBQueryModelFactory()
{
    functions.put(Equals.NAME, new DBEquals());
    functions.put(PropertyAccessor.NAME, new DBPropertyAccessor());
    functions.put(Score.NAME, new DBScore());
    functions.put(Upper.NAME, new DBUpper());
    functions.put(Lower.NAME, new DBLower());

    functions.put(NotEquals.NAME, new DBNotEquals());
    functions.put(LessThan.NAME, new DBLessThan());
    functions.put(LessThanOrEquals.NAME, new DBLessThanOrEquals());
    functions.put(GreaterThan.NAME, new DBGreaterThan());
    functions.put(GreaterThanOrEquals.NAME, new DBGreaterThanOrEquals());

    functions.put(In.NAME, new DBIn());
    functions.put(Like.NAME, new DBLike());
    functions.put(Exists.NAME, new DBExists());

    functions.put(Child.NAME, new DBChild());
    functions.put(Descendant.NAME, new DBDescendant());

    functions.put(FTSTerm.NAME, new DBFTSTerm());
    functions.put(FTSPhrase.NAME, new DBFTSPhrase());
    functions.put(FTSProximity.NAME, new DBFTSProximity());
    functions.put(FTSRange.NAME, new DBFTSRange());
    functions.put(FTSPrefixTerm.NAME, new DBFTSPrefixTerm());
    functions.put(FTSWildTerm.NAME, new DBFTSWildTerm());
    functions.put(FTSFuzzyTerm.NAME, new DBFTSFuzzyTerm());
}
 
Example #2
Source File: LuceneQuery.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
public List<SortDefinition> buildSortDefinitions(Set<String> selectors, LuceneQueryBuilderContext<Q, S, E> luceneContext, FunctionEvaluationContext functionContext)
{
    if ((getOrderings() == null) || (getOrderings().size() == 0))
    {
        return Collections.<SortDefinition>emptyList();
    }

    ArrayList<SortDefinition> definitions = new ArrayList<SortDefinition>(getOrderings().size());

    for (Ordering ordering : getOrderings())
    {
        if (ordering.getColumn().getFunction().getName().equals(PropertyAccessor.NAME))
        {
            PropertyArgument property = (PropertyArgument) ordering.getColumn().getFunctionArguments().get(PropertyAccessor.ARG_PROPERTY);

            if (property == null)
            {
                throw new IllegalStateException();
            }

            String propertyName = property.getPropertyName();

            String fieldName = functionContext.getLuceneFieldName(propertyName);
            
            definitions.add(new SortDefinition(SortType.FIELD, fieldName, ordering.getOrder() == Order.ASCENDING));
        }
        else if (ordering.getColumn().getFunction().getName().equals(Score.NAME))
        {
            definitions.add(new SortDefinition(SortType.SCORE, null, ordering.getOrder() == Order.ASCENDING));
        }
    }

    return definitions;
}
 
Example #3
Source File: LuceneQueryModelFactory.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Default lucene query model factory and functions
 */
public LuceneQueryModelFactory()
{
    functions.put(Equals.NAME, new LuceneEquals<Q, S, E>());
    functions.put(PropertyAccessor.NAME, new LucenePropertyAccessor<Q, S, E>());
    functions.put(Score.NAME, new LuceneScore<Q, S, E>());
    functions.put(Upper.NAME, new LuceneUpper<Q, S, E>());
    functions.put(Lower.NAME, new LuceneLower<Q, S, E>());

    functions.put(NotEquals.NAME, new LuceneNotEquals<Q, S, E>());
    functions.put(LessThan.NAME, new LuceneLessThan<Q, S, E>());
    functions.put(LessThanOrEquals.NAME, new LuceneLessThanOrEquals<Q, S, E>());
    functions.put(GreaterThan.NAME, new LuceneGreaterThan<Q, S, E>());
    functions.put(GreaterThanOrEquals.NAME, new LuceneGreaterThanOrEquals<Q, S, E>());

    functions.put(In.NAME, new LuceneIn<Q, S, E>());
    functions.put(Like.NAME, new LuceneLike<Q, S, E>());
    functions.put(Exists.NAME, new LuceneExists<Q, S, E>());

    functions.put(Child.NAME, new LuceneChild<Q, S, E>());
    functions.put(Descendant.NAME, new LuceneDescendant<Q, S, E>());

    functions.put(FTSTerm.NAME, new LuceneFTSTerm<Q, S, E>());
    functions.put(FTSPhrase.NAME, new LuceneFTSPhrase<Q, S, E>());
    functions.put(FTSProximity.NAME, new LuceneFTSProximity<Q, S, E>());
    functions.put(FTSRange.NAME, new LuceneFTSRange<Q, S, E>());
    functions.put(FTSPrefixTerm.NAME, new LuceneFTSPrefixTerm<Q, S, E>());
    functions.put(FTSWildTerm.NAME, new LuceneFTSWildTerm<Q, S, E>());
    functions.put(FTSFuzzyTerm.NAME, new LuceneFTSFuzzyTerm<Q, S, E>());
}
 
Example #4
Source File: CMISQueryParser.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void checkPredicateConditionsForLike(Map<String, Argument> functionArguments,
        FunctionEvaluationContext functionEvaluationContext, Map<String, Column> columnMap)
{
    if (options.getQueryMode() == CMISQueryMode.CMS_STRICT)
    {
        PropertyArgument propertyArgument = (PropertyArgument) functionArguments.get(Like.ARG_PROPERTY);

        boolean isMultiValued = functionEvaluationContext.isMultiValued(propertyArgument.getPropertyName());

        if (isMultiValued)
        {
            throw new QueryModelException("Like is not supported for multi-valued properties");
        }

        String cmisPropertyName = propertyArgument.getPropertyName();

        Column column = columnMap.get(cmisPropertyName);
        if (column != null)
        {
            // check for function type
            if (column.getFunction().getName().equals(PropertyAccessor.NAME))
            {
                PropertyArgument arg = (PropertyArgument) column.getFunctionArguments().get(
                        PropertyAccessor.ARG_PROPERTY);
                cmisPropertyName = arg.getPropertyName();
            } else
            {
                throw new CmisInvalidArgumentException("Complex column reference not supoprted in LIKE "
                        + cmisPropertyName);
            }
        }

        PropertyDefinitionWrapper propDef = cmisDictionaryService.findPropertyByQueryName(cmisPropertyName);
        if (propDef.getPropertyDefinition().getPropertyType() != PropertyType.STRING)
        {
            throw new CmisInvalidArgumentException("LIKE is only supported against String types" + cmisPropertyName);
        }
    }
}
 
Example #5
Source File: FTSQueryParser.java    From alfresco-data-model with GNU Lesser General Public License v3.0 4 votes vote down vote up
static public PropertyArgument buildFieldReference(String argumentName, CommonTree fieldReferenceNode, QueryModelFactory factory,
        FunctionEvaluationContext functionEvaluationContext, Selector selector, Map<String, Column> columnMap)
{
    if (fieldReferenceNode.getType() != FTSParser.FIELD_REF)
    {
        throw new FTSQueryException("Not column ref  ..." + fieldReferenceNode.getText());
    }
    String fieldName = getText(fieldReferenceNode.getChild(0));
    if (columnMap != null)
    {
        for (Column column : columnMap.values())
        {
            if (column.getAlias().equals(fieldName))
            {
                // TODO: Check selector matches ...
                PropertyArgument arg = (PropertyArgument) column.getFunctionArguments().get(PropertyAccessor.ARG_PROPERTY);
                fieldName = arg.getPropertyName();
                break;
            }
        }
    }

    // prepend prefixes and name spaces

    if (fieldReferenceNode.getChildCount() > 1)
    {
        CommonTree child = (CommonTree) fieldReferenceNode.getChild(1);
        if (child.getType() == FTSParser.PREFIX)
        {
            fieldName = getText(child.getChild(0)) + ":" + fieldName;
        }
        else if (child.getType() == FTSParser.NAME_SPACE)
        {
            fieldName = getText(child.getChild(0)) + fieldName;
        }
    }

    String alias = "";
    if (selector != null)
    {
        functionEvaluationContext.checkFieldApplies(selector, fieldName);
        alias = selector.getAlias();
    }

    return factory.createPropertyArgument(argumentName, functionEvaluationContext.isQueryable(fieldName), functionEvaluationContext.isOrderable(fieldName), alias, fieldName);
}
 
Example #6
Source File: CMISQueryParser.java    From alfresco-data-model with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void checkPredicateConditionsForIn(Map<String, Argument> functionArguments,
        FunctionEvaluationContext functionEvaluationContext, Map<String, Column> columnMap)
{
    if (options.getQueryMode() == CMISQueryMode.CMS_STRICT)
    {
        PropertyArgument propertyArgument = (PropertyArgument) functionArguments.get(In.ARG_PROPERTY);
        LiteralArgument modeArgument = (LiteralArgument) functionArguments.get(In.ARG_MODE);
        String modeString = DefaultTypeConverter.INSTANCE.convert(String.class,
                modeArgument.getValue(functionEvaluationContext));
        PredicateMode mode = PredicateMode.valueOf(modeString);
        String propertyName = propertyArgument.getPropertyName();

        Column column = columnMap.get(propertyName);
        if (column != null)
        {
            // check for function type
            if (column.getFunction().getName().equals(PropertyAccessor.NAME))
            {
                PropertyArgument arg = (PropertyArgument) column.getFunctionArguments().get(
                        PropertyAccessor.ARG_PROPERTY);
                propertyName = arg.getPropertyName();
            } else
            {
                throw new CmisInvalidArgumentException("Complex column reference not supoprted in LIKE "
                        + propertyName);
            }
        }

        boolean isMultiValued = functionEvaluationContext.isMultiValued(propertyName);

        switch (mode)
        {
        case ANY:
            if (isMultiValued)
            {
                break;
            } else
            {
                throw new QueryModelException("Predicate mode " + PredicateMode.ANY
                        + " is not supported for IN and single valued properties");
            }
        case SINGLE_VALUED_PROPERTY:
            if (isMultiValued)
            {
                throw new QueryModelException("Predicate mode " + PredicateMode.SINGLE_VALUED_PROPERTY
                        + " is not supported for IN and multi-valued properties");
            } else
            {
                break;
            }
        default:
            throw new QueryModelException("Unsupported predicate mode " + mode);
        }

        PropertyDefinitionWrapper propDef = cmisDictionaryService.findPropertyByQueryName(propertyName);
        if (propDef.getPropertyDefinition().getPropertyType() == PropertyType.BOOLEAN)
        {
            throw new QueryModelException("In is not supported for properties of type Boolean");
        }
    }

}
 
Example #7
Source File: CMISQueryParser.java    From alfresco-data-model with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void checkPredicateConditionsForComparisons(Function function, Map<String, Argument> functionArguments,
        FunctionEvaluationContext functionEvaluationContext, Map<String, Column> columnMap)
{
    if (options.getQueryMode() == CMISQueryMode.CMS_STRICT)
    {
        ((BaseComparison) function).setPropertyAndStaticArguments(functionArguments);
        String propertyName = ((BaseComparison) function).getPropertyName();
        LiteralArgument modeArgument = (LiteralArgument) functionArguments.get(BaseComparison.ARG_MODE);
        String modeString = DefaultTypeConverter.INSTANCE.convert(String.class,
                modeArgument.getValue(functionEvaluationContext));
        PredicateMode mode = PredicateMode.valueOf(modeString);

        Column column = columnMap.get(propertyName);
        if (column != null)
        {
            // check for function type
            if (column.getFunction().getName().equals(PropertyAccessor.NAME))
            {
                PropertyArgument arg = (PropertyArgument) column.getFunctionArguments().get(
                        PropertyAccessor.ARG_PROPERTY);
                propertyName = arg.getPropertyName();
            } else
            {
                throw new CmisInvalidArgumentException("Complex column reference not supoprted in LIKE "
                        + propertyName);
            }
        }

        boolean isMultiValued = functionEvaluationContext.isMultiValued(propertyName);

        switch (mode)
        {
        case ANY:
            if (isMultiValued)
            {
                if (function.getName().equals(Equals.NAME))
                {
                    break;
                } else
                {
                    throw new QueryModelException("Predicate mode " + PredicateMode.ANY + " is only supported for "
                            + Equals.NAME + " (and multi-valued properties).");
                }
            } else
            {
                throw new QueryModelException("Predicate mode " + PredicateMode.ANY + " is not supported for "
                        + function.getName() + " and single valued properties");
            }
        case SINGLE_VALUED_PROPERTY:
            if (isMultiValued)
            {
                throw new QueryModelException("Predicate mode " + PredicateMode.SINGLE_VALUED_PROPERTY
                        + " is not supported for " + function.getName() + " and multi-valued properties");
            } else
            {
                break;
            }
        default:
            throw new QueryModelException("Unsupported predicate mode " + mode);
        }

        // limit support for ID and Boolean

        PropertyDefinitionWrapper propDef = cmisDictionaryService.findPropertyByQueryName(propertyName);
        if (propDef.getPropertyDefinition().getPropertyType() == PropertyType.ID)
        {
            if (function.getName().equals(Equals.NAME) || function.getName().equals(NotEquals.NAME))
            {
                return;
            } else
            {
                throw new QueryModelException("Comparison " + function.getName()
                        + " is not supported for properties of type ID");
            }
        } else if (propDef.getPropertyDefinition().getPropertyType() == PropertyType.BOOLEAN)
        {
            if (function.getName().equals(Equals.NAME))
            {
                return;
            } else
            {
                throw new QueryModelException("Comparison " + function.getName()
                        + " is not supported for properties of type Boolean");
            }
        }
    }

}
 
Example #8
Source File: CMISQueryParser.java    From alfresco-data-model with GNU Lesser General Public License v3.0 4 votes vote down vote up
public PropertyArgument buildColumnReference(String argumentName, CommonTree columnReferenceNode,
        QueryModelFactory factory, Map<String, Selector> selectors, Map<String, Column> columnMap)
{
    String cmisPropertyName = columnReferenceNode.getChild(0).getText();
    String qualifier = "";
    if (columnReferenceNode.getChildCount() > 1)
    {
        qualifier = columnReferenceNode.getChild(1).getText();
    }

    if ((qualifier == "") && (columnMap != null))
    {
        Column column = columnMap.get(cmisPropertyName);
        if (column != null)
        {
            // check for function type
            if (column.getFunction().getName().equals(PropertyAccessor.NAME))
            {
                PropertyArgument arg = (PropertyArgument) column.getFunctionArguments().get(
                        PropertyAccessor.ARG_PROPERTY);
                cmisPropertyName = arg.getPropertyName();
                qualifier = arg.getSelector();
            } else
            {
                // TODO: should be able to return non property arguments
                // The implementation should throw out what it can not
                // support at build time.
                throw new CmisInvalidArgumentException(
                        "Complex column reference unsupported (only direct column references are currently supported) "
                                + cmisPropertyName);
            }
        }
    }

    PropertyDefinitionWrapper propDef = cmisDictionaryService.findPropertyByQueryName(cmisPropertyName);
    if (propDef == null)
    {
        throw new CmisInvalidArgumentException("Unknown column/property " + cmisPropertyName);
    }

    if (selectors != null)
    {
        Selector selector = selectors.get(qualifier);
        if (selector == null)
        {
            if ((qualifier.equals("")) && (selectors.size() == 1))
            {
                selector = selectors.get(selectors.keySet().iterator().next());
            } else
            {
                throw new CmisInvalidArgumentException("No selector for " + qualifier);
            }
        }

        TypeDefinitionWrapper typeDef = cmisDictionaryService.findTypeForClass(selector.getType(), validScopes);
        if (typeDef == null)
        {
            throw new CmisInvalidArgumentException("Type unsupported in CMIS queries: " + selector.getAlias());
        }

        // Check column/property applies to selector/type

        if (typeDef.getPropertyById(propDef.getPropertyId()) == null)
        {
            throw new CmisInvalidArgumentException("Invalid column for "
                    + typeDef.getTypeDefinition(false).getQueryName() + "." + cmisPropertyName);
        }
    }

    if (options.getQueryMode() == CMISQueryMode.CMS_STRICT)
    {
        if (!propDef.getPropertyDefinition().isQueryable())
        {
            throw new CmisInvalidArgumentException("Column is not queryable " + qualifier + "." + cmisPropertyName);
        }
    }
    return factory.createPropertyArgument(argumentName, propDef.getPropertyDefinition().isQueryable(), propDef
            .getPropertyDefinition().isOrderable(), qualifier, propDef.getPropertyId());
}