Rename PagingDetails to ScriptPagingDetails in preparation for merging with PagingRequest. (JS object name is unchanged, which is the main use)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28310 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Nick Burch
2011-06-09 14:27:08 +00:00
parent eb64645c97
commit 0e9f85789b
6 changed files with 119 additions and 84 deletions

View File

@@ -27,7 +27,7 @@ import org.alfresco.service.cmr.module.ModuleService;
import org.alfresco.service.cmr.repository.NodeRef; import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.NamespaceService; import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName; import org.alfresco.service.namespace.QName;
import org.alfresco.util.PagingDetails; import org.alfresco.util.ScriptPagingDetails;
import org.springframework.extensions.surf.util.I18NUtil; import org.springframework.extensions.surf.util.I18NUtil;
import org.springframework.extensions.surf.util.ISO8601DateFormat; import org.springframework.extensions.surf.util.ISO8601DateFormat;
@@ -173,9 +173,18 @@ public final class ScriptUtils extends BaseScopableProcessorExtension
* Builds a paging object, from the supplied * Builds a paging object, from the supplied
* Max Items and Skip Count * Max Items and Skip Count
*/ */
public PagingDetails createPaging(int maxItems, int skipCount) public ScriptPagingDetails createPaging(int maxItems, int skipCount)
{ {
return new PagingDetails(maxItems, skipCount); return new ScriptPagingDetails(maxItems, skipCount);
}
/**
* Builds a paging object, from the supplied
* Max Items, Skip Count and Query Execution ID
*/
public ScriptPagingDetails createPaging(int maxItems, int skipCount, String queryExecutionId)
{
return new ScriptPagingDetails(maxItems, skipCount, queryExecutionId);
} }
/** /**
@@ -183,10 +192,12 @@ public final class ScriptUtils extends BaseScopableProcessorExtension
* Requires that the parameters have their standard names, * Requires that the parameters have their standard names,
* i.e. "maxItems" and "skipCount" * i.e. "maxItems" and "skipCount"
*/ */
public PagingDetails createPaging(Map<String, String> args) public ScriptPagingDetails createPaging(Map<String, String> args)
{ {
int maxItems = -1; int maxItems = -1;
int skipCount = -1; int skipCount = -1;
String queryId = null;
if(args.containsKey("maxItems")) if(args.containsKey("maxItems"))
{ {
try try
@@ -206,7 +217,16 @@ public final class ScriptUtils extends BaseScopableProcessorExtension
{} {}
} }
return new PagingDetails(maxItems, skipCount); if(args.containsKey("queryId"))
{
queryId = args.get("queryId");
}
else if(args.containsKey("queryExecutionId"))
{
queryId = args.get("queryExecutionId");
}
return new ScriptPagingDetails(maxItems, skipCount, queryId);
} }
/** /**

View File

@@ -27,7 +27,7 @@ import org.alfresco.repo.jscript.BaseScopableProcessorExtension;
import org.alfresco.repo.security.authority.UnknownAuthorityException; import org.alfresco.repo.security.authority.UnknownAuthorityException;
import org.alfresco.service.cmr.security.AuthorityService; import org.alfresco.service.cmr.security.AuthorityService;
import org.alfresco.service.cmr.security.AuthorityType; import org.alfresco.service.cmr.security.AuthorityType;
import org.alfresco.util.PagingDetails; import org.alfresco.util.ScriptPagingDetails;
/** /**
* Script object representing the authority service. * Script object representing the authority service.
@@ -69,7 +69,7 @@ public class ScriptAuthorityService extends BaseScopableProcessorExtension
*/ */
public ScriptGroup[] searchRootGroupsInZone(String displayNamePattern, String zone, int maxItems, int skipCount) public ScriptGroup[] searchRootGroupsInZone(String displayNamePattern, String zone, int maxItems, int skipCount)
{ {
return searchRootGroupsInZone(displayNamePattern, zone, new PagingDetails(maxItems, skipCount), null); return searchRootGroupsInZone(displayNamePattern, zone, new ScriptPagingDetails(maxItems, skipCount), null);
} }
/** /**
@@ -79,7 +79,7 @@ public class ScriptAuthorityService extends BaseScopableProcessorExtension
* @param sortBy What to sort on (authorityName, shortName or displayName) * @param sortBy What to sort on (authorityName, shortName or displayName)
* @return The root groups (empty if there are no root groups) * @return The root groups (empty if there are no root groups)
*/ */
public ScriptGroup[] searchRootGroupsInZone(String displayNamePattern, String zone, PagingDetails paging, String sortBy) public ScriptGroup[] searchRootGroupsInZone(String displayNamePattern, String zone, ScriptPagingDetails paging, String sortBy)
{ {
Set<String> authorities; Set<String> authorities;
try { try {
@@ -117,14 +117,14 @@ public class ScriptAuthorityService extends BaseScopableProcessorExtension
*/ */
public ScriptGroup[] getAllRootGroups(int maxItems, int skipCount) public ScriptGroup[] getAllRootGroups(int maxItems, int skipCount)
{ {
return getAllRootGroups(new PagingDetails(maxItems, skipCount)); return getAllRootGroups(new ScriptPagingDetails(maxItems, skipCount));
} }
/** /**
* Search the root groups, those without a parent group. Searches in all zones. * Search the root groups, those without a parent group. Searches in all zones.
* @return The root groups (empty if there are no root groups) * @return The root groups (empty if there are no root groups)
*/ */
public ScriptGroup[] getAllRootGroups(PagingDetails paging) public ScriptGroup[] getAllRootGroups(ScriptPagingDetails paging)
{ {
Set<String> authorities; Set<String> authorities;
try{ try{
@@ -166,7 +166,7 @@ public class ScriptAuthorityService extends BaseScopableProcessorExtension
authorities = Collections.emptySet(); authorities = Collections.emptySet();
} }
return makeScriptGroups(authorities, new PagingDetails(maxItems, skipCount), null, authorityService); return makeScriptGroups(authorities, new ScriptPagingDetails(maxItems, skipCount), null, authorityService);
} }
/** /**
@@ -176,7 +176,7 @@ public class ScriptAuthorityService extends BaseScopableProcessorExtension
* @param sortBy What to sort on (authorityName, shortName or displayName) * @param sortBy What to sort on (authorityName, shortName or displayName)
* @return The root groups (empty if there are no root groups) * @return The root groups (empty if there are no root groups)
*/ */
public ScriptGroup[] getAllRootGroupsInZone(String zone, PagingDetails paging, String sortBy) public ScriptGroup[] getAllRootGroupsInZone(String zone, ScriptPagingDetails paging, String sortBy)
{ {
Set<String> authorities; Set<String> authorities;
try try
@@ -271,7 +271,7 @@ public class ScriptAuthorityService extends BaseScopableProcessorExtension
*/ */
public ScriptGroup[] searchGroupsInZone(String shortNameFilter, String zone, int maxItems, int skipCount) public ScriptGroup[] searchGroupsInZone(String shortNameFilter, String zone, int maxItems, int skipCount)
{ {
return searchGroupsInZone(shortNameFilter, zone, new PagingDetails(maxItems, skipCount), null); return searchGroupsInZone(shortNameFilter, zone, new ScriptPagingDetails(maxItems, skipCount), null);
} }
/** /**
@@ -284,7 +284,7 @@ public class ScriptAuthorityService extends BaseScopableProcessorExtension
* @param sortBy What to sort on (authorityName, shortName or displayName) * @param sortBy What to sort on (authorityName, shortName or displayName)
* @return the groups matching the query * @return the groups matching the query
*/ */
public ScriptGroup[] searchGroupsInZone(String shortNameFilter, String zone, PagingDetails paging, String sortBy) public ScriptGroup[] searchGroupsInZone(String shortNameFilter, String zone, ScriptPagingDetails paging, String sortBy)
{ {
String filter = shortNameFilter; String filter = shortNameFilter;

View File

@@ -34,7 +34,7 @@ import java.util.TreeSet;
import org.alfresco.service.cmr.security.AuthorityService; import org.alfresco.service.cmr.security.AuthorityService;
import org.alfresco.service.cmr.security.AuthorityType; import org.alfresco.service.cmr.security.AuthorityType;
import org.alfresco.util.ModelUtil; import org.alfresco.util.ModelUtil;
import org.alfresco.util.PagingDetails; import org.alfresco.util.ScriptPagingDetails;
/** /**
* The Script group is a GROUP authority exposed to the scripting API. * The Script group is a GROUP authority exposed to the scripting API.
@@ -186,7 +186,7 @@ public class ScriptGroup implements Authority, Serializable
*/ */
public ScriptUser[] getChildUsers() public ScriptUser[] getChildUsers()
{ {
return getChildUsers(new PagingDetails(), null); return getChildUsers(new ScriptPagingDetails(), null);
} }
/** /**
@@ -194,7 +194,7 @@ public class ScriptGroup implements Authority, Serializable
* @param paging Paging object with max number to return, and items to skip * @param paging Paging object with max number to return, and items to skip
* @param sortBy What to sort on (authorityName, shortName or displayName) * @param sortBy What to sort on (authorityName, shortName or displayName)
*/ */
public ScriptUser[] getChildUsers(PagingDetails paging, String sortBy) public ScriptUser[] getChildUsers(ScriptPagingDetails paging, String sortBy)
{ {
if (childUsers == null) if (childUsers == null)
{ {
@@ -216,7 +216,7 @@ public class ScriptGroup implements Authority, Serializable
private ScriptGroup[] childGroups; private ScriptGroup[] childGroups;
public ScriptGroup[] getChildGroups() public ScriptGroup[] getChildGroups()
{ {
return getChildGroups(new PagingDetails(), null); return getChildGroups(new ScriptPagingDetails(), null);
} }
/** /**
@@ -226,7 +226,7 @@ public class ScriptGroup implements Authority, Serializable
*/ */
public ScriptGroup[] getChildGroups(int maxItems, int skipCount) public ScriptGroup[] getChildGroups(int maxItems, int skipCount)
{ {
return getChildGroups(new PagingDetails(maxItems, skipCount), null); return getChildGroups(new ScriptPagingDetails(maxItems, skipCount), null);
} }
/** /**
@@ -234,7 +234,7 @@ public class ScriptGroup implements Authority, Serializable
* @param paging Paging object with max number to return, and items to skip * @param paging Paging object with max number to return, and items to skip
* @param sortBy What to sort on (authorityName, shortName or displayName) * @param sortBy What to sort on (authorityName, shortName or displayName)
*/ */
public ScriptGroup[] getChildGroups(PagingDetails paging, String sortBy) public ScriptGroup[] getChildGroups(ScriptPagingDetails paging, String sortBy)
{ {
if (childGroups == null) if (childGroups == null)
{ {
@@ -250,7 +250,7 @@ public class ScriptGroup implements Authority, Serializable
*/ */
public Authority[] getChildAuthorities() public Authority[] getChildAuthorities()
{ {
return getChildAuthorities(new PagingDetails(), null); return getChildAuthorities(new ScriptPagingDetails(), null);
} }
/** /**
@@ -258,7 +258,7 @@ public class ScriptGroup implements Authority, Serializable
* @param paging Paging object with max number to return, and items to skip * @param paging Paging object with max number to return, and items to skip
* @param sortBy What to sort on (authorityName, shortName or displayName) * @param sortBy What to sort on (authorityName, shortName or displayName)
*/ */
public Authority[] getChildAuthorities(PagingDetails paging, String sortBy) public Authority[] getChildAuthorities(ScriptPagingDetails paging, String sortBy)
{ {
Authority[] groups = getChildGroups(); Authority[] groups = getChildGroups();
Authority[] users = getChildUsers(); Authority[] users = getChildUsers();
@@ -282,7 +282,7 @@ public class ScriptGroup implements Authority, Serializable
*/ */
public ScriptGroup[] getParentGroups() public ScriptGroup[] getParentGroups()
{ {
return getParentGroups(new PagingDetails(), null); return getParentGroups(new ScriptPagingDetails(), null);
} }
/** /**
@@ -293,7 +293,7 @@ public class ScriptGroup implements Authority, Serializable
*/ */
public ScriptGroup[] getParentGroups(int maxItems, int skipCount) public ScriptGroup[] getParentGroups(int maxItems, int skipCount)
{ {
return getParentGroups(new PagingDetails(maxItems, skipCount), null); return getParentGroups(new ScriptPagingDetails(maxItems, skipCount), null);
} }
/** /**
@@ -302,7 +302,7 @@ public class ScriptGroup implements Authority, Serializable
* @param sortBy What to sort on (authorityName, shortName or displayName) * @param sortBy What to sort on (authorityName, shortName or displayName)
* @return the immediate parents of this group * @return the immediate parents of this group
*/ */
public ScriptGroup[] getParentGroups(PagingDetails paging, String sortBy) public ScriptGroup[] getParentGroups(ScriptPagingDetails paging, String sortBy)
{ {
if (parentCache == null) if (parentCache == null)
{ {
@@ -313,7 +313,7 @@ public class ScriptGroup implements Authority, Serializable
return makePagedAuthority(paging, sortBy, parentCache); return makePagedAuthority(paging, sortBy, parentCache);
} }
private <T extends Authority> T[] makePagedAuthority(PagingDetails paging, String sortBy, T[] groups) private <T extends Authority> T[] makePagedAuthority(ScriptPagingDetails paging, String sortBy, T[] groups)
{ {
// Sort the groups // Sort the groups
Arrays.sort(groups, new AuthorityComparator(sortBy)); Arrays.sort(groups, new AuthorityComparator(sortBy));
@@ -345,7 +345,7 @@ public class ScriptGroup implements Authority, Serializable
*/ */
public ScriptGroup[] getAllParentGroups() public ScriptGroup[] getAllParentGroups()
{ {
return getAllParentGroups(new PagingDetails(), null); return getAllParentGroups(new ScriptPagingDetails(), null);
} }
/** /**
@@ -357,7 +357,7 @@ public class ScriptGroup implements Authority, Serializable
*/ */
public ScriptGroup[] getAllParentGroups(int maxItems, int skipCount) public ScriptGroup[] getAllParentGroups(int maxItems, int skipCount)
{ {
return getAllParentGroups(new PagingDetails(maxItems, skipCount), null); return getAllParentGroups(new ScriptPagingDetails(maxItems, skipCount), null);
} }
/** /**
@@ -367,7 +367,7 @@ public class ScriptGroup implements Authority, Serializable
* @param sortBy What to sort on (authorityName, shortName or displayName) * @param sortBy What to sort on (authorityName, shortName or displayName)
* @return all the parents of this group * @return all the parents of this group
*/ */
public ScriptGroup[] getAllParentGroups(PagingDetails paging, String sortBy) public ScriptGroup[] getAllParentGroups(ScriptPagingDetails paging, String sortBy)
{ {
Set<String> parents = authorityService.getContainingAuthorities(AuthorityType.GROUP, fullName, false); Set<String> parents = authorityService.getContainingAuthorities(AuthorityType.GROUP, fullName, false);
return makeScriptGroups(parents, paging, sortBy, authorityService); return makeScriptGroups(parents, paging, sortBy, authorityService);
@@ -482,12 +482,12 @@ public class ScriptGroup implements Authority, Serializable
} }
public static ScriptGroup[] makeScriptGroups(Collection<String> authorities, public static ScriptGroup[] makeScriptGroups(Collection<String> authorities,
PagingDetails paging, AuthorityService authorityService) ScriptPagingDetails paging, AuthorityService authorityService)
{ {
return makeScriptGroups(authorities, paging, null, authorityService); return makeScriptGroups(authorities, paging, null, authorityService);
} }
public static ScriptGroup[] makeScriptGroups(Collection<String> authorities, public static ScriptGroup[] makeScriptGroups(Collection<String> authorities,
PagingDetails paging, final String sortBy, AuthorityService authorityService) ScriptPagingDetails paging, final String sortBy, AuthorityService authorityService)
{ {
final ArrayList<String> authList = new ArrayList<String>(authorities); final ArrayList<String> authList = new ArrayList<String>(authorities);

View File

@@ -91,7 +91,7 @@ public class ModelUtil
* *
* @param paging The paging object with total, skip, max etc * @param paging The paging object with total, skip, max etc
*/ */
public static Map<String, Object> buildPaging(PagingDetails paging) public static Map<String, Object> buildPaging(ScriptPagingDetails paging)
{ {
return buildPaging( return buildPaging(
paging.getTotalItems(), paging.getTotalItems(),
@@ -102,9 +102,9 @@ public class ModelUtil
public static <T> List<T> page(Collection<T> objects, int maxItems, int skipCount) public static <T> List<T> page(Collection<T> objects, int maxItems, int skipCount)
{ {
return page(objects, new PagingDetails(maxItems, skipCount)); return page(objects, new ScriptPagingDetails(maxItems, skipCount));
} }
public static <T> List<T> page(Collection<T> objects, PagingDetails paging) public static <T> List<T> page(Collection<T> objects, ScriptPagingDetails paging)
{ {
int maxItems = paging.getMaxItems(); int maxItems = paging.getMaxItems();
int skipCount = paging.getSkipCount(); int skipCount = paging.getSkipCount();

View File

@@ -1,50 +0,0 @@
package org.alfresco.util;
/**
* A simple paging details wrapper, to hold things like
* the skip count, max items and total items.
* This is typically used with {@link ModelUtil}.
* Note that {@link org.alfresco.repo.web.paging.Paging}
* provides an alternate solution for other paging
* use cases.
*/
public class PagingDetails
{
private int totalItems = -1;
private int maxItems = -1;
private int skipCount = -1;
public PagingDetails() {}
public PagingDetails(int maxItems, int skipCount)
{
this.maxItems = maxItems;
this.skipCount = skipCount;
}
public int getTotalItems()
{
return totalItems;
}
public void setTotalItems(int totalItems)
{
this.totalItems = totalItems;
}
public int getMaxItems()
{
return maxItems;
}
public void setMaxItems(int maxItems)
{
this.maxItems = maxItems;
}
public int getSkipCount()
{
return skipCount;
}
public void setSkipCount(int skipCount)
{
this.skipCount = skipCount;
}
}

View File

@@ -0,0 +1,65 @@
package org.alfresco.util;
/**
* A simple paging details wrapper, to hold things like the
* skip count, max items and total items. This is typically
* used with Scripts and WebScripts, and feeds into the
* Repository level paging support.
* This class is typically used with {@link ModelUtil}.
* Note that {@link org.alfresco.repo.web.paging.Paging}
* provides an alternate solution for other paging
* use cases.
*/
public class ScriptPagingDetails
{
private int totalItems = -1;
private int maxItems = -1; // TODO To PagingRequest
private int skipCount = -1; // TODO To PagingRequest
private String queryExecutionId = null; // TODO To PagingRequest
public ScriptPagingDetails() {}
public ScriptPagingDetails(int maxItems, int skipCount)
{
this(maxItems, skipCount, null);
}
public ScriptPagingDetails(int maxItems, int skipCount, String queryExecutionId)
{
this.maxItems = maxItems;
this.skipCount = skipCount;
this.queryExecutionId = queryExecutionId;
}
public int getTotalItems()
{
return totalItems;
}
public void setTotalItems(int totalItems)
{
this.totalItems = totalItems;
}
public int getMaxItems()
{
return maxItems;
}
public void setMaxItems(int maxItems)
{
this.maxItems = maxItems;
}
public int getSkipCount()
{
return skipCount;
}
public void setSkipCount(int skipCount)
{
this.skipCount = skipCount;
}
public String getQueryExecutionId() {
return queryExecutionId;
}
public void setQueryExecutionId(String queryExecutionId) {
this.queryExecutionId = queryExecutionId;
}
}