Search in sources :

Example 6 with QueryModelException

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

the class DBFTSTerm 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);
    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)

Example 7 with QueryModelException

use of org.alfresco.repo.search.impl.querymodel.QueryModelException 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 8 with QueryModelException

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

the class DBConjunction 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) {
    for (Constraint constraint : getConstraints()) {
        if (constraint instanceof DBQueryBuilderComponent) {
            if (constraint.getOccur() == Occur.OPTIONAL) {
                throw new QueryModelException("Disjunctions are not suported");
            }
            DBQueryBuilderComponent dbQueryBuilderComponent = (DBQueryBuilderComponent) constraint;
            dbQueryBuilderComponent.prepare(namespaceService, dictionaryService, qnameDAO, nodeDAO, tenantService, selectors, functionArgs, functionContext, supportBooleanFloatAndDouble);
        } else {
            throw new UnsupportedOperationException();
        }
    }
}
Also used : Constraint(org.alfresco.repo.search.impl.querymodel.Constraint) QueryModelException(org.alfresco.repo.search.impl.querymodel.QueryModelException)

Example 9 with QueryModelException

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

the class OpenCmisQueryTest method testQuery.

@SuppressWarnings("unchecked")
private <T> T testQuery(String query, int size, boolean dump, String returnPropertyName, T returnType, boolean shouldThrow, CMISQueryMode mode) throws Exception {
    CMISResultSet rs = null;
    try {
        T returnValue = null;
        CMISQueryOptions options = new CMISQueryOptions(query, rootNodeRef.getStoreRef());
        options.setQueryMode(mode);
        options.setIncludeInTransactionData(true);
        rs = cmisQueryService.query(options);
        for (CMISResultSetRow row : rs) {
            if (row.getIndex() == 0) {
                Serializable sValue = row.getValue(returnPropertyName);
                returnValue = (T) DefaultTypeConverter.INSTANCE.convert(returnType.getClass(), sValue);
                if (dump) {
                    System.out.println(cmisConnector.getNodeProperties(cmisConnector.createNodeInfo(row.getNodeRef(rs.getMetaData().getSelectorNames()[0])), null));
                }
            }
            if (dump) {
                System.out.println("ID =" + row.getValue("cmis:objectId") + " " + ((returnPropertyName != null) ? (returnPropertyName + "=" + row.getValue(returnPropertyName)) : "") + " Score=" + row.getScore() + " " + row.getScores());
            }
        }
        if (size >= 0) {
            assertEquals(size, rs.getLength());
        }
        if (shouldThrow) {
            fail();
        }
        return returnValue;
    } catch (CmisBaseException e) {
        if (shouldThrow) {
            return null;
        } else {
            throw e;
        }
    } catch (QueryModelException e) {
        if (shouldThrow) {
            return null;
        } else {
            throw e;
        }
    } catch (FTSQueryException e) {
        if (shouldThrow) {
            return null;
        } else {
            throw e;
        }
    } catch (UnsupportedOperationException e) {
        if (shouldThrow) {
            return null;
        } else {
            throw e;
        }
    } finally {
        if (rs != null) {
            try {
                rs.close();
            } finally {
                rs = null;
            }
        }
    }
}
Also used : Serializable(java.io.Serializable) CmisBaseException(org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException) QueryModelException(org.alfresco.repo.search.impl.querymodel.QueryModelException) FTSQueryException(org.alfresco.repo.search.impl.parsers.FTSQueryException)

Example 10 with QueryModelException

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

the class DBChild 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)
     */
@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_PARENT);
    String id = (String) argument.getValue(functionContext);
    argument = functionArgs.get(ARG_SELECTOR);
    if (argument != null) {
        String selector = (String) argument.getValue(functionContext);
        if (!selectors.contains(selector)) {
            throw new QueryModelException("Unkown selector " + selector);
        }
    } else {
        if (selectors.size() > 1) {
            throw new QueryModelException("Selector must be specified for child constraint (IN_FOLDER) and join");
        }
    }
    ParentSupport parentSupport = new ParentSupport();
    parentSupport.setDbid(DBQuery.getDbid(id, nodeDAO, tenantService));
    parentSupport.setCommandType(DBQueryBuilderPredicatePartCommandType.EQUALS);
    builderSupport = parentSupport;
}
Also used : Argument(org.alfresco.repo.search.impl.querymodel.Argument) QueryModelException(org.alfresco.repo.search.impl.querymodel.QueryModelException) ParentSupport(org.alfresco.repo.search.impl.querymodel.impl.db.ParentSupport)

Aggregations

QueryModelException (org.alfresco.repo.search.impl.querymodel.QueryModelException)16 QName (org.alfresco.service.namespace.QName)9 ArrayList (java.util.ArrayList)4 Argument (org.alfresco.repo.search.impl.querymodel.Argument)4 PropertyArgument (org.alfresco.repo.search.impl.querymodel.PropertyArgument)4 AnalysisMode (org.alfresco.repo.search.adaptor.lucene.AnalysisMode)3 ParentSupport (org.alfresco.repo.search.impl.querymodel.impl.db.ParentSupport)3 PropertySupport (org.alfresco.repo.search.impl.querymodel.impl.db.PropertySupport)3 ResultSet (org.alfresco.service.cmr.search.ResultSet)3 Serializable (java.io.Serializable)2 HashSet (java.util.HashSet)2 Node (org.alfresco.repo.domain.node.Node)2 SolrJSONResultSet (org.alfresco.repo.search.impl.lucene.SolrJSONResultSet)2 FTSQueryException (org.alfresco.repo.search.impl.parsers.FTSQueryException)2 AspectSupport (org.alfresco.repo.search.impl.querymodel.impl.db.AspectSupport)2 TypeSupport (org.alfresco.repo.search.impl.querymodel.impl.db.TypeSupport)2 ChildAssocRefResultSet (org.alfresco.repo.search.results.ChildAssocRefResultSet)2 AspectDefinition (org.alfresco.service.cmr.dictionary.AspectDefinition)2 DataTypeDefinition (org.alfresco.service.cmr.dictionary.DataTypeDefinition)2 TypeDefinition (org.alfresco.service.cmr.dictionary.TypeDefinition)2