mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-14 17:58:59 +00:00
ALF-10429 Refactor the common new webscript code for building a PagingRequest object
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@31159 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -41,6 +41,7 @@ import org.alfresco.service.cmr.site.SiteService;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.util.GUID;
|
||||
import org.alfresco.util.ISO8601DateFormat;
|
||||
import org.alfresco.util.ScriptPagingDetails;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.JSONException;
|
||||
@@ -279,10 +280,7 @@ public abstract class AbstractCalendarWebScript extends DeclarativeWebScript
|
||||
*/
|
||||
protected PagingRequest buildPagingRequest(WebScriptRequest req)
|
||||
{
|
||||
// TODO Check the request for standard paging options
|
||||
PagingRequest paging = new PagingRequest(MAX_QUERY_ENTRY_COUNT);
|
||||
paging.setRequestTotalCountMax(MAX_QUERY_ENTRY_COUNT);
|
||||
return paging;
|
||||
return new ScriptPagingDetails(req, MAX_QUERY_ENTRY_COUNT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -43,6 +43,7 @@ import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.alfresco.service.cmr.site.SiteService;
|
||||
import org.alfresco.util.Pair;
|
||||
import org.alfresco.util.ScriptPagingDetails;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.simple.JSONArray;
|
||||
@@ -131,38 +132,7 @@ public abstract class AbstractDiscussionWebScript extends DeclarativeWebScript
|
||||
*/
|
||||
protected PagingRequest buildPagingRequest(WebScriptRequest req)
|
||||
{
|
||||
int pageSize = MAX_QUERY_ENTRY_COUNT;
|
||||
int startIndex = 0;
|
||||
|
||||
String pageSizeS = req.getParameter("pageSize");
|
||||
if (pageSizeS != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
pageSize = Integer.parseInt(pageSizeS);
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Paging size parameters invalid");
|
||||
}
|
||||
}
|
||||
|
||||
String startIndexS = req.getParameter("startIndex");
|
||||
if (startIndexS != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
startIndex = Integer.parseInt(startIndexS);
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Paging size parameters invalid");
|
||||
}
|
||||
}
|
||||
|
||||
PagingRequest paging = new PagingRequest( startIndex, pageSize );
|
||||
paging.setRequestTotalCountMax( Math.max(10*pageSize,startIndex+2*pageSize) );
|
||||
return paging;
|
||||
return new ScriptPagingDetails(req, MAX_QUERY_ENTRY_COUNT);
|
||||
}
|
||||
|
||||
protected List<String> getTags(JSONObject json)
|
||||
|
@@ -35,6 +35,7 @@ import org.alfresco.service.cmr.repository.NodeService;
|
||||
import org.alfresco.service.cmr.security.PersonService;
|
||||
import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.alfresco.service.cmr.site.SiteService;
|
||||
import org.alfresco.util.ScriptPagingDetails;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.simple.JSONArray;
|
||||
@@ -145,28 +146,11 @@ public abstract class AbstractLinksWebScript extends DeclarativeWebScript
|
||||
*/
|
||||
protected PagingRequest buildPagingRequest(WebScriptRequest req)
|
||||
{
|
||||
String pageNumberS = req.getParameter("page");
|
||||
String pageSizeS = req.getParameter("pageSize");
|
||||
if (pageNumberS == null || pageSizeS == null)
|
||||
if (req.getParameter("page") == null || req.getParameter("pageSize") == null)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Paging size parameters missing");
|
||||
}
|
||||
|
||||
int pageNumber;
|
||||
int pageSize;
|
||||
try
|
||||
{
|
||||
pageNumber = Integer.parseInt(pageNumberS);
|
||||
pageSize = Integer.parseInt(pageSizeS);
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Paging size parameters invalid");
|
||||
}
|
||||
|
||||
PagingRequest paging = new PagingRequest( (pageNumber-1) * pageSize, pageSize );
|
||||
paging.setRequestTotalCountMax( Math.max(10, pageNumber) * pageSize );
|
||||
return paging;
|
||||
return new ScriptPagingDetails(req, 100);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -33,6 +33,7 @@ import org.alfresco.service.cmr.site.SiteInfo;
|
||||
import org.alfresco.service.cmr.site.SiteService;
|
||||
import org.alfresco.service.cmr.wiki.WikiPageInfo;
|
||||
import org.alfresco.service.cmr.wiki.WikiService;
|
||||
import org.alfresco.util.ScriptPagingDetails;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.json.simple.JSONObject;
|
||||
@@ -108,38 +109,7 @@ public abstract class AbstractWikiWebScript extends DeclarativeWebScript
|
||||
*/
|
||||
protected PagingRequest buildPagingRequest(WebScriptRequest req)
|
||||
{
|
||||
int pageSize = MAX_QUERY_ENTRY_COUNT;
|
||||
int pageNumber = 1;
|
||||
|
||||
String pageSizeS = req.getParameter("pageSize");
|
||||
if (pageSizeS != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
pageSize = Integer.parseInt(pageSizeS);
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Paging size parameters invalid");
|
||||
}
|
||||
}
|
||||
|
||||
String pageNumberS = req.getParameter("page");
|
||||
if (pageNumberS != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
pageNumber = Integer.parseInt(pageNumberS);
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
throw new WebScriptException(Status.STATUS_BAD_REQUEST, "Paging size parameters invalid");
|
||||
}
|
||||
}
|
||||
|
||||
PagingRequest paging = new PagingRequest( (pageNumber-1) * pageSize, pageSize );
|
||||
paging.setRequestTotalCountMax( Math.max(10, pageNumber) * pageSize );
|
||||
return paging;
|
||||
return new ScriptPagingDetails(req, MAX_QUERY_ENTRY_COUNT);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user