2

I have a couple test functions I've written to illustrate a problem (or at least some behavior that I don't understand). I am just doing some basic CMIS queries on an Alfresco 4.2.e community repository, but am getting some unexpected results depending on whether I use session.query() or session.queryObjects(). Specifically, the queryObjects doesn't return properties for custom aspects. Both return the relationships/associations fine. Am I doing something wrong, or is this a bug? I'm using opencmis 0.10, and the CMIS 1.1 URL.

private static Collection<Document> testCmisObjectQuery(Session session) {
    List<Document> rv = new LinkedList<>();
    OperationContext opCon = session.createOperationContext();
    opCon.setLoadSecondaryTypeProperties(true);
    opCon.setIncludeRelationships(IncludeRelationships.BOTH);

    ItemIterable<CmisObject> cmisObjs = 
            session.queryObjects("D:af:insuringFormInstance", null, false, opCon);
    for (CmisObject o : cmisObjs) {
        Document d = (Document) o;
        rv.add(d);
        printDocProps(d);
    }
    return rv;
}

private static Collection<Document> testCmisQuery(Session session) {
    List<Document> rv = new LinkedList<>();
    String queryString = "SELECT cmis:objectId FROM af:insuringFormInstance";
    OperationContext opCon = session.createOperationContext();
    opCon.setIncludeRelationships(IncludeRelationships.SOURCE);
    ItemIterable<QueryResult> results = session.query(queryString, false);
    for (QueryResult qResult : results) {
        String objectId = qResult.getPropertyValueByQueryName("cmis:objectId");
        Document doc = (Document)   session.getObject(session.createObjectId(objectId),opCon);
        printDocProps(doc);
        rv.add(doc);
    }
    return rv;
}
BrianV
  • 105
  • 7

2 Answers2

2

Looks like, you are missing a join as in

select d.*, o.* from cmis:document as d join cm:ownable as o on d.cmis:objectId = o.cmis:objectId

Have a look at https://wiki.alfresco.com/wiki/CMIS#Aspect_Query for further details.

Andreas Steffan
  • 6,039
  • 2
  • 23
  • 25
  • Thanks, but the session.query example (i.e. the one with the cql string) works fine. The query just gets the objectId, and then I retrieve the object from that. The object query, though, which doesn't include a cql statement at all, is the one that won't get the aspects. You're probably right, though, in that that query isn't doing the underlying join required to fetch all the aspect/secondary type properties. Unless I'm misunderstanding what you said... – BrianV Mar 19 '14 at 22:54
  • Exactly. Try tcpdump or something similar to see what's executed under the covers and what is sent over the wire. – Andreas Steffan Mar 20 '14 at 06:51
0

Before Document d = (Document) o; You can use o = session.getObject(o.getId()); to reload the cmisObject. After the reloading, the aspects/secondaryTypes can be retrieved.
It works for me. I am using Chemistry 1.0.0, CMIS version 1.1, and browser binding.

There is a similar question: session.queryObjects does not support secondary types

Aaron
  • 36
  • 5