Search in sources :

Example 1 with CMISResultSet

use of org.alfresco.opencmis.search.CMISResultSet in project alfresco-repository by Alfresco.

the class SolrOpenCMISQueryServiceImpl method query.

@Override
public CMISResultSet query(CMISQueryOptions options) {
    SearchParameters searchParameters = options.getAsSearchParmeters();
    searchParameters.addExtraParameter("cmisVersion", options.getCmisVersion().toString());
    ResultSet rs = solrQueryLanguage.executeQuery(searchParameters);
    CapabilityJoin joinSupport = getJoinSupport();
    if (options.getQueryMode() == CMISQueryOptions.CMISQueryMode.CMS_WITH_ALFRESCO_EXTENSIONS) {
        joinSupport = CapabilityJoin.INNERANDOUTER;
    }
    // TODO: Refactor to avoid duplication of valid scopes here and in CMISQueryParser
    BaseTypeId[] validScopes = (options.getQueryMode() == CMISQueryMode.CMS_STRICT) ? CmisFunctionEvaluationContext.STRICT_SCOPES : CmisFunctionEvaluationContext.ALFRESCO_SCOPES;
    CmisFunctionEvaluationContext functionContext = new CmisFunctionEvaluationContext();
    functionContext.setCmisDictionaryService(cmisDictionaryService);
    functionContext.setNodeService(nodeService);
    functionContext.setValidScopes(validScopes);
    CMISQueryParser parser = new CMISQueryParser(options, cmisDictionaryService, joinSupport);
    Query query = parser.parse(new LuceneQueryModelFactory(), functionContext);
    Map<String, ResultSet> wrapped = new HashMap<String, ResultSet>();
    for (Set<String> group : query.getSource().getSelectorGroups(functionContext)) {
        for (String selector : group) {
            wrapped.put(selector, rs);
        }
    }
    LimitBy limitBy = null;
    limitBy = rs.getResultSetMetaData().getLimitedBy();
    CMISResultSet cmis = new CMISResultSet(wrapped, options, limitBy, nodeService, query, cmisDictionaryService, alfrescoDictionaryService);
    return cmis;
}
Also used : CmisFunctionEvaluationContext(org.alfresco.opencmis.search.CmisFunctionEvaluationContext) CapabilityQuery(org.apache.chemistry.opencmis.commons.enums.CapabilityQuery) Query(org.alfresco.repo.search.impl.querymodel.Query) HashMap(java.util.HashMap) LimitBy(org.alfresco.service.cmr.search.LimitBy) BaseTypeId(org.apache.chemistry.opencmis.commons.enums.BaseTypeId) CapabilityJoin(org.apache.chemistry.opencmis.commons.enums.CapabilityJoin) CMISResultSet(org.alfresco.opencmis.search.CMISResultSet) SearchParameters(org.alfresco.service.cmr.search.SearchParameters) LuceneQueryModelFactory(org.alfresco.repo.search.impl.querymodel.impl.lucene.LuceneQueryModelFactory) ResultSet(org.alfresco.service.cmr.search.ResultSet) CMISResultSet(org.alfresco.opencmis.search.CMISResultSet) CMISQueryParser(org.alfresco.opencmis.search.CMISQueryParser)

Example 2 with CMISResultSet

use of org.alfresco.opencmis.search.CMISResultSet in project alfresco-repository by Alfresco.

the class CMISConnector method query.

@SuppressWarnings("unchecked")
public ObjectList query(String statement, Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, BigInteger maxItems, BigInteger skipCount) /*, CmisVersion cmisVersion*/
{
    // prepare results
    ObjectListImpl result = new ObjectListImpl();
    result.setObjects(new ArrayList<ObjectData>());
    // prepare query
    CMISQueryOptions options = new CMISQueryOptions(statement, getRootStoreRef());
    CmisVersion cmisVersion = getRequestCmisVersion();
    options.setCmisVersion(cmisVersion);
    options.setQueryMode(CMISQueryMode.CMS_WITH_ALFRESCO_EXTENSIONS);
    int skip = 0;
    if ((skipCount != null) && (skipCount.intValue() >= 0)) {
        skip = skipCount.intValue();
        options.setSkipCount(skip);
    }
    if ((maxItems != null) && (maxItems.intValue() >= 0)) {
        options.setMaxItems(maxItems.intValue());
    }
    boolean fetchObject = includeAllowableActions || (includeRelationships != IncludeRelationships.NONE) || (!RENDITION_NONE.equals(renditionFilter));
    // query
    CMISResultSet rs = getOpenCMISQueryService().query(options);
    try {
        CMISResultSetColumn[] columns = rs.getMetaData().getColumns();
        for (CMISResultSetRow row : rs) {
            NodeRef nodeRef = row.getNodeRef();
            if (!nodeService.exists(nodeRef) || filter(nodeRef)) {
                continue;
            }
            TypeDefinitionWrapper type = getType(nodeRef);
            if (type == null) {
                continue;
            }
            ObjectDataImpl hit = new ObjectDataImpl();
            PropertiesImpl properties = new PropertiesImpl();
            hit.setProperties(properties);
            Map<String, Serializable> values = row.getValues();
            for (CMISResultSetColumn column : columns) {
                AbstractPropertyData<?> property = getProperty(column.getCMISDataType(), column.getCMISPropertyDefinition(), values.get(column.getName()));
                property.setQueryName(column.getName());
                properties.addProperty(property);
            }
            if (fetchObject) {
                // set allowable actions
                if (includeAllowableActions) {
                    CMISNodeInfoImpl nodeInfo = createNodeInfo(nodeRef);
                    if (!nodeInfo.getObjectVariant().equals(CMISObjectVariant.NOT_EXISTING)) {
                        hit.setAllowableActions(getAllowableActions(nodeInfo));
                    }
                }
                // set relationships
                if (includeRelationships != IncludeRelationships.NONE) {
                    hit.setRelationships(getRelationships(nodeRef, includeRelationships));
                }
                // set renditions
                if (!RENDITION_NONE.equals(renditionFilter)) {
                    List<RenditionData> renditions = getRenditions(nodeRef, renditionFilter, null, null);
                    if ((renditions != null) && (!renditions.isEmpty())) {
                        hit.setRenditions(renditions);
                    } else {
                        hit.setRenditions(Collections.EMPTY_LIST);
                    }
                }
            }
            result.getObjects().add(hit);
        }
        long numberFound = rs.getNumberFound();
        if (numberFound != -1) {
            result.setNumItems(BigInteger.valueOf(numberFound));
        }
        result.setHasMoreItems(rs.hasMore());
    } finally {
        rs.close();
    }
    return result;
}
Also used : CmisVersion(org.apache.chemistry.opencmis.commons.enums.CmisVersion) Serializable(java.io.Serializable) PropertiesImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.PropertiesImpl) ItemTypeDefinitionWrapper(org.alfresco.opencmis.dictionary.ItemTypeDefinitionWrapper) TypeDefinitionWrapper(org.alfresco.opencmis.dictionary.TypeDefinitionWrapper) DocumentTypeDefinitionWrapper(org.alfresco.opencmis.dictionary.DocumentTypeDefinitionWrapper) ObjectData(org.apache.chemistry.opencmis.commons.data.ObjectData) ObjectListImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectListImpl) CMISQueryOptions(org.alfresco.opencmis.search.CMISQueryOptions) PropertyString(org.apache.chemistry.opencmis.commons.data.PropertyString) CMISResultSet(org.alfresco.opencmis.search.CMISResultSet) CMISResultSetRow(org.alfresco.opencmis.search.CMISResultSetRow) ObjectDataImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectDataImpl) CMISResultSetColumn(org.alfresco.opencmis.search.CMISResultSetColumn) NodeRef(org.alfresco.service.cmr.repository.NodeRef) RenditionData(org.apache.chemistry.opencmis.commons.data.RenditionData)

Aggregations

CMISResultSet (org.alfresco.opencmis.search.CMISResultSet)2 Serializable (java.io.Serializable)1 HashMap (java.util.HashMap)1 DocumentTypeDefinitionWrapper (org.alfresco.opencmis.dictionary.DocumentTypeDefinitionWrapper)1 ItemTypeDefinitionWrapper (org.alfresco.opencmis.dictionary.ItemTypeDefinitionWrapper)1 TypeDefinitionWrapper (org.alfresco.opencmis.dictionary.TypeDefinitionWrapper)1 CMISQueryOptions (org.alfresco.opencmis.search.CMISQueryOptions)1 CMISQueryParser (org.alfresco.opencmis.search.CMISQueryParser)1 CMISResultSetColumn (org.alfresco.opencmis.search.CMISResultSetColumn)1 CMISResultSetRow (org.alfresco.opencmis.search.CMISResultSetRow)1 CmisFunctionEvaluationContext (org.alfresco.opencmis.search.CmisFunctionEvaluationContext)1 Query (org.alfresco.repo.search.impl.querymodel.Query)1 LuceneQueryModelFactory (org.alfresco.repo.search.impl.querymodel.impl.lucene.LuceneQueryModelFactory)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 LimitBy (org.alfresco.service.cmr.search.LimitBy)1 ResultSet (org.alfresco.service.cmr.search.ResultSet)1 SearchParameters (org.alfresco.service.cmr.search.SearchParameters)1 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)1 PropertyString (org.apache.chemistry.opencmis.commons.data.PropertyString)1 RenditionData (org.apache.chemistry.opencmis.commons.data.RenditionData)1