Search in sources :

Example 1 with QueryResult

use of org.apache.chemistry.opencmis.client.api.QueryResult in project iaf by ibissource.

the class CmisSender method sendMessageForActionFind.

private String sendMessageForActionFind(String correlationID, String message, ParameterResolutionContext prc) throws SenderException, TimeOutException {
    Element queryElement = null;
    try {
        if (XmlUtils.isWellFormed(message, "query")) {
            queryElement = XmlUtils.buildElement(message);
        } else {
            queryElement = XmlUtils.buildElement("<query/>");
        }
    } catch (DomBuilderException e) {
        throw new SenderException(e);
    }
    String statement = XmlUtils.getChildTagAsString(queryElement, "statement");
    String maxItems = XmlUtils.getChildTagAsString(queryElement, "maxItems");
    String skipCount = XmlUtils.getChildTagAsString(queryElement, "skipCount");
    String searchAllVersions = XmlUtils.getChildTagAsString(queryElement, "searchAllVersions");
    String includeAllowableActions = XmlUtils.getChildTagAsString(queryElement, "includeAllowableActions");
    OperationContext operationContext = session.createOperationContext();
    if (StringUtils.isNotEmpty(maxItems)) {
        operationContext.setMaxItemsPerPage(Integer.parseInt(maxItems));
    }
    boolean sav = false;
    if (StringUtils.isNotEmpty(searchAllVersions)) {
        sav = Boolean.parseBoolean(searchAllVersions);
    }
    if (StringUtils.isNotEmpty(includeAllowableActions)) {
        operationContext.setIncludeAllowableActions(Boolean.parseBoolean(searchAllVersions));
    }
    ItemIterable<QueryResult> q = session.query(statement, sav, operationContext);
    if (StringUtils.isNotEmpty(skipCount)) {
        long sc = Long.parseLong(skipCount);
        q = q.skipTo(sc);
    }
    if (StringUtils.isNotEmpty(maxItems)) {
        q = q.getPage();
    }
    XmlBuilder cmisXml = new XmlBuilder("cmis");
    XmlBuilder rowsetXml = new XmlBuilder("rowset");
    for (QueryResult qResult : q) {
        XmlBuilder rowXml = new XmlBuilder("row");
        for (PropertyData<?> property : qResult.getProperties()) {
            rowXml.addSubElement(getPropertyXml(property));
        }
        rowsetXml.addSubElement(rowXml);
    }
    cmisXml.addSubElement(rowsetXml);
    return cmisXml.toXML();
}
Also used : OperationContext(org.apache.chemistry.opencmis.client.api.OperationContext) QueryResult(org.apache.chemistry.opencmis.client.api.QueryResult) Element(org.w3c.dom.Element) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) SenderException(nl.nn.adapterframework.core.SenderException)

Example 2 with QueryResult

use of org.apache.chemistry.opencmis.client.api.QueryResult in project SearchServices by Alfresco.

the class CMISDataCreatorTest method testCreateLots.

public void testCreateLots() throws Exception {
    Session session = getSession("admin", "admin");
    Folder root = session.getRootFolder();
    String folderNameBase = getRootFolderName();
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
    properties.put(PropertyIds.NAME, folderNameBase);
    Folder base = root.createFolder(properties);
    for (int i = 0; i < 10; i++) {
        AccessControlPrincipalDataImpl principal = new AccessControlPrincipalDataImpl("" + i + i + i);
        List<String> permissions = new ArrayList<String>(1);
        permissions.add(BasicPermissions.ALL);
        List<Ace> addAces = new ArrayList<Ace>(1);
        addAces.add(new AccessControlEntryImpl(principal, permissions));
        base.addAcl(addAces, AclPropagation.PROPAGATE);
    }
    Thread last = null;
    for (int i = 0; i < 10; i++) {
        Creator creator = new Creator(base.getPath(), i);
        Thread thread = new Thread(creator);
        thread.start();
        last = thread;
    }
    if (last != null) {
        last.join();
    }
    ItemIterable<QueryResult> result = session.query("select * from cmis:folder", false);
    assertTrue(result.getTotalNumItems() > 0);
// result = session.query("select * from cmis:folder where cmis:name = '"+folderName+"'", false);
// assertTrue(result.getTotalNumItems() > 0);
}
Also used : AccessControlEntryImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlEntryImpl) Ace(org.apache.chemistry.opencmis.commons.data.Ace) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Folder(org.apache.chemistry.opencmis.client.api.Folder) QueryResult(org.apache.chemistry.opencmis.client.api.QueryResult) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) AccessControlPrincipalDataImpl(org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlPrincipalDataImpl) Session(org.apache.chemistry.opencmis.client.api.Session)

Example 3 with QueryResult

use of org.apache.chemistry.opencmis.client.api.QueryResult in project SearchServices by Alfresco.

the class CMISDataCreatorTest method testQueryFolderProperties.

public void testQueryFolderProperties() {
    Session session = getSession("admin", "admin");
    String folderName = getRootFolderName();
    Folder root = session.getRootFolder();
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
    properties.put(PropertyIds.NAME, folderName);
    // create the folder
    Folder newFolder = root.createFolder(properties);
    ItemIterable<QueryResult> result = session.query("select * from cmis:folder where cmis:name = '" + folderName + "'", false);
    assertEquals(1, result.getTotalNumItems());
    String uniqueName = getUniqueName();
    Map<String, Object> uProperties = new HashMap<String, Object>();
    uProperties.put(PropertyIds.OBJECT_TYPE_ID, "cmis:folder");
    uProperties.put(PropertyIds.NAME, uniqueName);
    Folder uniqueFolder = newFolder.createFolder(uProperties);
    result = session.query("select * from cmis:folder where cmis:name = '" + uniqueName + "'", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:folder where cmis:name = '" + uniqueName + "' AND IN_FOLDER('" + uniqueFolder.getParentId() + "')", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:folder where IN_FOLDER('" + uniqueFolder.getParentId() + "')", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:folder where cmis:name = '" + uniqueName + "' AND cmis:createdBy = '" + uniqueFolder.getCreatedBy() + "'", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:folder where cmis:name = '" + uniqueName + "' AND cmis:objectId = '" + uniqueFolder.getId() + "'", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:folder where cmis:name = '" + uniqueName + "' AND cmis:lastModifiedBy = '" + uniqueFolder.getLastModifiedBy() + "'", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:folder where cmis:name = '" + uniqueFolder.getName() + "'", false);
    assertEquals(1, result.getTotalNumItems());
    String creationDate = ISO8601DateFormat.format(uniqueFolder.getCreationDate().getTime());
    result = session.query("select * from cmis:folder where cmis:name = '" + uniqueName + "' AND cmis:creationDate = '" + creationDate + "'", false);
    assertEquals(1, result.getTotalNumItems());
    String modificationDate = ISO8601DateFormat.format(uniqueFolder.getLastModificationDate().getTime());
    result = session.query("select * from cmis:folder where cmis:name = '" + uniqueName + "' AND cmis:lastModificationDate = '" + modificationDate + "'", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:folder where cmis:name = '" + uniqueName + "' AND cmis:objectTypeId = '" + uniqueFolder.getType().getQueryName() + "'", false);
    assertEquals(1, result.getTotalNumItems());
    result = session.query("select * from cmis:folder where cmis:name = '" + uniqueName + "' AND cmis:baseTypeId = '" + uniqueFolder.getBaseType().getQueryName() + "'", false);
    assertEquals(1, result.getTotalNumItems());
}
Also used : QueryResult(org.apache.chemistry.opencmis.client.api.QueryResult) HashMap(java.util.HashMap) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) Folder(org.apache.chemistry.opencmis.client.api.Folder) Session(org.apache.chemistry.opencmis.client.api.Session)

Example 4 with QueryResult

use of org.apache.chemistry.opencmis.client.api.QueryResult in project camel by apache.

the class CMISSessionFacade method retrieveResult.

//some duplication
public List<Map<String, Object>> retrieveResult(Boolean retrieveContent, Integer readSize, ItemIterable<QueryResult> itemIterable) {
    List<Map<String, Object>> result = new ArrayList<Map<String, Object>>();
    boolean queryForContent = retrieveContent != null ? retrieveContent : readContent;
    int documentsToRead = readSize != null ? readSize : readCount;
    int count = 0;
    int pageNumber = 0;
    boolean finished = false;
    while (!finished) {
        ItemIterable<QueryResult> currentPage = itemIterable.skipTo(count).getPage();
        LOG.debug("Processing page {}", pageNumber);
        for (QueryResult item : currentPage) {
            Map<String, Object> properties = CMISHelper.propertyDataToMap(item.getProperties());
            if (queryForContent) {
                InputStream inputStream = getContentStreamFor(item);
                properties.put(CamelCMISConstants.CAMEL_CMIS_CONTENT_STREAM, inputStream);
            }
            result.add(properties);
            count++;
            if (count == documentsToRead) {
                finished = true;
                break;
            }
        }
        pageNumber++;
        if (!currentPage.getHasMoreItems()) {
            finished = true;
        }
    }
    return result;
}
Also used : QueryResult(org.apache.chemistry.opencmis.client.api.QueryResult) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with QueryResult

use of org.apache.chemistry.opencmis.client.api.QueryResult in project camel by apache.

the class CMISSessionFacade method pollWithQuery.

private int pollWithQuery(CMISConsumer cmisConsumer) throws Exception {
    int count = 0;
    int pageNumber = 0;
    boolean finished = false;
    ItemIterable<QueryResult> itemIterable = executeQuery(query);
    while (!finished) {
        ItemIterable<QueryResult> currentPage = itemIterable.skipTo(count).getPage();
        LOG.debug("Processing page {}", pageNumber);
        for (QueryResult item : currentPage) {
            Map<String, Object> properties = CMISHelper.propertyDataToMap(item.getProperties());
            Object objectTypeId = item.getPropertyValueById(PropertyIds.OBJECT_TYPE_ID);
            InputStream inputStream = null;
            if (readContent && CamelCMISConstants.CMIS_DOCUMENT.equals(objectTypeId)) {
                inputStream = getContentStreamFor(item);
            }
            cmisConsumer.sendExchangeWithPropsAndBody(properties, inputStream);
            count++;
            if (count == readCount) {
                finished = true;
                break;
            }
        }
        pageNumber++;
        if (!currentPage.getHasMoreItems()) {
            finished = true;
        }
    }
    return count;
}
Also used : QueryResult(org.apache.chemistry.opencmis.client.api.QueryResult) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CmisObject(org.apache.chemistry.opencmis.client.api.CmisObject)

Aggregations

QueryResult (org.apache.chemistry.opencmis.client.api.QueryResult)8 CmisObject (org.apache.chemistry.opencmis.client.api.CmisObject)7 HashMap (java.util.HashMap)6 Folder (org.apache.chemistry.opencmis.client.api.Folder)5 Session (org.apache.chemistry.opencmis.client.api.Session)5 ArrayList (java.util.ArrayList)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 Document (org.apache.chemistry.opencmis.client.api.Document)2 Ace (org.apache.chemistry.opencmis.commons.data.Ace)2 AccessControlEntryImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlEntryImpl)2 AccessControlPrincipalDataImpl (org.apache.chemistry.opencmis.commons.impl.dataobjects.AccessControlPrincipalDataImpl)2 Map (java.util.Map)1 SenderException (nl.nn.adapterframework.core.SenderException)1 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)1 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)1 OperationContext (org.apache.chemistry.opencmis.client.api.OperationContext)1 Element (org.w3c.dom.Element)1