BrianV
BrianV

Reputation: 105

CMIS session.queryObjects doesn't return aspects

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;
}

Upvotes: 2

Views: 1253

Answers (2)

Aaron
Aaron

Reputation: 36

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

Upvotes: 0

Andreas Steffan
Andreas Steffan

Reputation: 6169

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.

Upvotes: 2

Related Questions