]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-5506: Return a new Exception message and corresponding custom HTTP status...
authorAron Roberts <aron@socrates.berkeley.edu>
Fri, 30 Nov 2012 02:23:47 +0000 (18:23 -0800)
committerAron Roberts <aron@socrates.berkeley.edu>
Fri, 30 Nov 2012 02:23:47 +0000 (18:23 -0800)
services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResourceImpl.java
services/common/src/main/java/org/collectionspace/services/common/document/TransactionException.java [new file with mode: 0644]
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocHandlerBase.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java

index d7d5335856198db6e78614090bbd6ebbb724eb01..c85a1b8bb2fd4d0895d1cb0f698c21d7b7457a2c 100644 (file)
@@ -40,6 +40,7 @@ import org.collectionspace.services.common.document.BadRequestException;
 import org.collectionspace.services.common.document.DocumentException;\r
 import org.collectionspace.services.common.document.DocumentHandler;\r
 import org.collectionspace.services.common.document.DocumentNotFoundException;\r
+import org.collectionspace.services.common.document.TransactionException;\r
 import org.collectionspace.services.common.repository.RepositoryClient;\r
 import org.collectionspace.services.common.repository.RepositoryClientFactory;\r
 import org.collectionspace.services.common.security.UnauthorizedException;\r
@@ -448,6 +449,11 @@ public abstract class AbstractCollectionSpaceResourceImpl<IT, OT>
                logException = false;\r
             response = Response.status(Response.Status.NOT_FOUND).entity(serviceMsg + " on " + getClass().getName() + " csid=" + csid).type("text/plain").build();\r
             result = new WebApplicationException(response);\r
+            \r
+        } else if (e instanceof TransactionException) {\r
+            int code = ((TransactionException) e).getErrorCode();\r
+            response = Response.status(code).entity(e.getMessage()).type("text/plain").build();\r
+            result = new WebApplicationException(response);\r
 \r
         } else if (e instanceof BadRequestException) {\r
             int code = ((BadRequestException) e).getErrorCode();\r
diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/TransactionException.java b/services/common/src/main/java/org/collectionspace/services/common/document/TransactionException.java
new file mode 100644 (file)
index 0000000..2f49eb0
--- /dev/null
@@ -0,0 +1,87 @@
+/**
+ *  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);
+    }
+}
index 1064fa4a85950d6b27dd88f750cfbbfe62b16287..175c209b32e7bf1dff1fff8792c3efd244c3cbc0 100644 (file)
@@ -278,7 +278,7 @@ public abstract class DocHandlerBase<T> extends RemoteDocumentModelHandlerImpl<T
                }\r
                throw new DocumentException(e);\r
                } finally {\r
-                       // If we got/aquired a new seesion then we're responsible for releasing it.\r
+                       // If we got/aquired a new session then we're responsible for releasing it.\r
                        if (releaseRepoSession && repoSession != null) {\r
                                repoClient.releaseRepositorySession(sc, repoSession);\r
                        }\r
index a11a0b9d582c8a895553122b00392027cd2f15f9..6e7a945dee8c05dfd545b634c571a973516df983 100644 (file)
@@ -304,7 +304,7 @@ public abstract class DocumentModelHandler<T, TL>
      * @throws PropertyException the property exception
      */
     abstract public AuthorityRefList getAuthorityRefs(String csid,
-               List<AuthRefConfigInfo> authRefsInfo) throws PropertyException;    
+               List<AuthRefConfigInfo> authRefsInfo) throws PropertyException, Exception;    
 
     /*
      * Subclasses should override this method if they need to customize their refname generation
index 7fd63f622d56bfdfbf606a38ea31102568f2c835..a3416934a3d08d2ed495eee1eb6b267adc464474 100644 (file)
@@ -592,7 +592,7 @@ public abstract class   RemoteDocumentModelHandlerImpl<T, TL>
     @Override
     public AuthorityRefList getAuthorityRefs(
             String csid,
-            List<AuthRefConfigInfo> authRefsInfo) throws PropertyException {
+            List<AuthRefConfigInfo> authRefsInfo) throws PropertyException, Exception {
 
         AuthorityRefList authRefList = new AuthorityRefList();
         AbstractCommonList commonList = (AbstractCommonList) authRefList;
index 154c429a55c0c25ee5cdaefaa557b4675196f0ab..628bf3213fbf8e61bd22253ab975f7ae315f9ce2 100644 (file)
@@ -47,6 +47,7 @@ import org.collectionspace.services.common.document.DocumentNotFoundException;
 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;
@@ -59,6 +60,7 @@ import org.nuxeo.ecm.core.api.DocumentRef;
 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
@@ -129,12 +131,14 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
      *            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) {
@@ -202,11 +206,13 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
      * @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(
@@ -250,16 +256,18 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
     }
 
     /**
-     * get document from the Nuxeo repository, using the docFilter params.
+     * get 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;
 
@@ -331,14 +339,17 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
      * 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;
 
@@ -411,13 +422,16 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
      * 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;
 
@@ -441,14 +455,18 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
 
     /**
      * 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 {
@@ -584,7 +602,10 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
      * 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(
@@ -592,7 +613,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
             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;
 
@@ -625,7 +646,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
      */
     @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");
@@ -670,11 +691,13 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
      * @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");
@@ -762,10 +785,10 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
     }
 
     /**
-     * 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 {
@@ -812,11 +835,12 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
      * @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();
@@ -965,16 +989,19 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
      * 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(
@@ -1044,8 +1071,10 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
     /**
      * 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(
@@ -1075,8 +1104,10 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
      * 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(
@@ -1108,7 +1139,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
      */
     @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");
@@ -1397,7 +1428,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
      *
      * @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
@@ -1409,6 +1440,10 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
             } 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
@@ -1422,5 +1457,5 @@ public class RepositoryJavaClientImpl implements RepositoryClient<PoxPayloadIn,
                        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
        }
-
+                
 }