]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
NOJIRA added jpastorage. refactored context and dochandler to isolate multipart proce...
authorSanjay Dalal <sanjay.dalal@berkeley.edu>
Thu, 19 Nov 2009 03:20:22 +0000 (03:20 +0000)
committerSanjay Dalal <sanjay.dalal@berkeley.edu>
Thu, 19 Nov 2009 03:20:22 +0000 (03:20 +0000)
introduced servicecontext factory to free up abstractresource from assumption that
it is used only to process multipart remote requests. affected services are fixed.
mvn test passes. account is not yet plugged into service build. account build fails.

M    services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java
M    services/common/src/main/java/org/collectionspace/services/common/CollectionSpaceResource.java
M    services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResource.java
A    services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContextFactory.java
M    services/common/src/main/java/org/collectionspace/services/common/context/RemoteServiceContext.java
M    services/common/src/main/java/org/collectionspace/services/common/context/RemoteServiceContextImpl.java
M    services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java
A    services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContext.java
M    services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContext.java
A    services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContextImpl.java
A    services/common/src/main/java/org/collectionspace/services/common/context/ServiceContextFactory.java
A    services/common/src/main/java/org/collectionspace/services/common/storage/jpa
A    services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaStorageClient.java
M    services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandler.java
A    services/common/src/main/java/org/collectionspace/services/common/document/AbstractMultipartDocumentHandler.java
M    services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java
A    services/common/src/main/java/org/collectionspace/services/common/document/MultipartDocumentHandler.java
M    services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClient.java
M    services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandler.java
M    services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java
M    services/common/pom.xml
M    services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/AcquisitionResource.java
_M   services/account/service
M    services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountDocumentHandler.java
M    services/account/service/src/main/java/org/collectionspace/services/account/AccountResource.java
M    services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java
M    services/intake/service/src/main/java/org/collectionspace/services/intake/IntakeResource.java
M    services/relation/service/src/main/java/org/collectionspace/services/relation/NewRelationResource.java

26 files changed:
services/account/service/src/main/java/org/collectionspace/services/account/AccountResource.java
services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountDocumentHandler.java
services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/AcquisitionResource.java
services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java
services/common/pom.xml
services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResource.java
services/common/src/main/java/org/collectionspace/services/common/CollectionSpaceResource.java
services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContext.java
services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContext.java [new file with mode: 0644]
services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContextFactory.java [new file with mode: 0644]
services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContextImpl.java [new file with mode: 0644]
services/common/src/main/java/org/collectionspace/services/common/context/RemoteServiceContext.java
services/common/src/main/java/org/collectionspace/services/common/context/RemoteServiceContextImpl.java
services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java
services/common/src/main/java/org/collectionspace/services/common/context/ServiceContextFactory.java [new file with mode: 0644]
services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandler.java
services/common/src/main/java/org/collectionspace/services/common/document/AbstractMultipartDocumentHandler.java [new file with mode: 0644]
services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java
services/common/src/main/java/org/collectionspace/services/common/document/MultipartDocumentHandler.java [new file with mode: 0644]
services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaStorageClient.java [new file with mode: 0644]
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandler.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClient.java
services/intake/service/src/main/java/org/collectionspace/services/intake/IntakeResource.java
services/relation/service/src/main/java/org/collectionspace/services/relation/NewRelationResource.java
services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java

index 6665462c834f797fed9cabff5ea4c439c93557fb..014022c69b9f04183d5a71abb140e3eab060c7c5 100644 (file)
@@ -38,19 +38,18 @@ import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
 
 import org.collectionspace.services.common.AbstractCollectionSpaceResource;
-import org.collectionspace.services.common.context.RemoteServiceContext;
+import org.collectionspace.services.common.context.RemoteServiceContextImpl;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.document.DocumentNotFoundException;
 import org.collectionspace.services.common.document.DocumentHandler;
-import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
 import org.jboss.resteasy.util.HttpResponseCodes;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 @Path("/accounts")
-@Consumes("multipart/mixed")
-@Produces("multipart/mixed")
+@Consumes("application/xml")
+@Produces("application/xml")
 public class AccountResource
         extends AbstractCollectionSpaceResource {
 
@@ -62,15 +61,21 @@ public class AccountResource
         return serviceName;
     }
 
+    private <T> ServiceContext createServiceContext(T obj) {
+        ServiceContext ctx = new RemoteServiceContextImpl<T, T>(getServiceName());
+        ctx.setInput(obj);
+        return ctx;
+    }
+
     @Override
-    public DocumentHandler createDocumentHandler(RemoteServiceContext ctx) throws Exception {
+    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
         throw new IllegalStateException();
     }
 
     @POST
-    public Response createAccount(MultipartInput input) {
+    public Response createAccount(AccountsCommon input) {
         try {
-            RemoteServiceContext ctx = createServiceContext(input);
+            ServiceContext ctx = createServiceContext(input);
             String csid = "";
             UriBuilder path = UriBuilder.fromResource(AccountResource.class);
             path.path("" + csid);
@@ -88,7 +93,7 @@ public class AccountResource
 
     @GET
     @Path("{csid}")
-    public MultipartOutput getAccount(
+    public AccountsCommon getAccount(
             @PathParam("csid") String csid) {
         if (logger.isDebugEnabled()) {
             logger.debug("getAccount with csid=" + csid);
@@ -100,11 +105,11 @@ public class AccountResource
                     "text/plain").build();
             throw new WebApplicationException(response);
         }
-        MultipartOutput result = null;
+        AccountsCommon result = null;
         try {
-            RemoteServiceContext ctx = createServiceContext(null);
+            ServiceContext ctx = createServiceContext((AccountsCommon)null);
 
-            result = ctx.getOutput();
+            result = (AccountsCommon) ctx.getOutput();
         } catch (DocumentNotFoundException dnfe) {
             if (logger.isDebugEnabled()) {
                 logger.debug("getAccount", dnfe);
@@ -136,7 +141,7 @@ public class AccountResource
     public AccountsCommonList getAccountList(@Context UriInfo ui) {
         AccountsCommonList accountList = new AccountsCommonList();
         try {
-            RemoteServiceContext ctx = createServiceContext(null);
+            ServiceContext ctx = createServiceContext((AccountsCommonList)null);
 
             accountList = null;
         } catch (Exception e) {
@@ -152,9 +157,9 @@ public class AccountResource
 
     @PUT
     @Path("{csid}")
-    public MultipartOutput updateAccount(
+    public AccountsCommon updateAccount(
             @PathParam("csid") String csid,
-            MultipartInput theUpdate) {
+            AccountsCommon theUpdate) {
         if (logger.isDebugEnabled()) {
             logger.debug("updateAccount with csid=" + csid);
         }
@@ -165,11 +170,11 @@ public class AccountResource
                     "text/plain").build();
             throw new WebApplicationException(response);
         }
-        MultipartOutput result = null;
+        AccountsCommon result = null;
         try {
-            RemoteServiceContext ctx = createServiceContext(theUpdate);
+            ServiceContext ctx = createServiceContext(theUpdate);
 
-            result = ctx.getOutput();
+            result = (AccountsCommon)ctx.getOutput();
         } catch (DocumentNotFoundException dnfe) {
             if (logger.isDebugEnabled()) {
                 logger.debug("caugth exception in updateAccount", dnfe);
@@ -201,7 +206,7 @@ public class AccountResource
             throw new WebApplicationException(response);
         }
         try {
-            ServiceContext ctx = createServiceContext(null);
+            ServiceContext ctx = createServiceContext((AccountsCommon)null);
 
             return Response.status(HttpResponseCodes.SC_OK).build();
         } catch (DocumentNotFoundException dnfe) {
index d76d73473681d94dacb2b76d69bc3c7cf3f42453..cc554b9eb36884c60981781f21bc756811b8d593 100644 (file)
@@ -23,6 +23,7 @@
  */
 package org.collectionspace.services.account.storage;
 
+import java.util.UUID;
 import org.collectionspace.services.account.AccountsCommon;
 import org.collectionspace.services.account.AccountsCommonList;
 import org.collectionspace.services.common.document.AbstractDocumentHandler;
@@ -34,47 +35,40 @@ import org.collectionspace.services.common.document.DocumentWrapper;
  * @author 
  */
 public class AccountDocumentHandler
-        extends AbstractDocumentHandler<AccountsCommon, AccountsCommonList> {
+        extends AbstractDocumentHandler<AccountsCommon, AccountsCommonList, AccountsCommon, AccountsCommonList> {
 
     @Override
-    public void handleCreate(DocumentWrapper wrapDoc) throws Exception {
+    public void handleCreate(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
+        String id = UUID.randomUUID().toString();
+        AccountsCommon account = wrapDoc.getWrappedObject();
+        account.setCsid(id);
     }
 
     @Override
-    public void handleUpdate(DocumentWrapper wrapDoc) throws Exception {
+    public void handleUpdate(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
     }
 
     @Override
-    public void handleGet(DocumentWrapper wrapDoc) throws Exception {
+    public void handleGet(DocumentWrapper<AccountsCommon> wrapDoc) throws Exception {
     }
 
     @Override
-    public void handleGetAll(DocumentWrapper wrapDoc) throws Exception {
+    public void handleGetAll(DocumentWrapper< AccountsCommonList> wrapDoc) throws Exception {
     }
 
     @Override
-    public void extractAllParts(DocumentWrapper wrapDoc)
-            throws Exception {
-    }
-
-    @Override
-    public void fillAllParts(DocumentWrapper wrapDoc)
-            throws Exception {
-    }
-
-    @Override
-    public AccountsCommon extractCommonPart(DocumentWrapper wrapDoc)
+    public AccountsCommon extractCommonPart(DocumentWrapper<AccountsCommon> wrapDoc)
             throws Exception {
         return null;
     }
 
     @Override
-    public void fillCommonPart(AccountsCommon obj, DocumentWrapper wrapDoc)
+    public void fillCommonPart(AccountsCommon obj, DocumentWrapper<AccountsCommon> wrapDoc)
             throws Exception {
     }
 
     @Override
-    public AccountsCommonList extractCommonPartList(DocumentWrapper wrapDoc)
+    public AccountsCommonList extractCommonPartList(DocumentWrapper<AccountsCommonList> wrapDoc)
             throws Exception {
         return null;
     }
index 8e606825f5b830a622a1e911e23aca3678c91d75..26ef178a1363ab9a84adfe7aedf45a4ddadbc908 100644 (file)
@@ -39,7 +39,8 @@ import javax.ws.rs.core.UriInfo;
 
 import org.collectionspace.services.acquisition.nuxeo.AcquisitionHandlerFactory;
 import org.collectionspace.services.common.AbstractCollectionSpaceResource;
-import org.collectionspace.services.common.context.RemoteServiceContext;
+import org.collectionspace.services.common.context.MultipartServiceContext;
+import org.collectionspace.services.common.context.MultipartServiceContextFactory;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.document.DocumentNotFoundException;
 import org.collectionspace.services.common.document.DocumentHandler;
@@ -64,13 +65,13 @@ public class AcquisitionResource
     }
 
     @Override
-    public DocumentHandler createDocumentHandler(RemoteServiceContext ctx) throws Exception {
+    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
         DocumentHandler docHandler = AcquisitionHandlerFactory.getInstance().getHandler(
                 ctx.getRepositoryClientType().toString());
         docHandler.setServiceContext(ctx);
-        if(ctx.getInput() != null){
-            Object obj = ctx.getInputPart(ctx.getCommonPartLabel(), AcquisitionsCommon.class);
-            if(obj != null){
+        if (ctx.getInput() != null) {
+            Object obj = ((MultipartServiceContext)ctx).getInputPart(ctx.getCommonPartLabel(), AcquisitionsCommon.class);
+            if (obj != null) {
                 docHandler.setCommonPart((AcquisitionsCommon) obj);
             }
         }
@@ -84,16 +85,16 @@ public class AcquisitionResource
     @POST
     public Response createAcquisition(MultipartInput input) {
 
-        try{
-            RemoteServiceContext ctx = createServiceContext(input);
+        try {
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getServiceName());
             DocumentHandler handler = createDocumentHandler(ctx);
             String csid = getRepositoryClient(ctx).create(ctx, handler);
             UriBuilder path = UriBuilder.fromResource(AcquisitionResource.class);
             path.path("" + csid);
             Response response = Response.created(path.build()).build();
             return response;
-        }catch(Exception e){
-            if(logger.isDebugEnabled()){
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("Caught exception in createAcquisition", e);
             }
             Response response = Response.status(
@@ -106,10 +107,10 @@ public class AcquisitionResource
     @Path("{csid}")
     public MultipartOutput getAcquisition(
             @PathParam("csid") String csid) {
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug("getAcquisition with csid=" + csid);
         }
-        if(csid == null || "".equals(csid)){
+        if (csid == null || "".equals(csid)) {
             logger.error("getAcquisition: missing csid!");
             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
                     "get failed on Acquisition csid=" + csid).type(
@@ -117,21 +118,21 @@ public class AcquisitionResource
             throw new WebApplicationException(response);
         }
         MultipartOutput result = null;
-        try{
-            RemoteServiceContext ctx = createServiceContext(null);
+        try {
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).get(ctx, csid, handler);
-            result = ctx.getOutput();
-        }catch(DocumentNotFoundException dnfe){
-            if(logger.isDebugEnabled()){
+            result = (MultipartOutput) ctx.getOutput();
+        } catch (DocumentNotFoundException dnfe) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("getAcquisition", dnfe);
             }
             Response response = Response.status(Response.Status.NOT_FOUND).entity(
                     "Get failed on Acquisition csid=" + csid).type(
                     "text/plain").build();
             throw new WebApplicationException(response);
-        }catch(Exception e){
-            if(logger.isDebugEnabled()){
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("getAcquisition", e);
             }
             Response response = Response.status(
@@ -139,7 +140,7 @@ public class AcquisitionResource
             throw new WebApplicationException(response);
         }
 
-        if(result == null){
+        if (result == null) {
             Response response = Response.status(Response.Status.NOT_FOUND).entity(
                     "Get failed, the requested Acquisition CSID:" + csid + ": was not found.").type(
                     "text/plain").build();
@@ -152,13 +153,13 @@ public class AcquisitionResource
     @Produces("application/xml")
     public AcquisitionsCommonList getAcquisitionList(@Context UriInfo ui) {
         AcquisitionsCommonList acquisitionObjectList = new AcquisitionsCommonList();
-        try{
-            RemoteServiceContext ctx = createServiceContext(null);
+        try {
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).getAll(ctx, handler);
             acquisitionObjectList = (AcquisitionsCommonList) handler.getCommonPartList();
-        }catch(Exception e){
-            if(logger.isDebugEnabled()){
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("Caught exception in getAcquisitionList", e);
             }
             Response response = Response.status(
@@ -173,34 +174,34 @@ public class AcquisitionResource
     public MultipartOutput updateAcquisition(
             @PathParam("csid") String csid,
             MultipartInput theUpdate) {
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug("updateAcquisition with csid=" + csid);
         }
-        if(csid == null || "".equals(csid)){
+        if (csid == null || "".equals(csid)) {
             logger.error("updateAcquisition: missing csid!");
             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
                     "update failed on Acquisition csid=" + csid).type(
                     "text/plain").build();
             throw new WebApplicationException(response);
         }
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug("updateAcquisition with input: ", theUpdate);
         }
         MultipartOutput result = null;
-        try{
-            RemoteServiceContext ctx = createServiceContext(theUpdate);
+        try {
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(theUpdate, getServiceName());
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).update(ctx, csid, handler);
-            result = ctx.getOutput();
-        }catch(DocumentNotFoundException dnfe){
-            if(logger.isDebugEnabled()){
+            result = (MultipartOutput) ctx.getOutput();
+        } catch (DocumentNotFoundException dnfe) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("caugth exception in updateAcquisition", dnfe);
             }
             Response response = Response.status(Response.Status.NOT_FOUND).entity(
                     "Update failed on Acquisition csid=" + csid).type(
                     "text/plain").build();
             throw new WebApplicationException(response);
-        }catch(Exception e){
+        } catch (Exception e) {
             Response response = Response.status(
                     Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build();
             throw new WebApplicationException(response);
@@ -212,34 +213,33 @@ public class AcquisitionResource
     @Path("{csid}")
     public Response deleteAcquisition(@PathParam("csid") String csid) {
 
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug("deleteAcquisition with csid=" + csid);
         }
-        if(csid == null || "".equals(csid)){
+        if (csid == null || "".equals(csid)) {
             logger.error("deleteAcquisition: missing csid!");
             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
                     "delete failed on Acquisition csid=" + csid).type(
                     "text/plain").build();
             throw new WebApplicationException(response);
         }
-        try{
-            ServiceContext ctx = createServiceContext(null);
+        try {
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
             getRepositoryClient(ctx).delete(ctx, csid);
             return Response.status(HttpResponseCodes.SC_OK).build();
-        }catch(DocumentNotFoundException dnfe){
-            if(logger.isDebugEnabled()){
+        } catch (DocumentNotFoundException dnfe) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("caught exception in deleteAcquisition", dnfe);
             }
             Response response = Response.status(Response.Status.NOT_FOUND).entity(
                     "Delete failed on Acquisition csid=" + csid).type(
                     "text/plain").build();
             throw new WebApplicationException(response);
-        }catch(Exception e){
+        } catch (Exception e) {
             Response response = Response.status(
                     Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build();
             throw new WebApplicationException(response);
         }
 
     }
-
 }
index 1d5fd147f87f73ac7e7c5f28afd2a763912e8bed..efc67f77d2fe55cddae8eeedc5a029371db60779 100644 (file)
@@ -40,7 +40,8 @@ import javax.ws.rs.core.UriInfo;
 
 import org.collectionspace.services.collectionobject.nuxeo.CollectionObjectHandlerFactory;
 import org.collectionspace.services.common.AbstractCollectionSpaceResource;
-import org.collectionspace.services.common.context.RemoteServiceContext;
+import org.collectionspace.services.common.context.MultipartServiceContext;
+import org.collectionspace.services.common.context.MultipartServiceContextFactory;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.document.DocumentNotFoundException;
 import org.collectionspace.services.common.document.DocumentHandler;
@@ -65,13 +66,13 @@ public class CollectionObjectResource
     }
 
     @Override
-    public DocumentHandler createDocumentHandler(RemoteServiceContext ctx) throws Exception {
+    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
         DocumentHandler docHandler = CollectionObjectHandlerFactory.getInstance().getHandler(
                 ctx.getRepositoryClientType().toString());
         docHandler.setServiceContext(ctx);
-        if(ctx.getInput() != null){
-            Object obj = ctx.getInputPart(ctx.getCommonPartLabel(), CollectionobjectsCommon.class);
-            if(obj != null){
+        if (ctx.getInput() != null) {
+            Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), CollectionobjectsCommon.class);
+            if (obj != null) {
                 docHandler.setCommonPart((CollectionobjectsCommon) obj);
             }
         }
@@ -80,16 +81,16 @@ public class CollectionObjectResource
 
     @POST
     public Response createCollectionObject(MultipartInput input) {
-        try{
-            RemoteServiceContext ctx = createServiceContext(input);
+        try {
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getServiceName());
             DocumentHandler handler = createDocumentHandler(ctx);
             String csid = getRepositoryClient(ctx).create(ctx, handler);
             UriBuilder path = UriBuilder.fromResource(CollectionObjectResource.class);
             path.path("" + csid);
             Response response = Response.created(path.build()).build();
             return response;
-        }catch(Exception e){
-            if(logger.isDebugEnabled()){
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("Caught exception in createCollectionObject", e);
             }
             Response response = Response.status(
@@ -102,10 +103,10 @@ public class CollectionObjectResource
     @Path("{csid}")
     public MultipartOutput getCollectionObject(
             @PathParam("csid") String csid) {
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug("getCollectionObject with csid=" + csid);
         }
-        if(csid == null || "".equals(csid)){
+        if (csid == null || "".equals(csid)) {
             logger.error("getCollectionObject: missing csid!");
             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
                     "get failed on CollectionObject csid=" + csid).type(
@@ -113,21 +114,21 @@ public class CollectionObjectResource
             throw new WebApplicationException(response);
         }
         MultipartOutput result = null;
-        try{
-            RemoteServiceContext ctx = createServiceContext(null);
+        try {
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).get(ctx, csid, handler);
-            result = ctx.getOutput();
-        }catch(DocumentNotFoundException dnfe){
-            if(logger.isDebugEnabled()){
+            result = (MultipartOutput) ctx.getOutput();
+        } catch (DocumentNotFoundException dnfe) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("getCollectionObject", dnfe);
             }
             Response response = Response.status(Response.Status.NOT_FOUND).entity(
                     "Get failed on CollectionObject csid=" + csid).type(
                     "text/plain").build();
             throw new WebApplicationException(response);
-        }catch(Exception e){
-            if(logger.isDebugEnabled()){
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("getCollectionObject", e);
             }
             Response response = Response.status(
@@ -135,7 +136,7 @@ public class CollectionObjectResource
             throw new WebApplicationException(response);
         }
 
-        if(result == null){
+        if (result == null) {
             Response response = Response.status(Response.Status.NOT_FOUND).entity(
                     "Get failed, the requested CollectionObject CSID:" + csid + ": was not found.").type(
                     "text/plain").build();
@@ -148,13 +149,13 @@ public class CollectionObjectResource
     @Produces("application/xml")
     public CollectionobjectsCommonList getCollectionObjectList(@Context UriInfo ui) {
         CollectionobjectsCommonList collectionObjectList = new CollectionobjectsCommonList();
-        try{
-            RemoteServiceContext ctx = createServiceContext(null);
+        try {
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).getAll(ctx, handler);
             collectionObjectList = (CollectionobjectsCommonList) handler.getCommonPartList();
-        }catch(Exception e){
-            if(logger.isDebugEnabled()){
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("Caught exception in getCollectionObjectList", e);
             }
             Response response = Response.status(
@@ -169,10 +170,10 @@ public class CollectionObjectResource
     public MultipartOutput updateCollectionObject(
             @PathParam("csid") String csid,
             MultipartInput theUpdate) {
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug("updateCollectionObject with csid=" + csid);
         }
-        if(csid == null || "".equals(csid)){
+        if (csid == null || "".equals(csid)) {
             logger.error("updateCollectionObject: missing csid!");
             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
                     "update failed on CollectionObject csid=" + csid).type(
@@ -180,20 +181,20 @@ public class CollectionObjectResource
             throw new WebApplicationException(response);
         }
         MultipartOutput result = null;
-        try{
-            RemoteServiceContext ctx = createServiceContext(theUpdate);
+        try {
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(theUpdate, getServiceName());
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).update(ctx, csid, handler);
-            result = ctx.getOutput();
-        }catch(DocumentNotFoundException dnfe){
-            if(logger.isDebugEnabled()){
+            result = (MultipartOutput) ctx.getOutput();
+        } catch (DocumentNotFoundException dnfe) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("caugth exception in updateCollectionObject", dnfe);
             }
             Response response = Response.status(Response.Status.NOT_FOUND).entity(
                     "Update failed on CollectionObject csid=" + csid).type(
                     "text/plain").build();
             throw new WebApplicationException(response);
-        }catch(Exception e){
+        } catch (Exception e) {
             Response response = Response.status(
                     Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build();
             throw new WebApplicationException(response);
@@ -205,29 +206,29 @@ public class CollectionObjectResource
     @Path("{csid}")
     public Response deleteCollectionObject(@PathParam("csid") String csid) {
 
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug("deleteCollectionObject with csid=" + csid);
         }
-        if(csid == null || "".equals(csid)){
+        if (csid == null || "".equals(csid)) {
             logger.error("deleteCollectionObject: missing csid!");
             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
                     "delete failed on CollectionObject csid=" + csid).type(
                     "text/plain").build();
             throw new WebApplicationException(response);
         }
-        try{
-            ServiceContext ctx = createServiceContext(null);
+        try {
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
             getRepositoryClient(ctx).delete(ctx, csid);
             return Response.status(HttpResponseCodes.SC_OK).build();
-        }catch(DocumentNotFoundException dnfe){
-            if(logger.isDebugEnabled()){
+        } catch (DocumentNotFoundException dnfe) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("caught exception in deleteCollectionObject", dnfe);
             }
             Response response = Response.status(Response.Status.NOT_FOUND).entity(
                     "Delete failed on CollectionObject csid=" + csid).type(
                     "text/plain").build();
             throw new WebApplicationException(response);
-        }catch(Exception e){
+        } catch (Exception e) {
             Response response = Response.status(
                     Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build();
             throw new WebApplicationException(response);
index 5aaefcd9abe78a37811068ec91300c94399a4a6e..9cd0d834c4e14e17a15312338a6dae96644ac6cc 100644 (file)
@@ -16,7 +16,7 @@
         <dependency>\r
             <groupId>com.sun.xml.bind</groupId>\r
             <artifactId>jaxb-impl</artifactId>\r
-         </dependency>\r
+        </dependency>\r
         <dependency>\r
             <groupId>org.jvnet.jaxb2-commons</groupId>\r
             <artifactId>property-listener-injector</artifactId>\r
             <scope>provided</scope>\r
         </dependency>\r
         -->\r
-        \r
+        <dependency>\r
+            <groupId>javax.persistence</groupId>\r
+            <artifactId>persistence-api</artifactId>\r
+        </dependency>\r
+        <dependency>\r
+            <groupId>org.hibernate</groupId>\r
+            <artifactId>hibernate-entitymanager</artifactId>\r
+        </dependency>\r
         <!-- jboss -->\r
         <dependency>\r
             <groupId>jboss</groupId>\r
index 55041d1ff3929417adad9e3d34485709e7d05933..67b916489a4feb5680b2b8c5c3055ef729877fb1 100644 (file)
  */\r
 package org.collectionspace.services.common;\r
 \r
-import org.collectionspace.services.common.context.RemoteServiceContext;\r
 import org.collectionspace.services.common.context.ServiceContext;\r
-import org.collectionspace.services.common.context.RemoteServiceContextImpl;\r
 import org.collectionspace.services.common.document.DocumentHandler;\r
 import org.collectionspace.services.common.repository.RepositoryClient;\r
 import org.collectionspace.services.common.repository.RepositoryClientFactory;\r
-import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;\r
+import org.collectionspace.services.common.storage.StorageClient;\r
+import org.collectionspace.services.common.storage.jpa.JpaStorageClient;\r
 \r
 public abstract class AbstractCollectionSpaceResource\r
         implements CollectionSpaceResource {\r
@@ -37,6 +36,7 @@ public abstract class AbstractCollectionSpaceResource
     // Fields for default client factory and client\r
     private RepositoryClientFactory repositoryClientFactory;\r
     private RepositoryClient repositoryClient;\r
+    private StorageClient storageClient;\r
 \r
     public AbstractCollectionSpaceResource() {\r
         repositoryClientFactory = RepositoryClientFactory.getInstance();\r
@@ -45,10 +45,6 @@ public abstract class AbstractCollectionSpaceResource
     @Override\r
     abstract public String getServiceName();\r
 \r
-    @Override\r
-    public RepositoryClientFactory getRepositoryClientFactory() {\r
-        return repositoryClientFactory;\r
-    }\r
 \r
     @Override\r
     synchronized public RepositoryClient getRepositoryClient(ServiceContext ctx) {\r
@@ -60,17 +56,14 @@ public abstract class AbstractCollectionSpaceResource
     }\r
 \r
     @Override\r
-    public RemoteServiceContext createServiceContext(MultipartInput input) throws Exception {\r
-        return createServiceContext(input,getServiceName());\r
-    }\r
-\r
-    @Override\r
-    public RemoteServiceContext createServiceContext(MultipartInput input, String serviceName) throws Exception {\r
-        RemoteServiceContext ctx = new RemoteServiceContextImpl(serviceName);\r
-        ctx.setInput(input);\r
-        return ctx;\r
+    synchronized public StorageClient getStorageClient(ServiceContext ctx) {\r
+        if(storageClient != null) {\r
+            return storageClient;\r
+        }\r
+        storageClient = new JpaStorageClient();\r
+        return storageClient;\r
     }\r
 \r
     @Override\r
-    abstract public DocumentHandler createDocumentHandler(RemoteServiceContext ctx) throws Exception ;\r
+    abstract public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception ;\r
 }\r
index 1bba8506305f90fa70c46830796d1496ce06669f..1e6dd4a9cc3bde637fbacf590a04c9137a3768c4 100644 (file)
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-
 package org.collectionspace.services.common;
 
-import org.collectionspace.services.common.context.RemoteServiceContext;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.document.DocumentHandler;
 import org.collectionspace.services.common.repository.RepositoryClient;
-import org.collectionspace.services.common.repository.RepositoryClientFactory;
-import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
+import org.collectionspace.services.common.storage.StorageClient;
 
 /**
  * CollectionSpaceResource is a resource interface implemented by every
@@ -41,12 +38,7 @@ public interface CollectionSpaceResource {
      * getServiceName returns the name of the service
      */
     public String getServiceName();
-    
-    /**
-     * getRepositoryClientFactory
-     * @return
-     */
-    public RepositoryClientFactory getRepositoryClientFactory();
+
 
     /**
      * getRepositoryClient
@@ -55,23 +47,11 @@ public interface CollectionSpaceResource {
     public RepositoryClient getRepositoryClient(ServiceContext ctx);
 
     /**
-     * createServiceContext is a factory method to create a service context
-     * a service context is created on every service request call
-     * This form uses the serviceName as the default context
-     * @param input
-     * @return
-     */
-    public RemoteServiceContext createServiceContext(MultipartInput input) throws Exception;
-
-    /**
-     * createServiceContext is a factory method to create a service context
-     * a service context is created on every service request call
-     * @param input
-     * @param serviceName which service/repository context to use
-     * @return
+     * getStorageClient
+     * @param ctx service context
      */
-    public RemoteServiceContext createServiceContext(MultipartInput input, String serviceName) throws Exception;
-
+    public StorageClient getStorageClient(ServiceContext ctx);
+    
     /**
      * createDocumentHandler creates a document handler and populates it with given
      * service context. document handler should never be used
@@ -80,5 +60,5 @@ public interface CollectionSpaceResource {
      * @param ctx
      * @return
      */
-    public DocumentHandler createDocumentHandler(RemoteServiceContext ctx) throws Exception ;
+    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception;
 }
index 78b1b106a0aefa68e2e3dff819a3e1e4fc140b1b..48fd89583a8b40bbd7f31386e77a74c9a90afca7 100644 (file)
@@ -181,13 +181,13 @@ public abstract class AbstractServiceContext<IT, OT>
     public abstract IT getInput();
 
     @Override
-    public abstract void setInput(IT input) throws Exception;
+    public abstract void setInput(IT input);
 
     @Override
     public abstract OT getOutput();
 
     @Override
-    public abstract void setOutput(OT output) throws Exception;
+    public abstract void setOutput(OT output);
 
     @Override
     public String toString() {
diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContext.java b/services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContext.java
new file mode 100644 (file)
index 0000000..e17a5ab
--- /dev/null
@@ -0,0 +1,82 @@
+/**
+ *  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
+
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.collectionspace.services.common.context;
+
+import java.io.IOException;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
+import org.w3c.dom.Document;
+
+/**
+ * RemoteServiceContext is used to encapsulate the service context of a
+ * remotely invokable service
+ */
+public interface MultipartServiceContext
+        extends RemoteServiceContext<MultipartInput, MultipartOutput> {
+
+    /**
+     * Get input parts as received over the wire from service consumer
+     * @return the input
+     */
+    @Override
+    public MultipartInput getInput();
+
+    /**
+     * setInput is used to set request input before starting to
+     * process input data
+     * @param input
+     */
+    @Override
+    public void setInput(MultipartInput input);
+
+    /**
+     * Get output parts to send over the wire to service consumer
+     * @return the output
+     */
+    @Override
+    public MultipartOutput getOutput();
+
+    /**
+     * Set output parts to send over the wire to service consumer
+     * @return the output
+     */
+    @Override
+    public void setOutput(MultipartOutput output);
+
+    /**
+     * getInputPart returns part for given label from input
+     * @param label
+     * @param clazz class of the object
+     * @return part
+     */
+    public Object getInputPart(String label, Class clazz) throws IOException;
+
+    /**
+     * addOutputPart adds given XML part with given label and content type to output
+     * @param label
+     * @param document
+     * @param contentType media type
+     */
+    public void addOutputPart(String label, Document doc, String contentType) throws Exception;
+}
diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContextFactory.java b/services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContextFactory.java
new file mode 100644 (file)
index 0000000..98277c2
--- /dev/null
@@ -0,0 +1,59 @@
+/**
+ *  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
+
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.collectionspace.services.common.context;
+
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
+
+/**
+ *
+ * MultipartRemoteServiceContextFactory creates a service context for
+ * a service processing multipart messages
+ *
+ */
+public class MultipartServiceContextFactory
+        implements ServiceContextFactory<MultipartInput> {
+
+    final private static MultipartServiceContextFactory self = new MultipartServiceContextFactory();
+
+    private MultipartServiceContextFactory() {
+    }
+
+    public static MultipartServiceContextFactory get() {
+        return self;
+    }
+
+    /**
+     * createServiceContext is a factory method to create a service context
+     * a service context is created on every service request call
+     * @param input
+     * @param serviceName which service/repository context to use
+     * @return
+     */
+    @Override
+    public ServiceContext createServiceContext(MultipartInput input, String serviceName) throws Exception {
+        MultipartServiceContext ctx = new MultipartServiceContextImpl(serviceName);
+        ctx.setInput(input);
+        return ctx;
+    }
+}
diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContextImpl.java b/services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContextImpl.java
new file mode 100644 (file)
index 0000000..a204f06
--- /dev/null
@@ -0,0 +1,110 @@
+/**
+ *  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
+
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.collectionspace.services.common.context;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import javax.ws.rs.core.MediaType;
+import org.collectionspace.services.common.document.DocumentUtils;
+import org.jboss.resteasy.plugins.providers.multipart.InputPart;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
+import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.w3c.dom.Document;
+
+/**
+ * RemoteServiceContextImpl
+ *
+ * $LastChangedRevision: $
+ * $LastChangedDate: $
+ */
+public class MultipartServiceContextImpl
+        extends RemoteServiceContextImpl<MultipartInput, MultipartOutput>
+        implements MultipartServiceContext {
+
+    final Logger logger = LoggerFactory.getLogger(MultipartServiceContextImpl.class);
+
+    public MultipartServiceContextImpl(String serviceName) {
+        super(serviceName);
+        setOutput(new MultipartOutput());
+    }
+
+
+    @Override
+    public Object getInputPart(String label, Class clazz) throws IOException {
+        Object obj = null;
+        if(getInput() != null){
+            MultipartInput fdip = getInput();
+
+            for(InputPart part : fdip.getParts()){
+                String partLabel = part.getHeaders().getFirst("label");
+                if(label.equalsIgnoreCase(partLabel)){
+                    if(logger.isDebugEnabled()){
+                        logger.debug("received part label=" + partLabel +
+                                "\npayload=" + part.getBodyAsString());
+                    }
+                    obj = part.getBody(clazz, null);
+                    break;
+                }
+            }
+        }
+        return obj;
+    }
+
+    @Override
+    public void addOutputPart(String label, Document doc, String contentType) throws Exception {
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        try{
+            DocumentUtils.writeDocument(doc, baos);
+            baos.close();
+            OutputPart part = getOutput().addPart(new String(baos.toByteArray()),
+                    MediaType.valueOf(contentType));
+            part.getHeaders().add("label", label);
+        }finally{
+            if(baos != null){
+                try{
+                    baos.close();
+                }catch(Exception e){
+                }
+            }
+        }
+    }
+
+    @Override
+    public ServiceContext getLocalContext(String localContextClassName) throws Exception {
+        ClassLoader cloader = Thread.currentThread().getContextClassLoader();
+        Class ctxClass = cloader.loadClass(localContextClassName);
+        if(!ServiceContext.class.isAssignableFrom(ctxClass)) {
+            throw new IllegalArgumentException("getLocalContext requires " +
+                    " implementation of " + ServiceContext.class.getName());
+        }
+        
+        Constructor ctor = ctxClass.getConstructor(java.lang.String.class);
+        ServiceContext ctx = (ServiceContext)ctor.newInstance(getServiceName());
+        return ctx;
+    }
+}
index 9ec071da843f935279d13afb256c0a567ef4a698..01fed3c86fd842ad8a6601fe76a02278300a3278 100644 (file)
  */
 package org.collectionspace.services.common.context;
 
-import java.io.IOException;
-import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
-import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
-import org.w3c.dom.Document;
-
 /**
  * RemoteServiceContext is used to encapsulate the service context of a
  * remotely invokable service
  */
-public interface RemoteServiceContext
-        extends ServiceContext<MultipartInput, MultipartOutput> {
+public interface RemoteServiceContext<IT, OT>
+        extends ServiceContext<IT, OT> {
 
     /**
      * Get input parts as received over the wire from service consumer
      * @return the input
      */
     @Override
-    public MultipartInput getInput();
+    public IT getInput();
 
     /**
      * setInput is used to set request input before starting to
@@ -49,37 +44,22 @@ public interface RemoteServiceContext
      * @exception IOException
      */
     @Override
-    public void setInput(MultipartInput input) throws Exception;
+    public void setInput(IT input);
 
     /**
      * Get output parts to send over the wire to service consumer
      * @return the output
      */
     @Override
-    public MultipartOutput getOutput();
+    public OT getOutput();
 
     /**
      * Set output parts to send over the wire to service consumer
      * @return the output
      */
     @Override
-    public void setOutput(MultipartOutput output) throws Exception;
-
-    /**
-     * getInputPart returns part for given label from input
-     * @param label
-     * @param clazz class of the object
-     * @return part
-     */
-    public Object getInputPart(String label, Class clazz) throws IOException;
+    public void setOutput(OT output);
 
-    /**
-     * addOutputPart adds given XML part with given label and content type to output
-     * @param label
-     * @param document
-     * @param contentType media type
-     */
-    public void addOutputPart(String label, Document doc, String contentType) throws Exception;
 
     /**
      * getLocalContext clones the remote context minus remote messaging data parts
index 4d6be9049a307379d7659cc82e7fba6e7c29c8ea..a5bdb2f4eee5c39c2d0f17dc62505c211ae50ccd 100644 (file)
  */
 package org.collectionspace.services.common.context;
 
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
 import java.lang.reflect.Constructor;
-import javax.ws.rs.core.MediaType;
-import org.collectionspace.services.common.document.DocumentUtils;
-import org.jboss.resteasy.plugins.providers.multipart.InputPart;
-import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
-import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
-import org.jboss.resteasy.plugins.providers.multipart.OutputPart;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.w3c.dom.Document;
 
 /**
  * RemoteServiceContextImpl
@@ -42,79 +33,39 @@ import org.w3c.dom.Document;
  * $LastChangedRevision: $
  * $LastChangedDate: $
  */
-public class RemoteServiceContextImpl
-        extends AbstractServiceContext<MultipartInput, MultipartOutput>
-        implements RemoteServiceContext {
+public class RemoteServiceContextImpl<IT, OT>
+        extends AbstractServiceContext<IT, OT>
+        implements RemoteServiceContext<IT, OT> {
 
     final Logger logger = LoggerFactory.getLogger(RemoteServiceContextImpl.class);
     //input stores original content as received over the wire
-    private MultipartInput input;
-    private MultipartOutput output;
+    private IT input;
+    private OT output;
 
     public RemoteServiceContextImpl(String serviceName) {
         super(serviceName);
-        output = new MultipartOutput();
     }
 
     @Override
-    public MultipartInput getInput() {
+    public IT getInput() {
         return input;
     }
 
     @Override
-    public void setInput(MultipartInput input) throws IOException {
+    public void setInput(IT input){
         this.input = input;
     }
 
     @Override
-    public MultipartOutput getOutput() {
+    public OT getOutput() {
         return output;
     }
 
     @Override
-    public void setOutput(MultipartOutput output) throws Exception {
+    public void setOutput(OT output){
         this.output = output;
     }
 
-    @Override
-    public Object getInputPart(String label, Class clazz) throws IOException {
-        Object obj = null;
-        if(getInput() != null){
-            MultipartInput fdip = getInput();
-
-            for(InputPart part : fdip.getParts()){
-                String partLabel = part.getHeaders().getFirst("label");
-                if(label.equalsIgnoreCase(partLabel)){
-                    if(logger.isDebugEnabled()){
-                        logger.debug("received part label=" + partLabel +
-                                "\npayload=" + part.getBodyAsString());
-                    }
-                    obj = part.getBody(clazz, null);
-                    break;
-                }
-            }
-        }
-        return obj;
-    }
-
-    @Override
-    public void addOutputPart(String label, Document doc, String contentType) throws Exception {
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        try{
-            DocumentUtils.writeDocument(doc, baos);
-            baos.close();
-            OutputPart part = output.addPart(new String(baos.toByteArray()),
-                    MediaType.valueOf(contentType));
-            part.getHeaders().add("label", label);
-        }finally{
-            if(baos != null){
-                try{
-                    baos.close();
-                }catch(Exception e){
-                }
-            }
-        }
-    }
 
     @Override
     public ServiceContext getLocalContext(String localContextClassName) throws Exception {
index 5b209ef8a6e58f2319a073ff98193f2cf94b90cd..c3723c06d8ef924aecfa1740ed926e23bf657cc9 100644 (file)
@@ -134,9 +134,8 @@ public interface ServiceContext<IT, OT> {
      * setInput is used to set request input before starting to
      * process input data
      * @param input
-     * @exception Exception
      */
-    public void setInput(IT input) throws Exception;
+    public void setInput(IT input);
 
     /**
      * Get output parts to send over the wire to service consumer
@@ -148,7 +147,7 @@ public interface ServiceContext<IT, OT> {
      * setOutput set output
      * @param output
      */
-    public void setOutput(OT output) throws Exception;
+    public void setOutput(OT output);
 
     /**
      * getPartsMetadata returns metadata for object parts used by the service
diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContextFactory.java b/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContextFactory.java
new file mode 100644 (file)
index 0000000..ae76e6d
--- /dev/null
@@ -0,0 +1,43 @@
+/**
+ *  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
+
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.collectionspace.services.common.context;
+
+/**
+ *
+ * ServiceContextFactory creates a service context
+ *
+ */
+public interface ServiceContextFactory<T> {
+
+
+    /**
+     * createServiceContext is a factory method to create a service context
+     * a service context is created on every service request call
+     * @param input
+     * @param serviceName which service/repository context to use
+     * @return
+     */
+    public ServiceContext createServiceContext(T input, String serviceName) throws Exception;
+
+}
index bb9690a1b28e4eba0b8125b7168c5a9cbedaeccb..c3c4c9aa4debd9c7175c118ee91f16c5ce1856d6 100644 (file)
@@ -145,14 +145,6 @@ public abstract class AbstractDocumentHandler<T, TL, WT, WTL>
         //no specific action needed
     }
 
-    @Override
-    public abstract void extractAllParts(DocumentWrapper<WT> wrapDoc)
-            throws Exception;
-
-    @Override
-    public abstract void fillAllParts(DocumentWrapper<WT> wrapDoc)
-            throws Exception;
-
     @Override
     public abstract T extractCommonPart(DocumentWrapper<WT> wrapDoc)
             throws Exception;
diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/AbstractMultipartDocumentHandler.java b/services/common/src/main/java/org/collectionspace/services/common/document/AbstractMultipartDocumentHandler.java
new file mode 100644 (file)
index 0000000..fef1b5d
--- /dev/null
@@ -0,0 +1,97 @@
+/**
+ *  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
+
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.collectionspace.services.common.document;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import java.util.StringTokenizer;
+import org.collectionspace.services.common.context.ServiceContext;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * AbstractMultipartDocumentHandler
+ *
+ * $LastChangedRevision: $
+ * $LastChangedDate: $
+ */
+public abstract class AbstractMultipartDocumentHandler<T, TL, WT, WTL>
+        extends AbstractDocumentHandler<T, TL, WT, WTL>
+        implements MultipartDocumentHandler<T, TL, WT, WTL> {
+
+    private final Logger logger = LoggerFactory.getLogger(AbstractMultipartDocumentHandler.class);
+
+    public AbstractMultipartDocumentHandler() {
+    }
+
+    @Override
+    public abstract void handleCreate(DocumentWrapper<WT> wrapDoc) throws Exception;
+
+    @Override
+    public abstract void handleUpdate(DocumentWrapper<WT> wrapDoc) throws Exception;
+
+    @Override
+    public abstract void handleGet(DocumentWrapper<WT> wrapDoc) throws Exception;
+
+    @Override
+    public abstract void handleGetAll(DocumentWrapper<WTL> wrapDoc) throws Exception;
+
+    @Override
+    public abstract void extractAllParts(DocumentWrapper<WT> wrapDoc)
+            throws Exception;
+
+    @Override
+    public abstract void fillAllParts(DocumentWrapper<WT> wrapDoc)
+            throws Exception;
+
+    @Override
+    public abstract T extractCommonPart(DocumentWrapper<WT> wrapDoc)
+            throws Exception;
+
+    @Override
+    public abstract void fillCommonPart(T obj, DocumentWrapper<WT> wrapDoc)
+            throws Exception;
+
+    @Override
+    public abstract TL extractCommonPartList(DocumentWrapper<WTL> wrapDoc)
+            throws Exception;
+
+    @Override
+    public abstract T getCommonPart();
+
+    @Override
+    public abstract void setCommonPart(T obj);
+
+    @Override
+    public abstract TL getCommonPartList();
+
+    @Override
+    public abstract void setCommonPartList(TL obj);
+
+    @Override
+    public abstract String getQProperty(String prop);
+
+}
index 5fbda3564d7d39c95301dc6b224eacb63144eb10..804c7ed451769f16c71f7e156286a1656b859748 100644 (file)
@@ -32,6 +32,11 @@ import org.collectionspace.services.common.context.ServiceContext;
  * repository client calls prepare on the handler
  * The repository client then calls handle on the handler
  *
+ * T - Entity Type (e.g. CollectionObjectsCommon)
+ * TL - Entity List Type (e.g. CollectionObjectsCommonList)
+ * WT - Wrapped Type (e.g. DocumentModel)
+ * WTL - Wrapped List Type (e.g. DocumentModelList)
+ *
  */
 public interface DocumentHandler<T, TL, WT, WTL> {
 
@@ -120,25 +125,6 @@ public interface DocumentHandler<T, TL, WT, WTL> {
      */
     public void completeUpdate(DocumentWrapper<WT> wrapDoc) throws Exception;
 
-    /**
-     * extractAllParts extracts all parts of a CS object from given document.
-     * this is usually called AFTER the get operation is invoked on the repository
-     * Called in handle GET/GET_ALL actions.
-     * @param docWrap document
-     * @throws Exception
-     */
-    public void extractAllParts(DocumentWrapper<WT> docWrap) throws Exception;
-
-    /**
-     * fillAllParts sets parts of CS object into given document
-     * this is usually called BEFORE create/update operations are invoked on the
-     * repository. Called in handle CREATE/UPDATE actions.
-     * @param obj input object
-     * @param docWrap target document
-     * @throws Exception
-     */
-    public void fillAllParts(DocumentWrapper<WT> docWrap) throws Exception;
-
     /**
      * extractCommonPart extracts common part of a CS object from given document.
      * this is usually called AFTER the get operation is invoked on the repository.
diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/MultipartDocumentHandler.java b/services/common/src/main/java/org/collectionspace/services/common/document/MultipartDocumentHandler.java
new file mode 100644 (file)
index 0000000..2a84a04
--- /dev/null
@@ -0,0 +1,51 @@
+/**
+ *  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;
+
+/**
+ * MultipartDocumentHandler is a DocumentHandler provides document processing
+ * methods for entities using schema extension that are mapped to multipart
+ * request and response.
+ * @author
+ * @param <T>
+ * @param <TL>
+ * @param <WT>
+ * @param <WTL>
+ */
+public interface MultipartDocumentHandler<T, TL, WT, WTL>
+        extends DocumentHandler<T, TL, WT, WTL> {
+
+    /**
+     * extractAllParts extracts all parts of a CS object from given document.
+     * this is usually called AFTER the get operation is invoked on the repository
+     * Called in handle GET/GET_ALL actions.
+     * @param docWrap document
+     * @throws Exception
+     */
+    public void extractAllParts(DocumentWrapper<WT> docWrap) throws Exception;
+
+    /**
+     * fillAllParts sets parts of CS object into given document
+     * this is usually called BEFORE create/update operations are invoked on the
+     * repository. Called in handle CREATE/UPDATE actions.
+     * @param obj input object
+     * @param docWrap target document
+     * @throws Exception
+     */
+    public void fillAllParts(DocumentWrapper<WT> docWrap) throws Exception;
+}
\ No newline at end of file
diff --git a/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaStorageClient.java b/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaStorageClient.java
new file mode 100644 (file)
index 0000000..32a3267
--- /dev/null
@@ -0,0 +1,382 @@
+/**
+ *  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.storage.jpa;
+
+import java.lang.reflect.Method;
+import java.util.List;
+import javax.persistence.EntityManager;
+import javax.persistence.EntityManagerFactory;
+import javax.persistence.Persistence;
+import javax.persistence.Query;
+import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.common.document.BadRequestException;
+import org.collectionspace.services.common.document.DocumentException;
+import org.collectionspace.services.common.document.DocumentFilter;
+import org.collectionspace.services.common.document.DocumentHandler;
+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.storage.StorageClient;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * JpaStorageClient is used to perform CRUD operations on documents in Nuxeo
+ * repository using Remote Java APIs. It uses @see DocumentHandler as IOHandler
+ * with the client.
+ *
+ * $LastChangedRevision: $ $LastChangedDate: $
+ */
+public class JpaStorageClient implements StorageClient {
+
+    private final Logger logger = LoggerFactory.getLogger(JpaStorageClient.class);
+
+    public JpaStorageClient() {
+    }
+
+    @Override
+    public String create(ServiceContext ctx,
+            DocumentHandler handler) throws BadRequestException,
+            DocumentException {
+
+        String docType = ctx.getDocumentType();
+        if (docType == null) {
+            throw new DocumentNotFoundException(
+                    "Unable to find DocumentType for service " + ctx.getServiceName());
+        }
+        if (handler == null) {
+            throw new IllegalArgumentException(
+                    "JpaStorageClient.create: handler is missing");
+        }
+        EntityManagerFactory emf = null;
+        EntityManager em = null;
+        try {
+            handler.prepare(Action.CREATE);
+            Object po = handler.getCommonPart();
+            DocumentWrapper<Object> wrapDoc = new DocumentWrapperImpl<Object>(po);
+            handler.handle(Action.CREATE, wrapDoc);
+            emf = getEntityManagerFactory(docType);
+            em = emf.createEntityManager();
+            em.getTransaction().begin();
+            em.persist(po);
+            em.getTransaction().commit();
+            handler.complete(Action.CREATE, wrapDoc);
+            return getCsid(po);
+        } catch (Exception e) {
+            if (em != null) {
+                em.getTransaction().rollback();
+            }
+            if (logger.isDebugEnabled()) {
+                logger.debug("Caught exception ", e);
+            }
+            throw new DocumentException(e);
+        } finally {
+            if (em != null) {
+                releaseEntityManagerFactory(emf);
+            }
+        }
+
+    }
+
+    @Override
+    public void get(ServiceContext ctx, String id, DocumentHandler handler)
+            throws DocumentNotFoundException, DocumentException {
+        if (handler == null) {
+            throw new IllegalArgumentException(
+                    "JpaStorageClient.get: handler is missing");
+        }
+        DocumentFilter docFilter = handler.getDocumentFilter();
+        if (docFilter == null) {
+            throw new IllegalArgumentException(
+                    "JpaStorageClient.get: handler has no Filter specified");
+        }
+        String docType = ctx.getDocumentType();
+        if (docType == null) {
+            throw new DocumentNotFoundException(
+                    "Unable to find DocumentType for service " + ctx.getServiceName());
+        }
+        EntityManagerFactory emf = null;
+        EntityManager em = null;
+        try {
+            handler.prepare(Action.GET);
+            StringBuilder queryStr = new StringBuilder("SELECT * FROM ");
+            queryStr.append(docType);
+            queryStr.append(" WHERE csid = :csid");
+            //TODO: add tenant id
+            String where = docFilter.getWhereClause();
+            if ((null != where) && (where.length() > 0)) {
+                queryStr.append(" AND " + where);
+            }
+            emf = getEntityManagerFactory(docType);
+            em = emf.createEntityManager();
+            Query q = em.createQuery(queryStr.toString());
+            q.setParameter("csid", id);
+            //TODO: add tenant id
+
+            //TODO: get page
+            if ((docFilter.getOffset() > 0) || (docFilter.getPageSize() > 0)) {
+            } else {
+            }
+            //require transaction for get?
+            em.getTransaction().begin();
+            Object o = q.getSingleResult();
+            em.getTransaction().commit();
+            DocumentWrapper<Object> wrapDoc = new DocumentWrapperImpl<Object>(o);
+            handler.handle(Action.GET, wrapDoc);
+            handler.complete(Action.GET, wrapDoc);
+        } catch (IllegalArgumentException iae) {
+            throw iae;
+        } catch (DocumentException de) {
+            throw de;
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("Caught exception ", e);
+            }
+            throw new DocumentException(e);
+        } finally {
+            if (emf != null) {
+                releaseEntityManagerFactory(emf);
+            }
+        }
+    }
+
+    @Override
+    public void getAll(ServiceContext ctx, DocumentHandler handler)
+            throws DocumentNotFoundException, DocumentException {
+        throw new UnsupportedOperationException("use getFiltered instead");
+    }
+
+    /**
+     * getFiltered get all documents for an entity service from the Document repository,
+     * given filter parameters specified by the handler.
+     * @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 DocumentException
+     */
+    public void getFiltered(ServiceContext ctx, DocumentHandler handler)
+            throws DocumentNotFoundException, DocumentException {
+        if (handler == null) {
+            throw new IllegalArgumentException(
+                    "JpaStorageClient.getFiltered: handler is missing");
+        }
+        DocumentFilter docFilter = handler.getDocumentFilter();
+        if (docFilter == null) {
+            throw new IllegalArgumentException(
+                    "JpaStorageClient.getFiltered: handler has no Filter specified");
+        }
+        String docType = ctx.getDocumentType();
+        if (docType == null) {
+            throw new DocumentNotFoundException(
+                    "Unable to find DocumentType for service " + ctx.getServiceName());
+        }
+
+        EntityManagerFactory emf = null;
+        EntityManager em = null;
+        try {
+            handler.prepare(Action.GET_ALL);
+
+            StringBuilder queryStr = new StringBuilder("SELECT * FROM ");
+            queryStr.append(docType);
+            //TODO: add tenant id
+            String where = docFilter.getWhereClause();
+            if ((null != where) && (where.length() > 0)) {
+                queryStr.append(" AND " + where);
+            }
+            emf = getEntityManagerFactory(docType);
+            em = emf.createEntityManager();
+            Query q = em.createQuery(queryStr.toString());
+            //TODO: add tenant id
+            //TODO: get page
+            if ((docFilter.getOffset() > 0) || (docFilter.getPageSize() > 0)) {
+            } else {
+            }
+            //FIXME is transaction required for get?
+            em.getTransaction().begin();
+            List list = q.getResultList();
+            em.getTransaction().commit();
+            DocumentWrapper<List> wrapDoc = new DocumentWrapperImpl<List>(list);
+            handler.handle(Action.GET_ALL, wrapDoc);
+            handler.complete(Action.GET_ALL, wrapDoc);
+        } catch (DocumentException de) {
+            throw de;
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("Caught exception ", e);
+            }
+            throw new DocumentException(e);
+        } finally {
+            if (emf != null) {
+                releaseEntityManagerFactory(emf);
+            }
+        }
+    }
+
+    @Override
+    public void update(ServiceContext ctx, String id, DocumentHandler handler)
+            throws BadRequestException, DocumentNotFoundException,
+            DocumentException {
+        String docType = ctx.getDocumentType();
+        if (docType == null) {
+            throw new DocumentNotFoundException(
+                    "Unable to find DocumentType for service " + ctx.getServiceName());
+        }
+        if (handler == null) {
+            throw new IllegalArgumentException(
+                    "JpaStorageClient.update: handler is missing");
+        }
+        EntityManagerFactory emf = null;
+        EntityManager em = null;
+        try {
+            handler.prepare(Action.UPDATE);
+            Object po = handler.getCommonPart();
+            setCsid(po, id);
+            DocumentWrapper<Object> wrapDoc = new DocumentWrapperImpl<Object>(po);
+            handler.handle(Action.UPDATE, wrapDoc);
+            emf = getEntityManagerFactory(docType);
+            em = emf.createEntityManager();
+            em.getTransaction().begin();
+            em.merge(po);
+            em.getTransaction().commit();
+            handler.complete(Action.UPDATE, wrapDoc);
+        } catch (DocumentException de) {
+            throw de;
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("Caught exception ", e);
+            }
+            throw new DocumentException(e);
+        } finally {
+        }
+    }
+
+    /**
+     * delete a document from the Nuxeo repository
+     * @param ctx service context under which this method is invoked
+     * @param id
+     *            of the document
+     * @throws DocumentException
+     */
+    @Override
+    public void delete(ServiceContext ctx, String id) throws DocumentNotFoundException,
+            DocumentException {
+
+        if (logger.isDebugEnabled()) {
+            logger.debug("deleting document with id=" + id);
+        }
+        String docType = ctx.getDocumentType();
+        if (docType == null) {
+            throw new DocumentNotFoundException(
+                    "Unable to find DocumentType for service " + ctx.getServiceName());
+        }
+        EntityManagerFactory emf = null;
+        EntityManager em = null;
+        try {
+            StringBuilder deleteStr = new StringBuilder("DELETE FROM ");
+            deleteStr.append(docType);
+            deleteStr.append(" WHERE csid = :csid");
+            //TODO: add tenant id
+
+            emf = getEntityManagerFactory(docType);
+            em = emf.createEntityManager();
+            Query q = em.createQuery(deleteStr.toString());
+            q.setParameter("csid", id);
+            //TODO: add tenant id
+            em.getTransaction().begin();
+            int rcount = q.executeUpdate();
+            em.getTransaction().commit();
+            if (rcount != 1) {
+                throw new DocumentException("failed to delete " + docType +
+                        " csid=" + id);
+            }
+        } catch (DocumentException de) {
+            if (em != null) {
+                em.getTransaction().rollback();
+            }
+            throw de;
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("Caught exception ", e);
+            }
+            if (em != null) {
+                em.getTransaction().rollback();
+            }
+            throw new DocumentException(e);
+        } finally {
+            if (emf != null) {
+                releaseEntityManagerFactory(emf);
+            }
+        }
+    }
+
+    private EntityManagerFactory getEntityManagerFactory(String persistenceUnit) {
+        return Persistence.createEntityManagerFactory(persistenceUnit);
+
+    }
+
+    private void releaseEntityManagerFactory(EntityManagerFactory emf) {
+        if (emf != null) {
+            emf.close();
+        }
+    }
+
+    private String getCsid(Object o) throws Exception {
+        Class c = o.getClass();
+        Method m = c.getMethod("getCsid");
+        if (m == null) {
+            String msg = "Could not find csid in object of class=" + o.getClass().getCanonicalName();
+            logger.error(msg);
+            throw new IllegalArgumentException(msg);
+        }
+        Object r = m.invoke(o);
+        if (logger.isDebugEnabled()) {
+            logger.debug("getCsid returned csid=" + r.toString() +
+                    " for " + c.getName());
+        }
+        return (String) r;
+    }
+
+    private void setCsid(Object o, String csid) throws Exception {
+        //verify csid 
+        String id = getCsid(o);
+        if (id != null) {
+            if (!id.equals(csid)) {
+                String msg = "Csids do not match!";
+                logger.error(msg);
+                throw new BadRequestException(msg);
+            } else {
+                //no need to set
+                return;
+            }
+        }
+        //set csid
+        Class c = o.getClass();
+        Method m = c.getMethod("setCsid");
+        if (m == null) {
+            String msg = "Could not find csid in object of class=" + o.getClass().getCanonicalName();
+            logger.error(msg);
+            throw new IllegalArgumentException(msg);
+        }
+        Object r = m.invoke(o, csid);
+        if (logger.isDebugEnabled()) {
+            logger.debug("setCsid returned csid=" + r.toString() +
+                    " for " + c.getName());
+        }
+    }
+}
\ No newline at end of file
index d929813aaac4553892fad761c56ecbb5ba9bd11f..ff1d0c603d4f306919e1d2f8e2cb373e0d3e30e6 100644 (file)
@@ -23,8 +23,8 @@
  */
 package org.collectionspace.services.nuxeo.client.java;
 
+import org.collectionspace.services.common.document.AbstractMultipartDocumentHandler;
 import org.collectionspace.services.common.document.DocumentWrapper;
-import org.collectionspace.services.common.document.AbstractDocumentHandler;
 import org.collectionspace.services.nuxeo.client.*;
 import org.nuxeo.ecm.core.api.DocumentModel;
 import org.nuxeo.ecm.core.api.DocumentModelList;
@@ -40,7 +40,7 @@ import org.slf4j.LoggerFactory;
  * $LastChangedDate: $
  */
 public abstract class DocumentModelHandler<T, TL>
-        extends AbstractDocumentHandler<T, TL, DocumentModel, DocumentModelList> {
+        extends AbstractMultipartDocumentHandler<T, TL, DocumentModel, DocumentModelList> {
 
     private final Logger logger = LoggerFactory.getLogger(DocumentModelHandler.class);
     private RepositoryInstance repositorySession;
index af09b24274e6e41a580d5d9ec52e439535f73448..31e42a2a3909d97ef3e6b9a17d74a8557364435f 100644 (file)
@@ -30,7 +30,7 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Set;
 import javax.ws.rs.core.MediaType;
-import org.collectionspace.services.common.context.RemoteServiceContext;
+import org.collectionspace.services.common.context.MultipartServiceContext;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.document.BadRequestException;
 import org.collectionspace.services.common.document.DocumentUtils;
@@ -56,11 +56,11 @@ public abstract class RemoteDocumentModelHandler<T, TL>
 
     @Override
     public void setServiceContext(ServiceContext ctx) {
-        if(ctx instanceof RemoteServiceContext){
+        if(ctx instanceof MultipartServiceContext){
             super.setServiceContext(ctx);
         }else{
             throw new IllegalArgumentException("setServiceContext requires instance of " +
-                    RemoteServiceContext.class.getName());
+                    MultipartServiceContext.class.getName());
         }
     }
 
@@ -72,7 +72,7 @@ public abstract class RemoteDocumentModelHandler<T, TL>
         DocumentModel docModel = wrapDoc.getWrappedObject();
         //return at least those document part(s) that were received
         Map<String, ObjectPartType> partsMetaMap = getServiceContext().getPartsMetadata();
-        RemoteServiceContext ctx = (RemoteServiceContext) getServiceContext();
+        MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext();
         List<InputPart> inputParts = ctx.getInput().getParts();
         for(InputPart part : inputParts){
             String partLabel = part.getHeaders().getFirst("label");
@@ -103,7 +103,7 @@ public abstract class RemoteDocumentModelHandler<T, TL>
         //Nuxeo APIs lack to support stream/byte[] input, get/setting properties is
         //not an ideal way of populating objects.
         DocumentModel docModel = wrapDoc.getWrappedObject();
-        RemoteServiceContext ctx = (RemoteServiceContext) getServiceContext();
+        MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext();
         MultipartInput input = ctx.getInput();
         if(input.getParts().isEmpty()){
             String msg = "No payload found!";
@@ -181,7 +181,7 @@ public abstract class RemoteDocumentModelHandler<T, TL>
             if(logger.isDebugEnabled()){
                 DocumentUtils.writeDocument(doc, System.out);
             }
-            RemoteServiceContext ctx = (RemoteServiceContext) getServiceContext();
+            MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext();
             ctx.addOutputPart(schema, doc, partMeta.getContent().getContentType());
         } //TODO: handle other media types
     }
index 9ccb51be18f9603be1e3f25cbc1afd1cb0cf1457..0b23a002b693cbeeb692c7712ab97235cff65fdb 100644 (file)
@@ -75,11 +75,11 @@ public class RepositoryJavaClient implements RepositoryClient {
 
         if (ctx.getDocumentType() == null) {
             throw new IllegalArgumentException(
-                    "RemoteRepositoryClient.create: docType is missing");
+                    "RepositoryJavaClient.create: docType is missing");
         }
         if (handler == null) {
             throw new IllegalArgumentException(
-                    "RemoteRepositoryClient.create: handler is missing");
+                    "RepositoryJavaClient.create: handler is missing");
         }
         String nuxeoWspaceId = ctx.getRepositoryWorkspaceId();
         if (nuxeoWspaceId == null) {
@@ -136,7 +136,7 @@ public class RepositoryJavaClient implements RepositoryClient {
 
         if (handler == null) {
             throw new IllegalArgumentException(
-                    "RemoteRepositoryClient.get: handler is missing");
+                    "RepositoryJavaClient.get: handler is missing");
         }
         RepositoryInstance repoSession = null;
 
@@ -188,7 +188,7 @@ public class RepositoryJavaClient implements RepositoryClient {
             throws DocumentNotFoundException, DocumentException {
         if (handler == null) {
             throw new IllegalArgumentException(
-                    "RemoteRepositoryClient.getAll: handler is missing");
+                    "RepositoryJavaClient.getAll: handler is missing");
         }
         String nuxeoWspaceId = ctx.getRepositoryWorkspaceId();
         if (nuxeoWspaceId == null) {
@@ -235,12 +235,12 @@ public class RepositoryJavaClient implements RepositoryClient {
             throws DocumentNotFoundException, DocumentException {
         if (handler == null) {
             throw new IllegalArgumentException(
-                    "RemoteRepositoryClient.getFiltered: handler is missing");
+                    "RepositoryJavaClient.getFiltered: handler is missing");
         }
         DocumentFilter docFilter = handler.getDocumentFilter();
         if (docFilter == null) {
             throw new IllegalArgumentException(
-                    "RemoteRepositoryClient.getFiltered: handler has no Filter specified");
+                    "RepositoryJavaClient.getFiltered: handler has no Filter specified");
         }
         String docType = ctx.getDocumentType();
         if (docType == null) {
@@ -306,13 +306,9 @@ public class RepositoryJavaClient implements RepositoryClient {
     public void update(ServiceContext ctx, String id, DocumentHandler handler)
             throws BadRequestException, DocumentNotFoundException,
             DocumentException {
-        if (id == null) {
-            throw new BadRequestException(
-                    "RemoteRepositoryClient.update: id is missing");
-        }
         if (handler == null) {
             throw new IllegalArgumentException(
-                    "RemoteRepositoryClient.update: handler is missing");
+                    "RepositoryJavaClient.update: handler is missing");
         }
         RepositoryInstance repoSession = null;
         try {
index fd936e728ec0fb621284e44f0180246c893942a5..e1a965c410ab167f795638482c27c1f38cfa5305 100644 (file)
@@ -43,7 +43,8 @@ import org.collectionspace.services.intake.IntakesCommonList.*;
 import org.collectionspace.services.intake.nuxeo.IntakeHandlerFactory;
 import org.collectionspace.services.common.ClientType;
 import org.collectionspace.services.common.ServiceMain;
-import org.collectionspace.services.common.context.RemoteServiceContext;
+import org.collectionspace.services.common.context.MultipartServiceContext;
+import org.collectionspace.services.common.context.MultipartServiceContextFactory;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.document.DocumentNotFoundException;
 import org.collectionspace.services.common.document.DocumentHandler;
@@ -73,13 +74,13 @@ public class IntakeResource extends AbstractCollectionSpaceResource {
     }
 
     @Override
-    public DocumentHandler createDocumentHandler(RemoteServiceContext ctx) throws Exception {
+    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
         DocumentHandler docHandler = IntakeHandlerFactory.getInstance().getHandler(
                 ctx.getRepositoryClientType().toString());
         docHandler.setServiceContext(ctx);
-        if(ctx.getInput() != null){
-            Object obj = ctx.getInputPart(ctx.getCommonPartLabel(), IntakesCommon.class);
-            if(obj != null){
+        if (ctx.getInput() != null) {
+            Object obj = ((MultipartServiceContext)ctx).getInputPart(ctx.getCommonPartLabel(), IntakesCommon.class);
+            if (obj != null) {
                 docHandler.setCommonPart((IntakesCommon) obj);
             }
         }
@@ -88,8 +89,8 @@ public class IntakeResource extends AbstractCollectionSpaceResource {
 
     @POST
     public Response createIntake(MultipartInput input) {
-        try{
-            RemoteServiceContext ctx = createServiceContext(input);
+        try {
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getServiceName());
             DocumentHandler handler = createDocumentHandler(ctx);
             String csid = getRepositoryClient(ctx).create(ctx, handler);
             //intakeObject.setCsid(csid);
@@ -97,8 +98,8 @@ public class IntakeResource extends AbstractCollectionSpaceResource {
             path.path("" + csid);
             Response response = Response.created(path.build()).build();
             return response;
-        }catch(Exception e){
-            if(logger.isDebugEnabled()){
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("Caught exception in createIntake", e);
             }
             Response response = Response.status(
@@ -111,10 +112,10 @@ public class IntakeResource extends AbstractCollectionSpaceResource {
     @Path("{csid}")
     public MultipartOutput getIntake(
             @PathParam("csid") String csid) {
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug("getIntake with csid=" + csid);
         }
-        if(csid == null || "".equals(csid)){
+        if (csid == null || "".equals(csid)) {
             logger.error("getIntake: missing csid!");
             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
                     "get failed on Intake csid=" + csid).type(
@@ -122,28 +123,28 @@ public class IntakeResource extends AbstractCollectionSpaceResource {
             throw new WebApplicationException(response);
         }
         MultipartOutput result = null;
-        try{
-            RemoteServiceContext ctx = createServiceContext(null);
+        try {
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).get(ctx, csid, handler);
-            result = ctx.getOutput();
-        }catch(DocumentNotFoundException dnfe){
-            if(logger.isDebugEnabled()){
+            result = (MultipartOutput) ctx.getOutput();
+        } catch (DocumentNotFoundException dnfe) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("getIntake", dnfe);
             }
             Response response = Response.status(Response.Status.NOT_FOUND).entity(
                     "Get failed on Intake csid=" + csid).type(
                     "text/plain").build();
             throw new WebApplicationException(response);
-        }catch(Exception e){
-            if(logger.isDebugEnabled()){
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("getIntake", e);
             }
             Response response = Response.status(
                     Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
             throw new WebApplicationException(response);
         }
-        if(result == null){
+        if (result == null) {
             Response response = Response.status(Response.Status.NOT_FOUND).entity(
                     "Get failed, the requested Intake CSID:" + csid + ": was not found.").type(
                     "text/plain").build();
@@ -156,13 +157,13 @@ public class IntakeResource extends AbstractCollectionSpaceResource {
     @Produces("application/xml")
     public IntakesCommonList getIntakeList(@Context UriInfo ui) {
         IntakesCommonList intakeObjectList = new IntakesCommonList();
-        try{
-            RemoteServiceContext ctx = createServiceContext(null);
+        try {
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).getAll(ctx, handler);
             intakeObjectList = (IntakesCommonList) handler.getCommonPartList();
-        }catch(Exception e){
-            if(logger.isDebugEnabled()){
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("Caught exception in getIntakeList", e);
             }
             Response response = Response.status(
@@ -177,10 +178,10 @@ public class IntakeResource extends AbstractCollectionSpaceResource {
     public MultipartOutput updateIntake(
             @PathParam("csid") String csid,
             MultipartInput theUpdate) {
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug("updateIntake with csid=" + csid);
         }
-        if(csid == null || "".equals(csid)){
+        if (csid == null || "".equals(csid)) {
             logger.error("updateIntake: missing csid!");
             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
                     "update failed on Intake csid=" + csid).type(
@@ -188,20 +189,20 @@ public class IntakeResource extends AbstractCollectionSpaceResource {
             throw new WebApplicationException(response);
         }
         MultipartOutput result = null;
-        try{
-            RemoteServiceContext ctx = createServiceContext(theUpdate);
+        try {
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(theUpdate, getServiceName());
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).update(ctx, csid, handler);
-            result = ctx.getOutput();
-        }catch(DocumentNotFoundException dnfe){
-            if(logger.isDebugEnabled()){
+            result = (MultipartOutput) ctx.getOutput();
+        } catch (DocumentNotFoundException dnfe) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("caugth exception in updateIntake", dnfe);
             }
             Response response = Response.status(Response.Status.NOT_FOUND).entity(
                     "Update failed on Intake csid=" + csid).type(
                     "text/plain").build();
             throw new WebApplicationException(response);
-        }catch(Exception e){
+        } catch (Exception e) {
             Response response = Response.status(
                     Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build();
             throw new WebApplicationException(response);
@@ -213,29 +214,29 @@ public class IntakeResource extends AbstractCollectionSpaceResource {
     @Path("{csid}")
     public Response deleteIntake(@PathParam("csid") String csid) {
 
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug("deleteIntake with csid=" + csid);
         }
-        if(csid == null || "".equals(csid)){
+        if (csid == null || "".equals(csid)) {
             logger.error("deleteIntake: missing csid!");
             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
                     "delete failed on Intake csid=" + csid).type(
                     "text/plain").build();
             throw new WebApplicationException(response);
         }
-        try{
-            ServiceContext ctx = createServiceContext(null);
+        try {
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
             getRepositoryClient(ctx).delete(ctx, csid);
             return Response.status(HttpResponseCodes.SC_OK).build();
-        }catch(DocumentNotFoundException dnfe){
-            if(logger.isDebugEnabled()){
+        } catch (DocumentNotFoundException dnfe) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("caught exception in deleteIntake", dnfe);
             }
             Response response = Response.status(Response.Status.NOT_FOUND).entity(
                     "Delete failed on Intake csid=" + csid).type(
                     "text/plain").build();
             throw new WebApplicationException(response);
-        }catch(Exception e){
+        } catch (Exception e) {
             Response response = Response.status(
                     Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build();
             throw new WebApplicationException(response);
index 35ce07a8f1fcada98c41f3d9a9b4744fd21f9c1a..552a34210eef1450c0ccce260099b0ae40027506 100644 (file)
@@ -44,7 +44,8 @@ import javax.ws.rs.core.UriInfo;
 
 
 import org.collectionspace.services.common.AbstractCollectionSpaceResource;
-import org.collectionspace.services.common.context.RemoteServiceContext;
+import org.collectionspace.services.common.context.MultipartServiceContext;
+import org.collectionspace.services.common.context.MultipartServiceContextFactory;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.relation.IRelationsManager;
 import org.collectionspace.services.common.document.DocumentNotFoundException;
@@ -70,13 +71,13 @@ public class NewRelationResource extends AbstractCollectionSpaceResource {
     }
 
     @Override
-    public DocumentHandler createDocumentHandler(RemoteServiceContext ctx) throws Exception {
+    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
         DocumentHandler docHandler = RelationHandlerFactory.getInstance().getHandler(
                 ctx.getRepositoryClientType().toString());
         docHandler.setServiceContext(ctx);
-        if(ctx.getInput() != null){
-            Object obj = ctx.getInputPart(ctx.getCommonPartLabel(), RelationsCommon.class);
-            if(obj != null){
+        if (ctx.getInput() != null) {
+            Object obj = ((MultipartServiceContext)ctx).getInputPart(ctx.getCommonPartLabel(), RelationsCommon.class);
+            if (obj != null) {
                 docHandler.setCommonPart((RelationsCommon) obj);
             }
         }
@@ -86,16 +87,16 @@ public class NewRelationResource extends AbstractCollectionSpaceResource {
     @POST
     public Response createRelation(MultipartInput input) {
 
-        try{
-            RemoteServiceContext ctx = createServiceContext(input);
+        try {
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getServiceName());
             DocumentHandler handler = createDocumentHandler(ctx);
             String csid = getRepositoryClient(ctx).create(ctx, handler);
             UriBuilder path = UriBuilder.fromResource(NewRelationResource.class);
             path.path("" + csid);
             Response response = Response.created(path.build()).build();
             return response;
-        }catch(Exception e){
-            if(logger.isDebugEnabled()){
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("Caught exception in createRelation", e);
             }
             Response response = Response.status(
@@ -108,30 +109,30 @@ public class NewRelationResource extends AbstractCollectionSpaceResource {
     @GET
     @Path("{csid}")
     public MultipartOutput getRelation(@PathParam("csid") String csid) {
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug("getRelation with csid=" + csid);
         }
-        if(csid == null || "".equals(csid)){
+        if (csid == null || "".equals(csid)) {
             logger.error("getRelation: missing csid!");
             Response response = Response.status(Response.Status.BAD_REQUEST).entity("get failed on Relation csid=" + csid).type(
                     "text/plain").build();
             throw new WebApplicationException(response);
         }
         MultipartOutput result = null;
-        try{
-            RemoteServiceContext ctx = createServiceContext(null);
+        try {
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).get(ctx, csid, handler);
-            result = ctx.getOutput();
-        }catch(DocumentNotFoundException dnfe){
-            if(logger.isDebugEnabled()){
+            result = (MultipartOutput) ctx.getOutput();
+        } catch (DocumentNotFoundException dnfe) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("getRelation", dnfe);
             }
             Response response = Response.status(Response.Status.NOT_FOUND).entity("Get failed on Relation csid=" + csid).type(
                     "text/plain").build();
             throw new WebApplicationException(response);
-        }catch(Exception e){
-            if(logger.isDebugEnabled()){
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("getRelation", e);
             }
             Response response = Response.status(
@@ -139,7 +140,7 @@ public class NewRelationResource extends AbstractCollectionSpaceResource {
             throw new WebApplicationException(response);
         }
 
-        if(result == null){
+        if (result == null) {
             Response response = Response.status(Response.Status.NOT_FOUND).entity(
                     "Get failed, the requested Relation CSID:" + csid + ": was not found.").type("text/plain").build();
             throw new WebApplicationException(response);
@@ -243,29 +244,29 @@ public class NewRelationResource extends AbstractCollectionSpaceResource {
     @Path("{csid}")
     public MultipartOutput updateRelation(@PathParam("csid") String csid,
             MultipartInput theUpdate) {
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug("updateRelation with csid=" + csid);
         }
-        if(csid == null || "".equals(csid)){
+        if (csid == null || "".equals(csid)) {
             logger.error("updateRelation: missing csid!");
             Response response = Response.status(Response.Status.BAD_REQUEST).entity("update failed on Relation csid=" + csid).type(
                     "text/plain").build();
             throw new WebApplicationException(response);
         }
         MultipartOutput result = null;
-        try{
-            RemoteServiceContext ctx = createServiceContext(theUpdate);
+        try {
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(theUpdate, getServiceName());
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).update(ctx, csid, handler);
-            result = ctx.getOutput();
-        }catch(DocumentNotFoundException dnfe){
-            if(logger.isDebugEnabled()){
+            result = (MultipartOutput) ctx.getOutput();
+        } catch (DocumentNotFoundException dnfe) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("caugth exception in updateRelation", dnfe);
             }
             Response response = Response.status(Response.Status.NOT_FOUND).entity("Update failed on Relation csid=" + csid).type(
                     "text/plain").build();
             throw new WebApplicationException(response);
-        }catch(Exception e){
+        } catch (Exception e) {
             Response response = Response.status(
                     Response.Status.INTERNAL_SERVER_ERROR).entity(
                     "Update failed").type("text/plain").build();
@@ -278,27 +279,27 @@ public class NewRelationResource extends AbstractCollectionSpaceResource {
     @Path("{csid}")
     public Response deleteRelation(@PathParam("csid") String csid) {
 
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug("deleteRelation with csid=" + csid);
         }
-        if(csid == null || "".equals(csid)){
+        if (csid == null || "".equals(csid)) {
             logger.error("deleteRelation: missing csid!");
             Response response = Response.status(Response.Status.BAD_REQUEST).entity("delete failed on Relation csid=" + csid).type(
                     "text/plain").build();
             throw new WebApplicationException(response);
         }
-        try{
-            ServiceContext ctx = createServiceContext(null);
+        try {
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
             getRepositoryClient(ctx).delete(ctx, csid);
             return Response.status(HttpResponseCodes.SC_OK).build();
-        }catch(DocumentNotFoundException dnfe){
-            if(logger.isDebugEnabled()){
+        } catch (DocumentNotFoundException dnfe) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("caught exception in deleteRelation", dnfe);
             }
             Response response = Response.status(Response.Status.NOT_FOUND).entity("Delete failed on Relation csid=" + csid).type(
                     "text/plain").build();
             throw new WebApplicationException(response);
-        }catch(Exception e){
+        } catch (Exception e) {
             Response response = Response.status(
                     Response.Status.INTERNAL_SERVER_ERROR).entity(
                     "Delete failed").type("text/plain").build();
@@ -322,8 +323,8 @@ public class NewRelationResource extends AbstractCollectionSpaceResource {
             String objectCsid)
             throws WebApplicationException {
         RelationsCommonList relationList = new RelationsCommonList();
-        try{
-            RemoteServiceContext ctx = createServiceContext(null);
+        try {
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
             DocumentHandler handler = createDocumentHandler(ctx);
             Map propsFromPath = handler.getProperties();
             propsFromPath.put(IRelationsManager.SUBJECT, subjectCsid);
@@ -331,8 +332,8 @@ public class NewRelationResource extends AbstractCollectionSpaceResource {
             propsFromPath.put(IRelationsManager.OBJECT, objectCsid);
             getRepositoryClient(ctx).getAll(ctx, handler);
             relationList = (RelationsCommonList) handler.getCommonPartList();
-        }catch(Exception e){
-            if(logger.isDebugEnabled()){
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("Caught exception in getRelationList", e);
             }
             Response response = Response.status(
index 66220a8e71d5f21e8ed807bf9d756a61b577a9ef..f627bb8927e302370a45e94a6add675d4324efc0 100644 (file)
@@ -23,9 +23,6 @@
  */
 package org.collectionspace.services.vocabulary;
 
-import java.util.List;
-import java.util.Map;
-
 import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
@@ -34,7 +31,6 @@ import javax.ws.rs.PUT;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
 import javax.ws.rs.core.MultivaluedMap;
@@ -45,7 +41,8 @@ import javax.ws.rs.core.UriInfo;
 import org.collectionspace.services.common.AbstractCollectionSpaceResource;
 import org.collectionspace.services.common.ClientType;
 import org.collectionspace.services.common.ServiceMain;
-import org.collectionspace.services.common.context.RemoteServiceContext;
+import org.collectionspace.services.common.context.MultipartServiceContext;
+import org.collectionspace.services.common.context.MultipartServiceContextFactory;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.document.DocumentFilter;
 import org.collectionspace.services.common.document.DocumentHandler;
@@ -85,37 +82,36 @@ public class VocabularyResource extends AbstractCollectionSpaceResource {
 
     /*
     public RemoteServiceContext createItemServiceContext(MultipartInput input) throws Exception {
-        RemoteServiceContext ctx = new RemoteServiceContextImpl(getItemServiceName());
-        ctx.setInput(input);
-        return ctx;
+    RemoteServiceContext ctx = new RemoteServiceContextImpl(getItemServiceName());
+    ctx.setInput(input);
+    return ctx;
     }
-    */
-
+     */
     @Override
-    public DocumentHandler createDocumentHandler(RemoteServiceContext ctx) throws Exception {
+    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
         DocumentHandler docHandler = VocabularyHandlerFactory.getInstance().getHandler(
                 ctx.getRepositoryClientType().toString());
         docHandler.setServiceContext(ctx);
-        if(ctx.getInput() != null){
-            Object obj = ctx.getInputPart(ctx.getCommonPartLabel(), VocabulariesCommon.class);
-            if(obj != null){
+        if (ctx.getInput() != null) {
+            Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), VocabulariesCommon.class);
+            if (obj != null) {
                 docHandler.setCommonPart((VocabulariesCommon) obj);
             }
         }
         return docHandler;
     }
-    
+
     private DocumentHandler createItemDocumentHandler(
-               RemoteServiceContext ctx,
-               String inVocabulary) throws Exception {
+            ServiceContext ctx,
+            String inVocabulary) throws Exception {
         DocumentHandler docHandler = VocabularyItemHandlerFactory.getInstance().getHandler(
                 ctx.getRepositoryClientType().toString());
         docHandler.setServiceContext(ctx);
-        ((VocabularyItemDocumentModelHandler)docHandler).setInVocabulary(inVocabulary);
-        if(ctx.getInput() != null){
-            Object obj = ctx.getInputPart(ctx.getCommonPartLabel(getItemServiceName()),
-                                                                                               VocabularyitemsCommon.class);
-            if(obj != null){
+        ((VocabularyItemDocumentModelHandler) docHandler).setInVocabulary(inVocabulary);
+        if (ctx.getInput() != null) {
+            Object obj = ((MultipartServiceContext)ctx).getInputPart(ctx.getCommonPartLabel(getItemServiceName()),
+                    VocabularyitemsCommon.class);
+            if (obj != null) {
                 docHandler.setCommonPart((VocabularyitemsCommon) obj);
             }
         }
@@ -124,8 +120,8 @@ public class VocabularyResource extends AbstractCollectionSpaceResource {
 
     @POST
     public Response createVocabulary(MultipartInput input) {
-        try{
-            RemoteServiceContext ctx = createServiceContext(input);
+        try {
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getServiceName());
             DocumentHandler handler = createDocumentHandler(ctx);
             String csid = getRepositoryClient(ctx).create(ctx, handler);
             //vocabularyObject.setCsid(csid);
@@ -133,8 +129,8 @@ public class VocabularyResource extends AbstractCollectionSpaceResource {
             path.path("" + csid);
             Response response = Response.created(path.build()).build();
             return response;
-        }catch(Exception e){
-            if(logger.isDebugEnabled()){
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("Caught exception in createVocabulary", e);
             }
             Response response = Response.status(
@@ -146,40 +142,40 @@ public class VocabularyResource extends AbstractCollectionSpaceResource {
     @GET
     @Path("{csid}")
     public MultipartOutput getVocabulary(@PathParam("csid") String csid) {
-       String idValue = null;
-       if(csid == null){
+        String idValue = null;
+        if (csid == null) {
             logger.error("getVocabulary: missing csid!");
             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
                     "get failed on Vocabulary csid=" + csid).type(
                     "text/plain").build();
             throw new WebApplicationException(response);
         }
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug("getVocabulary with path(id)=" + csid);
         }
         MultipartOutput result = null;
-        try{
-            RemoteServiceContext ctx = createServiceContext(null);
+        try {
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
             DocumentHandler handler = createDocumentHandler(ctx);
-               getRepositoryClient(ctx).get(ctx, csid, handler);
-            result = ctx.getOutput();
-        }catch(DocumentNotFoundException dnfe){
-            if(logger.isDebugEnabled()){
+            getRepositoryClient(ctx).get(ctx, csid, handler);
+            result = (MultipartOutput) ctx.getOutput();
+        } catch (DocumentNotFoundException dnfe) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("getVocabulary", dnfe);
             }
             Response response = Response.status(Response.Status.NOT_FOUND).entity(
                     "Get failed on Vocabulary csid=" + csid).type(
                     "text/plain").build();
             throw new WebApplicationException(response);
-        }catch(Exception e){
-            if(logger.isDebugEnabled()){
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("getVocabulary", e);
             }
             Response response = Response.status(
                     Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
             throw new WebApplicationException(response);
         }
-        if(result == null){
+        if (result == null) {
             Response response = Response.status(Response.Status.NOT_FOUND).entity(
                     "Get failed, the requested Vocabulary CSID:" + csid + ": was not found.").type(
                     "text/plain").build();
@@ -192,9 +188,9 @@ public class VocabularyResource extends AbstractCollectionSpaceResource {
     @Produces("application/xml")
     public VocabulariesCommonList getVocabularyList(@Context UriInfo ui) {
         VocabulariesCommonList vocabularyObjectList = new VocabulariesCommonList();
-        try{
-            RemoteServiceContext ctx = createServiceContext(null);
-            MultivaluedMap<String,String> queryParams = ui.getQueryParameters(); 
+        try {
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+            MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
             DocumentHandler handler = createDocumentHandler(ctx);
             DocumentFilter myFilter = 
                DocumentFilter.CreatePaginatedDocumentFilter(queryParams);
@@ -205,8 +201,8 @@ public class VocabularyResource extends AbstractCollectionSpaceResource {
             handler.setDocumentFilter(myFilter);
             getRepositoryClient(ctx).getFiltered(ctx, handler);
             vocabularyObjectList = (VocabulariesCommonList) handler.getCommonPartList();
-        }catch(Exception e){
-            if(logger.isDebugEnabled()){
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("Caught exception in getVocabularyList", e);
             }
             Response response = Response.status(
@@ -221,10 +217,10 @@ public class VocabularyResource extends AbstractCollectionSpaceResource {
     public MultipartOutput updateVocabulary(
             @PathParam("csid") String csid,
             MultipartInput theUpdate) {
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug("updateVocabulary with csid=" + csid);
         }
-        if(csid == null || "".equals(csid)){
+        if (csid == null || "".equals(csid)) {
             logger.error("updateVocabulary: missing csid!");
             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
                     "update failed on Vocabulary csid=" + csid).type(
@@ -232,20 +228,20 @@ public class VocabularyResource extends AbstractCollectionSpaceResource {
             throw new WebApplicationException(response);
         }
         MultipartOutput result = null;
-        try{
-            RemoteServiceContext ctx = createServiceContext(theUpdate);
+        try {
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(theUpdate, getServiceName());
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).update(ctx, csid, handler);
-            result = ctx.getOutput();
-        }catch(DocumentNotFoundException dnfe){
-            if(logger.isDebugEnabled()){
+            result = (MultipartOutput) ctx.getOutput();
+        } catch (DocumentNotFoundException dnfe) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("caugth exception in updateVocabulary", dnfe);
             }
             Response response = Response.status(Response.Status.NOT_FOUND).entity(
                     "Update failed on Vocabulary csid=" + csid).type(
                     "text/plain").build();
             throw new WebApplicationException(response);
-        }catch(Exception e){
+        } catch (Exception e) {
             Response response = Response.status(
                     Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build();
             throw new WebApplicationException(response);
@@ -257,29 +253,29 @@ public class VocabularyResource extends AbstractCollectionSpaceResource {
     @Path("{csid}")
     public Response deleteVocabulary(@PathParam("csid") String csid) {
 
-        if(logger.isDebugEnabled()){
+        if (logger.isDebugEnabled()) {
             logger.debug("deleteVocabulary with csid=" + csid);
         }
-        if(csid == null || "".equals(csid)){
+        if (csid == null || "".equals(csid)) {
             logger.error("deleteVocabulary: missing csid!");
             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
                     "delete failed on Vocabulary csid=" + csid).type(
                     "text/plain").build();
             throw new WebApplicationException(response);
         }
-        try{
-            ServiceContext ctx = createServiceContext(null);
+        try {
+ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
             getRepositoryClient(ctx).delete(ctx, csid);
             return Response.status(HttpResponseCodes.SC_OK).build();
-        }catch(DocumentNotFoundException dnfe){
-            if(logger.isDebugEnabled()){
+        } catch (DocumentNotFoundException dnfe) {
+            if (logger.isDebugEnabled()) {
                 logger.debug("caught exception in deleteVocabulary", dnfe);
             }
             Response response = Response.status(Response.Status.NOT_FOUND).entity(
                     "Delete failed on Vocabulary csid=" + csid).type(
                     "text/plain").build();
             throw new WebApplicationException(response);
-        }catch(Exception e){
+        } catch (Exception e) {
             Response response = Response.status(
                     Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build();
             throw new WebApplicationException(response);
@@ -290,197 +286,195 @@ public class VocabularyResource extends AbstractCollectionSpaceResource {
     /*************************************************************************
      * VocabularyItem parts - this is a sub-resource of Vocabulary
      *************************************************************************/
+    @POST
+    @Path("{csid}/items")
+    public Response createVocabularyItem(@PathParam("csid") String parentcsid, MultipartInput input) {
+        try {
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getItemServiceName());
+            DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
+            String itemcsid = getRepositoryClient(ctx).create(ctx, handler);
+            UriBuilder path = UriBuilder.fromResource(VocabularyResource.class);
+            path.path(parentcsid + "/items/" + itemcsid);
+            Response response = Response.created(path.build()).build();
+            return response;
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("Caught exception in createVocabularyItem", e);
+            }
+            Response response = Response.status(
+                    Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build();
+            throw new WebApplicationException(response);
+        }
+    }
 
-     @POST
-     @Path("{csid}/items")
-     public Response createVocabularyItem(@PathParam("csid") String parentcsid, MultipartInput input) {
-         try{
-             RemoteServiceContext ctx = createServiceContext(input, getItemServiceName());
-             DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
-             String itemcsid = getRepositoryClient(ctx).create(ctx, handler);
-             UriBuilder path = UriBuilder.fromResource(VocabularyResource.class);
-             path.path(parentcsid + "/items/" + itemcsid);
-             Response response = Response.created(path.build()).build();
-             return response;
-         }catch(Exception e){
-             if(logger.isDebugEnabled()){
-                 logger.debug("Caught exception in createVocabularyItem", e);
-             }
-             Response response = Response.status(
-                     Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build();
-             throw new WebApplicationException(response);
-         }
-     }
-
-     @GET
-     @Path("{csid}/items/{itemcsid}")
-     public MultipartOutput getVocabularyItem(
-                @PathParam("csid") String parentcsid,
-             @PathParam("itemcsid") String itemcsid) {
-         if(logger.isDebugEnabled()){
-             logger.debug("getVocabularyItem with parentcsid=" 
-                        + parentcsid + " and itemcsid=" + itemcsid);
-         }
-         if(parentcsid == null || "".equals(parentcsid)){
-             logger.error("getVocabularyItem: missing csid!");
-             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
-                     "get failed on VocabularyItem csid=" + parentcsid).type(
-                     "text/plain").build();
-             throw new WebApplicationException(response);
-         }
-         if(itemcsid == null || "".equals(itemcsid)){
-             logger.error("getVocabularyItem: missing itemcsid!");
-             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
-                     "get failed on VocabularyItem itemcsid=" + itemcsid).type(
-                     "text/plain").build();
-             throw new WebApplicationException(response);
-         }
-         MultipartOutput result = null;
-         try{
-                // Note that we have to create the service context for the Items, not the main service 
-             RemoteServiceContext ctx = createServiceContext(null, getItemServiceName());
-             DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
-             getRepositoryClient(ctx).get(ctx, itemcsid, handler);
-             // TODO should we assert that the item is in the passed vocab?
-             result = ctx.getOutput();
-         }catch(DocumentNotFoundException dnfe){
-             if(logger.isDebugEnabled()){
-                 logger.debug("getVocabularyItem", dnfe);
-             }
-             Response response = Response.status(Response.Status.NOT_FOUND).entity(
-                     "Get failed on VocabularyItem csid=" + itemcsid).type(
-                     "text/plain").build();
-             throw new WebApplicationException(response);
-         }catch(Exception e){
-             if(logger.isDebugEnabled()){
-                 logger.debug("getVocabularyItem", e);
-             }
-             Response response = Response.status(
-                     Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
-             throw new WebApplicationException(response);
-         }
-         if(result == null){
-             Response response = Response.status(Response.Status.NOT_FOUND).entity(
-                     "Get failed, the requested VocabularyItem CSID:" + itemcsid + ": was not found.").type(
-                     "text/plain").build();
-             throw new WebApplicationException(response);
-         }
-         return result;
-     }
+    @GET
+    @Path("{csid}/items/{itemcsid}")
+    public MultipartOutput getVocabularyItem(
+            @PathParam("csid") String parentcsid,
+            @PathParam("itemcsid") String itemcsid) {
+        if (logger.isDebugEnabled()) {
+            logger.debug("getVocabularyItem with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid);
+        }
+        if (parentcsid == null || "".equals(parentcsid)) {
+            logger.error("getVocabularyItem: missing csid!");
+            Response response = Response.status(Response.Status.BAD_REQUEST).entity(
+                    "get failed on VocabularyItem csid=" + parentcsid).type(
+                    "text/plain").build();
+            throw new WebApplicationException(response);
+        }
+        if (itemcsid == null || "".equals(itemcsid)) {
+            logger.error("getVocabularyItem: missing itemcsid!");
+            Response response = Response.status(Response.Status.BAD_REQUEST).entity(
+                    "get failed on VocabularyItem itemcsid=" + itemcsid).type(
+                    "text/plain").build();
+            throw new WebApplicationException(response);
+        }
+        MultipartOutput result = null;
+        try {
+            // Note that we have to create the service context for the Items, not the main service
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getItemServiceName());
+            DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
+            getRepositoryClient(ctx).get(ctx, itemcsid, handler);
+            // TODO should we assert that the item is in the passed vocab?
+            result = (MultipartOutput)ctx.getOutput();
+        } catch (DocumentNotFoundException dnfe) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("getVocabularyItem", dnfe);
+            }
+            Response response = Response.status(Response.Status.NOT_FOUND).entity(
+                    "Get failed on VocabularyItem csid=" + itemcsid).type(
+                    "text/plain").build();
+            throw new WebApplicationException(response);
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("getVocabularyItem", e);
+            }
+            Response response = Response.status(
+                    Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build();
+            throw new WebApplicationException(response);
+        }
+        if (result == null) {
+            Response response = Response.status(Response.Status.NOT_FOUND).entity(
+                    "Get failed, the requested VocabularyItem CSID:" + itemcsid + ": was not found.").type(
+                    "text/plain").build();
+            throw new WebApplicationException(response);
+        }
+        return result;
+    }
 
-     @GET
-     @Path("{csid}/items")
-     @Produces("application/xml")
-     public VocabularyitemsCommonList getVocabularyItemList(
-                @PathParam("csid") String parentcsid,
-                @Context UriInfo ui) {
-         VocabularyitemsCommonList vocabularyItemObjectList = new VocabularyitemsCommonList();
-         try{
-                // Note that docType defaults to the ServiceName, so we're fine with that.
-             RemoteServiceContext ctx = createServiceContext(null, getItemServiceName());
-             DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
-             DocumentFilter myFilter = new DocumentFilter(
-                        "vocabularyitems_common:inVocabulary='"+parentcsid+"'", 0, 0);
-             handler.setDocumentFilter(myFilter);
-             getRepositoryClient(ctx).getFiltered(ctx, handler);
-             vocabularyItemObjectList = (VocabularyitemsCommonList) handler.getCommonPartList();
-         }catch(Exception e){
-             if(logger.isDebugEnabled()){
-                 logger.debug("Caught exception in getVocabularyItemList", e);
-             }
-             Response response = Response.status(
-                     Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
-             throw new WebApplicationException(response);
-         }
-         return vocabularyItemObjectList;
-     }
+    @GET
+    @Path("{csid}/items")
+    @Produces("application/xml")
+    public VocabularyitemsCommonList getVocabularyItemList(
+            @PathParam("csid") String parentcsid,
+            @Context UriInfo ui) {
+        VocabularyitemsCommonList vocabularyItemObjectList = new VocabularyitemsCommonList();
+        try {
+            // Note that docType defaults to the ServiceName, so we're fine with that.
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getItemServiceName());
+            DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
+            DocumentFilter myFilter = new DocumentFilter(
+                    "vocabularyitems_common:inVocabulary='" + parentcsid + "'", 0, 0);
+            handler.setDocumentFilter(myFilter);
+            getRepositoryClient(ctx).getFiltered(ctx, handler);
+            vocabularyItemObjectList = (VocabularyitemsCommonList) handler.getCommonPartList();
+        } catch (Exception e) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("Caught exception in getVocabularyItemList", e);
+            }
+            Response response = Response.status(
+                    Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build();
+            throw new WebApplicationException(response);
+        }
+        return vocabularyItemObjectList;
+    }
 
-     @PUT
-     @Path("{csid}/items/{itemcsid}")
-     public MultipartOutput updateVocabularyItem(
-                @PathParam("csid") String parentcsid,
-             @PathParam("itemcsid") String itemcsid,
-             MultipartInput theUpdate) {
-         if(logger.isDebugEnabled()){
-             logger.debug("updateVocabularyItem with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid);
-         }
-         if(parentcsid == null || "".equals(parentcsid)){
-             logger.error("updateVocabularyItem: missing csid!");
-             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
-                     "update failed on VocabularyItem parentcsid=" + parentcsid).type(
-                     "text/plain").build();
-             throw new WebApplicationException(response);
-         }
-         if(itemcsid == null || "".equals(itemcsid)){
-             logger.error("updateVocabularyItem: missing itemcsid!");
-             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
-                     "update failed on VocabularyItem=" + itemcsid).type(
-                     "text/plain").build();
-             throw new WebApplicationException(response);
-         }
-         MultipartOutput result = null;
-         try{
-                // Note that we have to create the service context for the Items, not the main service 
-             RemoteServiceContext ctx = createServiceContext(theUpdate, getItemServiceName());
-             DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
-             getRepositoryClient(ctx).update(ctx, itemcsid, handler);
-             result = ctx.getOutput();
-         }catch(DocumentNotFoundException dnfe){
-             if(logger.isDebugEnabled()){
-                 logger.debug("caugth exception in updateVocabularyItem", dnfe);
-             }
-             Response response = Response.status(Response.Status.NOT_FOUND).entity(
-                     "Update failed on VocabularyItem csid=" + itemcsid).type(
-                     "text/plain").build();
-             throw new WebApplicationException(response);
-         }catch(Exception e){
-             Response response = Response.status(
-                     Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build();
-             throw new WebApplicationException(response);
-         }
-         return result;
-     }
+    @PUT
+    @Path("{csid}/items/{itemcsid}")
+    public MultipartOutput updateVocabularyItem(
+            @PathParam("csid") String parentcsid,
+            @PathParam("itemcsid") String itemcsid,
+            MultipartInput theUpdate) {
+        if (logger.isDebugEnabled()) {
+            logger.debug("updateVocabularyItem with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid);
+        }
+        if (parentcsid == null || "".equals(parentcsid)) {
+            logger.error("updateVocabularyItem: missing csid!");
+            Response response = Response.status(Response.Status.BAD_REQUEST).entity(
+                    "update failed on VocabularyItem parentcsid=" + parentcsid).type(
+                    "text/plain").build();
+            throw new WebApplicationException(response);
+        }
+        if (itemcsid == null || "".equals(itemcsid)) {
+            logger.error("updateVocabularyItem: missing itemcsid!");
+            Response response = Response.status(Response.Status.BAD_REQUEST).entity(
+                    "update failed on VocabularyItem=" + itemcsid).type(
+                    "text/plain").build();
+            throw new WebApplicationException(response);
+        }
+        MultipartOutput result = null;
+        try {
+            // Note that we have to create the service context for the Items, not the main service
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(theUpdate, getItemServiceName());
+            DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
+            getRepositoryClient(ctx).update(ctx, itemcsid, handler);
+            result = (MultipartOutput)ctx.getOutput();
+        } catch (DocumentNotFoundException dnfe) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("caugth exception in updateVocabularyItem", dnfe);
+            }
+            Response response = Response.status(Response.Status.NOT_FOUND).entity(
+                    "Update failed on VocabularyItem csid=" + itemcsid).type(
+                    "text/plain").build();
+            throw new WebApplicationException(response);
+        } catch (Exception e) {
+            Response response = Response.status(
+                    Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build();
+            throw new WebApplicationException(response);
+        }
+        return result;
+    }
 
-     @DELETE
-     @Path("{csid}/items/{itemcsid}")
-     public Response deleteVocabularyItem(
-                @PathParam("csid") String parentcsid,
-         @PathParam("itemcsid") String itemcsid) {
-         if(logger.isDebugEnabled()){
-             logger.debug("deleteVocabularyItem with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid);
-         }
-         if(parentcsid == null || "".equals(parentcsid)){
-             logger.error("deleteVocabularyItem: missing csid!");
-             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
-                     "delete failed on VocabularyItem parentcsid=" + parentcsid).type(
-                     "text/plain").build();
-             throw new WebApplicationException(response);
-         }
-         if(itemcsid == null || "".equals(itemcsid)){
-             logger.error("deleteVocabularyItem: missing itemcsid!");
-             Response response = Response.status(Response.Status.BAD_REQUEST).entity(
-                     "delete failed on VocabularyItem=" + itemcsid).type(
-                     "text/plain").build();
-             throw new WebApplicationException(response);
-         }
-         try{
-                // Note that we have to create the service context for the Items, not the main service 
-             RemoteServiceContext ctx = createServiceContext(null, getItemServiceName());
-             getRepositoryClient(ctx).delete(ctx, itemcsid);
-             return Response.status(HttpResponseCodes.SC_OK).build();
-         }catch(DocumentNotFoundException dnfe){
-             if(logger.isDebugEnabled()){
-                 logger.debug("caught exception in deleteVocabulary", dnfe);
-             }
-             Response response = Response.status(Response.Status.NOT_FOUND).entity(
-                     "Delete failed on VocabularyItem itemcsid=" + itemcsid).type(
-                     "text/plain").build();
-             throw new WebApplicationException(response);
-         }catch(Exception e){
-             Response response = Response.status(
-                     Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build();
-             throw new WebApplicationException(response);
-         }
+    @DELETE
+    @Path("{csid}/items/{itemcsid}")
+    public Response deleteVocabularyItem(
+            @PathParam("csid") String parentcsid,
+            @PathParam("itemcsid") String itemcsid) {
+        if (logger.isDebugEnabled()) {
+            logger.debug("deleteVocabularyItem with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid);
+        }
+        if (parentcsid == null || "".equals(parentcsid)) {
+            logger.error("deleteVocabularyItem: missing csid!");
+            Response response = Response.status(Response.Status.BAD_REQUEST).entity(
+                    "delete failed on VocabularyItem parentcsid=" + parentcsid).type(
+                    "text/plain").build();
+            throw new WebApplicationException(response);
+        }
+        if (itemcsid == null || "".equals(itemcsid)) {
+            logger.error("deleteVocabularyItem: missing itemcsid!");
+            Response response = Response.status(Response.Status.BAD_REQUEST).entity(
+                    "delete failed on VocabularyItem=" + itemcsid).type(
+                    "text/plain").build();
+            throw new WebApplicationException(response);
+        }
+        try {
+            // Note that we have to create the service context for the Items, not the main service
+            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getItemServiceName());
+            getRepositoryClient(ctx).delete(ctx, itemcsid);
+            return Response.status(HttpResponseCodes.SC_OK).build();
+        } catch (DocumentNotFoundException dnfe) {
+            if (logger.isDebugEnabled()) {
+                logger.debug("caught exception in deleteVocabulary", dnfe);
+            }
+            Response response = Response.status(Response.Status.NOT_FOUND).entity(
+                    "Delete failed on VocabularyItem itemcsid=" + itemcsid).type(
+                    "text/plain").build();
+            throw new WebApplicationException(response);
+        } catch (Exception e) {
+            Response response = Response.status(
+                    Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build();
+            throw new WebApplicationException(response);
+        }
 
-     }
+    }
 }