Zone Query
Zone query can be used to expand objects, or you can use it to evaluate select expressions on a list of objects. It is a more generic service that can be more flexible than using the more type specific REST API endpoints.
Below is an example showing how to expand an item 5 level and traversing the result.
const QueryInput = Java.type('com.technia.dsx.threedspace.zone.QueryInput');
const spaceService = context.dsxAPI().getSpaceService();
const session = context.dsxAPI().getTenantSession(spaceService);
const zoneQueryService = spaceService.getZoneQueryService();
const query = new QueryInput();
query.getRootPath().add(itemId);
query.addObjectSelects("name", "ds6w:type", "ds6w:label");
query.addObjectSelects("revision", "current", "vault");
query.addObjectSelects("ds6w:manufacturable");
query.addObjectSelects("ds6w:contentStructure");
query.addRelationshipSelects("type");
query.setExpandDepth(5);
const queryResult = zoneQueryService.perform(session, query);
const structure = zoneQueryService.toStructure(queryResult);
const nodeFn = (node, level=0) => {
const id = node.getPhysicalId();
const attributes = node.getAttributes(); // Map<String, Object>
node.getOut().forEach(rel => {
const relId = rel.getPhysicalId();
const relAttributes = rel.getAttributes();
nodeFn(rel.getTo(), level+1);
});
};
structure.getRoots().forEach(node => nodeFn(node, 0));