mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
Fixed OpenCMIS server getObjectRelationships() operation
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29064 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -142,7 +142,7 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
public class AlfrescoCmisService extends AbstractCmisService
|
public class AlfrescoCmisService extends AbstractCmisService
|
||||||
{
|
{
|
||||||
private static Log logger = LogFactory.getLog(AlfrescoCmisService.class);
|
private static Log logger = LogFactory.getLog(AlfrescoCmisService.class);
|
||||||
|
|
||||||
private CMISConnector connector;
|
private CMISConnector connector;
|
||||||
private CallContext context;
|
private CallContext context;
|
||||||
private UserTransaction txn;
|
private UserTransaction txn;
|
||||||
@@ -511,30 +511,30 @@ public class AlfrescoCmisService extends AbstractCmisService
|
|||||||
Boolean includePathSegment, BigInteger maxItems, BigInteger skipCount, ExtensionsData extension)
|
Boolean includePathSegment, BigInteger maxItems, BigInteger skipCount, ExtensionsData extension)
|
||||||
{
|
{
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
|
|
||||||
checkRepositoryId(repositoryId);
|
checkRepositoryId(repositoryId);
|
||||||
|
|
||||||
// convert BigIntegers to int
|
// convert BigIntegers to int
|
||||||
int max = (maxItems == null ? Integer.MAX_VALUE : maxItems.intValue());
|
int max = (maxItems == null ? Integer.MAX_VALUE : maxItems.intValue());
|
||||||
int skip = (skipCount == null || skipCount.intValue() < 0 ? 0 : skipCount.intValue());
|
int skip = (skipCount == null || skipCount.intValue() < 0 ? 0 : skipCount.intValue());
|
||||||
|
|
||||||
ObjectInFolderListImpl result = new ObjectInFolderListImpl();
|
ObjectInFolderListImpl result = new ObjectInFolderListImpl();
|
||||||
List<ObjectInFolderData> list = new ArrayList<ObjectInFolderData>();
|
List<ObjectInFolderData> list = new ArrayList<ObjectInFolderData>();
|
||||||
result.setObjects(list);
|
result.setObjects(list);
|
||||||
|
|
||||||
// get the children references
|
// get the children references
|
||||||
NodeRef folderNodeRef = connector.getFolderNodeRef("Folder", folderId);
|
NodeRef folderNodeRef = connector.getFolderNodeRef("Folder", folderId);
|
||||||
|
|
||||||
// convert orderBy to sortProps
|
// convert orderBy to sortProps
|
||||||
List<Pair<QName, Boolean>> sortProps = null;
|
List<Pair<QName, Boolean>> sortProps = null;
|
||||||
if (orderBy != null)
|
if (orderBy != null)
|
||||||
{
|
{
|
||||||
sortProps = new ArrayList<Pair<QName, Boolean>>(1);
|
sortProps = new ArrayList<Pair<QName, Boolean>>(1);
|
||||||
|
|
||||||
String[] parts = orderBy.split(",");
|
String[] parts = orderBy.split(",");
|
||||||
int len = parts.length;
|
int len = parts.length;
|
||||||
final int origLen = len;
|
final int origLen = len;
|
||||||
|
|
||||||
if (origLen > 0)
|
if (origLen > 0)
|
||||||
{
|
{
|
||||||
int maxSortProps = GetChildrenCannedQuery.MAX_FILTER_SORT_PROPS;
|
int maxSortProps = GetChildrenCannedQuery.MAX_FILTER_SORT_PROPS;
|
||||||
@@ -542,17 +542,19 @@ public class AlfrescoCmisService extends AbstractCmisService
|
|||||||
{
|
{
|
||||||
if (logger.isDebugEnabled())
|
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;
|
len = maxSortProps;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
String[] sort = parts[i].split(" +");
|
String[] sort = parts[i].split(" +");
|
||||||
|
|
||||||
if (sort.length > 0)
|
if (sort.length > 0)
|
||||||
{
|
{
|
||||||
PropertyDefintionWrapper propDef = connector.getOpenCMISDictionaryService().findPropertyByQueryName(sort[0]);
|
PropertyDefintionWrapper propDef = connector.getOpenCMISDictionaryService()
|
||||||
|
.findPropertyByQueryName(sort[0]);
|
||||||
if (propDef != null)
|
if (propDef != null)
|
||||||
{
|
{
|
||||||
QName sortProp = propDef.getPropertyAccessor().getMappedProperty();
|
QName sortProp = propDef.getPropertyAccessor().getMappedProperty();
|
||||||
@@ -560,80 +562,88 @@ public class AlfrescoCmisService extends AbstractCmisService
|
|||||||
{
|
{
|
||||||
boolean sortAsc = ((sort.length == 1) || (sortAsc = (sort[1].equalsIgnoreCase("asc"))));
|
boolean sortAsc = ((sort.length == 1) || (sortAsc = (sort[1].equalsIgnoreCase("asc"))));
|
||||||
sortProps.add(new Pair<QName, Boolean>(sortProp, sortAsc));
|
sortProps.add(new Pair<QName, Boolean>(sortProp, sortAsc));
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if (logger.isDebugEnabled())
|
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())
|
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)
|
if (sortProps.size() < origLen)
|
||||||
{
|
{
|
||||||
logger.warn("Sort properties trimmed - either too many and/or not found: \n" +
|
logger.warn("Sort properties trimmed - either too many and/or not found: \n" + " orig: " + orderBy
|
||||||
" orig: " + orderBy + "\n" +
|
+ "\n" + " final: " + sortProps);
|
||||||
" final: " + sortProps);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PagingRequest pageRequest = new PagingRequest(skipCount.intValue(), maxItems.intValue(), null);
|
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
|
pageRequest.setRequestTotalCountMax(skipCount.intValue() + 1000); // TODO
|
||||||
|
// make
|
||||||
PagingResults<FileInfo> pageOfNodeInfos = connector.getFileFolderService().list(folderNodeRef, true, true, null, sortProps, pageRequest);
|
// this
|
||||||
|
// optional/configurable
|
||||||
|
// -
|
||||||
|
// affects
|
||||||
|
// whether
|
||||||
|
// numItems
|
||||||
|
// may
|
||||||
|
// be
|
||||||
|
// returned
|
||||||
|
|
||||||
|
PagingResults<FileInfo> pageOfNodeInfos = connector.getFileFolderService().list(folderNodeRef, true, true,
|
||||||
|
null, sortProps, pageRequest);
|
||||||
List<FileInfo> childrenList = pageOfNodeInfos.getPage();
|
List<FileInfo> childrenList = pageOfNodeInfos.getPage();
|
||||||
|
|
||||||
if (max > 0)
|
if (max > 0)
|
||||||
{
|
{
|
||||||
int lastIndex = (max + skip > childrenList.size() ? childrenList.size() : max + skip) - 1;
|
int lastIndex = (max + skip > childrenList.size() ? childrenList.size() : max + skip) - 1;
|
||||||
for (int i = skip; i <= lastIndex; i++)
|
for (int i = skip; i <= lastIndex; i++)
|
||||||
{
|
{
|
||||||
FileInfo child = childrenList.get(i);
|
FileInfo child = childrenList.get(i);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// create a child CMIS object
|
// create a child CMIS object
|
||||||
ObjectData object = connector.createCMISObject(child, filter,
|
ObjectData object = connector.createCMISObject(child, filter, includeAllowableActions,
|
||||||
includeAllowableActions, includeRelationships, renditionFilter, false, false);
|
includeRelationships, renditionFilter, false, false);
|
||||||
|
|
||||||
if (context.isObjectInfoRequired())
|
if (context.isObjectInfoRequired())
|
||||||
{
|
{
|
||||||
getObjectInfo(repositoryId, object.getId());
|
getObjectInfo(repositoryId, object.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
ObjectInFolderDataImpl childData = new ObjectInFolderDataImpl();
|
ObjectInFolderDataImpl childData = new ObjectInFolderDataImpl();
|
||||||
childData.setObject(object);
|
childData.setObject(object);
|
||||||
|
|
||||||
// include path segment
|
// include path segment
|
||||||
if (includePathSegment)
|
if (includePathSegment)
|
||||||
{
|
{
|
||||||
childData.setPathSegment(child.getName());
|
childData.setPathSegment(child.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
// add it
|
// add it
|
||||||
list.add(childData);
|
list.add(childData);
|
||||||
|
|
||||||
} catch (InvalidNodeRefException e)
|
} catch (InvalidNodeRefException e)
|
||||||
{
|
{
|
||||||
// ignore invalid children
|
// ignore invalid children
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// has more ?
|
// / has more ?
|
||||||
result.setHasMoreItems(pageOfNodeInfos.hasMoreItems());
|
result.setHasMoreItems(pageOfNodeInfos.hasMoreItems());
|
||||||
|
|
||||||
// total count ?
|
// total count ?
|
||||||
Pair<Integer, Integer> totalCounts = pageOfNodeInfos.getTotalResultCount();
|
Pair<Integer, Integer> totalCounts = pageOfNodeInfos.getTotalResultCount();
|
||||||
if (totalCounts != null)
|
if (totalCounts != null)
|
||||||
@@ -645,12 +655,13 @@ public class AlfrescoCmisService extends AbstractCmisService
|
|||||||
result.setNumItems(BigInteger.valueOf(totalCountLower));
|
result.setNumItems(BigInteger.valueOf(totalCountLower));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logger.isDebugEnabled())
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2301,6 +2312,27 @@ public class AlfrescoCmisService extends AbstractCmisService
|
|||||||
throw new CmisInvalidArgumentException("Object is a relationship!");
|
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<ObjectData>());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
NodeRef nodeRef = connector.getNodeRefIfCurrent("Object", objectId);
|
NodeRef nodeRef = connector.getNodeRefIfCurrent("Object", objectId);
|
||||||
return connector.getObjectRelationships(nodeRef, relationshipDirection, typeId, filter,
|
return connector.getObjectRelationships(nodeRef, relationshipDirection, typeId, filter,
|
||||||
includeAllowableActions, maxItems, skipCount);
|
includeAllowableActions, maxItems, skipCount);
|
||||||
|
@@ -1872,7 +1872,7 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen
|
|||||||
// relationships from and to versions are not preserved
|
// relationships from and to versions are not preserved
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get relationships
|
// get relationships
|
||||||
List<AssociationRef> assocs = new ArrayList<AssociationRef>();
|
List<AssociationRef> assocs = new ArrayList<AssociationRef>();
|
||||||
if (relationshipDirection == RelationshipDirection.SOURCE
|
if (relationshipDirection == RelationshipDirection.SOURCE
|
||||||
@@ -1903,7 +1903,7 @@ public class CMISConnector implements ApplicationContextAware, ApplicationListen
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((typeId != null) && !assocRef.getId().equals(typeId))
|
if ((typeId != null) && !assocTypeDef.getTypeId().equals(typeId))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user