use of org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectInFolderListImpl in project alfresco-repository by Alfresco.
the class AlfrescoCmisServiceImpl method getChildren.
// --- navigation service ---
@Override
public ObjectInFolderList getChildren(String repositoryId, String folderId, String filter, String orderBy, Boolean includeAllowableActions, IncludeRelationships includeRelationships, String renditionFilter, Boolean includePathSegment, BigInteger maxItems, BigInteger skipCount, ExtensionsData extension) {
long start = System.currentTimeMillis();
checkRepositoryId(repositoryId);
// convert BigIntegers to int
int max = (maxItems == null ? Integer.MAX_VALUE : maxItems.intValue());
int skip = (skipCount == null || skipCount.intValue() < 0 ? 0 : skipCount.intValue());
ObjectInFolderListImpl result = new ObjectInFolderListImpl();
List<ObjectInFolderData> list = new ArrayList<ObjectInFolderData>();
result.setObjects(list);
// get the children references
NodeRef folderNodeRef = getOrCreateFolderInfo(folderId, "Folder").getNodeRef();
// convert orderBy to sortProps
List<Pair<QName, Boolean>> sortProps = null;
if (orderBy != null) {
sortProps = new ArrayList<Pair<QName, Boolean>>(1);
String[] parts = orderBy.split(",");
int len = parts.length;
final int origLen = len;
if (origLen > 0) {
int maxSortProps = GetChildrenCannedQuery.MAX_FILTER_SORT_PROPS;
if (len > maxSortProps) {
if (logger.isDebugEnabled()) {
logger.debug("Too many sort properties in 'orderBy' - ignore those above max (max=" + maxSortProps + ",actual=" + len + ")");
}
len = maxSortProps;
}
for (int i = 0; i < len; i++) {
String[] sort = parts[i].split(" +");
if (sort.length > 0) {
// MNT-10529: Leading spaces result in an empty string value after the split operation. Leading spaces may occur in the 'orderBy' statement when the
// elements of statement separated by a comma and a space(s)
int index = (sort[0].isEmpty()) ? (1) : (0);
Pair<QName, Boolean> sortProp = connector.getSortProperty(sort[index], sort.length > (index + 1) ? sort[index + 1] : null);
sortProps.add(sortProp);
}
}
}
if (sortProps.size() < origLen) {
logger.warn("Sort properties trimmed - either too many and/or not found: \n" + " orig: " + orderBy + "\n" + " final: " + sortProps);
}
}
PagingRequest pageRequest = new PagingRequest(skip, max, null);
// TODO make this optional/configurable
pageRequest.setRequestTotalCountMax(skip + 10000);
// - affects whether numItems may be returned
Set<QName> typeqnames = new HashSet<QName>();
List<TypeDefinitionWrapper> allTypes = connector.getOpenCMISDictionaryService().getAllTypes();
for (TypeDefinitionWrapper type : allTypes) {
typeqnames.add(type.getAlfrescoClass());
}
PagingResults<FileInfo> pageOfNodeInfos = connector.getFileFolderService().list(folderNodeRef, typeqnames, // ignoreAspectQNames,
null, sortProps, pageRequest);
if (max > 0) {
for (FileInfo child : pageOfNodeInfos.getPage()) {
try {
// TODO this will break the paging if filtering is performed...
if (connector.filter(child.getNodeRef())) {
continue;
}
// create a child CMIS object
// note: checkExists=false (don't need to check again)
CMISNodeInfo ni = createNodeInfo(child.getNodeRef(), child.getType(), child.getProperties(), null, false);
// Skip non-cmis objects
if (ni.getObjectVariant() == CMISObjectVariant.INVALID_ID || ni.getObjectVariant() == CMISObjectVariant.NOT_EXISTING || ni.getObjectVariant() == CMISObjectVariant.NOT_A_CMIS_OBJECT || ni.getObjectVariant() == CMISObjectVariant.PERMISSION_DENIED) {
continue;
}
ObjectData object = connector.createCMISObject(ni, filter, includeAllowableActions, includeRelationships, renditionFilter, false, false);
boolean isObjectInfoRequired = getContext().isObjectInfoRequired();
if (isObjectInfoRequired) {
getObjectInfo(repositoryId, ni.getObjectId(), includeRelationships);
}
ObjectInFolderDataImpl childData = new ObjectInFolderDataImpl();
childData.setObject(object);
// include path segment
if (includePathSegment) {
childData.setPathSegment(child.getName());
}
// add it
list.add(childData);
} catch (InvalidNodeRefException e) {
// ignore invalid children
} catch (CmisObjectNotFoundException e) {
// ignore objects that have not been found (perhaps because their type is unknown to CMIS)
}
}
}
// has more ?
result.setHasMoreItems(pageOfNodeInfos.hasMoreItems());
// total count ?
Pair<Integer, Integer> totalCounts = pageOfNodeInfos.getTotalResultCount();
if (totalCounts != null) {
Integer totalCountLower = totalCounts.getFirst();
Integer totalCountUpper = totalCounts.getSecond();
if ((totalCountLower != null) && (totalCountLower.equals(totalCountUpper))) {
result.setNumItems(BigInteger.valueOf(totalCountLower));
}
}
logGetObjectsCall("getChildren", start, folderId, list.size(), filter, includeAllowableActions, includeRelationships, renditionFilter, includePathSegment, extension, skipCount, maxItems, orderBy, null);
return result;
}
use of org.apache.chemistry.opencmis.commons.impl.dataobjects.ObjectInFolderListImpl in project iaf by ibissource.
the class CmisUtils method xml2ObjectsInFolderList.
public static ObjectInFolderList xml2ObjectsInFolderList(Element result) {
ObjectInFolderListImpl objectInFolderList = new ObjectInFolderListImpl();
objectInFolderList.setNumItems(CmisUtils.parseBigIntegerAttr(result, "numberOfItems"));
objectInFolderList.setHasMoreItems(CmisUtils.parseBooleanAttr(result, "hasMoreItems"));
List<ObjectInFolderData> objects = new ArrayList<ObjectInFolderData>();
Element objectsElem = XmlUtils.getFirstChildTag(result, "objects");
for (Node type : XmlUtils.getChildTags(objectsElem, "object")) {
ObjectInFolderDataImpl oifd = new ObjectInFolderDataImpl();
String pathSegment = CmisUtils.parseStringAttr(result, "pathSegment");
oifd.setPathSegment(pathSegment);
ObjectData objectData = xml2ObjectData((Element) type, null);
oifd.setObject(objectData);
objects.add(oifd);
}
objectInFolderList.setObjects(objects);
return objectInFolderList;
}
Aggregations