//\r
// Query params for CMIS queries on the relationship (Relation) table.\r
//\r
- final static String SEARCH_RELATED_TO_CSID_SUBJECT = "rt_sbj";\r
- final static String SEARCH_RELATED_TO_CSID_OBJECT = "rd_obj";\r
+ final static String SEARCH_RELATED_TO_CSID_SUBJECT = "rtSbj";\r
+ final static String SEARCH_RELATED_TO_CSID_OBJECT = "rtObj";\r
+ \r
+ //\r
+ // Generic CMIS property mapping constants\r
+ //\r
+ final static String CMIS_OBJECT_ID = "cmis:objectId";\r
+ final static String CMIS_NAME = "cmis:name";\r
+ //\r
+ // Nuxeo related CMIS property mapping constants\r
+ final static String CMIS_NUXEO_ID = CMIS_OBJECT_ID;\r
+ final static String CMIS_NUXEO_NAME = CMIS_NAME;\r
+ final static String CMIS_NUXEO_TITLE = "dc:title";\r
+ \r
+ // CollectionSpace CMIS property mapping constants\r
+ final static String CMIS_TARGET_PREFIX = "DOC";\r
+ // Relations CMIS property mapping constants\r
+ final static String CMIS_RELATIONS_PREFIX = "REL";\r
+ \r
+ final static String CMIS_TARGET_NUXEO_ID = CMIS_TARGET_PREFIX + "." + CMIS_NUXEO_ID;\r
+ final static String CMIS_TARGET_CSID = CMIS_TARGET_PREFIX + "." + CMIS_NUXEO_NAME;\r
+ final static String CMIS_TARGET_TITLE = CMIS_TARGET_PREFIX + "." + CMIS_NUXEO_TITLE;\r
+ final static String CMIS_TARGET_NAME = CMIS_TARGET_PREFIX + "." + CMIS_NUXEO_NAME;\r
\r
public void execQuery(String queryString);\r
\r
<artifactId>org.collectionspace.services.client</artifactId>\r
<version>${project.version}</version>\r
</dependency>\r
+ <dependency>\r
+ <groupId>org.collectionspace.services</groupId>\r
+ <artifactId>org.collectionspace.services.relation.client</artifactId>\r
+ <version>${project.version}</version>\r
+ </dependency>\r
<dependency>\r
<groupId>org.collectionspace.services</groupId>\r
<artifactId>org.collectionspace.services.authentication.jaxb</artifactId>\r
//
return null;
}
+
+ public boolean isCMISQuery() {
+ return false;
+ }
}
* information in the current service context -which includes things like the query parameters, etc.
*/
public String getCMISQuery();
+
+ public boolean isCMISQuery();
}
import java.util.Collection;
import java.util.List;
+import javax.ws.rs.core.MultivaluedMap;
+
+import org.collectionspace.services.client.IQueryManager;
import org.collectionspace.services.client.PoxPayloadIn;
import org.collectionspace.services.client.PoxPayloadOut;
+import org.collectionspace.services.client.RelationClient;
import org.collectionspace.services.common.authorityref.AuthorityRefList;
import org.collectionspace.services.common.context.ServiceContext;
import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils;
COLLECTIONSPACE_CORE_UPDATED_BY, userId);
}
}
+
+ /*
+ * If we see the "rtSbj" query param then we need to perform a CMIS query. Currently, we have only one
+ * CMIS query, but we could add more. If we do, this method should look at the incoming request and corresponding
+ * query params to determine if we need to do a CMIS query
+ * (non-Javadoc)
+ * @see org.collectionspace.services.common.document.AbstractDocumentHandlerImpl#isCMISQuery()
+ */
+ public boolean isCMISQuery() {
+ boolean result = false;
+
+ MultivaluedMap<String, String> queryParams = getServiceContext().getQueryParams();
+ //
+ // Look the query params to see if we need to make a CMSIS query.
+ //
+ String subjectCsid = (String)queryParams.getFirst(IQueryManager.SEARCH_RELATED_TO_CSID_SUBJECT);
+ if (subjectCsid != null) {
+ result = true;
+ }
+
+ return result;
+ }
+
+ /**
+ * 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.
+ */
+ @Override
+ public String getCMISQuery() {
+ String result = null;
+
+ if (isCMISQuery() == true) {
+ MultivaluedMap<String, String> queryParams = getServiceContext().getQueryParams();
+ String subjectCsid = (String)queryParams.getFirst(IQueryManager.SEARCH_RELATED_TO_CSID_SUBJECT);
+ String docType = this.getServiceContext().getDocumentType();
+
+ String selectFields = IQueryManager.CMIS_TARGET_NAME + ", "
+ + IQueryManager.CMIS_TARGET_TITLE + ", "
+ + RelationClient.CMIS_CSPACE_RELATIONS_TITLE + ", "
+ + RelationClient.CMIS_CSPACE_RELATIONS_SUBJECT_ID;
+ String targetTable = docType + " " + IQueryManager.CMIS_TARGET_PREFIX;
+ String relationTable = RelationClient.SERVICE_DOC_TYPE + " " + IQueryManager.CMIS_RELATIONS_PREFIX;
+ String relationObjectCsid = RelationClient.CMIS_CSPACE_RELATIONS_OBJECT_ID;
+ String relationSubjectCsid = RelationClient.CMIS_CSPACE_RELATIONS_SUBJECT_ID;
+ String targetCsid = IQueryManager.CMIS_TARGET_CSID;
+
+ result = "SELECT " + selectFields
+ + " FROM " + targetTable + " JOIN " + relationTable
+ + " ON " + relationObjectCsid + " = " + targetCsid
+ + " WHERE " + relationSubjectCsid + " = " + "'" + subjectCsid + "'";
+
+ // 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'
+
+ if (logger.isDebugEnabled() == true && result != null) {
+ logger.debug("The CMIS query for the Movement service is: " + result);
+ }
+ }
+
+ return result;
+ }
+
}
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MultivaluedMap;
+import org.collectionspace.services.client.IQueryManager;
import org.collectionspace.services.client.PoxPayloadIn;
import org.collectionspace.services.client.PoxPayloadOut;
import org.collectionspace.services.client.workflow.WorkflowClient;
* See CSPACE-5036 - How to make CMISQL queries from Nuxeo
*/
private IterableQueryResult makeCMISQLQuery(RepositoryInstance repoSession, String query) {
+ IterableQueryResult result = null;
+
// the NuxeoRepository should be constructed only once, then cached
// (its construction is expensive)
try {
NuxeoCmisService cmisService = new NuxeoCmisService(repo,
callContext, repoSession);
- IterableQueryResult result = repoSession.queryAndFetch(query,
+ result = repoSession.queryAndFetch(query,
"CMISQL", cmisService);
- for (Map<String, Serializable> row : result) {
- logger.debug(
- // "dc:title is: " + (String)row.get("dc:title")
- "" + " Hierarchy Table ID is:" + row.get("cmis:objectId")
- + " cmis:name is: " + row.get("cmis:name")
- // + " nuxeo:lifecycleState is: " +
- // row.get("nuxeo:lifecycleState")
- );
- }
} catch (ClientException e) {
// TODO Auto-generated catch block
- e.printStackTrace();
+ logger.error("Encounter trouble making the following CMIS query: " + query, e);
}
+
+ return result;
}
/**
Profiler profiler = new Profiler(this, 2);
profiler.log("Executing NXQL query: " + query.toString());
profiler.start();
- if (handler.getCMISQuery() != null) {
- docList = getFilteredCMIS(ctx, handler, queryContext);
+ if (handler.isCMISQuery() == true) {
+ docList = getFilteredCMIS(repoSession, ctx, handler, queryContext); //FIXME: REM - Need to deal with paging info in CMIS query
} else if ((queryContext.getDocFilter().getOffset() > 0) || (queryContext.getDocFilter().getPageSize() > 0)) {
docList = repoSession.query(query, null,
queryContext.getDocFilter().getPageSize(), queryContext.getDocFilter().getOffset(), true);
profiler.start();
//
IterableQueryResult queryResult = makeCMISQLQuery(repoSession, query);
- for (Map<String, Serializable> row : queryResult) {
- logger.debug(
- // "dc:title is: " + (String)row.get("dc:title")
- "" + " Hierarchy Table ID is:" + row.get("cmis:objectId")
- + " cmis:name is: " + row.get("cmis:name")
- // + " nuxeo:lifecycleState is: " +
- // row.get("nuxeo:lifecycleState")
- );
- String nuxeoId = (String) row.get("cmis:objectId");
- DocumentModel docModel = NuxeoUtils.getDocumentModel(repoSession, nuxeoId);
- result.add(docModel);
- }
+ 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);
+ }
+ } finally {
+ queryResult.close();
+ }
//
profiler.stop();
logger.debug("Caught exception ", e);
}
throw new DocumentException(e);
- } finally {
- if (repoSession != null) {
- releaseRepositorySession(repoSession);
- }
}
return result;
import java.util.Iterator;
import java.util.List;
+import javax.ws.rs.core.MultivaluedMap;
+
import org.collectionspace.services.dimension.DimensionJAXBSchema;
-import org.collectionspace.services.common.document.DocumentHandler.Action;
+import org.collectionspace.services.client.IQueryManager;
+import org.collectionspace.services.client.RelationClient;
import org.collectionspace.services.common.document.DocumentWrapper;
import org.collectionspace.services.dimension.DimensionsCommon;
import org.collectionspace.services.dimension.DimensionsCommonList;
import org.collectionspace.services.jaxb.AbstractCommonList;
import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl;
-import org.collectionspace.services.nuxeo.util.NuxeoUtils;
import org.nuxeo.ecm.core.api.DocumentModel;
import org.nuxeo.ecm.core.api.DocumentModelList;
import org.slf4j.Logger;
public String getQProperty(String prop) {
return DimensionConstants.NUXEO_SCHEMA_NAME + ":" + prop;
}
-
+
}
return result;
}
- @Override
- protected AbstractCommonList getList(MultivaluedMap<String, String> queryParams) {
- if (isSet(IQueryManager.SEARCH_RELATED_TO_CSID_SUBJECT, queryParams) == false) {
- //
- // It's not a "related to" query so we can use our normal call to getList and not our CMIS query
- //
- return super.getList(queryParams);
- } else {
- //
- // We need to use CMIS query method since we'll be doing a join with the Relation table
- //
- try {
- ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(queryParams);
- DocumentHandler handler = createDocumentHandler(ctx);
- String relationToCsid = queryParams.getFirst(IQueryManager.SEARCH_RELATED_TO_CSID_SUBJECT);
-
- getRepositoryClient(ctx).getFilteredCMIS(ctx, handler);
-
- AbstractCommonList list = (AbstractCommonList) handler.getCommonPartList();
- return list;
- } catch (Exception e) {
- throw bigReThrow(e, ServiceMessages.LIST_FAILED);
- }
- }
- }
+// @Override
+// protected AbstractCommonList getList(MultivaluedMap<String, String> queryParams) {
+// if (isSet(IQueryManager.SEARCH_RELATED_TO_CSID_SUBJECT, queryParams) == false) {
+// //
+// // It's not a "related to" query so we can use our normal call to getList and not our CMIS query
+// //
+// return super.getList(queryParams);
+// } else {
+// //
+// // We need to use CMIS query method since we'll be doing a join with the Relation table
+// //
+// try {
+// ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx = createServiceContext(queryParams);
+// DocumentHandler handler = createDocumentHandler(ctx);
+// String relationToCsid = queryParams.getFirst(IQueryManager.SEARCH_RELATED_TO_CSID_SUBJECT);
+//
+// getRepositoryClient(ctx).getFilteredCMIS(ctx, handler);
+//
+// AbstractCommonList list = (AbstractCommonList) handler.getCommonPartList();
+// return list;
+// } catch (Exception e) {
+// throw bigReThrow(e, ServiceMessages.LIST_FAILED);
+// }
+// }
+// }
}
*/
package org.collectionspace.services.movement.nuxeo;
-import javax.ws.rs.core.MultivaluedMap;
-
-import org.collectionspace.services.client.IQueryManager;
-import org.collectionspace.services.movement.MovementResource;
import org.collectionspace.services.movement.MovementsCommon;
import org.collectionspace.services.nuxeo.client.java.DocHandlerBase;
import org.slf4j.Logger;
extends DocHandlerBase<MovementsCommon> {
final Logger logger = LoggerFactory.getLogger(MovementDocumentModelHandler.class);
-
- /**
- * 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.
- */
- @Override
- public String getCMISQuery() {
- String result = null;
-
- String subjectCsid = (String)getServiceContext().getQueryParams().get(IQueryManager.SEARCH_RELATED_TO_CSID_SUBJECT);
-
- //
- // For Debugging purposes only
- //
- String cmis_movement = System.getenv("CMIS_MOVEMENT");
-
- if (cmis_movement != null && !cmis_movement.isEmpty()) {
- result = cmis_movement;
- } else {
- result = "SELECT M.cmis:name, M.dc:title, R.dc:title, R.relations_common:subjectCsid "
- + "FROM Movement M JOIN Relation R ON R.relations_common:objectCsid = M.cmis:name "
- + "WHERE R.relations_common:subjectCsid = "
- + "'" + subjectCsid + "'";
- }
-
- if (logger.isDebugEnabled() == true) {
- logger.debug("The CMIS query for the Movement service is: " + result);
- }
-
- return result;
- }
-
}
* The Class RelationClient.
*/
public class RelationClient extends AbstractPoxServiceClientImpl<RelationsCommonList, RelationProxy> {
+ public static final String SERVICE_DOC_TYPE = "Relation"; // Used for CMIS queries only -should be the same as what's in the tenant bindings
public static final String SERVICE_NAME = "relations";
public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME;
public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT;
public static final String SERVICE_COMMONPART_NAME = SERVICE_NAME + PART_LABEL_SEPARATOR + PART_COMMON_LABEL;
+ // Relations CMIS property mapping constants
+ public final static String CMIS_CSPACE_RELATIONS_SUBJECT_ID = IQueryManager.CMIS_RELATIONS_PREFIX
+ + "." + 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_TITLE = IQueryManager.CMIS_RELATIONS_PREFIX
+ + "." + IQueryManager.CMIS_NUXEO_TITLE;
+
@Override
public String getServiceName() {
return SERVICE_NAME;