*/\r
package org.collectionspace.services.common.repository;\r
\r
+import java.util.List;\r
+\r
+import javax.ws.rs.core.MultivaluedMap;\r
+\r
/**\r
* DocumentFilter bundles simple query filtering parameters. \r
* It is designed to be used with filtered get and search calls to RepositoryClient.\r
* fetched by a RepositoryClient when calling filtered get methods.\r
*/\r
public class DocumentFilter {\r
+ public static final String PAGE_SIZE_PARAM = "pgSz";\r
+ public static final String START_PAGE_PARAM = "pgNum";\r
public static final int DEFAULT_PAGE_SIZE_INIT = 40;\r
public static int defaultPageSize = DEFAULT_PAGE_SIZE_INIT;\r
protected String whereClause; // Filtering clause. Omit the "WHERE".\r
this.pageSize = (pageSize>0)?pageSize:defaultPageSize;\r
}\r
\r
+ public static DocumentFilter CreatePaginatedDocumentFilter(\r
+ MultivaluedMap<String,String> queryParams) {\r
+ String startPageStr = null;\r
+ String pageSizeStr = null;\r
+ List<String> list = queryParams.remove(PAGE_SIZE_PARAM);\r
+ if(list!=null)\r
+ pageSizeStr = list.get(0);\r
+ list = queryParams.remove(START_PAGE_PARAM);\r
+ if(list!=null)\r
+ startPageStr = list.get(0);\r
+ DocumentFilter newDocFilter = new DocumentFilter();\r
+ if(pageSizeStr!= null) {\r
+ try{ newDocFilter.pageSize = Integer.valueOf(pageSizeStr); } \r
+ catch(NumberFormatException e){\r
+ throw new NumberFormatException("Bad value for: "+PAGE_SIZE_PARAM);\r
+ }\r
+ }\r
+ if(startPageStr!= null) {\r
+ try{ newDocFilter.startPage = Integer.valueOf(startPageStr); } \r
+ catch(NumberFormatException e){\r
+ throw new NumberFormatException("Bad value for: "+START_PAGE_PARAM);\r
+ }\r
+ }\r
+ return newDocFilter;\r
+ }\r
+ \r
/**\r
* @return the current default page size for new DocumentFilter instances\r
*/\r
String where = docFilter.getWhereClause();
if((null!=where)&&(where.length()>0))
query.append(" WHERE "+where);
- if(docFilter.getOffset()>0)
- query.append(" OFFSET "+docFilter.getOffset());
- if(docFilter.getPageSize()>0)
- query.append(" LIMIT "+docFilter.getPageSize());
- DocumentModelList docList = repoSession.query(query.toString());
+ DocumentModelList docList = null;
+ if((docFilter.getOffset()>0)||(docFilter.getPageSize()>0)) {
+ docList = repoSession.query(query.toString(), null,
+ docFilter.getPageSize(), docFilter.getOffset(), false);
+ } else {
+ docList = repoSession.query(query.toString());
+ }
//set repoSession to handle the document
((DocumentModelHandler) handler).setRepositorySession(repoSession);
DocumentModelListWrapper wrapDoc = new DocumentModelListWrapper(
}
return docHandler;
}
-
+
private DocumentHandler createItemDocumentHandler(
RemoteServiceContext ctx,
String inVocabulary) throws Exception {
VocabulariesCommonList vocabularyObjectList = new VocabulariesCommonList();
try{
RemoteServiceContext ctx = createServiceContext(null);
- DocumentHandler handler = createDocumentHandler(ctx);
MultivaluedMap<String,String> queryParams = ui.getQueryParameters();
- if(queryParams.size()>0) {
- String nameQ = queryParams.getFirst("name");
- if(nameQ!= null) {
- DocumentFilter myFilter = new DocumentFilter(
- "vocabularies_common:refName='"+nameQ+"'", 0, 0);
- handler.setDocumentFilter(myFilter);
- }
- }
+ DocumentHandler handler = createDocumentHandler(ctx);
+ DocumentFilter myFilter =
+ DocumentFilter.CreatePaginatedDocumentFilter(queryParams);
+ String nameQ = queryParams.getFirst("name");
+ if(nameQ!= null) {
+ myFilter.setWhereClause("vocabularies_common:refName='"+nameQ+"'");
+ }
+ handler.setDocumentFilter(myFilter);
getRepositoryClient(ctx).getFiltered(ctx, handler);
vocabularyObjectList = (VocabulariesCommonList) handler.getCommonPartList();
}catch(Exception e){
// Note that docType defaults to the ServiceName, so we're fine with that.
RemoteServiceContext ctx = createServiceContext(null, getItemServiceName());
DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
- /*
- // Note that we replace the getAll() call with a basic search on the parent vocab
- handler.prepare(Action.GET_ALL);
- client = NuxeoConnector.getInstance().getClient();
- repoSession = client.openRepository();
- if (logger.isDebugEnabled()) {
- logger.debug("getVocabularyItemList() repository root: " + repoSession.getRootDocument());
- }
- DocumentModelList docList =
- repoSession.query("SELECT * FROM Vocabularyitem WHERE vocabularyitems_common:inVocabulary='"
- +parentcsid+"'");
- //set repoSession to handle the document
- ((DocumentModelHandler) handler).setRepositorySession(repoSession);
- DocumentModelListWrapper wrapDoc = new DocumentModelListWrapper(
- docList);
- handler.handle(Action.GET_ALL, wrapDoc);
- handler.complete(Action.GET_ALL, wrapDoc);
- */
DocumentFilter myFilter = new DocumentFilter(
"vocabularyitems_common:inVocabulary='"+parentcsid+"'", 0, 0);
handler.setDocumentFilter(myFilter);