--- /dev/null
+/**
+ * This document is a part of the source code and related artifacts
+ * for CollectionSpace, an open source collections management system
+ * for museums and related institutions:
+
+ * http://www.collectionspace.org
+ * http://wiki.collectionspace.org
+
+ * Copyright 2009 University of California at Berkeley
+
+ * Licensed under the Educational Community License (ECL), Version 2.0.
+ * You may not use this file except in compliance with this License.
+
+ * You may obtain a copy of the ECL 2.0 License at
+
+ * https://source.collectionspace.org/collection-space/LICENSE.txt
+ */
+package org.collectionspace.services.common.document;
+
+/**
+ * TransactionException
+ *
+ */
+public class TransactionException extends DocumentException {
+
+ // Custom HTTP status code, per the extensibility offered via RFC-2616
+ // e.g. http://tools.ietf.org/html/rfc2616#section-6.1.1
+ final public static int HTTP_CODE = 590;
+
+ final static String TRANSACTION_FAILED_MSG =
+ "A transaction failed, whether due to exceeding a timeout value or some other cause. Please contact your system administrator.";
+
+ /**
+ * Creates a new instance of <code>TransactionException</code> without detail message.
+ */
+ public TransactionException() {
+ super(TRANSACTION_FAILED_MSG);
+ setErrorCode(HTTP_CODE);
+ }
+
+ /**
+ * Constructs an instance of <code>TransactionException</code> with the specified detail message.
+ * @param msg the detail message.
+ */
+ public TransactionException(String msg) {
+ super(msg);
+ setErrorCode(HTTP_CODE);
+ }
+
+ /**
+ * Constructs a new exception with the specified detail message and
+ * cause. <p>Note that the detail message associated with
+ * <code>cause</code> is <i>not</i> automatically incorporated in
+ * this exception's detail message.
+ *
+ * @param message the detail message (which is saved for later retrieval
+ * by the {@link #getMessage()} method).
+ * @param cause the cause (which is saved for later retrieval by the
+ * {@link #getCause()} method). (A <tt>null</tt> value is
+ * permitted, and indicates that the cause is nonexistent or
+ * unknown.)
+ * @since 1.4
+ */
+ public TransactionException(String message, Throwable cause) {
+ super(message, cause);
+ setErrorCode(HTTP_CODE);
+ }
+
+ /**
+ * Constructs a new exception with the specified cause and a detail
+ * message of <tt>(cause==null ? null : cause.toString())</tt> (which
+ * typically contains the class and detail message of <tt>cause</tt>).
+ * This constructor is useful for exceptions that are little more than
+ * wrappers for other throwables (for example, {@link
+ * java.security.PrivilegedActionException}).
+ *
+ * @param cause the cause (which is saved for later retrieval by the
+ * {@link #getCause()} method). (A <tt>null</tt> value is
+ * permitted, and indicates that the cause is nonexistent or
+ * unknown.)
+ * @since 1.4
+ */
+ public TransactionException(Throwable cause) {
+ super(TRANSACTION_FAILED_MSG, cause);
+ setErrorCode(HTTP_CODE);
+ }
+}
import org.collectionspace.services.common.document.DocumentHandler.Action;
import org.collectionspace.services.common.document.DocumentWrapper;
import org.collectionspace.services.common.document.DocumentWrapperImpl;
+import org.collectionspace.services.common.document.TransactionException;
import org.nuxeo.common.utils.IdUtils;
import org.nuxeo.ecm.core.api.ClientException;
import org.nuxeo.ecm.core.api.IdRef;
import org.nuxeo.ecm.core.api.PathRef;
import org.nuxeo.ecm.core.api.repository.RepositoryInstance;
+import org.nuxeo.runtime.transaction.TransactionRuntimeException;
//
// CSPACE-5036 - How to make CMISQL queries from Nuxeo
* should be used by the caller to provide and transform the
* document
* @return id in repository of the newly created document
+ * @throws BadRequestException
+ * @throws TransactionException
* @throws DocumentException
*/
@Override
public String create(ServiceContext ctx,
DocumentHandler handler) throws BadRequestException,
- DocumentException {
+ TransactionException, DocumentException {
String docType = NuxeoUtils.getTenantQualifiedDocType(ctx); //ctx.getDocumentType();
if (docType == null) {
* @param handler
* should be used by the caller to provide and transform the
* document
+ * @throws DocumentNotFoundException if the document cannot be found in the repository
+ * @throws TransactionException
* @throws DocumentException
*/
@Override
public void get(ServiceContext ctx, String id, DocumentHandler handler)
- throws DocumentNotFoundException, DocumentException {
+ throws DocumentNotFoundException, TransactionException, DocumentException {
if (handler == null) {
throw new IllegalArgumentException(
}
/**
- * get document from the Nuxeo repository, using the docFilter params.
+ * get a document from the Nuxeo repository, using the docFilter params.
* @param ctx service context under which this method is invoked
* @param handler
* should be used by the caller to provide and transform the
* document. Handler must have a docFilter set to return a single item.
+ * @throws DocumentNotFoundException if the document cannot be found in the repository
+ * @throws TransactionException
* @throws DocumentException
*/
@Override
public void get(ServiceContext ctx, DocumentHandler handler)
- throws DocumentNotFoundException, DocumentException {
+ throws DocumentNotFoundException, TransactionException, DocumentException {
QueryContext queryContext = new QueryContext(ctx, handler);
RepositoryInstance repoSession = null;
* of the current context.
*
* @param ctx service context under which this method is invoked
- * @param id
+ * @param csid
* of the document to retrieve
+ * @throws DocumentNotFoundException
+ * @throws TransactionException
* @throws DocumentException
+ * @return a wrapped documentModel
*/
@Override
public DocumentWrapper<DocumentModel> getDoc(
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
- String csid) throws DocumentNotFoundException, DocumentException {
+ String csid) throws DocumentNotFoundException, TransactionException, DocumentException {
RepositoryInstance repoSession = null;
DocumentWrapper<DocumentModel> wrapDoc = null;
* find wrapped documentModel from the Nuxeo repository
* @param ctx service context under which this method is invoked
* @param whereClause where NXQL where clause to get the document
+ * @throws DocumentNotFoundException
+ * @throws TransactionException
* @throws DocumentException
+ * @return a wrapped documentModel retrieved by the repository query
*/
@Override
public DocumentWrapper<DocumentModel> findDoc(
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx,
String whereClause)
- throws DocumentNotFoundException, DocumentException {
+ throws DocumentNotFoundException, TransactionException, DocumentException {
RepositoryInstance repoSession = null;
DocumentWrapper<DocumentModel> wrapDoc = null;
/**
* find doc and return CSID from the Nuxeo repository
+ * @param repoSession
* @param ctx service context under which this method is invoked
* @param whereClause where NXQL where clause to get the document
+ * @throws DocumentNotFoundException
+ * @throws TransactionException
* @throws DocumentException
+ * @return the CollectionSpace ID (CSID) of the requested document
*/
@Override
public String findDocCSID(RepositoryInstance repoSession,
ServiceContext<PoxPayloadIn, PoxPayloadOut> ctx, String whereClause)
- throws DocumentNotFoundException, DocumentException {
+ throws DocumentNotFoundException, TransactionException, DocumentException {
String csid = null;
boolean releaseSession = false;
try {
* Find a list of documentModels from the Nuxeo repository
* @param docTypes a list of DocType names to match
* @param whereClause where the clause to qualify on
- * @return
+ * @throws DocumentNotFoundException
+ * @throws TransactionException
+ * @throws DocumentException
+ * @return a list of documentModels
*/
@Override
public DocumentWrapper<DocumentModelList> findDocs(
List<String> docTypes,
String whereClause,
int pageSize, int pageNum, boolean computeTotal)
- throws DocumentNotFoundException, DocumentException {
+ throws DocumentNotFoundException, TransactionException, DocumentException {
RepositoryInstance repoSession = null;
DocumentWrapper<DocumentModelList> wrapDoc = null;
*/
@Override
public void get(ServiceContext ctx, List<String> csidList, DocumentHandler handler)
- throws DocumentNotFoundException, DocumentException {
+ throws DocumentNotFoundException, TransactionException, DocumentException {
if (handler == null) {
throw new IllegalArgumentException(
"RepositoryJavaClient.getAll: handler is missing");
* @param handler
* should be used by the caller to provide and transform the
* document
+ * @throws DocumentNotFoundException
+ * @throws TransactionException
* @throws DocumentException
*/
@Override
public void getAll(ServiceContext ctx, DocumentHandler handler)
- throws DocumentNotFoundException, DocumentException {
+ throws DocumentNotFoundException, TransactionException, DocumentException {
if (handler == null) {
throw new IllegalArgumentException(
"RepositoryJavaClient.getAll: handler is missing");
}
/**
- * find doc and return CSID from the Nuxeo repository
- * @param ctx service context under which this method is invoked
- * @param whereClause where NXQL where clause to get the document
- * @throws DocumentException
+ * Returns a URI value for a document in the Nuxeo repository
+ * @param wrappedDoc a wrapped documentModel
+ * @throws ClientException
+ * @return a document URI
*/
@Override
public String getDocURI(DocumentWrapper<DocumentModel> wrappedDoc) throws ClientException {
* @param ctx service context under which this method is invoked
* @param handler should be used by the caller to provide and transform the document
* @throws DocumentNotFoundException if workspace not found
+ * @throws TransactionException
* @throws DocumentException
*/
@Override
public void getFiltered(ServiceContext ctx, DocumentHandler handler)
- throws DocumentNotFoundException, DocumentException {
+ throws DocumentNotFoundException, TransactionException, DocumentException {
DocumentFilter filter = handler.getDocumentFilter();
String oldOrderBy = filter.getOrderByClause();
* update given document in the Nuxeo repository
*
* @param ctx service context under which this method is invoked
- * @param id
+ * @param csid
* of the document
* @param handler
* should be used by the caller to provide and transform the
* document
+ * @throws BadRequestException
+ * @throws DocumentNotFoundException
+ * @throws TransactionException if the transaction times out or otherwise cannot be successfully completed
* @throws DocumentException
*/
@Override
public void update(ServiceContext ctx, String csid, DocumentHandler handler)
- throws BadRequestException, DocumentNotFoundException,
+ throws BadRequestException, DocumentNotFoundException, TransactionException,
DocumentException {
if (handler == null) {
throw new IllegalArgumentException(
/**
* Save a documentModel to the Nuxeo repository.
* @param ctx service context under which this method is invoked
+ * @param repoSession
* @param docModel the document to save
* @param fSaveSession if TRUE, will call CoreSession.save() to save accumulated changes.
+ * @throws ClientException
* @throws DocumentException
*/
public void saveDocWithoutHandlerProcessing(
* Save a list of documentModels to the Nuxeo repository.
*
* @param ctx service context under which this method is invoked
- * @param docModel the document to save
+ * @param repoSession a repository session
+ * @param docModelList a list of document models
* @param fSaveSession if TRUE, will call CoreSession.save() to save accumulated changes.
+ * @throws ClientException
* @throws DocumentException
*/
public void saveDocListWithoutHandlerProcessing(
*/
@Override
public void delete(ServiceContext ctx, String id, DocumentHandler handler) throws DocumentNotFoundException,
- DocumentException {
+ DocumentException, TransactionException {
if (ctx == null) {
throw new IllegalArgumentException(
"delete(ctx, ix, handler): ctx is missing");
*
* @param repoSession the repo session
*/
- public void releaseRepositorySession(ServiceContext ctx, RepositoryInstance repoSession) {
+ public void releaseRepositorySession(ServiceContext ctx, RepositoryInstance repoSession) throws TransactionException {
try {
NuxeoClientEmbedded client = NuxeoConnectorEmbedded.getInstance().getClient();
// release session
} else {
client.releaseRepository(repoSession); //repo session was acquired without a service context
}
+ } catch (TransactionRuntimeException tre) {
+ TransactionException te = new TransactionException(tre);
+ logger.error(te.getMessage(), tre); // Log the standard transaction exception message, plus an exception-specific stack trace
+ throw te;
} catch (Exception e) {
logger.error("Could not close the repository session", e);
// no need to throw this service specific exception
DocumentException {
// This is a placeholder for when we change the StorageClient interface to treat workflow transitions as 1st class operations like 'get', 'create', 'update, 'delete', etc
}
-
+
}