final static String SEARCH_RELATED_TO_CSID_AS_SUBJECT = "rtSbj";\r
final static String SEARCH_RELATED_TO_CSID_AS_OBJECT = "rtObj";\r
final static String SEARCH_RELATED_TO_CSID_AS_EITHER = "rtEither";\r
+ final static String SEARCH_RELATED_MATCH_OBJ_DOCTYPES = "rtObjDocTypes";\r
+ final static String SELECT_DOC_TYPE_FIELD = "selectDocType";\r
\r
//\r
// Generic CMIS property mapping constants\r
+ "." + SERVICE_COMMONPART_NAME + ":subjectCsid";
public final static String CMIS_CSPACE_RELATIONS_OBJECT_ID = IQueryManager.CMIS_RELATIONS_PREFIX
+ "." + SERVICE_COMMONPART_NAME + ":objectCsid";
+ public final static String CMIS_CSPACE_RELATIONS_OBJECT_TYPE = IQueryManager.CMIS_RELATIONS_PREFIX
+ + "." + SERVICE_COMMONPART_NAME + ":objectDocumentType";
public final static String CMIS_CSPACE_RELATIONS_TITLE = IQueryManager.CMIS_RELATIONS_PREFIX
+ "." + IQueryManager.CMIS_NUXEO_TITLE;
String result = null;
if (isCMISQuery() == true) {
- String docType = this.getServiceContext().getDocumentType();
+ //
+ // Build up the query arguments
+ //
+ String theOnClause = "";
+ String theWhereClause = "";
+ MultivaluedMap<String, String> queryParams = getServiceContext().getQueryParams();
+ String asSubjectCsid = (String)queryParams.getFirst(IQueryManager.SEARCH_RELATED_TO_CSID_AS_SUBJECT);
+ String asObjectCsid = (String)queryParams.getFirst(IQueryManager.SEARCH_RELATED_TO_CSID_AS_OBJECT);
+ String asEitherCsid = (String)queryParams.getFirst(IQueryManager.SEARCH_RELATED_TO_CSID_AS_EITHER);
+ String matchObjDocTypes = (String)queryParams.getFirst(IQueryManager.SEARCH_RELATED_MATCH_OBJ_DOCTYPES);
+ String selectDocType = (String)queryParams.getFirst(IQueryManager.SELECT_DOC_TYPE_FIELD);
+
+ String docType = this.getServiceContext().getDocumentType();
+ if (selectDocType != null && !selectDocType.isEmpty()) {
+ docType = selectDocType;
+ }
String selectFields = IQueryManager.CMIS_TARGET_CSID + ", "
+ IQueryManager.CMIS_TARGET_TITLE + ", "
+ IRelationsManager.CMIS_CSPACE_RELATIONS_TITLE + ", "
String relObjectCsidCol = IRelationsManager.CMIS_CSPACE_RELATIONS_OBJECT_ID;
String relSubjectCsidCol = IRelationsManager.CMIS_CSPACE_RELATIONS_SUBJECT_ID;
String targetCsidCol = IQueryManager.CMIS_TARGET_CSID;
- //
- // Build up the query arguments
- //
- String theOnClause = "";
- String theWhereClause = "";
- MultivaluedMap<String, String> queryParams = getServiceContext().getQueryParams();
- String asSubjectCsid = (String)queryParams.getFirst(IQueryManager.SEARCH_RELATED_TO_CSID_AS_SUBJECT);
- String asObjectCsid = (String)queryParams.getFirst(IQueryManager.SEARCH_RELATED_TO_CSID_AS_OBJECT);
- String asEitherCsid = (String)queryParams.getFirst(IQueryManager.SEARCH_RELATED_TO_CSID_AS_EITHER);
//
// Create the "ON" and "WHERE" query clauses based on the params passed into the HTTP request.
logger.error("Attempt to make CMIS query failed because the HTTP request was missing valid query parameters.");
}
+ // Now consider a constraint on the object doc types (for search by service group)
+ if (matchObjDocTypes != null && !matchObjDocTypes.isEmpty()) {
+ // Since our query param is the "subject" value, join the tables where the CSID of the document is the other side (the "object") of the relationship.
+ theWhereClause += " AND (" + IRelationsManager.CMIS_CSPACE_RELATIONS_OBJECT_TYPE
+ + " IN " + matchObjDocTypes + ")";
+ }
+
StringBuilder query = new StringBuilder();
// assemble the query from the string arguments
query.append("SELECT ");
//
import org.apache.chemistry.opencmis.commons.server.CallContext;
import org.apache.chemistry.opencmis.server.impl.CallContextImpl;
+import org.apache.chemistry.opencmis.server.support.query.CmisQlExtParser_CmisBaseGrammar.boolean_factor_return;
import org.nuxeo.ecm.core.opencmis.impl.server.NuxeoCmisService;
import org.nuxeo.ecm.core.opencmis.impl.server.NuxeoRepository;
if (logger.isDebugEnabled()) {
logger.debug("findDocs() NXQL: "+query);
}
- docList = repoSession.query(query, null, pageSize, pageNum, computeTotal);
+ docList = repoSession.query(query, null, pageSize, pageSize*pageNum, computeTotal);
wrapDoc = new DocumentWrapperImpl<DocumentModelList>(docList);
} catch (IllegalArgumentException iae) {
throw iae;
return wrapDoc;
}
+ protected static String buildInListForDocTypes(List<String> docTypes) {
+ StringBuilder sb = new StringBuilder();
+ sb.append("(");
+ boolean first = true;
+ for(String docType:docTypes) {
+ if(first) {
+ first = false;
+ } else {
+ sb.append(",");
+ }
+ sb.append("'");
+ sb.append(docType);
+ sb.append("'");
+ }
+ sb.append(")");
+ return sb.toString();
+ }
+
+ public DocumentWrapper<DocumentModelList> findDocs(
+ ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
+ DocumentHandler handler,
+ RepositoryInstance repoSession,
+ List<String> docTypes)
+ throws DocumentNotFoundException, DocumentException {
+ DocumentWrapper<DocumentModelList> wrapDoc = null;
+
+ DocumentFilter filter = handler.getDocumentFilter();
+ String oldOrderBy = filter.getOrderByClause();
+ QueryContext queryContext = new QueryContext(ctx, handler);
+
+ try {
+ if (docTypes == null || docTypes.size() < 1) {
+ throw new DocumentNotFoundException(
+ "The findDocs() method must specify at least one DocumentType.");
+ }
+ DocumentModelList docList = null;
+ if (handler.isCMISQuery() == true) {
+ // We have to omit the ORDER BY until we can get the "Document" table bug addressed.
+ // CF Nuxeo JIRA NXP-9562
+ String inList = buildInListForDocTypes(docTypes);
+ ctx.getQueryParams().add(IQueryManager.SEARCH_RELATED_MATCH_OBJ_DOCTYPES, inList);
+ docList = getFilteredCMIS(repoSession, ctx, handler, queryContext);
+ } else {
+ if (isClauseEmpty(oldOrderBy) == true){
+ filter.setOrderByClause(DocumentFilter.ORDER_BY_LAST_UPDATED);
+ }
+ String query = NuxeoUtils.buildNXQLQuery(docTypes, queryContext);
+ if (logger.isDebugEnabled()) {
+ logger.debug("findDocs() NXQL: "+query);
+ }
+ docList = repoSession.query(query, null, filter.getPageSize(), filter.getOffset(), true);
+ }
+ wrapDoc = new DocumentWrapperImpl<DocumentModelList>(docList);
+ } catch (IllegalArgumentException iae) {
+ throw iae;
+ } catch (Exception e) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Caught exception ", e);
+ }
+ throw new DocumentException(e);
+ }
+
+ return wrapDoc;
+ }
+
+
+
/**
* Find a list of documentModels from the Nuxeo repository
* @param docTypes a list of DocType names to match
try {
String query = handler.getCMISQuery(queryContext);
+ DocumentFilter docFilter = handler.getDocumentFilter();
+ int pageSize = docFilter.getPageSize();
+ int offset = docFilter.getOffset();
if (logger.isDebugEnabled()) {
- logger.debug("Executing CMIS query: " + query.toString());
+ logger.debug("Executing CMIS query: " + query.toString()
+ + "with pageSize: "+pageSize+" at offset: "+offset);
}
// If we have limit and/or offset, then pass true to get totalSize
//
IterableQueryResult queryResult = makeCMISQLQuery(repoSession, query, queryContext);
try {
- for (Map<String, Serializable> row : queryResult) {
- logger.debug(""
- // + " dc:title is: " + (String)row.get("dc:title")
- + " Hierarchy Table ID is:" + row.get(IQueryManager.CMIS_TARGET_NUXEO_ID)
- + " cmis:name is: " + row.get(IQueryManager.CMIS_TARGET_NAME)
- // + " nuxeo:lifecycleState is: " + row.get("nuxeo:lifecycleState")
- );
- String nuxeoId = (String) row.get(IQueryManager.CMIS_TARGET_NUXEO_ID);
- DocumentModel docModel = NuxeoUtils.getDocumentModel(repoSession, nuxeoId);
- result.add(docModel);
- }
+ int totalSize = (int)queryResult.size();
+ ((DocumentModelListImpl)result).setTotalSize(totalSize);
+ // Skip the rows before our offset
+ if(offset>0) {
+ queryResult.skipTo(offset);
+ }
+ int nRows = 0;
+ for (Map<String, Serializable> row : queryResult) {
+ logger.debug(""
+ // + " dc:title is: " + (String)row.get("dc:title")
+ + " Hierarchy Table ID is:" + row.get(IQueryManager.CMIS_TARGET_NUXEO_ID)
+ + " cmis:name is: " + row.get(IQueryManager.CMIS_TARGET_NAME)
+ // + " nuxeo:lifecycleState is: " + row.get("nuxeo:lifecycleState")
+ );
+ String nuxeoId = (String) row.get(IQueryManager.CMIS_TARGET_NUXEO_ID);
+ DocumentModel docModel = NuxeoUtils.getDocumentModel(repoSession, nuxeoId);
+ result.add(docModel);
+ nRows++;
+ if(nRows >= pageSize) {
+ logger.debug("Got page full of items - quitting");
+ break;
+ }
+ }
} finally {
queryResult.close();
}
// Since we're not supporting paging yet for CMIS queries, we need to perform
// a workaround for the paging information we return in our list of results
//
+ /*
if (result != null) {
- int totalSize = result.size();
- DocumentFilter docFilter = handler.getDocumentFilter();
docFilter.setStartPage(0);
if (totalSize > docFilter.getPageSize()) {
docFilter.setPageSize(totalSize);
((DocumentModelListImpl)result).setTotalSize(totalSize);
}
}
+ */
return result;
}
groupsList = new ArrayList<String>();
groupsList.add(serviceGroupName);
}
- list = handler.getItemsForGroup(ctx, groupsList, keywords);
+ // set up a keyword search
+ if (keywords != null && !keywords.isEmpty()) {
+ String whereClause = QueryManager.createWhereClauseFromKeywords(keywords);
+ if(Tools.isEmpty(whereClause)) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("The WHERE clause is empty for keywords: ["+keywords+"]");
+ }
+ } else {
+ DocumentFilter documentFilter = handler.getDocumentFilter();
+ documentFilter.appendWhereClause(whereClause, IQueryManager.SEARCH_QUALIFIER_AND);
+ if (logger.isDebugEnabled()) {
+ logger.debug("The WHERE clause is: " + documentFilter.getWhereClause());
+ }
+ }
+ }
+ list = handler.getItemsForGroup(ctx, groupsList);
} catch (Exception e) {
throw bigReThrow(e, ServiceMessages.READ_FAILED, serviceGroupName);
}
public AbstractCommonList getItemsForGroup(
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
- List<String> serviceGroupNames,
- String keywords) throws Exception {
+ List<String> serviceGroupNames) throws Exception {
CommonList commonList = new CommonList();
AbstractCommonList list = (AbstractCommonList)commonList;
RepositoryInstance repoSession = null;
releaseRepoSession = true;
}
DocumentFilter myFilter = getDocumentFilter();
- String whereClause = null;
- if (keywords != null) {
- whereClause = QueryManager.createWhereClauseFromKeywords(keywords);
- if(Tools.isEmpty(whereClause)) {
- if (logger.isDebugEnabled()) {
- logger.debug("The WHERE clause is empty for keywords: ["+keywords+"]");
- }
- } else {
- myFilter.appendWhereClause(whereClause, IQueryManager.SEARCH_QUALIFIER_AND);
- if (logger.isDebugEnabled()) {
- logger.debug("The WHERE clause is: " + myFilter.getWhereClause());
- }
- }
- }
// Make sure we pick up workflow state, etc.
- whereClause = myFilter.getWhereClause();
int pageSize = myFilter.getPageSize();
int pageNum = myFilter.getStartPage();
- final boolean computeTotal = true;
list.setPageNum(pageNum);
list.setPageSize(pageSize);
queriedServiceBindings.put(docType, binding);
}
}
+
+ // This should be "Document" but CMIS is gagging on that right now.
+ ctx.getQueryParams().add(IQueryManager.SELECT_DOC_TYPE_FIELD, "cmis:document");
// Now we have to issue the search
// findDocs qill build a QueryContext, which wants to see a docType for our context
ctx.setDocumentType("Document");
- DocumentWrapper<DocumentModelList> docListWrapper = nuxeoRepoClient.findDocs(ctx, repoSession,
- docTypes, whereClause, pageSize, pageNum, computeTotal);
+ DocumentWrapper<DocumentModelList> docListWrapper =
+ nuxeoRepoClient.findDocs(ctx, this, repoSession, docTypes );
// Now we gather the info for each document into the list and return
DocumentModelList docList = docListWrapper.getWrappedObject();