org.alfresco.repo.search.impl.querymodel.PropertyArgument Java Examples

The following examples show how to use org.alfresco.repo.search.impl.querymodel.PropertyArgument. 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: LuceneFTSPrefixTerm.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Q addComponent(Set<String> selectors, Map<String, Argument> functionArgs, LuceneQueryBuilderContext<Q, S, E> luceneContext, FunctionEvaluationContext functionContext)
        throws E
{
    LuceneQueryParserAdaptor<Q, S, E> lqpa = luceneContext.getLuceneQueryParserAdaptor();
    Argument argument = functionArgs.get(ARG_TERM);
    String term = (String) argument.getValue(functionContext);
    // strip trailing wildcard *
    term = term.substring(0, term.length()-1);

    argument = functionArgs.get(ARG_TOKENISATION_MODE);
    AnalysisMode mode = (AnalysisMode) argument.getValue(functionContext);
    
    PropertyArgument propArg = (PropertyArgument) functionArgs.get(ARG_PROPERTY);
    Q query;
    if (propArg != null)
    {
        String prop = propArg.getPropertyName();
        query = lqpa.getPrefixQuery(functionContext.getLuceneFieldName(prop), term, mode);
    }
    else
    {
        query = lqpa.getPrefixQuery(lqpa.getField(), term, mode);
        
    }
    return query;
}
 
Example #2
Source File: LuceneFTSFuzzyTerm.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Q addComponent(Set<String> selectors, Map<String, Argument> functionArgs, LuceneQueryBuilderContext<Q, S, E> luceneContext, FunctionEvaluationContext functionContext)
        throws E
{
    LuceneQueryParserAdaptor<Q, S, E> lqpa = luceneContext.getLuceneQueryParserAdaptor();
    Argument argument = functionArgs.get(ARG_TERM);
    String term = (String) argument.getValue(functionContext);
    argument = functionArgs.get(ARG_MIN_SIMILARITY);
    Float minSimilarity = (Float) argument.getValue(functionContext);

    PropertyArgument propArg = (PropertyArgument) functionArgs.get(ARG_PROPERTY);
    Q query;
    if (propArg != null)
    {
        String prop = propArg.getPropertyName();
        query = lqpa.getFuzzyQuery(functionContext.getLuceneFieldName(prop), term, minSimilarity);
    }
    else
    {
        query = lqpa.getFuzzyQuery(lqpa.getField(), term, minSimilarity);
        
    }
    return query;
}
 
Example #3
Source File: LuceneFTSWildTerm.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Q addComponent(Set<String> selectors, Map<String, Argument> functionArgs, LuceneQueryBuilderContext<Q, S, E> luceneContext, FunctionEvaluationContext functionContext)
        throws E
{
    LuceneQueryParserAdaptor<Q, S, E> lqpa = luceneContext.getLuceneQueryParserAdaptor();
    Argument argument = functionArgs.get(ARG_TERM);
    String term = (String) argument.getValue(functionContext);

    argument = functionArgs.get(ARG_TOKENISATION_MODE);
    AnalysisMode mode = (AnalysisMode) argument.getValue(functionContext);
    
    PropertyArgument propArg = (PropertyArgument) functionArgs.get(ARG_PROPERTY);
    Q query;
    if (propArg != null)
    {
        String prop = propArg.getPropertyName();
        query = lqpa.getWildcardQuery(functionContext.getLuceneFieldName(prop), term, mode);
    }
    else
    {
        query = lqpa.getWildcardQuery(lqpa.getField(), term, mode);
        
    }
    return query;
}
 
Example #4
Source File: LuceneIn.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public Q addComponent(Set<String> selectors, Map<String, Argument> functionArgs, LuceneQueryBuilderContext<Q, S, E> luceneContext, FunctionEvaluationContext functionContext)
        throws E
{
    LuceneQueryParserAdaptor<Q, S, E> lqpa = luceneContext.getLuceneQueryParserAdaptor();
    PropertyArgument propertyArgument = (PropertyArgument) functionArgs.get(ARG_PROPERTY);
    Argument inverseArgument = functionArgs.get(ARG_NOT);
    Boolean not = DefaultTypeConverter.INSTANCE.convert(Boolean.class, inverseArgument.getValue(functionContext));
    LiteralArgument modeArgument = (LiteralArgument) functionArgs.get(ARG_MODE);
    String modeString = DefaultTypeConverter.INSTANCE.convert(String.class, modeArgument.getValue(functionContext));
    PredicateMode mode = PredicateMode.valueOf(modeString);

    ListArgument listArgument = (ListArgument) functionArgs.get(ARG_LIST);
    Collection<Serializable> collection = (Collection<Serializable>) listArgument.getValue(functionContext);

    Q query = functionContext.buildLuceneIn(lqpa, propertyArgument.getPropertyName(), collection, not, mode);

    if (query == null)
    {
        throw new QueryModelException("No query time mapping for property  " + propertyArgument.getPropertyName() + ", it should not be allowed in predicates");
    }

    return query;
}
 
Example #5
Source File: LuceneFTSRange.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Q addComponent(Set<String> selectors, Map<String, Argument> functionArgs, LuceneQueryBuilderContext<Q, S, E> luceneContext, FunctionEvaluationContext functionContext)
        throws E
{
    LuceneQueryParserAdaptor<Q, S, E> lqpa = luceneContext.getLuceneQueryParserAdaptor();
    Argument argument = functionArgs.get(ARG_FROM_INC);
    Boolean fromInc = (Boolean) argument.getValue(functionContext);
    argument = functionArgs.get(ARG_FROM);
    String from = (String) argument.getValue(functionContext);
    argument = functionArgs.get(ARG_TO);
    String to = (String) argument.getValue(functionContext);
    argument = functionArgs.get(ARG_TO_INC);
    Boolean toInc = (Boolean) argument.getValue(functionContext);
    
    PropertyArgument propArg = (PropertyArgument) functionArgs.get(ARG_PROPERTY);
    Q query;
    if (propArg != null)
    {
        String prop = propArg.getPropertyName();
        query = lqpa.getRangeQuery(functionContext.getLuceneFieldName(prop), from, to, fromInc, toInc, AnalysisMode.DEFAULT, LuceneFunction.FIELD);
    }
    else
    {
        query = lqpa.getRangeQuery(lqpa.getField(), from, to, fromInc, toInc, AnalysisMode.DEFAULT, LuceneFunction.FIELD);
    }
    return query;
}
 
Example #6
Source File: LuceneFTSTerm.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Q addComponent(Set<String> selectors, Map<String, Argument> functionArgs, LuceneQueryBuilderContext<Q, S, E> luceneContext, FunctionEvaluationContext functionContext)
        throws E
{
    LuceneQueryParserAdaptor<Q, S, E> lqpa = luceneContext.getLuceneQueryParserAdaptor();
    Argument argument = functionArgs.get(ARG_TERM);
    String term = (String) argument.getValue(functionContext);
    argument = functionArgs.get(ARG_TOKENISATION_MODE);
    AnalysisMode mode = (AnalysisMode) argument.getValue(functionContext);

    PropertyArgument propArg = (PropertyArgument) functionArgs.get(ARG_PROPERTY);
    Q query;
    if (propArg != null)
    {
        String prop = propArg.getPropertyName();
        query = lqpa.getFieldQuery(functionContext.getLuceneFieldName(prop), term, mode, LuceneFunction.FIELD);
    }
    else
    {
        query = lqpa.getFieldQuery(lqpa.getField(), term, mode, LuceneFunction.FIELD);
        
    }
    return query;
}
 
Example #7
Source File: LuceneLike.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Q addComponent(Set<String> selectors, Map<String, Argument> functionArgs, LuceneQueryBuilderContext<Q, S, E> luceneContext, FunctionEvaluationContext functionContext)
        throws E
{
    LuceneQueryParserAdaptor<Q, S, E> lqpa = luceneContext.getLuceneQueryParserAdaptor();
    PropertyArgument propertyArgument = (PropertyArgument) functionArgs.get(ARG_PROPERTY);
    Argument inverseArgument = functionArgs.get(ARG_NOT);
    Boolean not = DefaultTypeConverter.INSTANCE.convert(Boolean.class, inverseArgument.getValue(functionContext));
    Argument expressionArgument = functionArgs.get(ARG_EXP);
    Serializable expression = expressionArgument.getValue(functionContext);

    Q query = functionContext.buildLuceneLike(lqpa, propertyArgument.getPropertyName(), expression, not);

    if (query == null)
    {
        throw new QueryModelException("No query time mapping for property  " + propertyArgument.getPropertyName() + ", it should not be allowed in predicates");
    }

    return query;
}
 
Example #8
Source File: LuceneExists.java    From alfresco-data-model with GNU Lesser General Public License v3.0 6 votes vote down vote up
public Q addComponent(Set<String> selectors, Map<String, Argument> functionArgs, LuceneQueryBuilderContext<Q, S, E> luceneContext, FunctionEvaluationContext functionContext)
        throws E
{
    LuceneQueryParserAdaptor<Q, S, E> lqpa = luceneContext.getLuceneQueryParserAdaptor();
    PropertyArgument propertyArgument = (PropertyArgument) functionArgs.get(ARG_PROPERTY);
    Argument inverseArgument = functionArgs.get(ARG_NOT);
    Boolean not = DefaultTypeConverter.INSTANCE.convert(Boolean.class, inverseArgument.getValue(functionContext));

    Q query = functionContext.buildLuceneExists(lqpa, propertyArgument.getPropertyName(), not);

    if (query == null)
    {
        throw new QueryModelException("No query time mapping for property  " + propertyArgument.getPropertyName() + ", it should not be allowed in predicates");
    }

    return query;
}
 
Example #9
Source File: PropertyAccessor.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Serializable getValue(Map<String, Argument> args, FunctionEvaluationContext context)
{
    Argument arg = args.get(ARG_PROPERTY);
    if(!(arg instanceof PropertyArgument))
    {
        throw new QueryModelException("Function "+NAME+" requires a property argument");
    }
    return arg.getValue(context);
}
 
Example #10
Source File: LuceneFTSPhrase.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Q addComponent(Set<String> selectors, Map<String, Argument> functionArgs, LuceneQueryBuilderContext<Q, S, E> luceneContext, FunctionEvaluationContext functionContext)
        throws E
{
    LuceneQueryParserAdaptor<Q, S, E> lqpa = luceneContext.getLuceneQueryParserAdaptor();
    Argument argument = functionArgs.get(ARG_PHRASE);
    String term = (String) argument.getValue(functionContext);

    Integer slop = Integer.valueOf(lqpa.getPhraseSlop());
    argument = functionArgs.get(ARG_SLOP);
    if(argument != null)
    { 
       slop = (Integer) argument.getValue(functionContext);
    }
    
    argument = functionArgs.get(ARG_TOKENISATION_MODE);
    AnalysisMode mode = (AnalysisMode) argument.getValue(functionContext);
    
    PropertyArgument propArg = (PropertyArgument) functionArgs.get(ARG_PROPERTY);
    Q query;
    if (propArg != null)
    {
        String prop = propArg.getPropertyName();
        query = lqpa.getFieldQuery(functionContext.getLuceneFieldName(prop), term, mode, slop, LuceneFunction.FIELD);
    }
    else
    {
        query = lqpa.getFieldQuery(lqpa.getField(), term, mode, slop, LuceneFunction.FIELD);
    }
    return query;
}
 
Example #11
Source File: LuceneFTSProximity.java    From alfresco-data-model with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Q addComponent(Set<String> selectors, Map<String, Argument> functionArgs, LuceneQueryBuilderContext<Q, S, E> luceneContext, FunctionEvaluationContext functionContext)
        throws E
{
    LuceneQueryParserAdaptor<Q, S, E> lqpa = luceneContext.getLuceneQueryParserAdaptor();
    Argument argument = functionArgs.get(ARG_FIRST);
    String first = (String) argument.getValue(functionContext);
    argument = functionArgs.get(ARG_LAST);
    String last = (String) argument.getValue(functionContext);

    int slop = 100;
    argument = functionArgs.get(ARG_SLOP);
    if(argument != null)
    {
        String val = (String) argument.getValue(functionContext);
        try
        {
            slop = Integer.parseInt(val);
        }
        catch(NumberFormatException nfe)
        {
            // ignore rubbish
        }
    }
    
    
    PropertyArgument propArg = (PropertyArgument) functionArgs.get(ARG_PROPERTY);
    Q query;
    if (propArg != null)
    {
        String prop = propArg.getPropertyName();
        query = lqpa.getSpanQuery(functionContext.getLuceneFieldName(prop), first, last, slop, true);
    }
    else
    {
        query = lqpa.getSpanQuery(lqpa.getField(), first, last, slop, true);
        
    }
    return query;
}
 
Example #12
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 #13
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 #14
Source File: DBFTSPrefixTerm.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void prepare(NamespaceService namespaceService, DictionaryService dictionaryService, QNameDAO qnameDAO, NodeDAO nodeDAO, TenantService tenantService, Set<String> selectors,
        Map<String, Argument> functionArgs, FunctionEvaluationContext functionContext, boolean supportBooleanFloatAndDouble)
{
    Argument argument = functionArgs.get(ARG_TERM);
    String term = (String) argument.getValue(functionContext);
    // strip trailing wildcard *
    term = term.substring(0, term.length() - 1);
    PropertyArgument propertyArgument = (PropertyArgument) functionArgs.get(ARG_PROPERTY);

    argument = functionArgs.get(ARG_TOKENISATION_MODE);
    AnalysisMode mode = (AnalysisMode) argument.getValue(functionContext);
    if (mode != AnalysisMode.IDENTIFIER)
    {
        throw new QueryModelException("Analysis mode not supported for DB " + mode);
    }

    PropertySupport propertySupport = new PropertySupport();
    propertySupport.setValue(term + "%");

    QName propertyQName = QName.createQName(DBQuery.expandQName(functionContext.getAlfrescoPropertyName(propertyArgument.getPropertyName()), namespaceService));
    propertySupport.setPropertyQName(propertyQName);
    propertySupport.setPropertyDataType(DBQuery.getDataTypeDefinition(dictionaryService, propertyQName));
    propertySupport.setPair(qnameDAO.getQName(propertyQName));
    propertySupport.setJoinCommandType(DBQuery.getJoinCommandType(propertyQName));
    propertySupport.setFieldName(DBQuery.getFieldName(dictionaryService, propertyQName, supportBooleanFloatAndDouble));
    propertySupport.setCommandType(DBQueryBuilderPredicatePartCommandType.LIKE);
    builderSupport = propertySupport;

}
 
Example #15
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 #16
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 #17
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());
}
 
Example #18
Source File: LuceneQueryModelFactory.java    From alfresco-data-model with GNU Lesser General Public License v3.0 4 votes vote down vote up
public PropertyArgument createPropertyArgument(String name, boolean queryable, boolean orderable, String selector, String propertyName)
{
    return new LucenePropertyArgument(name, queryable, orderable, selector, propertyName);
}
 
Example #19
Source File: BaseComparison.java    From alfresco-data-model with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * @return the propertyArgument - there must be a property argument of a function argument
 */
protected PropertyArgument getPropertyArgument()
{
    return propertyArgument;
}
 
Example #20
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 #21
Source File: DBQueryModelFactory.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public PropertyArgument createPropertyArgument(String name, boolean queryable, boolean orderable, String selectorAlias, String propertyName)
{
    return new DBPropertyArgument(name, queryable, orderable, selectorAlias, propertyName);
}