mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-21 18:09:20 +00:00
Merged DEV to HEAD: (ALF-11606)
31637: THOR-358: update CMIS getChildren (V3.x => CMISServicesImpl) 31700: THOR-358: update CMIS getChildren (V3.x => CMISServicesImpl) git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@32155 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||||
*
|
*
|
||||||
* This file is part of Alfresco
|
* This file is part of Alfresco
|
||||||
*
|
*
|
||||||
@@ -19,6 +19,7 @@
|
|||||||
package org.alfresco.repo.cmis.rest;
|
package org.alfresco.repo.cmis.rest;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.math.BigInteger;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@@ -59,6 +60,7 @@ import org.alfresco.cmis.CMISTypesFilterEnum;
|
|||||||
import org.alfresco.cmis.CMISVersioningStateEnum;
|
import org.alfresco.cmis.CMISVersioningStateEnum;
|
||||||
import org.alfresco.cmis.CMISQueryOptions.CMISQueryMode;
|
import org.alfresco.cmis.CMISQueryOptions.CMISQueryMode;
|
||||||
import org.alfresco.cmis.acl.CMISAccessControlEntryImpl;
|
import org.alfresco.cmis.acl.CMISAccessControlEntryImpl;
|
||||||
|
import org.alfresco.query.PagingResults;
|
||||||
import org.alfresco.repo.cmis.reference.ObjectIdReference;
|
import org.alfresco.repo.cmis.reference.ObjectIdReference;
|
||||||
import org.alfresco.repo.cmis.reference.ReferenceFactory;
|
import org.alfresco.repo.cmis.reference.ReferenceFactory;
|
||||||
import org.alfresco.repo.jscript.Association;
|
import org.alfresco.repo.jscript.Association;
|
||||||
@@ -70,8 +72,10 @@ import org.alfresco.repo.web.util.paging.Page;
|
|||||||
import org.alfresco.repo.web.util.paging.PagedResults;
|
import org.alfresco.repo.web.util.paging.PagedResults;
|
||||||
import org.alfresco.repo.web.util.paging.Paging;
|
import org.alfresco.repo.web.util.paging.Paging;
|
||||||
import org.alfresco.service.ServiceRegistry;
|
import org.alfresco.service.ServiceRegistry;
|
||||||
|
import org.alfresco.service.cmr.model.FileInfo;
|
||||||
import org.alfresco.service.cmr.repository.AssociationRef;
|
import org.alfresco.service.cmr.repository.AssociationRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.util.Pair;
|
||||||
import org.mozilla.javascript.Context;
|
import org.mozilla.javascript.Context;
|
||||||
import org.mozilla.javascript.Scriptable;
|
import org.mozilla.javascript.Scriptable;
|
||||||
import org.mozilla.javascript.ScriptableObject;
|
import org.mozilla.javascript.ScriptableObject;
|
||||||
@@ -395,27 +399,53 @@ public class CMISScript extends BaseScopableProcessorExtension
|
|||||||
*/
|
*/
|
||||||
public PagedResults queryChildren(ScriptNode parent, String typesFilter, String orderBy, Page page)
|
public PagedResults queryChildren(ScriptNode parent, String typesFilter, String orderBy, Page page)
|
||||||
{
|
{
|
||||||
CMISTypesFilterEnum filter = resolveTypesFilter(typesFilter);
|
|
||||||
NodeRef[] children;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
children = cmisService.getChildren(parent.getNodeRef(), filter, orderBy);
|
CMISTypesFilterEnum filter = resolveTypesFilter(typesFilter);
|
||||||
|
|
||||||
|
int maxItems = page.getSize();
|
||||||
|
int skipCount = (page.getNumber() - (page.isZeroBasedIdx() ? 0 : 1)) * maxItems;
|
||||||
|
|
||||||
|
PagingResults<FileInfo> pageOfNodeInfos = cmisService.getChildren(parent.getNodeRef(), filter, BigInteger.valueOf(maxItems), BigInteger.valueOf(skipCount), orderBy);
|
||||||
|
|
||||||
|
int pageCnt = pageOfNodeInfos.getPage().size();
|
||||||
|
NodeRef[] children = new NodeRef[pageCnt];
|
||||||
|
|
||||||
|
int idx = 0;
|
||||||
|
for (FileInfo child : pageOfNodeInfos.getPage())
|
||||||
|
{
|
||||||
|
children[idx] = child.getNodeRef();
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
|
|
||||||
|
// total count ?
|
||||||
|
int totalCount = pageCnt;
|
||||||
|
Pair<Integer, Integer> totalCounts = pageOfNodeInfos.getTotalResultCount();
|
||||||
|
if (totalCounts != null)
|
||||||
|
{
|
||||||
|
Integer totalCountLower = totalCounts.getFirst();
|
||||||
|
Integer totalCountUpper = totalCounts.getSecond();
|
||||||
|
if ((totalCountLower != null) && (totalCountLower.equals(totalCountUpper)))
|
||||||
|
{
|
||||||
|
totalCount = totalCountLower;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Cursor cursor = paging.createCursor(totalCount, page);
|
||||||
|
|
||||||
|
ScriptNode[] nodes = new ScriptNode[pageCnt];
|
||||||
|
for (int i = 0; i < pageCnt; i++)
|
||||||
|
{
|
||||||
|
nodes[i] = new ScriptNode(children[i], services, getScope());
|
||||||
|
}
|
||||||
|
|
||||||
|
PagedResults results = paging.createPagedResults(nodes, cursor);
|
||||||
|
return results;
|
||||||
}
|
}
|
||||||
catch (CMISInvalidArgumentException e)
|
catch (CMISInvalidArgumentException e)
|
||||||
{
|
{
|
||||||
throw new WebScriptException(e.getStatusCode(), e.getMessage(), e);
|
throw new WebScriptException(e.getStatusCode(), e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
Cursor cursor = paging.createCursor(children.length, page);
|
|
||||||
int cnt = (cursor.getRowCount() < 0 ? 0 : cursor.getRowCount());
|
|
||||||
ScriptNode[] nodes = new ScriptNode[cnt];
|
|
||||||
for (int i = cursor.getStartRow(); i <= cursor.getEndRow(); i++)
|
|
||||||
{
|
|
||||||
nodes[i - cursor.getStartRow()] = new ScriptNode(children[i], services, getScope());
|
|
||||||
}
|
|
||||||
|
|
||||||
PagedResults results = paging.createPagedResults(nodes, cursor);
|
|
||||||
return results;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2005-2010 Alfresco Software Limited.
|
* Copyright (C) 2005-2011 Alfresco Software Limited.
|
||||||
*
|
*
|
||||||
* This file is part of Alfresco
|
* This file is part of Alfresco
|
||||||
*
|
*
|
||||||
@@ -29,11 +29,14 @@ import org.alfresco.cmis.CMISInvalidArgumentException;
|
|||||||
import org.alfresco.cmis.CMISServiceException;
|
import org.alfresco.cmis.CMISServiceException;
|
||||||
import org.alfresco.cmis.CMISTypesFilterEnum;
|
import org.alfresco.cmis.CMISTypesFilterEnum;
|
||||||
import org.alfresco.cmis.PropertyFilter;
|
import org.alfresco.cmis.PropertyFilter;
|
||||||
|
import org.alfresco.query.PagingResults;
|
||||||
import org.alfresco.repo.cmis.ws.utils.ExceptionUtil;
|
import org.alfresco.repo.cmis.ws.utils.ExceptionUtil;
|
||||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||||
import org.alfresco.repo.web.util.paging.Cursor;
|
import org.alfresco.repo.web.util.paging.Cursor;
|
||||||
|
import org.alfresco.service.cmr.model.FileInfo;
|
||||||
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
import org.alfresco.service.cmr.repository.ChildAssociationRef;
|
||||||
import org.alfresco.service.cmr.repository.NodeRef;
|
import org.alfresco.service.cmr.repository.NodeRef;
|
||||||
|
import org.alfresco.util.Pair;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Port for navigation service
|
* Port for navigation service
|
||||||
@@ -107,34 +110,54 @@ public class DMNavigationServicePort extends DMAbstractServicePort implements Na
|
|||||||
{
|
{
|
||||||
checkRepositoryId(repositoryId);
|
checkRepositoryId(repositoryId);
|
||||||
PropertyFilter propertyFilter = createPropertyFilter(filter);
|
PropertyFilter propertyFilter = createPropertyFilter(filter);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
NodeRef folderNodeRef = cmisService.getFolder(folderId);
|
NodeRef folderNodeRef = cmisService.getFolder(folderId);
|
||||||
|
|
||||||
NodeRef[] listing = cmisService.getChildren(folderNodeRef, CMISTypesFilterEnum.ANY, orderBy);
|
PagingResults<FileInfo> pageOfNodeInfos = cmisService.getChildren(folderNodeRef, CMISTypesFilterEnum.ANY, maxItems, skipCount, orderBy);
|
||||||
|
|
||||||
CmisObjectInFolderListType result = new CmisObjectInFolderListType();
|
int pageCnt = pageOfNodeInfos.getPage().size();
|
||||||
|
NodeRef[] children = new NodeRef[pageCnt];
|
||||||
Cursor cursor = createCursor(listing.length, skipCount, maxItems);
|
|
||||||
|
int idx = 0;
|
||||||
for (int index = cursor.getStartRow(); index <= cursor.getEndRow(); index++)
|
for (FileInfo child : pageOfNodeInfos.getPage())
|
||||||
{
|
{
|
||||||
CmisObjectType cmisObject = createCmisObject(listing[index], propertyFilter, includeRelationships,
|
children[idx] = child.getNodeRef();
|
||||||
|
idx++;
|
||||||
|
}
|
||||||
|
|
||||||
|
CmisObjectInFolderListType result = new CmisObjectInFolderListType();
|
||||||
|
|
||||||
|
// 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int index = 0; index < pageCnt; index++)
|
||||||
|
{
|
||||||
|
CmisObjectType cmisObject = createCmisObject(children[index], propertyFilter, includeRelationships,
|
||||||
includeAllowableActions, renditionFilter);
|
includeAllowableActions, renditionFilter);
|
||||||
CmisObjectInFolderType cmisObjectInFolder = new CmisObjectInFolderType();
|
CmisObjectInFolderType cmisObjectInFolder = new CmisObjectInFolderType();
|
||||||
cmisObjectInFolder.setObject(cmisObject);
|
cmisObjectInFolder.setObject(cmisObject);
|
||||||
if (includePathSegments != null && includePathSegments)
|
if (includePathSegments != null && includePathSegments)
|
||||||
{
|
{
|
||||||
cmisObjectInFolder.setPathSegment(propertiesUtil.getProperty(listing[index],
|
cmisObjectInFolder.setPathSegment(propertiesUtil.getProperty(children[index],
|
||||||
CMISDictionaryModel.PROP_NAME, ""));
|
CMISDictionaryModel.PROP_NAME, ""));
|
||||||
}
|
}
|
||||||
result.getObjects().add(cmisObjectInFolder);
|
result.getObjects().add(cmisObjectInFolder);
|
||||||
}
|
}
|
||||||
|
|
||||||
result.setHasMoreItems(cursor.getEndRow() < (listing.length - 1));
|
|
||||||
result.setNumItems(BigInteger.valueOf(listing.length));
|
|
||||||
|
|
||||||
// TODO: Process includeRelationships, includeACL
|
// TODO: Process includeRelationships, includeACL
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user