Search in sources :

Example 1 with PropertyArgument

use of org.alfresco.repo.search.impl.querymodel.PropertyArgument in project alfresco-repository by Alfresco.

the class DBFTSPrefixTerm method prepare.

/*
     * (non-Javadoc)
     * @see
     * org.alfresco.repo.search.impl.querymodel.impl.db.DBQueryBuilderComponent#prepare(org.alfresco.service.namespace
     * .NamespaceService, org.alfresco.service.cmr.dictionary.DictionaryService,
     * org.alfresco.repo.domain.qname.QNameDAO, org.alfresco.repo.domain.node.NodeDAO, java.util.Set, java.util.Map,
     * org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext)
     */
@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;
}
Also used : PropertyArgument(org.alfresco.repo.search.impl.querymodel.PropertyArgument) Argument(org.alfresco.repo.search.impl.querymodel.Argument) QName(org.alfresco.service.namespace.QName) QueryModelException(org.alfresco.repo.search.impl.querymodel.QueryModelException) AnalysisMode(org.alfresco.repo.search.adaptor.lucene.AnalysisMode) PropertyArgument(org.alfresco.repo.search.impl.querymodel.PropertyArgument) PropertySupport(org.alfresco.repo.search.impl.querymodel.impl.db.PropertySupport)

Example 2 with PropertyArgument

use of org.alfresco.repo.search.impl.querymodel.PropertyArgument in project alfresco-repository by Alfresco.

the class CMISResultSetRow method getValue.

/*
     * (non-Javadoc)
     * 
     * @see org.alfresco.cmis.search.CMISResultSetRow#getValue(java.lang.String)
     */
public Serializable getValue(String columnName) {
    CmisFunctionEvaluationContext context = new CmisFunctionEvaluationContext();
    context.setCmisDictionaryService(cmisDictionaryService);
    context.setNodeRefs(nodeRefs);
    context.setNodeInfos(nodeInfos);
    context.setNodeService(nodeService);
    context.setScores(scores);
    context.setScore(getScore());
    for (Column column : query.getColumns()) {
        // When an SCORE selector is included, score must be adapted to range 0..1 due to CMIS specification
        if (column.getFunction() != null && column.getFunction().getName().equals(Score.NAME)) {
            return getNormalisedScore();
        } else if (column.getAlias().equals(columnName)) {
            return column.getFunction().getValue(column.getFunctionArguments(), context);
        }
        // TODO: check SQL 92 for single alias table behaviour for selectors
        if (nodeRefs.size() == 1) {
            if (column.getFunction().getName().equals(PropertyAccessor.NAME)) {
                PropertyArgument arg = (PropertyArgument) column.getFunctionArguments().get(PropertyAccessor.ARG_PROPERTY);
                String propertyName = arg.getPropertyName();
                if (propertyName.equals(columnName)) {
                    return column.getFunction().getValue(column.getFunctionArguments(), context);
                }
                StringBuilder builder = new StringBuilder();
                builder.append(arg.getSelector()).append(".").append(propertyName);
                propertyName = builder.toString();
                if (propertyName.equals(columnName)) {
                    return column.getFunction().getValue(column.getFunctionArguments(), context);
                }
            }
        } else {
            if (column.getFunction().getName().equals(PropertyAccessor.NAME)) {
                PropertyArgument arg = (PropertyArgument) column.getFunctionArguments().get(PropertyAccessor.ARG_PROPERTY);
                StringBuilder builder = new StringBuilder();
                builder.append(arg.getSelector()).append(".").append(arg.getPropertyName());
                String propertyName = builder.toString();
                if (propertyName.equals(columnName)) {
                    return column.getFunction().getValue(column.getFunctionArguments(), context);
                }
            }
        }
    }
    return null;
}
Also used : Column(org.alfresco.repo.search.impl.querymodel.Column) PropertyArgument(org.alfresco.repo.search.impl.querymodel.PropertyArgument)

Example 3 with PropertyArgument

use of org.alfresco.repo.search.impl.querymodel.PropertyArgument in project alfresco-repository by Alfresco.

the class DBLike method prepare.

/* (non-Javadoc)
     * @see org.alfresco.repo.search.impl.querymodel.impl.db.DBQueryBuilderComponent#prepare(org.alfresco.service.namespace.NamespaceService, org.alfresco.service.cmr.dictionary.DictionaryService, org.alfresco.repo.domain.qname.QNameDAO, org.alfresco.repo.domain.node.NodeDAO, java.util.Set, java.util.Map, org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext)
     */
@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) {
    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);
    String expression = expressionArgument.getValue(functionContext).toString();
    if (propertyArgument.getPropertyName().equals(PropertyIds.CONTENT_STREAM_MIME_TYPE)) {
        PropertySupport propertySupport = new PropertySupport();
        propertySupport.setValue(expression);
        QName basePropertyQName = QName.createQName(DBQuery.expandQName(functionContext.getAlfrescoPropertyName(propertyArgument.getPropertyName()), namespaceService));
        propertySupport.setPropertyQName(basePropertyQName);
        propertySupport.setPropertyDataType(DBQuery.getDataTypeDefinition(dictionaryService, basePropertyQName));
        propertySupport.setPair(qnameDAO.getQName(basePropertyQName));
        propertySupport.setJoinCommandType(DBQueryBuilderJoinCommandType.CONTENT_MIMETYPE);
        propertySupport.setFieldName("mimetype_str");
        if ((not != null) && (not.equals(Boolean.TRUE))) {
            propertySupport.setCommandType(DBQueryBuilderPredicatePartCommandType.NOTLIKE);
        } else {
            propertySupport.setCommandType(DBQueryBuilderPredicatePartCommandType.LIKE);
        }
        builderSupport = propertySupport;
    } else {
        PropertySupport propertySupport = new PropertySupport();
        propertySupport.setValue(expression);
        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));
        if ((not != null) && (not.equals(Boolean.TRUE))) {
            propertySupport.setCommandType(DBQueryBuilderPredicatePartCommandType.NOTLIKE);
        } else {
            propertySupport.setCommandType(DBQueryBuilderPredicatePartCommandType.LIKE);
        }
        builderSupport = propertySupport;
    }
}
Also used : PropertyArgument(org.alfresco.repo.search.impl.querymodel.PropertyArgument) Argument(org.alfresco.repo.search.impl.querymodel.Argument) QName(org.alfresco.service.namespace.QName) PropertyArgument(org.alfresco.repo.search.impl.querymodel.PropertyArgument) PropertySupport(org.alfresco.repo.search.impl.querymodel.impl.db.PropertySupport)

Example 4 with PropertyArgument

use of org.alfresco.repo.search.impl.querymodel.PropertyArgument in project alfresco-repository by Alfresco.

the class DBExists method prepare.

/*
     * (non-Javadoc)
     * @see
     * org.alfresco.repo.search.impl.querymodel.impl.db.DBQueryBuilderComponent#prepare(org.alfresco.service.namespace
     * .NamespaceService, org.alfresco.service.cmr.dictionary.DictionaryService,
     * org.alfresco.repo.domain.qname.QNameDAO, org.alfresco.repo.domain.node.NodeDAO, java.util.Set, java.util.Map,
     * org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext)
     */
@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) {
    PropertyArgument propertyArgument = (PropertyArgument) functionArgs.get(ARG_PROPERTY);
    Argument inverseArgument = functionArgs.get(ARG_NOT);
    Boolean not = DefaultTypeConverter.INSTANCE.convert(Boolean.class, inverseArgument.getValue(functionContext));
    if (propertyArgument.getPropertyName().equals(PropertyIds.PARENT_ID)) {
        ParentSupport parentSupport = new ParentSupport();
        if ((not != null) && (not.equals(Boolean.TRUE))) {
            parentSupport.setCommandType(DBQueryBuilderPredicatePartCommandType.NOTEXISTS);
            parentSupport.setLeftOuter(true);
        } else {
            parentSupport.setCommandType(DBQueryBuilderPredicatePartCommandType.EXISTS);
        }
        builderSupport = parentSupport;
    } else if (propertyArgument.getPropertyName().equals(PropertyIds.OBJECT_ID)) {
        UUIDSupport uuidSupport = new UUIDSupport();
        if ((not != null) && (not.equals(Boolean.TRUE))) {
            uuidSupport.setCommandType(DBQueryBuilderPredicatePartCommandType.NOTEXISTS);
            uuidSupport.setLeftOuter(true);
        } else {
            uuidSupport.setCommandType(DBQueryBuilderPredicatePartCommandType.EXISTS);
        }
        builderSupport = uuidSupport;
    } else if (propertyArgument.getPropertyName().equals(PropertyIds.OBJECT_TYPE_ID)) {
        TypeSupport typeSupport = new TypeSupport();
        if ((not != null) && (not.equals(Boolean.TRUE))) {
            typeSupport.setCommandType(DBQueryBuilderPredicatePartCommandType.NOTEXISTS);
            typeSupport.setJoinType(JoinType.LEFT);
        } else {
            typeSupport.setCommandType(DBQueryBuilderPredicatePartCommandType.EXISTS);
        }
        builderSupport = typeSupport;
    } else if (propertyArgument.getPropertyName().equals(PropertyIds.BASE_TYPE_ID)) {
        TypeSupport typeSupport = new TypeSupport();
        if ((not != null) && (not.equals(Boolean.TRUE))) {
            typeSupport.setCommandType(DBQueryBuilderPredicatePartCommandType.NOTEXISTS);
            typeSupport.setJoinType(JoinType.LEFT);
        } else {
            typeSupport.setCommandType(DBQueryBuilderPredicatePartCommandType.EXISTS);
        }
        builderSupport = typeSupport;
    } else if (propertyArgument.getPropertyName().equals(PropertyIds.CONTENT_STREAM_MIME_TYPE)) {
        PropertySupport propertySupport = new PropertySupport();
        QName basePropertyQName = QName.createQName(DBQuery.expandQName(functionContext.getAlfrescoPropertyName(propertyArgument.getPropertyName()), namespaceService));
        propertySupport.setPropertyQName(basePropertyQName);
        propertySupport.setPropertyDataType(DBQuery.getDataTypeDefinition(dictionaryService, basePropertyQName));
        propertySupport.setPair(qnameDAO.getQName(basePropertyQName));
        propertySupport.setJoinCommandType(DBQueryBuilderJoinCommandType.CONTENT_MIMETYPE);
        propertySupport.setFieldName("mimetype_str");
        if ((not != null) && (not.equals(Boolean.TRUE))) {
            propertySupport.setCommandType(DBQueryBuilderPredicatePartCommandType.NOTEXISTS);
            propertySupport.setLeftOuter(true);
        } else {
            propertySupport.setCommandType(DBQueryBuilderPredicatePartCommandType.EXISTS);
        }
        builderSupport = propertySupport;
    } else if (propertyArgument.getPropertyName().equals(PropertyIds.CONTENT_STREAM_LENGTH)) {
        PropertySupport propertySupport = new PropertySupport();
        QName basePropertyQName = QName.createQName(DBQuery.expandQName(functionContext.getAlfrescoPropertyName(propertyArgument.getPropertyName()), namespaceService));
        propertySupport.setPropertyQName(basePropertyQName);
        propertySupport.setPropertyDataType(DBQuery.getDataTypeDefinition(dictionaryService, basePropertyQName));
        propertySupport.setPair(qnameDAO.getQName(basePropertyQName));
        propertySupport.setJoinCommandType(DBQueryBuilderJoinCommandType.CONTENT_URL);
        propertySupport.setFieldName("content_size");
        if ((not != null) && (not.equals(Boolean.TRUE))) {
            propertySupport.setCommandType(DBQueryBuilderPredicatePartCommandType.NOTEXISTS);
            propertySupport.setLeftOuter(true);
        } else {
            propertySupport.setCommandType(DBQueryBuilderPredicatePartCommandType.EXISTS);
        }
        builderSupport = propertySupport;
    } else {
        PropertySupport propertySupport = new PropertySupport();
        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));
        if ((not != null) && (not.equals(Boolean.TRUE))) {
            propertySupport.setCommandType(DBQueryBuilderPredicatePartCommandType.NOTEXISTS);
            propertySupport.setLeftOuter(true);
        } else {
            propertySupport.setCommandType(DBQueryBuilderPredicatePartCommandType.EXISTS);
        }
        builderSupport = propertySupport;
    }
}
Also used : Argument(org.alfresco.repo.search.impl.querymodel.Argument) PropertyArgument(org.alfresco.repo.search.impl.querymodel.PropertyArgument) UUIDSupport(org.alfresco.repo.search.impl.querymodel.impl.db.UUIDSupport) TypeSupport(org.alfresco.repo.search.impl.querymodel.impl.db.TypeSupport) QName(org.alfresco.service.namespace.QName) ParentSupport(org.alfresco.repo.search.impl.querymodel.impl.db.ParentSupport) PropertyArgument(org.alfresco.repo.search.impl.querymodel.PropertyArgument) PropertySupport(org.alfresco.repo.search.impl.querymodel.impl.db.PropertySupport)

Example 5 with PropertyArgument

use of org.alfresco.repo.search.impl.querymodel.PropertyArgument in project alfresco-repository by Alfresco.

the class DBFTSPhrase method prepare.

/*
     * (non-Javadoc)
     * @see
     * org.alfresco.repo.search.impl.querymodel.impl.db.DBQueryBuilderComponent#prepare(org.alfresco.service.namespace
     * .NamespaceService, org.alfresco.service.cmr.dictionary.DictionaryService,
     * org.alfresco.repo.domain.qname.QNameDAO, org.alfresco.repo.domain.node.NodeDAO, java.util.Set, java.util.Map,
     * org.alfresco.repo.search.impl.querymodel.FunctionEvaluationContext)
     */
@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_PHRASE);
    String term = (String) argument.getValue(functionContext);
    PropertyArgument propArg = (PropertyArgument) functionArgs.get(ARG_PROPERTY);
    if ((propArg == null) || (propArg.getPropertyName() == null)) {
        throw new QueryModelException("Default field not supported");
    } else if (propArg.getPropertyName().equals(QueryConstants.FIELD_PARENT)) {
        ParentSupport parentSupport = new ParentSupport();
        String id = (String) term;
        parentSupport.setDbid(DBQuery.getDbid(id, nodeDAO, tenantService));
        parentSupport.setCommandType(DBQueryBuilderPredicatePartCommandType.EQUALS);
        builderSupport = parentSupport;
    } else if (propArg.getPropertyName().equals(QueryConstants.FIELD_TYPE)) {
        TypeSupport typeSupport = new TypeSupport();
        typeSupport.setQnameIds(DBQuery.findTypeIds(term, namespaceService, dictionaryService, qnameDAO, false));
        typeSupport.setCommandType(DBQueryBuilderPredicatePartCommandType.IN);
        builderSupport = typeSupport;
    } else if (propArg.getPropertyName().equals(QueryConstants.FIELD_ASPECT)) {
        AspectSupport aspectSupport = new AspectSupport();
        aspectSupport.setQnameIds(DBQuery.findAspectIds(term, namespaceService, dictionaryService, qnameDAO, false));
        builderSupport = aspectSupport;
    } else if (propArg.getPropertyName().equals(QueryConstants.FIELD_EXACTTYPE)) {
        TypeSupport typeSupport = new TypeSupport();
        typeSupport.setQnameIds(DBQuery.findTypeIds(term, namespaceService, dictionaryService, qnameDAO, true));
        typeSupport.setCommandType(DBQueryBuilderPredicatePartCommandType.IN);
        builderSupport = typeSupport;
    } else if (propArg.getPropertyName().equals(QueryConstants.FIELD_EXACTASPECT)) {
        AspectSupport aspectSupport = new AspectSupport();
        aspectSupport.setQnameIds(DBQuery.findAspectIds(term, namespaceService, dictionaryService, qnameDAO, true));
        builderSupport = aspectSupport;
    } else {
        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(propArg.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.EQUALS);
        builderSupport = propertySupport;
    }
}
Also used : AspectSupport(org.alfresco.repo.search.impl.querymodel.impl.db.AspectSupport) Argument(org.alfresco.repo.search.impl.querymodel.Argument) PropertyArgument(org.alfresco.repo.search.impl.querymodel.PropertyArgument) TypeSupport(org.alfresco.repo.search.impl.querymodel.impl.db.TypeSupport) QName(org.alfresco.service.namespace.QName) QueryModelException(org.alfresco.repo.search.impl.querymodel.QueryModelException) ParentSupport(org.alfresco.repo.search.impl.querymodel.impl.db.ParentSupport) AnalysisMode(org.alfresco.repo.search.adaptor.lucene.AnalysisMode) PropertyArgument(org.alfresco.repo.search.impl.querymodel.PropertyArgument) PropertySupport(org.alfresco.repo.search.impl.querymodel.impl.db.PropertySupport)

Aggregations

PropertyArgument (org.alfresco.repo.search.impl.querymodel.PropertyArgument)8 QName (org.alfresco.service.namespace.QName)7 Argument (org.alfresco.repo.search.impl.querymodel.Argument)6 PropertySupport (org.alfresco.repo.search.impl.querymodel.impl.db.PropertySupport)6 QueryModelException (org.alfresco.repo.search.impl.querymodel.QueryModelException)4 ParentSupport (org.alfresco.repo.search.impl.querymodel.impl.db.ParentSupport)4 TypeSupport (org.alfresco.repo.search.impl.querymodel.impl.db.TypeSupport)4 AnalysisMode (org.alfresco.repo.search.adaptor.lucene.AnalysisMode)3 AspectSupport (org.alfresco.repo.search.impl.querymodel.impl.db.AspectSupport)2 UUIDSupport (org.alfresco.repo.search.impl.querymodel.impl.db.UUIDSupport)2 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Column (org.alfresco.repo.search.impl.querymodel.Column)1 ListArgument (org.alfresco.repo.search.impl.querymodel.ListArgument)1