From c6172b79ee15bf6b851063cdc31a85a8e7a9dc4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=BC?= Date: Fri, 15 Jul 2011 09:53:41 +0000 Subject: [PATCH] Fixed OpenCMIS server getObjectRelationships() operation git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29064 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../opencmis/AlfrescoCmisService.java | 112 +++++++++++------- .../org/alfresco/opencmis/CMISConnector.java | 4 +- 2 files changed, 74 insertions(+), 42 deletions(-) diff --git a/source/java/org/alfresco/opencmis/AlfrescoCmisService.java b/source/java/org/alfresco/opencmis/AlfrescoCmisService.java index bebdb05121..04fbbe01d0 100644 --- a/source/java/org/alfresco/opencmis/AlfrescoCmisService.java +++ b/source/java/org/alfresco/opencmis/AlfrescoCmisService.java @@ -142,7 +142,7 @@ import org.apache.commons.logging.LogFactory; public class AlfrescoCmisService extends AbstractCmisService { private static Log logger = LogFactory.getLog(AlfrescoCmisService.class); - + private CMISConnector connector; private CallContext context; private UserTransaction txn; @@ -511,30 +511,30 @@ public class AlfrescoCmisService extends AbstractCmisService 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 list = new ArrayList(); result.setObjects(list); - + // get the children references NodeRef folderNodeRef = connector.getFolderNodeRef("Folder", folderId); - + // convert orderBy to sortProps List> sortProps = null; if (orderBy != null) { sortProps = new ArrayList>(1); - + String[] parts = orderBy.split(","); int len = parts.length; final int origLen = len; - + if (origLen > 0) { int maxSortProps = GetChildrenCannedQuery.MAX_FILTER_SORT_PROPS; @@ -542,17 +542,19 @@ public class AlfrescoCmisService extends AbstractCmisService { if (logger.isDebugEnabled()) { - logger.debug("Too many sort properties in 'orderBy' - ignore those above max (max="+maxSortProps+",actual="+len+")"); + 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) { - PropertyDefintionWrapper propDef = connector.getOpenCMISDictionaryService().findPropertyByQueryName(sort[0]); + PropertyDefintionWrapper propDef = connector.getOpenCMISDictionaryService() + .findPropertyByQueryName(sort[0]); if (propDef != null) { QName sortProp = propDef.getPropertyAccessor().getMappedProperty(); @@ -560,80 +562,88 @@ public class AlfrescoCmisService extends AbstractCmisService { boolean sortAsc = ((sort.length == 1) || (sortAsc = (sort[1].equalsIgnoreCase("asc")))); sortProps.add(new Pair(sortProp, sortAsc)); - } - else + } else { if (logger.isDebugEnabled()) { - logger.debug("Ignore sort property '"+sort[0]+" - mapping not found"); + logger.debug("Ignore sort property '" + sort[0] + " - mapping not found"); } } - } - else + } else { if (logger.isDebugEnabled()) { - logger.debug("Ignore sort property '"+sort[0]+" - query name not found"); + logger.debug("Ignore sort property '" + sort[0] + " - query name not found"); } } } } } - + if (sortProps.size() < origLen) { - logger.warn("Sort properties trimmed - either too many and/or not found: \n" + - " orig: " + orderBy + "\n" + - " final: " + sortProps); + logger.warn("Sort properties trimmed - either too many and/or not found: \n" + " orig: " + orderBy + + "\n" + " final: " + sortProps); } } - + PagingRequest pageRequest = new PagingRequest(skipCount.intValue(), maxItems.intValue(), null); - pageRequest.setRequestTotalCountMax(skipCount.intValue() + 1000); // TODO make this optional/configurable - affects whether numItems may be returned - - PagingResults pageOfNodeInfos = connector.getFileFolderService().list(folderNodeRef, true, true, null, sortProps, pageRequest); + pageRequest.setRequestTotalCountMax(skipCount.intValue() + 1000); // TODO + // make + // this + // optional/configurable + // - + // affects + // whether + // numItems + // may + // be + // returned + + PagingResults pageOfNodeInfos = connector.getFileFolderService().list(folderNodeRef, true, true, + null, sortProps, pageRequest); List childrenList = pageOfNodeInfos.getPage(); - + if (max > 0) { int lastIndex = (max + skip > childrenList.size() ? childrenList.size() : max + skip) - 1; for (int i = skip; i <= lastIndex; i++) { FileInfo child = childrenList.get(i); - + try { // create a child CMIS object - ObjectData object = connector.createCMISObject(child, filter, - includeAllowableActions, includeRelationships, renditionFilter, false, false); - + ObjectData object = connector.createCMISObject(child, filter, includeAllowableActions, + includeRelationships, renditionFilter, false, false); + if (context.isObjectInfoRequired()) { getObjectInfo(repositoryId, object.getId()); } - + 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 } } } - - /// has more ? + + // / has more ? result.setHasMoreItems(pageOfNodeInfos.hasMoreItems()); - + // total count ? Pair totalCounts = pageOfNodeInfos.getTotalResultCount(); if (totalCounts != null) @@ -645,12 +655,13 @@ public class AlfrescoCmisService extends AbstractCmisService result.setNumItems(BigInteger.valueOf(totalCountLower)); } } - + if (logger.isDebugEnabled()) { - logger.debug("getChildren: "+childrenList.size()+" in "+(System.currentTimeMillis()-start)+" msecs"); + logger.debug("getChildren: " + childrenList.size() + " in " + (System.currentTimeMillis() - start) + + " msecs"); } - + return result; } @@ -2301,6 +2312,27 @@ public class AlfrescoCmisService extends AbstractCmisService throw new CmisInvalidArgumentException("Object is a relationship!"); } + // check if the relationship base type is requested + if (BaseTypeId.CMIS_RELATIONSHIP.value().equals(typeId)) + { + boolean isrt = (includeSubRelationshipTypes == null ? false : includeSubRelationshipTypes.booleanValue()); + if (isrt) + { + // all relationships are a direct subtype of the base type in + // Alfresco -> remove filter + typeId = null; + } else + { + // there are no relationships of the base type in ALfresco -> + // return empty list + ObjectListImpl result = new ObjectListImpl(); + result.setHasMoreItems(false); + result.setNumItems(BigInteger.ZERO); + result.setObjects(new ArrayList()); + return result; + } + } + NodeRef nodeRef = connector.getNodeRefIfCurrent("Object", objectId); return connector.getObjectRelationships(nodeRef, relationshipDirection, typeId, filter, includeAllowableActions, maxItems, skipCount); diff --git a/source/java/org/alfresco/opencmis/CMISConnector.java b/source/java/org/alfresco/opencmis/CMISConnector.java index f7bd0d605a..8fb72f437d 100644 --- a/source/java/org/alfresco/opencmis/CMISConnector.java +++ b/source/java/org/alfresco/opencmis/CMISConnector.java @@ -1872,7 +1872,7 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen // relationships from and to versions are not preserved return result; } - + // get relationships List assocs = new ArrayList(); if (relationshipDirection == RelationshipDirection.SOURCE @@ -1903,7 +1903,7 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen continue; } - if ((typeId != null) && !assocRef.getId().equals(typeId)) + if ((typeId != null) && !assocTypeDef.getTypeId().equals(typeId)) { continue; }