\r
// CollectionSpace CMIS property mapping constants\r
final static String CMIS_TARGET_PREFIX = "DOC";\r
+ final static String CMIS_CORESCHEMA_PREFIX = "CORE";\r
// Relations CMIS property mapping constants\r
final static String CMIS_RELATIONS_PREFIX = "REL";\r
\r
import java.util.StringTokenizer;
import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.common.query.QueryContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* Creates the CMIS query from the service context. Each document handler is responsible for returning a valid CMIS query using the
* information in the current service context -which includes things like the query parameters, etc.
*/
- public String getCMISQuery() {
+ @Override
+ public String getCMISQuery(QueryContext queryContext) {
//
// By default, return nothing. Child classes can override if they want.
//
return null;
}
+ @Override
public boolean isCMISQuery() {
return false;
}
import java.util.Map;
import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.common.query.QueryContext;
import org.collectionspace.services.lifecycle.Lifecycle;
import org.collectionspace.services.lifecycle.TransitionDef;
import org.nuxeo.ecm.core.api.DocumentModel;
* Creates the CMIS query from the service context. Each document handler is responsible for returning a valid CMIS query using the
* information in the current service context -which includes things like the query parameters, etc.
*/
- public String getCMISQuery();
+ public String getCMISQuery(QueryContext queryContext);
public boolean isCMISQuery();
}
import org.collectionspace.services.common.document.DocumentWrapper;
import org.collectionspace.services.nuxeo.util.NuxeoUtils;
import org.collectionspace.services.common.profile.Profiler;
+import org.collectionspace.services.common.query.QueryContext;
import org.collectionspace.services.common.repository.RepositoryClient;
import org.collectionspace.services.common.repository.RepositoryClientFactory;
import org.collectionspace.services.common.vocabulary.RefNameServiceUtils.AuthRefConfigInfo;
* 3. Document 'B' is either the object or the subject of the relationship
*/
@Override
- public String getCMISQuery() {
+ public String getCMISQuery(QueryContext queryContext) {
String result = null;
if (isCMISQuery() == true) {
logger.error("Attempt to make CMIS query failed because the HTTP request was missing valid query parameters.");
}
+ StringBuilder query = new StringBuilder();
// assemble the query from the string arguments
- result = "SELECT " + selectFields
- + " FROM " + targetTable + " JOIN " + relTable
- + " ON " + theOnClause
- + " WHERE " + theWhereClause;
+ query.append("SELECT ");
+ query.append(selectFields);
+ query.append(" FROM " + targetTable + " JOIN " + relTable);
+ query.append(" ON " + theOnClause);
+ query.append(" WHERE " + theWhereClause);
+
+ try {
+ NuxeoUtils.appendCMISOrderBy(query, queryContext);
+ } catch (Exception e) {
+ logger.error("Could not append ORDER BY clause to CMIS query", e);
+ }
// An example:
// SELECT D.cmis:name, D.dc:title, R.dc:title, R.relations_common:subjectCsid
// FROM Dimension D JOIN Relation R
// ON R.relations_common:objectCsid = D.cmis:name
// WHERE R.relations_common:subjectCsid = '737527ec-a560-4776-99de'
+ // ORDER BY D.collectionspace_core:updatedAt DESC
+ result = query.toString();
if (logger.isDebugEnabled() == true && result != null) {
- logger.debug("The CMIS query for the Movement service is: " + result);
+ logger.debug("The CMIS query is: " + result);
}
}
/*
* See CSPACE-5036 - How to make CMISQL queries from Nuxeo
*/
- private IterableQueryResult makeCMISQLQuery(RepositoryInstance repoSession, String query) {
+ private IterableQueryResult makeCMISQLQuery(RepositoryInstance repoSession, String query, QueryContext queryContext) {
IterableQueryResult result = null;
// the NuxeoRepository should be constructed only once, then cached
NuxeoCmisService cmisService = new NuxeoCmisService(repo,
callContext, repoSession);
- result = repoSession.queryAndFetch(query,
- "CMISQL", cmisService);
+ result = repoSession.queryAndFetch(query, "CMISQL", cmisService);
} catch (ClientException e) {
// TODO Auto-generated catch block
logger.error("Encounter trouble making the following CMIS query: " + query, e);
DocumentFilter filter = handler.getDocumentFilter();
String oldOrderBy = filter.getOrderByClause();
if (isClauseEmpty(oldOrderBy) == true){
- filter.setOrderByClause(DocumentFilter.ORDER_BY_LAST_UPDATED); //per http://issues.collectionspace.org/browse/CSPACE-705 (Doesn't this conflict with what happens with the QueryContext instance that we create below?)
+ filter.setOrderByClause(DocumentFilter.ORDER_BY_LAST_UPDATED);
}
QueryContext queryContext = new QueryContext(ctx, handler);
DocumentModelList result = new DocumentModelListImpl();
try {
- String query = handler.getCMISQuery();
+ String query = handler.getCMISQuery(queryContext);
if (logger.isDebugEnabled()) {
logger.debug("Executing CMIS query: " + query.toString());
profiler.log("Executing CMIS query: " + query.toString());
profiler.start();
//
- IterableQueryResult queryResult = makeCMISQLQuery(repoSession, query);
+ IterableQueryResult queryResult = makeCMISQLQuery(repoSession, query, queryContext);
try {
for (Map<String, Serializable> row : queryResult) {
logger.debug(""
* @throws DocumentException if the supplied value of the orderBy clause is not valid.
*
*/
- static private final void appendNXQLOrderBy(StringBuilder query, String orderByClause)
+ static private final void appendNXQLOrderBy(StringBuilder query, String orderByClause, String orderByPrefix)
throws Exception {
if (orderByClause != null && ! orderByClause.trim().isEmpty()) {
if (isValidOrderByClause(orderByClause)) {
query.append(" ORDER BY ");
+ if (orderByPrefix != null) {
+ query.append(orderByPrefix);
+ }
query.append(orderByClause);
} else {
throw new DocumentException("Invalid format in sort request '" + orderByClause
static private final void appendNXQLOrderBy(StringBuilder query, QueryContext queryContext)
throws Exception {
String orderByClause = queryContext.getOrderByClause();
- appendNXQLOrderBy(query, orderByClause);
+ appendNXQLOrderBy(query, orderByClause, null);
+ }
+
+ static public final void appendCMISOrderBy(StringBuilder query, QueryContext queryContext)
+ throws Exception {
+ String orderByClause = queryContext.getOrderByClause();
+ appendNXQLOrderBy(query, orderByClause, IQueryManager.CMIS_TARGET_PREFIX + ".");
}
/**
}
appendNXQLWhere(query, queryContext);
// For a set of DocTypes, there is no sensible ordering other than by updatedAt
- appendNXQLOrderBy(query, DocumentFilter.ORDER_BY_LAST_UPDATED);
+ appendNXQLOrderBy(query, DocumentFilter.ORDER_BY_LAST_UPDATED, null);
// FIXME add 'order by' clause here, if appropriate
return query.toString();
}