Search in sources :

Example 6 with CMISQueryOptions

use of org.alfresco.opencmis.search.CMISQueryOptions 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)

Example 7 with CMISQueryOptions

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

the class LuceneOpenCMISStrictSqlQueryLanguage method executeQuery.

public ResultSet executeQuery(SearchParameters searchParameters) {
    CMISQueryOptions options = CMISQueryOptions.create(searchParameters);
    options.setQueryMode(CMISQueryMode.CMS_STRICT);
    return new ResultSetSPIWrapper<CMISResultSetRow, CMISResultSetMetaData>(cmisQueryService.query(options));
}
Also used : CMISQueryOptions(org.alfresco.opencmis.search.CMISQueryOptions) ResultSetSPIWrapper(org.alfresco.repo.search.results.ResultSetSPIWrapper)

Aggregations

CMISQueryOptions (org.alfresco.opencmis.search.CMISQueryOptions)7 ResultSetSPIWrapper (org.alfresco.repo.search.results.ResultSetSPIWrapper)4 CMISQueryParser (org.alfresco.opencmis.search.CMISQueryParser)2 CmisFunctionEvaluationContext (org.alfresco.opencmis.search.CmisFunctionEvaluationContext)2 CapabilityJoin (org.apache.chemistry.opencmis.commons.enums.CapabilityJoin)2 Serializable (java.io.Serializable)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 CMISDictionaryService (org.alfresco.opencmis.dictionary.CMISDictionaryService)1 DocumentTypeDefinitionWrapper (org.alfresco.opencmis.dictionary.DocumentTypeDefinitionWrapper)1 ItemTypeDefinitionWrapper (org.alfresco.opencmis.dictionary.ItemTypeDefinitionWrapper)1 TypeDefinitionWrapper (org.alfresco.opencmis.dictionary.TypeDefinitionWrapper)1 CMISResultSet (org.alfresco.opencmis.search.CMISResultSet)1 CMISResultSetColumn (org.alfresco.opencmis.search.CMISResultSetColumn)1 CMISResultSetRow (org.alfresco.opencmis.search.CMISResultSetRow)1 QueryEngineResults (org.alfresco.repo.search.impl.querymodel.QueryEngineResults)1 DBQueryModelFactory (org.alfresco.repo.search.impl.querymodel.impl.db.DBQueryModelFactory)1 NodeRef (org.alfresco.service.cmr.repository.NodeRef)1 ResultSet (org.alfresco.service.cmr.search.ResultSet)1 ObjectData (org.apache.chemistry.opencmis.commons.data.ObjectData)1