]> git.aero2k.de Git - tmp/jakarta-migration.git/commitdiff
CSPACE-1349, 1422, 1428, 1469, 1470, 1473: Adding pagination support for default...
authorRichard Millet <richard.millet@berkeley.edu>
Fri, 16 Apr 2010 10:10:58 +0000 (10:10 +0000)
committerRichard Millet <richard.millet@berkeley.edu>
Fri, 16 Apr 2010 10:10:58 +0000 (10:10 +0000)
Passes *ALL* current tests and merged with the latest set of sources.

38 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/account/service/src/main/java/org/collectionspace/services/account/storage/AccountJpaFilter.java
services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/AcquisitionResource.java
services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/PermissionResource.java
services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/PermissionRoleSubResource.java
services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/RoleResource.java
services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionDocumentHandler.java
services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionJpaFilter.java
services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionRoleDocumentHandler.java
services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionRoleStorageClient.java
services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/RoleDocumentHandler.java
services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/RoleJpaFilter.java
services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java
services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResourceImpl.java
services/common/src/main/java/org/collectionspace/services/common/CollectionSpaceResource.java
services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java
services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContextFactory.java
services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContextImpl.java
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
services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandlerImpl.java
services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java
services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java
services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaDocumentFilter.java
services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaStorageClientImpl.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java
services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoDocumentFilter.java
services/contact/service/src/main/java/org/collectionspace/services/contact/ContactResource.java
services/dimension/service/src/main/java/org/collectionspace/services/dimension/DimensionResource.java
services/intake/service/src/main/java/org/collectionspace/services/intake/IntakeResource.java
services/loanin/service/src/main/java/org/collectionspace/services/loanin/LoaninResource.java
services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java
services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.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 8c35ff148c7876bacd50fbf2b89bfc4661b02de4..b385280fcc61ff4028de9bbe5091e6560ab36249 100644 (file)
@@ -40,8 +40,9 @@ import javax.ws.rs.core.UriInfo;
 
 import org.collectionspace.services.account.storage.AccountStorageClient;
 import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl;
-import org.collectionspace.services.common.context.RemoteServiceContextImpl;
 import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.common.context.ServiceContextFactory;
+import org.collectionspace.services.common.context.RemoteServiceContextFactory;
 import org.collectionspace.services.common.document.BadRequestException;
 import org.collectionspace.services.common.document.DocumentFilter;
 import org.collectionspace.services.common.document.DocumentNotFoundException;
@@ -52,16 +53,27 @@ import org.jboss.resteasy.util.HttpResponseCodes;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+/**
+ * The Class AccountResource.
+ */
 @Path("/accounts")
 @Consumes("application/xml")
 @Produces("application/xml")
 public class AccountResource
-        extends AbstractCollectionSpaceResourceImpl {
+        extends AbstractCollectionSpaceResourceImpl<AccountsCommon, AccountsCommon> {
 
+    /** The service name. */
     final private String serviceName = "accounts";
+    
+    /** The logger. */
     final Logger logger = LoggerFactory.getLogger(AccountResource.class);
+    
+    /** The storage client. */
     final StorageClient storageClient = new AccountStorageClient();
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getVersionString()
+     */
     @Override
     protected String getVersionString() {
         /** The last change revision. */
@@ -69,36 +81,62 @@ public class AccountResource
         return lastChangeRevision;
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getServiceName()
+     */
     @Override
     public String getServiceName() {
         return serviceName;
     }
+    
+    @Override
+    public Class<AccountsCommon> getCommonPartClass() {
+       return AccountsCommon.class;
+    }    
 
-    private <T> ServiceContext createServiceContext(T obj) throws Exception {
-        ServiceContext ctx = new RemoteServiceContextImpl<T, T>(getServiceName());
-        ctx.setInput(obj);
-        ctx.setDocumentType(AccountsCommon.class.getPackage().getName()); //persistence unit
-        ctx.setProperty("entity-name", AccountsCommon.class.getName());
-        return ctx;
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.CollectionSpaceResource#getServiceContextFactory()
+     */
+    @Override
+    public ServiceContextFactory<AccountsCommon, AccountsCommon> getServiceContextFactory() {
+       return (ServiceContextFactory<AccountsCommon, AccountsCommon>)RemoteServiceContextFactory.get();
     }
+    
+//    private <T> ServiceContext createServiceContext(T obj) throws Exception {
+//        ServiceContext ctx = new RemoteServiceContextImpl<T, T>(getServiceName());
+//        ctx.setInput(obj);
+//        ctx.setDocumentType(AccountsCommon.class.getPackage().getName()); //persistence unit
+//        ctx.setProperty("entity-name", AccountsCommon.class.getName());
+//        return ctx;
+//    }
 
-    @Override
-    public StorageClient getStorageClient(ServiceContext ctx) {
-        //FIXME use ctx to identify storage client
+    /* (non-Javadoc)
+ * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getStorageClient(org.collectionspace.services.common.context.ServiceContext)
+ */
+@Override
+    public StorageClient getStorageClient(ServiceContext<AccountsCommon, AccountsCommon> ctx) {
+       //FIXME use ctx to identify storage client
         return storageClient;
     }
 
-    @Override
-    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
-        DocumentHandler docHandler = ctx.getDocumentHandler();
-        docHandler.setCommonPart(ctx.getInput());
-        return docHandler;
-    }
+//    @Override
+//    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
+//        DocumentHandler docHandler = ctx.getDocumentHandler();
+//        docHandler.setCommonPart(ctx.getInput());
+//        return docHandler;
+//    }
 
-    @POST
+    /**
+ * Creates the account.
+ * 
+ * @param input the input
+ * 
+ * @return the response
+ */
+@POST
     public Response createAccount(AccountsCommon input) {
         try {
-            ServiceContext ctx = createServiceContext(input);
+            ServiceContext<AccountsCommon, AccountsCommon> ctx = createServiceContext(input, AccountsCommon.class);
             DocumentHandler handler = createDocumentHandler(ctx);
             String csid = getStorageClient(ctx).create(ctx, handler);
             UriBuilder path = UriBuilder.fromResource(AccountResource.class);
@@ -123,6 +161,13 @@ public class AccountResource
         }
     }
 
+    /**
+     * Gets the account.
+     * 
+     * @param csid the csid
+     * 
+     * @return the account
+     */
     @GET
     @Path("{csid}")
     public AccountsCommon getAccount(
@@ -139,7 +184,7 @@ public class AccountResource
         }
         AccountsCommon result = null;
         try {
-            ServiceContext ctx = createServiceContext((AccountsCommon) null);
+            ServiceContext<AccountsCommon, AccountsCommon> ctx = createServiceContext((AccountsCommon) null, AccountsCommon.class);
             DocumentHandler handler = createDocumentHandler(ctx);
             getStorageClient(ctx).get(ctx, csid, handler);
             result = (AccountsCommon) ctx.getOutput();
@@ -173,16 +218,23 @@ public class AccountResource
         return result;
     }
 
+    /**
+     * Gets the account list.
+     * 
+     * @param ui the ui
+     * 
+     * @return the account list
+     */
     @GET
     @Produces("application/xml")
     public AccountsCommonList getAccountList(
             @Context UriInfo ui) {
         AccountsCommonList accountList = new AccountsCommonList();
         try {
-            ServiceContext ctx = createServiceContext((AccountsCommonList) null);
+            ServiceContext<AccountsCommon, AccountsCommon> ctx = createServiceContext((AccountsCommon) null, AccountsCommon.class);
             DocumentHandler handler = createDocumentHandler(ctx);
             MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
-            DocumentFilter myFilter = handler.createDocumentFilter(ctx);
+            DocumentFilter myFilter = handler.createDocumentFilter();
             myFilter.setPagination(queryParams);
             myFilter.setQueryParams(queryParams);
             handler.setDocumentFilter(myFilter);
@@ -204,6 +256,14 @@ public class AccountResource
         return accountList;
     }
 
+    /**
+     * Update account.
+     * 
+     * @param csid the csid
+     * @param theUpdate the the update
+     * 
+     * @return the accounts common
+     */
     @PUT
     @Path("{csid}")
     public AccountsCommon updateAccount(
@@ -221,7 +281,7 @@ public class AccountResource
         }
         AccountsCommon result = null;
         try {
-            ServiceContext ctx = createServiceContext(theUpdate);
+            ServiceContext<AccountsCommon, AccountsCommon> ctx = createServiceContext(theUpdate, AccountsCommon.class);
             DocumentHandler handler = createDocumentHandler(ctx);
             getStorageClient(ctx).update(ctx, csid, handler);
             result = (AccountsCommon) ctx.getOutput();
@@ -249,6 +309,13 @@ public class AccountResource
         return result;
     }
 
+    /**
+     * Delete account.
+     * 
+     * @param csid the csid
+     * 
+     * @return the response
+     */
     @DELETE
     @Path("{csid}")
     public Response deleteAccount(@PathParam("csid") String csid) {
@@ -264,7 +331,8 @@ public class AccountResource
             throw new WebApplicationException(response);
         }
         try {
-            ServiceContext ctx = createServiceContext((AccountsCommon) null);
+            ServiceContext<AccountsCommon, AccountsCommon> ctx = createServiceContext((AccountsCommon) null,
+                       AccountsCommon.class);
             getStorageClient(ctx).delete(ctx, csid);
             return Response.status(HttpResponseCodes.SC_OK).build();
         } catch (UnauthorizedException ue) {
index 40907bcd0db99f7dd2a34503ab466d867ecdab34..e5da7aca01aaf85e7040216f51f1ca23c4f115cd 100644 (file)
@@ -145,11 +145,8 @@ public class AccountDocumentHandler
     }
 
     @Override
-    public DocumentFilter createDocumentFilter(ServiceContext ctx) {
-       DocumentFilter  filter = new AccountJpaFilter();
-       filter.setPageSize(
-                       ctx.getServiceBindingPropertyValue(
-                                       DocumentFilter.PAGE_SIZE_DEFAULT_PROPERTY));
+    public DocumentFilter createDocumentFilter() {
+       DocumentFilter  filter = new AccountJpaFilter(this.getServiceContext());
        return filter;
     }
 
@@ -175,4 +172,11 @@ public class AccountDocumentHandler
         account.setPassword(null);
         account.setTenants(new ArrayList<AccountTenant>(0));
     }
+    
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.document.DocumentHandler#initializeDocumentFilter(org.collectionspace.services.common.context.ServiceContext)
+     */
+    public void initializeDocumentFilter(ServiceContext ctx) {
+       // set a default document filter in this method
+    }
 }
index 21d04f781e3dcb5a66d54b928b43acffb87468a0..3e87d65ce4bf20bad53c3012e851092b9f11241a 100644 (file)
@@ -27,6 +27,7 @@ package org.collectionspace.services.account.storage;
 import java.util.ArrayList;
 import java.util.List;
 import org.collectionspace.services.common.storage.jpa.JpaDocumentFilter;
+import org.collectionspace.services.common.context.ServiceContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -38,6 +39,10 @@ public class AccountJpaFilter extends JpaDocumentFilter {
 
     private final Logger logger = LoggerFactory.getLogger(AccountJpaFilter.class);
 
+    public AccountJpaFilter(ServiceContext ctx) {
+       super(ctx);
+    }
+    
     @Override
     public List<ParamBinding> buildWhereForSearch(StringBuilder queryStrBldr) {
 
index e9b5fb34e1284c08a79ed3676ea5927ad2504987..ab6a8c5d7edbef187265dab1d4d2acbfe848b454 100644 (file)
@@ -40,10 +40,8 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
 
-import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl;
+import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl;
 import org.collectionspace.services.common.authorityref.AuthorityRefList;
-import org.collectionspace.services.common.context.MultipartServiceContext;
-import org.collectionspace.services.common.context.MultipartServiceContextFactory;
 import org.collectionspace.services.common.context.MultipartServiceContextImpl;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.document.DocumentFilter;
@@ -69,7 +67,7 @@ import org.slf4j.LoggerFactory;
 @Consumes("multipart/mixed")
 @Produces("multipart/mixed")
 public class AcquisitionResource
-        extends AbstractCollectionSpaceResourceImpl {
+        extends AbstractMultiPartCollectionSpaceResourceImpl {
 
     /** The service name. */
     final private String serviceName = "acquisitions";
@@ -94,21 +92,26 @@ public class AcquisitionResource
     public String getServiceName() {
         return serviceName;
     }
+    
+    @Override
+    public Class<AcquisitionsCommon> getCommonPartClass() {
+       return AcquisitionsCommon.class;
+    }    
 
     /* (non-Javadoc)
      * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#createDocumentHandler(org.collectionspace.services.common.context.ServiceContext)
      */
-    @Override
-    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
-        DocumentHandler docHandler = ctx.getDocumentHandler();
-        if (ctx.getInput() != null) {
-            Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), AcquisitionsCommon.class);
-            if (obj != null) {
-                docHandler.setCommonPart((AcquisitionsCommon) obj);
-            }
-        }
-        return docHandler;
-    }
+//    @Override
+//    public DocumentHandler createDocumentHandler(ServiceContext<MultipartInput, MultipartOutput> ctx) throws Exception {
+//        DocumentHandler docHandler = ctx.getDocumentHandler();
+//        if (ctx.getInput() != null) {
+//            Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), AcquisitionsCommon.class);
+//            if (obj != null) {
+//                docHandler.setCommonPart((AcquisitionsCommon) obj);
+//            }
+//        }
+//        return docHandler;
+//    }
 
     /**
      * Instantiates a new acquisition resource.
@@ -128,7 +131,7 @@ public class AcquisitionResource
     public Response createAcquisition(MultipartInput input) {
 
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getServiceName());
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(input);
             DocumentHandler handler = createDocumentHandler(ctx);
             String csid = getRepositoryClient(ctx).create(ctx, handler);
             UriBuilder path = UriBuilder.fromResource(AcquisitionResource.class);
@@ -172,7 +175,7 @@ public class AcquisitionResource
         }
         MultipartOutput result = null;
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).get(ctx, csid, handler);
             result = (MultipartOutput) ctx.getOutput();
@@ -236,7 +239,7 @@ public class AcquisitionResource
     private AcquisitionsCommonList getAcquisitionsList() {
         AcquisitionsCommonList acquisitionObjectList;
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).getAll(ctx, handler);
             acquisitionObjectList = (AcquisitionsCommonList) handler.getCommonPartList();
@@ -283,7 +286,7 @@ public class AcquisitionResource
         }
         MultipartOutput result = null;
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(theUpdate, getServiceName());
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(theUpdate);
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).update(ctx, csid, handler);
             result = (MultipartOutput) ctx.getOutput();
@@ -329,7 +332,7 @@ public class AcquisitionResource
             throw new WebApplicationException(response);
         }
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             getRepositoryClient(ctx).delete(ctx, csid);
             return Response.status(HttpResponseCodes.SC_OK).build();
         } catch (UnauthorizedException ue) {
@@ -377,13 +380,13 @@ public class AcquisitionResource
     private AcquisitionsCommonList searchAcquisitions(String keywords) {
        AcquisitionsCommonList acquisitionObjectList;           
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             DocumentHandler handler = createDocumentHandler(ctx);
 
             // perform a keyword search
             if (keywords != null && !keywords.isEmpty()) {
                String whereClause = QueryManager.createWhereClauseFromKeywords(keywords);
-                   DocumentFilter documentFilter = handler.createDocumentFilter(ctx);
+                   DocumentFilter documentFilter = handler.getDocumentFilter();
                    documentFilter.setWhereClause(whereClause);
                    if (logger.isDebugEnabled()) {
                        logger.debug("The WHERE clause is: " + documentFilter.getWhereClause());
@@ -425,7 +428,7 @@ public class AcquisitionResource
                @Context UriInfo ui) {
        AuthorityRefList authRefList = null;
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             DocumentWrapper<DocumentModel> docWrapper = 
                getRepositoryClient(ctx).getDoc(ctx, csid);
             RemoteDocumentModelHandlerImpl handler 
index 88ccc3970cae30a25767e55dc954ebf520638c16..1913533376b25dedfb4ec6c46f8a1e560bf8be78 100644 (file)
@@ -39,8 +39,10 @@ import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
 
 import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl;
-import org.collectionspace.services.common.context.RemoteServiceContextImpl;
+//import org.collectionspace.services.common.context.RemoteServiceContextImpl;
 import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.common.context.RemoteServiceContextFactory;
+import org.collectionspace.services.common.context.ServiceContextFactory;
 import org.collectionspace.services.common.document.BadRequestException;
 import org.collectionspace.services.common.document.DocumentFilter;
 import org.collectionspace.services.common.document.DocumentNotFoundException;
@@ -52,16 +54,27 @@ import org.jboss.resteasy.util.HttpResponseCodes;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+/**
+ * The Class PermissionResource.
+ */
 @Path("/authorization/permissions")
 @Consumes("application/xml")
 @Produces("application/xml")
 public class PermissionResource
-        extends AbstractCollectionSpaceResourceImpl {
+        extends AbstractCollectionSpaceResourceImpl<Permission, Permission> {
 
+    /** The service name. */
     final private String serviceName = "authorization/permissions";
+    
+    /** The logger. */
     final Logger logger = LoggerFactory.getLogger(PermissionResource.class);
+    
+    /** The storage client. */
     final StorageClient storageClient = new JpaStorageClientImpl(Permission.class);
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getVersionString()
+     */
     @Override
     protected String getVersionString() {
         /** The last change revision. */
@@ -69,36 +82,57 @@ public class PermissionResource
         return lastChangeRevision;
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getServiceName()
+     */
     @Override
     public String getServiceName() {
         return serviceName;
     }
-
-    private <T> ServiceContext createServiceContext(T obj) throws Exception {
-        ServiceContext ctx = new RemoteServiceContextImpl<T, T>(getServiceName());
-        ctx.setInput(obj);
-        ctx.setDocumentType(Permission.class.getPackage().getName()); //persistence unit
-        ctx.setProperty("entity-name", Permission.class.getName());
-        return ctx;
+    
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.CollectionSpaceResource#getCommonPartClass()
+     */
+    @Override
+    public Class<Permission> getCommonPartClass() {
+       return Permission.class;
     }
-
+    
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.CollectionSpaceResource#getServiceContextFactory()
+     */
+    @Override
+    public ServiceContextFactory<Permission, Permission> getServiceContextFactory() {
+       return RemoteServiceContextFactory.get();
+    }
+                
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getStorageClient(org.collectionspace.services.common.context.ServiceContext)
+     */
     @Override
     public StorageClient getStorageClient(ServiceContext ctx) {
         //FIXME use ctx to identify storage client
         return storageClient;
     }
 
-    @Override
-    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
-        DocumentHandler docHandler = ctx.getDocumentHandler();
-        docHandler.setCommonPart(ctx.getInput());
-        return docHandler;
-    }
+//    @Override
+//    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
+//        DocumentHandler docHandler = ctx.getDocumentHandler();
+//        docHandler.setCommonPart(ctx.getInput());
+//        return docHandler;
+//    }
 
-    @POST
+    /**
+ * Creates the permission.
+ * 
+ * @param input the input
+ * 
+ * @return the response
+ */
+@POST
     public Response createPermission(Permission input) {
         try {
-            ServiceContext ctx = createServiceContext(input);
+            ServiceContext<Permission, Permission> ctx = createServiceContext(input, Permission.class);
             DocumentHandler handler = createDocumentHandler(ctx);
             String csid = getStorageClient(ctx).create(ctx, handler);
             UriBuilder path = UriBuilder.fromResource(PermissionResource.class);
@@ -126,6 +160,13 @@ public class PermissionResource
         }
     }
 
+    /**
+     * Gets the permission.
+     * 
+     * @param csid the csid
+     * 
+     * @return the permission
+     */
     @GET
     @Path("{csid}")
     public Permission getPermission(
@@ -142,7 +183,7 @@ public class PermissionResource
         }
         Permission result = null;
         try {
-            ServiceContext ctx = createServiceContext((Permission) null);
+            ServiceContext<Permission, Permission> ctx = createServiceContext();
             DocumentHandler handler = createDocumentHandler(ctx);
             getStorageClient(ctx).get(ctx, csid, handler);
             result = (Permission) ctx.getOutput();
@@ -178,16 +219,23 @@ public class PermissionResource
         return result;
     }
 
+    /**
+     * Gets the permission list.
+     * 
+     * @param ui the ui
+     * 
+     * @return the permission list
+     */
     @GET
     @Produces("application/xml")
     public PermissionsList getPermissionList(
             @Context UriInfo ui) {
         PermissionsList permissionList = new PermissionsList();
         try {
-            ServiceContext ctx = createServiceContext((PermissionsList) null);
+            ServiceContext<Permission, Permission> ctx = createServiceContext();
             DocumentHandler handler = createDocumentHandler(ctx);
             MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
-            DocumentFilter myFilter = handler.createDocumentFilter(ctx);
+            DocumentFilter myFilter = handler.createDocumentFilter();
             myFilter.setPagination(queryParams);
             myFilter.setQueryParams(queryParams);
             handler.setDocumentFilter(myFilter);
@@ -211,6 +259,14 @@ public class PermissionResource
         return permissionList;
     }
 
+    /**
+     * Update permission.
+     * 
+     * @param csid the csid
+     * @param theUpdate the the update
+     * 
+     * @return the permission
+     */
     @PUT
     @Path("{csid}")
     public Permission updatePermission(
@@ -228,7 +284,7 @@ public class PermissionResource
         }
         Permission result = null;
         try {
-            ServiceContext ctx = createServiceContext(theUpdate);
+            ServiceContext<Permission, Permission> ctx = createServiceContext(theUpdate);
             DocumentHandler handler = createDocumentHandler(ctx);
             getStorageClient(ctx).update(ctx, csid, handler);
             result = (Permission) ctx.getOutput();
@@ -259,6 +315,13 @@ public class PermissionResource
         return result;
     }
 
+    /**
+     * Delete permission.
+     * 
+     * @param csid the csid
+     * 
+     * @return the response
+     */
     @DELETE
     @Path("{csid}")
     public Response deletePermission(@PathParam("csid") String csid) {
@@ -274,7 +337,7 @@ public class PermissionResource
             throw new WebApplicationException(response);
         }
         try {
-            ServiceContext ctx = createServiceContext((Permission) null);
+            ServiceContext<Permission, Permission> ctx = createServiceContext();
             getStorageClient(ctx).delete(ctx, csid);
             return Response.status(HttpResponseCodes.SC_OK).build();
         } catch (UnauthorizedException ue) {
index 2b59ec2934876e33f25e259376ecc4745ac33823..a9c14b96847426d6b614e9f925e924babf7f13a6 100644 (file)
@@ -33,8 +33,10 @@ import javax.ws.rs.core.UriInfo;
 import org.collectionspace.services.authorization.storage.PermissionRoleStorageClient;
 
 import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl;
+import org.collectionspace.services.common.context.RemoteServiceContextFactory;
 import org.collectionspace.services.common.context.RemoteServiceContextImpl;
 import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.common.context.ServiceContextFactory;
 import org.collectionspace.services.common.document.DocumentFilter;
 import org.collectionspace.services.common.document.DocumentHandler;
 import org.collectionspace.services.common.storage.StorageClient;
@@ -47,14 +49,22 @@ import org.slf4j.LoggerFactory;
  * @author
  */
 public class PermissionRoleSubResource
-        extends AbstractCollectionSpaceResourceImpl {
+        extends AbstractCollectionSpaceResourceImpl<PermissionRole, PermissionRole> {
 
     //this service is never exposed as standalone RESTful service...just use unique
     //service name to identify binding
+    /** The service name. */
     final private String serviceName = "authorization/permroles";
+    
+    /** The logger. */
     final Logger logger = LoggerFactory.getLogger(PermissionRoleSubResource.class);
+    
+    /** The storage client. */
     final StorageClient storageClient = new PermissionRoleStorageClient();
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getVersionString()
+     */
     @Override
     protected String getVersionString() {
         /** The last change revision. */
@@ -62,14 +72,45 @@ public class PermissionRoleSubResource
         return lastChangeRevision;
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getServiceName()
+     */
     @Override
     public String getServiceName() {
         return serviceName;
     }
+    
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.CollectionSpaceResource#getCommonPartClass()
+     */
+    @Override
+    public Class<PermissionRole> getCommonPartClass() {
+       return PermissionRole.class;
+    }
+    
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.CollectionSpaceResource#getServiceContextFactory()
+     */
+    @Override
+    public ServiceContextFactory<PermissionRole, PermissionRole> getServiceContextFactory() {
+       return RemoteServiceContextFactory.get();
+    }    
 
-    private <T> ServiceContext createServiceContext(T obj, SubjectType subject) throws Exception {
-        ServiceContext ctx = new RemoteServiceContextImpl<T, T>(getServiceName());
-        ctx.setInput(obj);
+    /**
+     * Creates the service context.
+     * 
+     * @param input the input
+     * @param subject the subject
+     * 
+     * @return the service context< permission role, permission role>
+     * 
+     * @throws Exception the exception
+     */
+    private ServiceContext<PermissionRole, PermissionRole> createServiceContext(PermissionRole input,
+               SubjectType subject) throws Exception {
+       ServiceContext<PermissionRole, PermissionRole> ctx = createServiceContext(input);
+//      ServiceContext ctx = new RemoteServiceContextImpl<T, T>(getServiceName());
+//      ctx.setInput(input);
         ctx.setDocumentType(PermissionRole.class.getPackage().getName()); //persistence unit
         ctx.setProperty("entity-name", PermissionRoleRel.class.getName());
         //subject name is necessary to indicate if role or permission is a subject
@@ -77,18 +118,21 @@ public class PermissionRoleSubResource
         return ctx;
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getStorageClient(org.collectionspace.services.common.context.ServiceContext)
+     */
     @Override
-    public StorageClient getStorageClient(ServiceContext ctx) {
+    public StorageClient getStorageClient(ServiceContext<PermissionRole, PermissionRole> ctx) {
         //FIXME use ctx to identify storage client
         return storageClient;
     }
 
-    @Override
-    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
-        DocumentHandler docHandler = ctx.getDocumentHandler();
-        docHandler.setCommonPart(ctx.getInput());
-        return docHandler;
-    }
+//    @Override
+//    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
+//        DocumentHandler docHandler = ctx.getDocumentHandler();
+//        docHandler.setCommonPart(ctx.getInput());
+//        return docHandler;
+//    }
 
     /**
      * createPermissionRole creates one or more permission-role relationships
@@ -101,7 +145,7 @@ public class PermissionRoleSubResource
     public String createPermissionRole(PermissionRole input, SubjectType subject)
             throws Exception {
 
-        ServiceContext ctx = createServiceContext(input, subject);
+        ServiceContext<PermissionRole, PermissionRole> ctx = createServiceContext(input, subject);
         DocumentHandler handler = createDocumentHandler(ctx);
         return getStorageClient(ctx).create(ctx, handler);
     }
@@ -121,7 +165,7 @@ public class PermissionRoleSubResource
             logger.debug("getPermissionRole with csid=" + csid);
         }
         PermissionRole result = null;
-        ServiceContext ctx = createServiceContext((PermissionRole) null, subject);
+        ServiceContext<PermissionRole, PermissionRole> ctx = createServiceContext((PermissionRole) null, subject);
         DocumentHandler handler = createDocumentHandler(ctx);
         getStorageClient(ctx).get(ctx, csid, handler);
         result = (PermissionRole) ctx.getOutput();
@@ -143,7 +187,7 @@ public class PermissionRoleSubResource
         if (logger.isDebugEnabled()) {
             logger.debug("deletePermissionRole with csid=" + csid);
         }
-        ServiceContext ctx = createServiceContext((PermissionRole) null, subject);
+        ServiceContext<PermissionRole, PermissionRole> ctx = createServiceContext((PermissionRole) null, subject);
         getStorageClient(ctx).delete(ctx, csid);
     }
 }
index d36d497f5581487951a5440e4db4457583b5f04d..73f02d7d73e3247f75783ffeae07b399bfbe261c 100644 (file)
@@ -39,8 +39,10 @@ import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
 
 import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl;
-import org.collectionspace.services.common.context.RemoteServiceContextImpl;
+//import org.collectionspace.services.common.context.RemoteServiceContextImpl;
 import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.common.context.ServiceContextFactory;
+import org.collectionspace.services.common.context.RemoteServiceContextFactory;
 import org.collectionspace.services.common.document.BadRequestException;
 import org.collectionspace.services.common.document.DocumentFilter;
 import org.collectionspace.services.common.document.DocumentNotFoundException;
@@ -53,16 +55,27 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 
+/**
+ * The Class RoleResource.
+ */
 @Path("/authorization/roles")
 @Consumes("application/xml")
 @Produces("application/xml")
 public class RoleResource
         extends AbstractCollectionSpaceResourceImpl {
 
+    /** The service name. */
     final private String serviceName = "authorization/roles";
+    
+    /** The logger. */
     final Logger logger = LoggerFactory.getLogger(RoleResource.class);
+    
+    /** The storage client. */
     final StorageClient storageClient = new JpaStorageClientImpl();
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getVersionString()
+     */
     @Override
     protected String getVersionString() {
         /** The last change revision. */
@@ -70,36 +83,66 @@ public class RoleResource
         return lastChangeRevision;
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getServiceName()
+     */
     @Override
     public String getServiceName() {
         return serviceName;
     }
-
-    private <T> ServiceContext createServiceContext(T obj) throws Exception {
-        ServiceContext ctx = new RemoteServiceContextImpl<T, T>(getServiceName());
-        ctx.setInput(obj);
-        ctx.setDocumentType(Role.class.getPackage().getName()); //persistence unit
-        ctx.setProperty("entity-name", Role.class.getName());
-        return ctx;
+    
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.CollectionSpaceResource#getCommonPartClass()
+     */
+    @Override
+    public Class<RoleResource> getCommonPartClass() {
+       return RoleResource.class;
     }
-
+    
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.CollectionSpaceResource#getServiceContextFactory()
+     */
     @Override
+    public ServiceContextFactory getServiceContextFactory() {
+       return RemoteServiceContextFactory.get();
+    }
+    
+
+//    private <T> ServiceContext createServiceContext(T obj) throws Exception {
+//        ServiceContext ctx = new RemoteServiceContextImpl<T, T>(getServiceName());
+//        ctx.setInput(obj);
+//        ctx.setDocumentType(Role.class.getPackage().getName()); //persistence unit
+//        ctx.setProperty("entity-name", Role.class.getName());
+//        return ctx;
+//    }
+
+    /* (non-Javadoc)
+ * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getStorageClient(org.collectionspace.services.common.context.ServiceContext)
+ */
+@Override
     public StorageClient getStorageClient(ServiceContext ctx) {
         //FIXME use ctx to identify storage client
         return storageClient;
     }
 
-    @Override
-    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
-        DocumentHandler docHandler = ctx.getDocumentHandler();
-        docHandler.setCommonPart(ctx.getInput());
-        return docHandler;
-    }
+//    @Override
+//    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
+//        DocumentHandler docHandler = ctx.getDocumentHandler();
+//        docHandler.setCommonPart(ctx.getInput());
+//        return docHandler;
+//    }
 
-    @POST
+    /**
+ * Creates the role.
+ * 
+ * @param input the input
+ * 
+ * @return the response
+ */
+@POST
     public Response createRole(Role input) {
         try {
-            ServiceContext ctx = createServiceContext(input);
+            ServiceContext ctx = createServiceContext(input, Role.class);
             DocumentHandler handler = createDocumentHandler(ctx);
             String csid = getStorageClient(ctx).create(ctx, handler);
             UriBuilder path = UriBuilder.fromResource(RoleResource.class);
@@ -124,6 +167,13 @@ public class RoleResource
         }
     }
 
+    /**
+     * Gets the role.
+     * 
+     * @param csid the csid
+     * 
+     * @return the role
+     */
     @GET
     @Path("{csid}")
     public Role getRole(
@@ -140,7 +190,7 @@ public class RoleResource
         }
         Role result = null;
         try {
-            ServiceContext ctx = createServiceContext((Role) null);
+            ServiceContext ctx = createServiceContext((Role) null, Role.class);
             DocumentHandler handler = createDocumentHandler(ctx);
             getStorageClient(ctx).get(ctx, csid, handler);
             result = (Role) ctx.getOutput();
@@ -174,16 +224,23 @@ public class RoleResource
         return result;
     }
 
+    /**
+     * Gets the role list.
+     * 
+     * @param ui the ui
+     * 
+     * @return the role list
+     */
     @GET
     @Produces("application/xml")
     public RolesList getRoleList(
             @Context UriInfo ui) {
         RolesList roleList = new RolesList();
         try {
-            ServiceContext ctx = createServiceContext((RolesList) null);
+            ServiceContext ctx = createServiceContext((RolesList) null, Role.class);
             DocumentHandler handler = createDocumentHandler(ctx);
             MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
-            DocumentFilter myFilter = handler.createDocumentFilter(ctx);
+            DocumentFilter myFilter = handler.createDocumentFilter();
             myFilter.setPagination(queryParams);
             myFilter.setQueryParams(queryParams);
             handler.setDocumentFilter(myFilter);
@@ -205,6 +262,14 @@ public class RoleResource
         return roleList;
     }
 
+    /**
+     * Update role.
+     * 
+     * @param csid the csid
+     * @param theUpdate the the update
+     * 
+     * @return the role
+     */
     @PUT
     @Path("{csid}")
     public Role updateRole(
@@ -222,7 +287,7 @@ public class RoleResource
         }
         Role result = null;
         try {
-            ServiceContext ctx = createServiceContext(theUpdate);
+            ServiceContext ctx = createServiceContext(theUpdate, Role.class);
             DocumentHandler handler = createDocumentHandler(ctx);
             getStorageClient(ctx).update(ctx, csid, handler);
             result = (Role) ctx.getOutput();
@@ -250,6 +315,13 @@ public class RoleResource
         return result;
     }
 
+    /**
+     * Delete role.
+     * 
+     * @param csid the csid
+     * 
+     * @return the response
+     */
     @DELETE
     @Path("{csid}")
     public Response deleteRole(@PathParam("csid") String csid) {
@@ -265,7 +337,7 @@ public class RoleResource
             throw new WebApplicationException(response);
         }
         try {
-            ServiceContext ctx = createServiceContext((Role) null);
+            ServiceContext ctx = createServiceContext((Role) null, Role.class);
             ((JpaStorageClientImpl)getStorageClient(ctx)).deleteWhere(ctx, csid);
             return Response.status(HttpResponseCodes.SC_OK).build();
         } catch (UnauthorizedException ue) {
index cc613fcf80f7dee3f85b6450954b126d58d72617..e525f45bc3bf18331b673a45d7016cbeb71ee595 100644 (file)
@@ -143,11 +143,8 @@ public class PermissionDocumentHandler
     }
 
     @Override
-    public DocumentFilter createDocumentFilter(ServiceContext ctx) {
-        DocumentFilter filter = new PermissionJpaFilter();
-        filter.setPageSize(
-                ctx.getServiceBindingPropertyValue(
-                DocumentFilter.PAGE_SIZE_DEFAULT_PROPERTY));
+    public DocumentFilter createDocumentFilter() {
+        DocumentFilter filter = new PermissionJpaFilter(this.getServiceContext());
         return filter;
     }
 
index e5cae5bcd54ab55b2311bca800282d4a1c10bf99..807d5f4c156cada0742238818d648f82d3f0b72e 100644 (file)
@@ -27,6 +27,7 @@ package org.collectionspace.services.authorization.storage;
 
 import java.util.ArrayList;
 import java.util.List;
+import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.storage.jpa.JpaDocumentFilter;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -39,6 +40,15 @@ public class PermissionJpaFilter extends JpaDocumentFilter {
 
     private final Logger logger = LoggerFactory.getLogger(PermissionJpaFilter.class);
 
+    /**
+     * Instantiates a new permission jpa filter.
+     * 
+     * @param ctx the ctx
+     */
+    public PermissionJpaFilter(ServiceContext ctx) {
+       super(ctx);
+    }
+    
     @Override
     public List<ParamBinding> buildWhereForSearch(StringBuilder queryStrBldr) {
 
index 8bd86ea50c1c2e4dbebac74284c4ed3744fed490..6151ea07aec676ba4c566dd409614012bf89a13d 100644 (file)
@@ -174,7 +174,7 @@ public class PermissionRoleDocumentHandler
     }
 
     @Override
-    public DocumentFilter createDocumentFilter(ServiceContext ctx) {
-        return new DocumentFilter();
+    public DocumentFilter createDocumentFilter() {
+        return new DocumentFilter(this.getServiceContext());
     }
 }
index 20c1b820f13a2b6253b88255368e97eda4b04e87..8afa3be31bdf0777251e18deaed793d80c493b9a 100644 (file)
@@ -145,7 +145,7 @@ public class PermissionRoleStorageClient extends JpaStorageClientImpl {
         }
         DocumentFilter docFilter = handler.getDocumentFilter();
         if (docFilter == null) {
-            docFilter = handler.createDocumentFilter(ctx);
+            docFilter = handler.createDocumentFilter();
         }
         EntityManagerFactory emf = null;
         EntityManager em = null;
index c01c204e55ab63c1810ad8767f01a753baffe8f4..ce4df4031f3f93163dfca5440231a36ca17e74fe 100644 (file)
@@ -143,11 +143,8 @@ public class RoleDocumentHandler
     }
 
     @Override
-    public DocumentFilter createDocumentFilter(ServiceContext ctx) {
-        DocumentFilter filter = new RoleJpaFilter();
-        filter.setPageSize(
-                ctx.getServiceBindingPropertyValue(
-                DocumentFilter.PAGE_SIZE_DEFAULT_PROPERTY));
+    public DocumentFilter createDocumentFilter() {
+        DocumentFilter filter = new RoleJpaFilter(this.getServiceContext());
         return filter;
     }
 
index 7cb44c05d338b18609b2e9ef0abbcda13c1710e6..cc30c603ce3f5f23f10e886c564ba39c8d7569b9 100644 (file)
@@ -26,6 +26,7 @@ package org.collectionspace.services.authorization.storage;
 import java.util.ArrayList;
 import java.util.List;
 import org.collectionspace.services.common.storage.jpa.JpaDocumentFilter;
+import org.collectionspace.services.common.context.ServiceContext;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -37,6 +38,10 @@ public class RoleJpaFilter extends JpaDocumentFilter {
 
     private final Logger logger = LoggerFactory.getLogger(RoleJpaFilter.class);
 
+    public RoleJpaFilter(ServiceContext ctx) {
+       super(ctx);
+    }
+    
     @Override
     public List<ParamBinding> buildWhereForSearch(StringBuilder queryStrBldr) {
 
index 069db4b2ced5cc948234dd8c1d04c7cb3d7c6832..643a29481af37f853c8c18e5b5f33bda8ffd1fb8 100644 (file)
@@ -43,9 +43,10 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
 
-import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl;
+import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl;
 import org.collectionspace.services.common.authorityref.AuthorityRefList;
-import org.collectionspace.services.common.context.MultipartServiceContext;
+import org.collectionspace.services.common.context.ServiceContextFactory;
+//import org.collectionspace.services.common.context.MultipartServiceContext;
 import org.collectionspace.services.common.context.MultipartServiceContextFactory;
 import org.collectionspace.services.common.context.MultipartServiceContextImpl;
 import org.collectionspace.services.common.context.ServiceContext;
@@ -79,7 +80,7 @@ import org.slf4j.LoggerFactory;
 @Consumes("multipart/mixed")
 @Produces("multipart/mixed")
 public class CollectionObjectResource
-        extends AbstractCollectionSpaceResourceImpl {
+        extends AbstractMultiPartCollectionSpaceResourceImpl {
 
     /** The Constant serviceName. */
     static final public String serviceName = "collectionobjects";
@@ -104,22 +105,30 @@ public class CollectionObjectResource
     public String getServiceName() {
         return serviceName;
     }
-
+    
     /* (non-Javadoc)
-     * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#createDocumentHandler(org.collectionspace.services.common.context.ServiceContext)
+     * @see org.collectionspace.services.common.CollectionSpaceResource#getCommonPartClass()
      */
     @Override
-    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
-        DocumentHandler docHandler = ctx.getDocumentHandler();
-        if (ctx.getInput() != null) {
-            Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(),
-                    CollectionobjectsCommon.class);
-            if (obj != null) {
-                docHandler.setCommonPart((CollectionobjectsCommon) obj);
-            }
-        }
-        return docHandler;
+    public Class<CollectionobjectsCommon> getCommonPartClass() {
+       return CollectionobjectsCommon.class;
     }
+    
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#createDocumentHandler(org.collectionspace.services.common.context.ServiceContext)
+     */
+//    @Override
+//    public DocumentHandler createDocumentHandler(ServiceContext<MultipartInput, MultipartOutput> ctx) throws Exception {
+//        DocumentHandler docHandler = ctx.getDocumentHandler();
+//        if (ctx.getInput() != null) {
+//            Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(),
+//                    CollectionobjectsCommon.class);
+//            if (obj != null) {
+//                docHandler.setCommonPart((CollectionobjectsCommon) obj);
+//            }
+//        }
+//        return docHandler;
+//    }
 
     /**
      * Creates the collection object.
@@ -131,7 +140,7 @@ public class CollectionObjectResource
     @POST
     public Response createCollectionObject(MultipartInput input) {
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getServiceName());
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(input); //
             DocumentHandler handler = createDocumentHandler(ctx);
             String csid = getRepositoryClient(ctx).create(ctx, handler);
             UriBuilder path = UriBuilder.fromResource(CollectionObjectResource.class);
@@ -179,7 +188,7 @@ public class CollectionObjectResource
         }
         MultipartOutput result = null;
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).get(ctx, csid, handler);
             result = (MultipartOutput) ctx.getOutput();
@@ -213,6 +222,14 @@ public class CollectionObjectResource
         return result;
     }
     
+    /**
+     * Gets the collection object list.
+     * 
+     * @param ui the ui
+     * @param keywords the keywords
+     * 
+     * @return the collection object list
+     */
     @GET
     @Produces("application/xml")
     public CollectionobjectsCommonList getCollectionObjectList(@Context UriInfo ui,
@@ -233,7 +250,7 @@ public class CollectionObjectResource
     private CollectionobjectsCommonList getCollectionObjectList() {
         CollectionobjectsCommonList collectionObjectList;
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).getAll(ctx, handler);
             collectionObjectList = (CollectionobjectsCommonList) handler.getCommonPartList();
@@ -277,7 +294,7 @@ public class CollectionObjectResource
         }
         MultipartOutput result = null;
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(theUpdate, getServiceName());
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(theUpdate);
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).update(ctx, csid, handler);
             result = (MultipartOutput) ctx.getOutput();
@@ -327,7 +344,7 @@ public class CollectionObjectResource
             throw new WebApplicationException(response);
         }
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             getRepositoryClient(ctx).delete(ctx, csid);
             return Response.status(HttpResponseCodes.SC_OK).build();
         } catch (UnauthorizedException ue) {
@@ -401,6 +418,14 @@ public class CollectionObjectResource
         return result;
     }
 
+    /**
+     * Gets the authority refs.
+     * 
+     * @param csid the csid
+     * @param ui the ui
+     * 
+     * @return the authority refs
+     */
     @GET
     @Path("{csid}/authorityrefs")
     @Produces("application/xml")
@@ -409,7 +434,7 @@ public class CollectionObjectResource
                @Context UriInfo ui) {
        AuthorityRefList authRefList = null;
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             DocumentWrapper<DocumentModel> docWrapper = 
                getRepositoryClient(ctx).getDoc(ctx, csid);
             RemoteDocumentModelHandlerImpl handler 
@@ -472,16 +497,24 @@ public class CollectionObjectResource
        return searchCollectionObjects(keywords);
     }    
     
+    /**
+     * Search collection objects.
+     * 
+     * @param keywords the keywords
+     * 
+     * @return the collectionobjects common list
+     */
     private CollectionobjectsCommonList searchCollectionObjects(String keywords) {
         CollectionobjectsCommonList collectionObjectList;
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             DocumentHandler handler = createDocumentHandler(ctx);
 
             // perform a keyword search
             if (keywords != null && !keywords.isEmpty()) {
                 String whereClause = QueryManager.createWhereClauseFromKeywords(keywords);
-                DocumentFilter documentFilter = handler.createDocumentFilter(ctx);
+                //DocumentFilter documentFilter = handler.createDocumentFilter(ctx);
+                DocumentFilter documentFilter = handler.getDocumentFilter();
                 documentFilter.setWhereClause(whereClause);
                 if (logger.isDebugEnabled()) {
                     logger.debug("The WHERE clause is: " + documentFilter.getWhereClause());
index 21ba6ed4df6ab661a654d518ce64bd7bf4422b01..9ad8bcce7b8ba000de59f8a021e1481499e3875b 100644 (file)
@@ -26,8 +26,11 @@ package org.collectionspace.services.common;
 import javax.ws.rs.GET;\r
 import javax.ws.rs.Path;\r
 import javax.ws.rs.Produces;\r
+import javax.ws.rs.core.MultivaluedMap;\r
 \r
+import org.collectionspace.services.common.context.RemoteServiceContext;\r
 import org.collectionspace.services.common.context.ServiceContext;\r
+import org.collectionspace.services.common.context.ServiceContextFactory;\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
@@ -37,8 +40,8 @@ import org.collectionspace.services.common.storage.jpa.JpaStorageClientImpl;
 /**\r
  * The Class AbstractCollectionSpaceResource.\r
  */\r
-public abstract class AbstractCollectionSpaceResourceImpl\r
-        implements CollectionSpaceResource {\r
+public abstract class AbstractCollectionSpaceResourceImpl<IT, OT>\r
+        implements CollectionSpaceResource<IT, OT> {\r
 \r
     // Fields for default client factory and client\r
     /** The repository client factory. */\r
@@ -68,7 +71,7 @@ public abstract class AbstractCollectionSpaceResourceImpl
      * @see org.collectionspace.services.common.CollectionSpaceResource#getRepositoryClient(org.collectionspace.services.common.context.ServiceContext)\r
      */\r
     @Override\r
-    synchronized public RepositoryClient getRepositoryClient(ServiceContext ctx) {\r
+    synchronized public RepositoryClient getRepositoryClient(ServiceContext<IT, OT> ctx) {\r
         if(repositoryClient != null){\r
             return repositoryClient;\r
         }\r
@@ -80,20 +83,208 @@ public abstract class AbstractCollectionSpaceResourceImpl
      * @see org.collectionspace.services.common.CollectionSpaceResource#getStorageClient(org.collectionspace.services.common.context.ServiceContext)\r
      */\r
     @Override\r
-    synchronized public StorageClient getStorageClient(ServiceContext ctx) {\r
+    synchronized public StorageClient getStorageClient(ServiceContext<IT, OT> ctx) {\r
         if(storageClient != null) {\r
             return storageClient;\r
         }\r
         storageClient = new JpaStorageClientImpl();\r
         return storageClient;\r
     }\r
-\r
+    \r
     /* (non-Javadoc)\r
      * @see org.collectionspace.services.common.CollectionSpaceResource#createDocumentHandler(org.collectionspace.services.common.context.ServiceContext)\r
      */\r
     @Override\r
-    abstract public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception ;\r
+    public DocumentHandler createDocumentHandler(ServiceContext<IT, OT> ctx) throws Exception {\r
+        DocumentHandler docHandler = createDocumentHandler(ctx, ctx.getInput());\r
+        return docHandler;\r
+    }\r
+    \r
+    /**\r
+     * Creates the document handler.\r
+     * \r
+     * @param ctx the ctx\r
+     * @param commonPart the common part\r
+     * \r
+     * @return the document handler\r
+     * \r
+     * @throws Exception the exception\r
+     */\r
+    public DocumentHandler createDocumentHandler(ServiceContext<IT, OT> ctx,\r
+               Object commonPart) throws Exception {\r
+        DocumentHandler docHandler = ctx.getDocumentHandler();\r
+        docHandler.setCommonPart(commonPart);\r
+        return docHandler;\r
+    }    \r
+    \r
+    /**\r
+     * Creates the service context.\r
+     * \r
+     * @return the service context< i t, o t>\r
+     * \r
+     * @throws Exception the exception\r
+     */\r
+    protected ServiceContext<IT, OT> createServiceContext() throws Exception {         \r
+        ServiceContext<IT, OT> ctx = createServiceContext(this.getServiceName(),\r
+                       (IT)null, //inputType\r
+                       (MultivaluedMap<String, String>)null, /*queryParams*/\r
+                       this.getCommonPartClass());\r
+        return ctx;\r
+    }    \r
+    \r
+    /**\r
+     * Creates the service context.\r
+     * \r
+     * @param serviceName the service name\r
+     * \r
+     * @return the service context< i t, o t>\r
+     * \r
+     * @throws Exception the exception\r
+     */\r
+    protected ServiceContext<IT, OT> createServiceContext(String serviceName) throws Exception {       \r
+        ServiceContext<IT, OT> ctx = createServiceContext(\r
+                       serviceName,\r
+                       (IT)null, /*input*/\r
+                       (MultivaluedMap<String, String>)null, /*queryParams*/\r
+                       (Class<?>)null  /*input type's Class*/);\r
+        return ctx;\r
+    }\r
     \r
+    /**\r
+     * Creates the service context.\r
+     * \r
+     * @param serviceName the service name\r
+     * @param input the input\r
+     * \r
+     * @return the service context< i t, o t>\r
+     * \r
+     * @throws Exception the exception\r
+     */\r
+    protected ServiceContext<IT, OT> createServiceContext(String serviceName,\r
+               IT input) throws Exception {            \r
+        ServiceContext<IT, OT> ctx = createServiceContext(serviceName, input,\r
+                       (MultivaluedMap<String, String>)null, /*queryParams*/\r
+                       (Class<?>)null  /*input type's Class*/);\r
+        return ctx;\r
+    }\r
+    \r
+    /**\r
+     * Creates the service context.\r
+     * \r
+     * @param serviceName the service name\r
+     * @param input the input\r
+     * \r
+     * @return the service context< i t, o t>\r
+     * \r
+     * @throws Exception the exception\r
+     */\r
+    protected ServiceContext<IT, OT> createServiceContext(String serviceName,\r
+               MultivaluedMap<String, String> queryParams) throws Exception {          \r
+        ServiceContext<IT, OT> ctx = createServiceContext(serviceName,\r
+                       (IT)null,\r
+                       queryParams,\r
+                       (Class<?>)null  /*input type's Class*/);\r
+        return ctx;\r
+    }    \r
+\r
+    /**\r
+     * Creates the service context.\r
+     * \r
+     * @param queryParams the query params\r
+     * \r
+     * @return the service context< i t, o t>\r
+     * \r
+     * @throws Exception the exception\r
+     */\r
+    protected ServiceContext<IT, OT> createServiceContext(MultivaluedMap<String, String> queryParams) throws Exception {       \r
+        ServiceContext<IT, OT> ctx = createServiceContext(\r
+                       (IT)null, /*input*/\r
+                       queryParams,\r
+                       (Class<?>)null  /*input type's Class*/);\r
+        return ctx;\r
+    }    \r
+        \r
+    /**\r
+     * Creates the service context.\r
+     * \r
+     * @param input the input\r
+     * \r
+     * @return the service context< i t, o t>\r
+     * \r
+     * @throws Exception the exception\r
+     */\r
+    protected ServiceContext<IT, OT> createServiceContext(IT input) throws Exception {         \r
+        ServiceContext<IT, OT> ctx = createServiceContext(\r
+                       input,\r
+                       (Class<?>)null /*input type's Class*/);\r
+        return ctx;\r
+    }\r
+    \r
+    /**\r
+     * Creates the service context.\r
+     * \r
+     * @param input the input\r
+     * @param theClass the the class\r
+     * \r
+     * @return the service context\r
+     * \r
+     * @throws Exception the exception\r
+     */\r
+    protected ServiceContext<IT, OT> createServiceContext(IT input, Class<?> theClass) throws Exception {      \r
+        ServiceContext<IT, OT> ctx = createServiceContext(\r
+                       input,\r
+                       (MultivaluedMap<String, String>)null, //queryParams,\r
+                       theClass);\r
+        return ctx;\r
+    }\r
+    \r
+    /**\r
+     * Creates the service context.\r
+     * \r
+     * @param input the input\r
+     * @param queryParams the query params\r
+     * @param theClass the the class\r
+     * \r
+     * @return the service context< i t, o t>\r
+     * \r
+     * @throws Exception the exception\r
+     */\r
+    protected ServiceContext<IT, OT> createServiceContext(\r
+               IT input,\r
+               MultivaluedMap<String, String> queryParams,\r
+               Class<?> theClass) throws Exception {\r
+       return createServiceContext(this.getServiceName(),\r
+                       input,\r
+                       queryParams,\r
+                       theClass);\r
+    }\r
+\r
+    /**\r
+     * Creates the service context.\r
+     * \r
+     * @param serviceName the service name\r
+     * @param input the input\r
+     * @param queryParams the query params\r
+     * @param theClass the the class\r
+     * \r
+     * @return the service context< i t, o t>\r
+     * \r
+     * @throws Exception the exception\r
+     */\r
+    private ServiceContext<IT, OT> createServiceContext(\r
+               String serviceName,\r
+               IT input,\r
+               MultivaluedMap<String, String> queryParams,\r
+               Class<?> theClass) throws Exception {\r
+        ServiceContext<IT, OT> ctx = getServiceContextFactory().createServiceContext(\r
+                       serviceName,\r
+                       input,\r
+                       queryParams,\r
+                       theClass != null ? theClass.getPackage().getName() : null,\r
+                       theClass != null ? theClass.getName() : null);\r
+        return ctx;\r
+    }\r
+        \r
     /**\r
      * Gets the version string.\r
      * \r
@@ -116,5 +307,4 @@ public abstract class AbstractCollectionSpaceResourceImpl
        \r
        return result;\r
     }\r
-    \r
 }\r
index 1e6dd4a9cc3bde637fbacf590a04c9137a3768c4..5fac316cb0874ec221e92258dd59cba51898b699 100644 (file)
@@ -24,6 +24,7 @@
 package org.collectionspace.services.common;
 
 import org.collectionspace.services.common.context.ServiceContext;
+import org.collectionspace.services.common.context.ServiceContextFactory;
 import org.collectionspace.services.common.document.DocumentHandler;
 import org.collectionspace.services.common.repository.RepositoryClient;
 import org.collectionspace.services.common.storage.StorageClient;
@@ -32,25 +33,31 @@ import org.collectionspace.services.common.storage.StorageClient;
  * CollectionSpaceResource is a resource interface implemented by every
  * entity/service in CollectionSpace
  */
-public interface CollectionSpaceResource {
+public interface CollectionSpaceResource<IT, OT> {
 
     /**
      * getServiceName returns the name of the service
      */
     public String getServiceName();
-
+    
+    /**
+     * Gets the common class.
+     * 
+     * @return the common class
+     */
+    public Class getCommonPartClass();
 
     /**
      * getRepositoryClient
      * @param ctx service context
      */
-    public RepositoryClient getRepositoryClient(ServiceContext ctx);
+    public RepositoryClient getRepositoryClient(ServiceContext<IT, OT> ctx);
 
     /**
      * getStorageClient
      * @param ctx service context
      */
-    public StorageClient getStorageClient(ServiceContext ctx);
+    public StorageClient getStorageClient(ServiceContext<IT, OT> ctx);
     
     /**
      * createDocumentHandler creates a document handler and populates it with given
@@ -60,5 +67,9 @@ public interface CollectionSpaceResource {
      * @param ctx
      * @return
      */
-    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception;
+    public DocumentHandler createDocumentHandler(ServiceContext<IT, OT> ctx) throws Exception;
+    
+    
+    public ServiceContextFactory<IT, OT> getServiceContextFactory();
+
 }
index 2715a1b1fa86e3263db410efaf73f38d0d06f86d..b30bf5a0db88b72f511c9a2547cd5996f963f925 100644 (file)
@@ -33,6 +33,8 @@ import java.util.Set;
 import javax.security.auth.Subject;
 import javax.security.jacc.PolicyContext;
 import javax.security.jacc.PolicyContextException;
+import javax.ws.rs.core.MultivaluedMap;
+
 import org.collectionspace.authentication.AuthN;
 import org.collectionspace.authentication.CSpaceTenant;
 
@@ -41,6 +43,7 @@ import org.collectionspace.services.common.ServiceMain;
 import org.collectionspace.services.common.config.PropertyItemUtils;
 import org.collectionspace.services.common.config.TenantBindingConfigReaderImpl;
 import org.collectionspace.services.common.document.DocumentHandler;
+import org.collectionspace.services.common.document.DocumentFilter;
 import org.collectionspace.services.common.document.ValidatorHandler;
 import org.collectionspace.services.common.security.UnauthorizedException;
 import org.collectionspace.services.common.service.ObjectPartType;
@@ -61,16 +64,43 @@ import org.slf4j.LoggerFactory;
 public abstract class AbstractServiceContextImpl<IT, OT>
         implements ServiceContext<IT, OT> {
 
+    /** The logger. */
     final Logger logger = LoggerFactory.getLogger(AbstractServiceContextImpl.class);
+    
+    /** The properties. */
     Map<String, Object> properties = new HashMap<String, Object>();
+    
+    /** The object part map. */
     Map<String, ObjectPartType> objectPartMap = new HashMap<String, ObjectPartType>();
+    
+    /** The service binding. */
     private ServiceBindingType serviceBinding;
+    
+    /** The tenant binding. */
     private TenantBindingType tenantBinding;
+    
+    /** The override document type. */
     private String overrideDocumentType = null;
+    
+    /** The val handlers. */
     private List<ValidatorHandler> valHandlers = null;
+    
+    /** The doc handler. */
     private DocumentHandler docHandler = null;
 
-    public AbstractServiceContextImpl(String serviceName) throws UnauthorizedException {
+    private AbstractServiceContextImpl() {} // private constructor for singleton pattern
+    
+    // request query params
+    private MultivaluedMap<String, String> queryParams;
+    
+    /**
+     * Instantiates a new abstract service context impl.
+     * 
+     * @param serviceName the service name
+     * 
+     * @throws UnauthorizedException the unauthorized exception
+     */
+    protected AbstractServiceContextImpl(String serviceName) throws UnauthorizedException {
         TenantBindingConfigReaderImpl tReader =
                 ServiceMain.getInstance().getTenantBindingConfigReader();
         //FIXME retrieveTenantId is not working consistently in non-auth mode
@@ -118,6 +148,9 @@ public abstract class AbstractServiceContextImpl<IT, OT>
         return schemaName.toLowerCase() + PART_LABEL_SEPERATOR + PART_COMMON_LABEL;
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.ServiceContext#getPartsMetadata()
+     */
     @Override
     public Map<String, ObjectPartType> getPartsMetadata() {
         if (objectPartMap.size() != 0) {
@@ -127,6 +160,13 @@ public abstract class AbstractServiceContextImpl<IT, OT>
         return objectPartMap;
     }
 
+    /**
+     * Gets the properties for part.
+     * 
+     * @param partLabel the part label
+     * 
+     * @return the properties for part
+     */
     public List<PropertyItemType> getPropertiesForPart(String partLabel) {
        Map<String, ObjectPartType> partMap = getPartsMetadata();
        ObjectPartType part = partMap.get(partLabel);
@@ -137,32 +177,68 @@ public abstract class AbstractServiceContextImpl<IT, OT>
        return propNodeList.isEmpty()?null:propNodeList.get(0).getItem();
     }
 
+    /**
+     * Gets the property values for part.
+     * 
+     * @param partLabel the part label
+     * @param propName the prop name
+     * 
+     * @return the property values for part
+     */
     public List<String> getPropertyValuesForPart(String partLabel, String propName) {
        List<PropertyItemType> allProps = getPropertiesForPart(partLabel);
        return PropertyItemUtils.getPropertyValuesByName(allProps, propName);
     }
 
+    /**
+     * Gets the all parts property values.
+     * 
+     * @param propName the prop name
+     * 
+     * @return the all parts property values
+     */
     public List<String> getAllPartsPropertyValues(String propName) {
         return ServiceBindingUtils.getAllPartsPropertyValues(getServiceBinding(), propName);
     }
     
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.ServiceContext#getServiceBindingPropertyValue(java.lang.String)
+     */
     public String getServiceBindingPropertyValue(String propName) {
         return ServiceBindingUtils.getPropertyValue(getServiceBinding(), propName);
     }
     
+    /**
+     * Gets the common part properties.
+     * 
+     * @return the common part properties
+     */
     public List<PropertyItemType> getCommonPartProperties() {
         return getPropertiesForPart(getCommonPartLabel());
     }
 
+    /**
+     * Gets the common part property values.
+     * 
+     * @param propName the prop name
+     * 
+     * @return the common part property values
+     */
     public List<String> getCommonPartPropertyValues(String propName) {
         return getPropertyValuesForPart(getCommonPartLabel(), propName);
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.ServiceContext#getQualifiedServiceName()
+     */
     @Override
     public String getQualifiedServiceName() {
         return TenantBindingConfigReaderImpl.getTenantQualifiedServiceName(getTenantId(), getServiceName());
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.ServiceContext#getRepositoryClientName()
+     */
     @Override
     public String getRepositoryClientName() {
         if (serviceBinding.getRepositoryClient() == null) {
@@ -171,39 +247,60 @@ public abstract class AbstractServiceContextImpl<IT, OT>
         return serviceBinding.getRepositoryClient().trim();
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.ServiceContext#getRepositoryClientType()
+     */
     @Override
     public ClientType getRepositoryClientType() {
         //assumption: there is only one repository client configured
         return ServiceMain.getInstance().getClientType();
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.ServiceContext#getRepositoryDomainName()
+     */
     @Override
     public String getRepositoryDomainName() {
         return tenantBinding.getRepositoryDomain();
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.ServiceContext#getRepositoryWorkspaceId()
+     */
     @Override
     public String getRepositoryWorkspaceId() {
         TenantBindingConfigReaderImpl tbConfigReader = ServiceMain.getInstance().getTenantBindingConfigReader();
         return tbConfigReader.getWorkspaceId(getTenantId(), getServiceName());
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.ServiceContext#getRepositoryWorkspaceName()
+     */
     @Override
     public String getRepositoryWorkspaceName() {
         //service name is workspace name by convention
         return serviceBinding.getName();
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.ServiceContext#getServiceBinding()
+     */
     @Override
     public ServiceBindingType getServiceBinding() {
         return serviceBinding;
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.ServiceContext#getServiceName()
+     */
     @Override
     public String getServiceName() {
         return serviceBinding.getName();
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.ServiceContext#getDocumentType()
+     */
     @Override
     public String getDocumentType() {
         // If they have not overridden the setting, use the type of the service
@@ -211,52 +308,92 @@ public abstract class AbstractServiceContextImpl<IT, OT>
         return (overrideDocumentType != null) ? overrideDocumentType : serviceBinding.getObject().getName();
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.ServiceContext#setDocumentType(java.lang.String)
+     */
     @Override
     public void setDocumentType(String docType) {
         overrideDocumentType = docType;
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.ServiceContext#getTenantId()
+     */
     @Override
     public String getTenantId() {
         return tenantBinding.getId();
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.ServiceContext#getTenantName()
+     */
     @Override
     public String getTenantName() {
         return tenantBinding.getName();
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.ServiceContext#getInput()
+     */
     @Override
     public abstract IT getInput();
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.ServiceContext#setInput(java.lang.Object)
+     */
     @Override
     public abstract void setInput(IT input);
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.ServiceContext#getOutput()
+     */
     @Override
     public abstract OT getOutput();
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.ServiceContext#setOutput(java.lang.Object)
+     */
     @Override
     public abstract void setOutput(OT output);
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.ServiceContext#getProperties()
+     */
     @Override
     public Map<String, Object> getProperties() {
         return properties;
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.ServiceContext#setProperties(java.util.Map)
+     */
     @Override
     public void setProperties(Map<String, Object> props) {
         properties.putAll(props);
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.ServiceContext#getProperty(java.lang.String)
+     */
     public Object getProperty(String name) {
         return properties.get(name);
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.ServiceContext#setProperty(java.lang.String, java.lang.Object)
+     */
     public void setProperty(String name, Object o) {
         properties.put(name, o);
     }
 
 
+    /**
+     * Retrieve tenant id.
+     * 
+     * @return the string
+     * 
+     * @throws UnauthorizedException the unauthorized exception
+     */
     private String retrieveTenantId() throws UnauthorizedException {
 
         String[] tenantIds = AuthN.get().getTenantIds();
@@ -269,12 +406,15 @@ public abstract class AbstractServiceContextImpl<IT, OT>
         //id should be matched with the one sent over the wire
         return tenantIds[0];
     }
-
-    @Override
-    public DocumentHandler getDocumentHandler() throws Exception {
-        if (docHandler != null) {
-            return docHandler;
-        }
+    
+    /**
+     * Creates the document handler instance.
+     * 
+     * @return the document handler
+     * 
+     * @throws Exception the exception
+     */
+    private DocumentHandler createDocumentHandlerInstance() throws Exception {
         ClassLoader tccl = Thread.currentThread().getContextClassLoader();
         Class c = tccl.loadClass(getDocumentHandlerClass());
         if (DocumentHandler.class.isAssignableFrom(c)) {
@@ -283,10 +423,47 @@ public abstract class AbstractServiceContextImpl<IT, OT>
             throw new IllegalArgumentException("Not of type "
                     + DocumentHandler.class.getCanonicalName());
         }
+        //
+        // create a default document filter with pagination if the context
+        // was created with query params
+        //
         docHandler.setServiceContext(this);
-        return docHandler;
+        DocumentFilter docFilter = docHandler.createDocumentFilter();
+        docFilter.setPagination(this.getQueryParams());
+        docHandler.setDocumentFilter(docFilter);
+        
+        return docHandler;     
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.ServiceContext#getDocumentHandler()
+     */
+    @Override
+    public DocumentHandler getDocumentHandler() throws Exception {
+       DocumentHandler result = docHandler;            
+       // create a new instance if one does not yet exist
+       if (result == null) {
+               result = createDocumentHandlerInstance();
+       }       
+       return result;
+    }
+        
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.ServiceContext#getDocumentHanlder(javax.ws.rs.core.MultivaluedMap)
+     */
+    @Override
+    public DocumentHandler getDocumentHandler(MultivaluedMap<String, String> queryParams) throws Exception {
+       DocumentHandler result = getDocumentHandler();
+       DocumentFilter documentFilter = result.getDocumentFilter(); //to see results in debugger variables view
+       documentFilter.setPagination(queryParams);
+       return result;
+    }
+
+    /**
+     * Gets the document handler class.
+     * 
+     * @return the document handler class
+     */
     private String getDocumentHandlerClass() {
         if (serviceBinding.getDocumentHandler() == null
                 || serviceBinding.getDocumentHandler().isEmpty()) {
@@ -299,6 +476,9 @@ public abstract class AbstractServiceContextImpl<IT, OT>
         return serviceBinding.getDocumentHandler().trim();
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.ServiceContext#getValidatorHandlers()
+     */
     @Override
     public List<ValidatorHandler> getValidatorHandlers() throws Exception {
         if (valHandlers != null) {
@@ -318,6 +498,9 @@ public abstract class AbstractServiceContextImpl<IT, OT>
         return valHandlers;
     }
 
+    /* (non-Javadoc)
+     * @see java.lang.Object#toString()
+     */
     @Override
     public String toString() {
         StringBuilder msg = new StringBuilder();
@@ -334,4 +517,14 @@ public abstract class AbstractServiceContextImpl<IT, OT>
         msg.append("]");
         return msg.toString();
     }
+    
+    @Override
+    public MultivaluedMap<String, String> getQueryParams() {
+       return this.queryParams;
+    }
+    
+    @Override
+    public void setQueryParams(MultivaluedMap<String, String> queryParams) {
+       this.queryParams = queryParams;
+    }    
 }
index 98277c254e141a8ac7bed23cce15a115b93a65d4..535b092e52fe4d800a6c471dcab7e8977eca8d90 100644 (file)
  */
 package org.collectionspace.services.common.context;
 
+import javax.ws.rs.core.MultivaluedMap;
+
 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
+import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
 
 /**
  *
@@ -32,28 +35,67 @@ import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
  *
  */
 public class MultipartServiceContextFactory
-        implements ServiceContextFactory<MultipartInput> {
+        implements ServiceContextFactory<MultipartInput, MultipartOutput> {
 
+    /** The Constant self. */
     final private static MultipartServiceContextFactory self = new MultipartServiceContextFactory();
 
-    private MultipartServiceContextFactory() {
-    }
+    /**
+     * Instantiates a new multipart service context factory.
+     */
+    private MultipartServiceContextFactory() {} // private constructor as part of the singleton pattern
 
+    /**
+     * Gets the.
+     * 
+     * @return the multipart service context factory
+     */
     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
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.ServiceContextFactory#createServiceContext(java.lang.String)
      */
     @Override
-    public ServiceContext createServiceContext(MultipartInput input, String serviceName) throws Exception {
+    public ServiceContext<MultipartInput, MultipartOutput> createServiceContext(String serviceName) throws Exception {
         MultipartServiceContext ctx = new MultipartServiceContextImpl(serviceName);
-        ctx.setInput(input);
         return ctx;
     }
+
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.ServiceContextFactory#createServiceContext(java.lang.String, java.lang.Object)
+     */
+    @Override
+    public ServiceContext<MultipartInput, MultipartOutput> createServiceContext(String serviceName,
+               MultipartInput input) throws Exception {
+        MultipartServiceContext ctx = new MultipartServiceContextImpl(serviceName, input);
+        return ctx;
+    }
+        
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.ServiceContextFactory#createServiceContext(java.lang.String, java.lang.Object, javax.ws.rs.core.MultivaluedMap)
+     */
+    @Override
+    public ServiceContext<MultipartInput, MultipartOutput> createServiceContext(String serviceName,
+               MultipartInput input, 
+               MultivaluedMap<String, String> queryParams)
+                       throws Exception {
+       ServiceContext<MultipartInput, MultipartOutput> ctx = new MultipartServiceContextImpl(serviceName,
+                       input,
+                       queryParams);
+       return ctx;
+    }
+    
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.ServiceContextFactory#createServiceContext(java.lang.String, java.lang.Object, javax.ws.rs.core.MultivaluedMap, java.lang.String, java.lang.String)
+     */
+    @Override
+    public ServiceContext<MultipartInput, MultipartOutput> createServiceContext(String serviceName, 
+               MultipartInput input,
+               MultivaluedMap<String, String> queryParams,
+               String documentType,
+               String entityName) throws Exception {
+       return this.createServiceContext(serviceName, input, queryParams);
+    }
 }
index a997a4102333de07984d2304b1f03452e49b0ceb..d760ecbf6a7787990a5376263f7b370dbabdde07 100644 (file)
@@ -29,6 +29,8 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.lang.reflect.Constructor;
 import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+
 import org.collectionspace.services.common.document.DocumentUtils;
 import org.collectionspace.services.common.security.UnauthorizedException;
 import org.jboss.resteasy.plugins.providers.multipart.InputPart;
@@ -49,14 +51,59 @@ public class MultipartServiceContextImpl
         extends RemoteServiceContextImpl<MultipartInput, MultipartOutput>
         implements MultipartServiceContext {
 
+    /** The logger. */
     final Logger logger = LoggerFactory.getLogger(MultipartServiceContextImpl.class);
 
-    public MultipartServiceContextImpl(String serviceName) throws UnauthorizedException {
-        super(serviceName);
+    /**
+     * Instantiates a new multipart service context impl.
+     * 
+     * @param serviceName the service name
+     * 
+     * @throws UnauthorizedException the unauthorized exception
+     */
+    protected MultipartServiceContextImpl(String serviceName)
+                       throws UnauthorizedException {
+       super(serviceName);
+       setOutput(new MultipartOutput());
+    }
+    
+    /**
+     * Instantiates a new multipart service context impl.
+     * 
+     * @param serviceName the service name
+     * 
+     * @throws UnauthorizedException the unauthorized exception
+     */
+    protected MultipartServiceContextImpl(String serviceName, MultipartInput theInput)
+               throws UnauthorizedException {
+        super(serviceName, theInput);
         setOutput(new MultipartOutput());
     }
 
+    /**
+     * Instantiates a new multipart service context impl.
+     * 
+     * @param serviceName the service name
+     * @param queryParams the query params
+     * 
+     * @throws UnauthorizedException the unauthorized exception
+     */
+    protected MultipartServiceContextImpl(String serviceName,
+               MultipartInput theInput,
+               MultivaluedMap<String, String> queryParams) throws UnauthorizedException {
+       super(serviceName, theInput, queryParams);
+       setOutput(new MultipartOutput());
+    }
 
+    /**
+     * Gets the input part.
+     * 
+     * @param label the label
+     * 
+     * @return the input part
+     * 
+     * @throws IOException Signals that an I/O exception has occurred.
+     */
     private InputPart getInputPart(String label) throws IOException {
         if (getInput() != null) {
             MultipartInput fdip = getInput();
@@ -75,6 +122,9 @@ public class MultipartServiceContextImpl
         return null;
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.MultipartServiceContext#getInputPart(java.lang.String, java.lang.Class)
+     */
     @Override
     public Object getInputPart(String label, Class clazz) throws IOException {
         Object obj = null;
@@ -85,6 +135,9 @@ public class MultipartServiceContextImpl
         return obj;
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.MultipartServiceContext#getInputPartAsString(java.lang.String)
+     */
     @Override
     public String getInputPartAsString(String label) throws IOException {
         InputPart part = getInputPart(label);
@@ -94,6 +147,9 @@ public class MultipartServiceContextImpl
         return null;
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.MultipartServiceContext#getInputPartAsStream(java.lang.String)
+     */
     @Override
     public InputStream getInputPartAsStream(String label) throws IOException {
         InputPart part = getInputPart(label);
@@ -103,8 +159,9 @@ public class MultipartServiceContextImpl
         return null;
     }
 
-
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.MultipartServiceContext#addOutputPart(java.lang.String, org.w3c.dom.Document, java.lang.String)
+     */
     @Override
     public void addOutputPart(String label, Document doc, String contentType) throws Exception {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
@@ -124,6 +181,9 @@ public class MultipartServiceContextImpl
         }
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.RemoteServiceContextImpl#getLocalContext(java.lang.String)
+     */
     @Override
     public ServiceContext getLocalContext(String localContextClassName) throws Exception {
         ClassLoader cloader = Thread.currentThread().getContextClassLoader();
index 01fed3c86fd842ad8a6601fe76a02278300a3278..74a539959f68badeadd0158ccff82f13ccb3d5a8 100644 (file)
@@ -23,6 +23,8 @@
  */
 package org.collectionspace.services.common.context;
 
+import javax.ws.rs.core.MultivaluedMap;
+
 /**
  * RemoteServiceContext is used to encapsulate the service context of a
  * remotely invokable service
@@ -68,4 +70,19 @@ public interface RemoteServiceContext<IT, OT>
      * @return local service context
      */
     public ServiceContext getLocalContext(String localContextClassName) throws Exception;
+    
+    /**
+     * Gets the query params.
+     * 
+     * @return the query params
+     */
+    public MultivaluedMap<String, String> getQueryParams();
+
+    /**
+     * Gets the query params.
+     * 
+     * @return the query params
+     */
+    public void setQueryParams(MultivaluedMap<String, String> queryParams);
 }
+
index 9391805f4db9b6ca9b05c17b8ee46733692de6be..a5e3eafe870bf45c7f0e566f33562d19fa38f95c 100644 (file)
 package org.collectionspace.services.common.context;
 
 import java.lang.reflect.Constructor;
+
+import javax.ws.rs.core.MultivaluedMap;
+
+import org.collectionspace.services.common.document.DocumentFilter;
+import org.collectionspace.services.common.document.DocumentHandler;
 import org.collectionspace.services.common.security.UnauthorizedException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -38,20 +43,65 @@ public class RemoteServiceContextImpl<IT, OT>
         extends AbstractServiceContextImpl<IT, OT>
         implements RemoteServiceContext<IT, OT> {
 
+    /** The logger. */
     final Logger logger = LoggerFactory.getLogger(RemoteServiceContextImpl.class);
     //input stores original content as received over the wire
+    /** The input. */
     private IT input;
+    
+    /** The output. */
     private OT output;
 
-    public RemoteServiceContextImpl(String serviceName) throws UnauthorizedException {
+    /**
+     * Instantiates a new remote service context impl.
+     * 
+     * @param serviceName the service name
+     * 
+     * @throws UnauthorizedException the unauthorized exception
+     */
+    protected RemoteServiceContextImpl(String serviceName) throws UnauthorizedException {
         super(serviceName);
     }
 
+    /**
+     * Instantiates a new remote service context impl. (This is "package" protected for the Factory class)
+     * 
+     * @param serviceName the service name
+     * 
+     * @throws UnauthorizedException the unauthorized exception
+     */
+    protected RemoteServiceContextImpl(String serviceName, IT theInput) throws UnauthorizedException {
+       this(serviceName);
+        this.input = theInput;
+    }
+
+    /**
+     * Instantiates a new remote service context impl. (This is "package" protected for the Factory class)
+     * 
+     * @param serviceName the service name
+     * @param theInput the the input
+     * @param queryParams the query params
+     * 
+     * @throws UnauthorizedException the unauthorized exception
+     */
+    protected RemoteServiceContextImpl(String serviceName,
+               IT theInput,
+               MultivaluedMap<String, String> queryParams) throws UnauthorizedException {
+        this(serviceName, theInput);
+        this.setQueryParams(queryParams);
+    }
+
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.AbstractServiceContextImpl#getInput()
+     */
     @Override
     public IT getInput() {
         return input;
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.AbstractServiceContextImpl#setInput(java.lang.Object)
+     */
     @Override
     public void setInput(IT input) {
         //for security reasons, do not allow to set input again (from handlers)
@@ -63,16 +113,25 @@ public class RemoteServiceContextImpl<IT, OT>
         this.input = input;
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.AbstractServiceContextImpl#getOutput()
+     */
     @Override
     public OT getOutput() {
         return output;
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.AbstractServiceContextImpl#setOutput(java.lang.Object)
+     */
     @Override
     public void setOutput(OT output) {
         this.output = output;
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.context.RemoteServiceContext#getLocalContext(java.lang.String)
+     */
     @Override
     public ServiceContext getLocalContext(String localContextClassName) throws Exception {
         ClassLoader cloader = Thread.currentThread().getContextClassLoader();
@@ -85,5 +144,5 @@ public class RemoteServiceContextImpl<IT, OT>
         Constructor ctor = ctxClass.getConstructor(java.lang.String.class);
         ServiceContext ctx = (ServiceContext) ctor.newInstance(getServiceName());
         return ctx;
-    }
+    }    
 }
index 9cebceadb1e39696ddbd8b99ec53d679e93a6d9f..f497f4ebebd6ee0091d67d59956e966c5131a4e2 100644 (file)
@@ -25,6 +25,9 @@ package org.collectionspace.services.common.context;
 
 import java.util.List;
 import java.util.Map;
+
+import javax.ws.rs.core.MultivaluedMap;
+
 import org.collectionspace.services.common.ClientType;
 import org.collectionspace.services.common.document.DocumentHandler;
 import org.collectionspace.services.common.document.ValidatorHandler;
@@ -43,6 +46,8 @@ public interface ServiceContext<IT, OT> {
      * The character used to separate the words in a part label
      */
     public static final String PART_LABEL_SEPERATOR = "_";
+    
+    /** The Constant PART_COMMON_LABEL. */
     public static final String PART_COMMON_LABEL = "common";
        
     /**
@@ -201,14 +206,23 @@ public interface ServiceContext<IT, OT> {
      */
     public String getServiceBindingPropertyValue(String propName);
 
-
-
     /**
      * getDocumentHanlder returns document handler configured in the the binding
      * it creates the handler if necessary.
      * @return document handler
      */
     public DocumentHandler getDocumentHandler() throws Exception;
+    
+    /**
+     * Gets the document hanlder.
+     * 
+     * @param queryParams the query params
+     * 
+     * @return the document hanlder
+     * 
+     * @throws Exception the exception
+     */
+    public DocumentHandler getDocumentHandler(MultivaluedMap<String, String> queryParams) throws Exception;   
 
     /**
      * getValidatorHandlers returns registered (from binding) validtor handlers
@@ -216,7 +230,20 @@ public interface ServiceContext<IT, OT> {
      * @return validation handlers
      */
     public List<ValidatorHandler> getValidatorHandlers() throws Exception;
-
+    
+    /**
+     * Gets the query params.
+     * 
+     * @return the query params
+     */
+    public MultivaluedMap<String, String> getQueryParams();
+    
+    /**
+     * Sets the query params.
+     * 
+     * @param queryParams the query params
+     */
+    public void setQueryParams(MultivaluedMap<String, String> queryParams);    
 }
 
 
index ae76e6dd30b1ff46f2bc1e05ba9f3abd8bb75ea1..49b78493acc1e68909da04efa851787447bd08b2 100644 (file)
  */
 package org.collectionspace.services.common.context;
 
+import javax.ws.rs.core.MultivaluedMap;
+
 /**
  *
  * ServiceContextFactory creates a service context
  *
  */
-public interface ServiceContextFactory<T> {
-
+public interface ServiceContextFactory<IT, OT> {
 
     /**
-     * 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
+     * Creates a new ServiceContext object.
+     * 
+     * @param serviceName the service name
+     * @param input the input
+     * 
+     * @return the service context
+     * 
+     * @throws Exception the exception
+     */
+    public ServiceContext<IT, OT> createServiceContext(String serviceName, IT input) throws Exception;
+    
+    /**
+     * Creates a new ServiceContext object.
+     * 
+     * @param serviceName the service name
+     * 
+     * @return the service context< i t, o t>
+     * 
+     * @throws Exception the exception
      */
-    public ServiceContext createServiceContext(T input, String serviceName) throws Exception;
+    public ServiceContext<IT, OT> createServiceContext(String serviceName) throws Exception;
 
+    /**
+     * Creates a new ServiceContext object.
+     * 
+     * @param serviceName the service name
+     * @param input the input
+     * @param queryParams the query params
+     * 
+     * @return the service context
+     * 
+     * @throws Exception the exception
+     */
+    public ServiceContext<IT, OT> createServiceContext(String serviceName,
+               IT input,
+               MultivaluedMap<String, String> queryParams) throws Exception;    
+        
+    /**
+     * Creates a new ServiceContext object.
+     * 
+     * @param serviceName the service name
+     * @param input the input
+     * @param queryParams the query params
+     * @param documentType the document type
+     * @param entityName the entity name
+     * 
+     * @return the service context
+     * 
+     * @throws Exception the exception
+     */
+    public ServiceContext<IT, OT> createServiceContext(
+               String serviceName,
+               IT input, 
+               MultivaluedMap<String, String> queryParams,
+               String documentType,
+               String entityName) throws Exception;
 }
index 39fb955d87830027b5bf3c0ffbee37137f4c4d40..ef756c263af39724a3d85a38dc6b6f31d983d1f2 100644 (file)
@@ -76,8 +76,13 @@ public abstract class AbstractDocumentHandlerImpl<T, TL, WT, WTL>
         this.properties = properties;
     }
 
+//    public void initializeDocumentFilter(ServiceContext ctx) {
+//     DocumentFilter docFilter = this.createDocumentFilter(ctx);
+//     this.setDocumentFilter(docFilter);
+//    }
+    
     @Override
-    public abstract DocumentFilter createDocumentFilter(ServiceContext ctx);
+    public abstract DocumentFilter createDocumentFilter();
 
     /**
      * @return the DocumentFilter
index 1fd48204efb974a2ede2e130dc4e6a843e48c7c9..87f17e593f2e5603a2a8b77add7a7e40aa473fde 100644 (file)
@@ -21,6 +21,7 @@ import java.util.ArrayList;
 import java.util.List;\r
 import javax.ws.rs.core.MultivaluedMap;\r
 import org.collectionspace.services.common.query.IQueryManager;\r
+import org.collectionspace.services.common.context.ServiceContext;\r
 \r
 //TODO: would be great to not rely on resteasy directly\r
 import org.jboss.resteasy.specimpl.MultivaluedMapImpl;\r
@@ -41,7 +42,8 @@ public class DocumentFilter {
     protected String whereClause;      // Filtering clause. Omit the "WHERE".\r
     protected int startPage;           // Pagination offset for list results\r
     protected int pageSize;                    // Pagination limit for list results\r
-    private MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl<String, String>();\r
+    private boolean pageSizeDirty = false; // True if default page size explicitly set/overridden\r
+    private MultivaluedMap<String, String> queryParams = null;\r
 \r
 \r
     /**\r
@@ -86,6 +88,16 @@ public class DocumentFilter {
         }\r
     }\r
     \r
+    /**\r
+     * Instantiates a new document filter.\r
+     * \r
+     * @param ctx the ctx\r
+     */\r
+    public DocumentFilter(ServiceContext ctx) {\r
+       this.setPageSize(ctx.getServiceBindingPropertyValue(\r
+                       DocumentFilter.PAGE_SIZE_DEFAULT_PROPERTY));\r
+    }\r
+    \r
     public DocumentFilter() {\r
         this("", 0, defaultPageSize);                  // Use empty string for easy concatenation\r
     }\r
@@ -96,26 +108,36 @@ public class DocumentFilter {
         this.pageSize = (pageSize > 0) ? pageSize : defaultPageSize;\r
     }\r
 \r
-    public void setPagination(MultivaluedMap<String, String> queryParams) {\r
-\r
-        String startPageStr = null;\r
-        String pageSizeStr = null;\r
+    /**\r
+     * Sets the pagination.\r
+     * \r
+     * @param queryParams the query params\r
+     */\r
+    public void setPagination(MultivaluedMap<String, String> queryParams) {            \r
+       //\r
+       // Bail if there are no params\r
+       //\r
+       if (queryParams == null) return;\r
+       \r
+        //\r
+       // Set the page size\r
+       //\r
+       String pageSizeStr = null;\r
         List<String> list = queryParams.remove(PAGE_SIZE_PARAM);\r
         if (list != null) {\r
             pageSizeStr = list.get(0);\r
         }\r
         setPageSize(pageSizeStr);\r
+\r
+        //\r
+        // Set the start page\r
+        //\r
+        String startPageStr = null;\r
         list = queryParams.remove(START_PAGE_PARAM);\r
         if (list != null) {\r
             startPageStr = list.get(0);\r
         }\r
-        if (startPageStr != null) {\r
-            try {\r
-                startPage = Integer.valueOf(startPageStr);\r
-            } catch (NumberFormatException e) {\r
-                throw new NumberFormatException("Bad value for: " + START_PAGE_PARAM);\r
-            }\r
-        }\r
+        setStartPage(startPageStr);\r
     }\r
 \r
     /**\r
@@ -192,25 +214,50 @@ public class DocumentFilter {
     public int getPageSize() {\r
         return pageSize;\r
     }\r
+    \r
+    public boolean getPageSizeDirty() {\r
+       return this.getPageSizeDirty();\r
+    }\r
 \r
     /**\r
      * @param pageSize the max number of items to return for list requests\r
      */\r
     public void setPageSize(int pageSize) {\r
         this.pageSize = pageSize;\r
+        this.pageSizeDirty = true; // page size explicity set/overriden\r
     }\r
 \r
     /**\r
      * @param pageSize the max number of items to return for list requests\r
      */\r
     public void setPageSize(String pageSizeStr) {\r
+       int pageSize = this.defaultPageSize;\r
         if (pageSizeStr != null) {\r
             try {\r
-                pageSize = Integer.valueOf(pageSizeStr);\r
+               pageSize = Integer.valueOf(pageSizeStr);\r
             } catch (NumberFormatException e) {\r
+               //FIXME This should cause a warning in the log file and should result in the\r
+               //FIXME page size being set to the default.  We don't need to throw an exception here.\r
                 throw new NumberFormatException("Bad value for: " + PAGE_SIZE_PARAM);\r
             }\r
         }\r
+        \r
+        setPageSize(pageSize);\r
+    }\r
+\r
+    /**\r
+     * Sets the start page.\r
+     * \r
+     * @param startPageStr the new start page\r
+     */\r
+    protected void setStartPage(String startPageStr) {\r
+        if (startPageStr != null) {\r
+            try {\r
+               startPage = Integer.valueOf(startPageStr);\r
+            } catch (NumberFormatException e) {\r
+                throw new NumberFormatException("Bad value for: " + START_PAGE_PARAM);\r
+            }\r
+        }\r
     }\r
 \r
     /**\r
index 360169c22a2b9b473dd6608550734f7e219cb351..4a6467dd25d7ed7c4737a32f447a2c214f086184 100644 (file)
@@ -224,7 +224,7 @@ public interface DocumentHandler<T, TL, WT, WTL> {
      * @param properties
      */
     public void setProperties(Map<String, Object> properties);
-
+    
     /**
      * createDocumentFilter is a factory method to create a document
      * filter that is relevant to be used with this document handler
@@ -233,7 +233,7 @@ public interface DocumentHandler<T, TL, WT, WTL> {
      * @param ctx ServiceContext used to fetch default pagination, etc.
      * @return
      */
-    public DocumentFilter createDocumentFilter(ServiceContext ctx);
+    public DocumentFilter createDocumentFilter();
 
     /**
      * getDocumentFilter
index e0d744793b81b45e58a0be6c4641075d6c03e90b..24e6e27fe76fac15cfd8689a4aa517609cd33537 100644 (file)
 package org.collectionspace.services.common.storage.jpa;
 
 import org.collectionspace.services.common.document.DocumentFilter;
+import org.collectionspace.services.common.context.ServiceContext;
+
 
 /**
  * JPA query specific document filter
  */
 public class JpaDocumentFilter extends DocumentFilter {
-
-
+       public JpaDocumentFilter(ServiceContext ctx) {
+               super(ctx);
+       }
 }
index 0203b73e1c6a1fef901a6085dc6c7a518c743c9d..dc29738e392681d1a240f78423efa259d72a9ffe 100644 (file)
@@ -173,7 +173,7 @@ public class JpaStorageClientImpl implements StorageClient {
         }
         DocumentFilter docFilter = handler.getDocumentFilter();
         if (docFilter == null) {
-            docFilter = handler.createDocumentFilter(ctx);
+            docFilter = handler.createDocumentFilter();
         }
         EntityManagerFactory emf = null;
         EntityManager em = null;
@@ -256,7 +256,7 @@ public class JpaStorageClientImpl implements StorageClient {
         }
         DocumentFilter docFilter = handler.getDocumentFilter();
         if (docFilter == null) {
-            docFilter = handler.createDocumentFilter(ctx);
+            docFilter = handler.createDocumentFilter();
         }
         EntityManagerFactory emf = null;
         EntityManager em = null;
index 005229fb293012a616460d0696b6aa0b7c3eb032..ac2c147a50f78a696d3dff9d253b5b5d780518c5 100644 (file)
@@ -113,13 +113,10 @@ public abstract class DocumentModelHandler<T, TL>
 
     @Override
     public abstract void setCommonPartList(TL obj);
-
+    
     @Override
-    public DocumentFilter createDocumentFilter(ServiceContext ctx) {
-       DocumentFilter filter = new NuxeoDocumentFilter();
-       filter.setPageSize(
-                       ctx.getServiceBindingPropertyValue(
-                                       DocumentFilter.PAGE_SIZE_DEFAULT_PROPERTY));
+    public DocumentFilter createDocumentFilter() {
+       DocumentFilter filter = new NuxeoDocumentFilter(this.getServiceContext());
        return filter;
     }
 
index fd74a93343e75ee66d08e76882271c9e0894a9fd..bf9411f82833877f2282a513cbaf6b9dc084ad9c 100644 (file)
 package org.collectionspace.services.nuxeo.client.java;
 
 import org.collectionspace.services.common.document.DocumentFilter;
+import org.collectionspace.services.common.context.ServiceContext;
 
 /**
  * NXQL specific document filter
  */
 public class NuxeoDocumentFilter extends DocumentFilter {
+       public NuxeoDocumentFilter(ServiceContext ctx) {
+               super(ctx);
+       }
 
 }
index 9d1eb50d261abbcc933c1b9911b96894aa6effb9..0a4d898268e2234ed78cd7f3a453513512378855 100644 (file)
@@ -37,7 +37,7 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
 
-import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl;
+import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl;
 import org.collectionspace.services.common.ClientType;
 import org.collectionspace.services.common.ServiceMain;
 import org.collectionspace.services.common.context.MultipartServiceContext;
@@ -53,20 +53,34 @@ import org.jboss.resteasy.util.HttpResponseCodes;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+/**
+ * The Class ContactResource.
+ */
 @Path("/contacts")
 @Consumes("multipart/mixed")
 @Produces("multipart/mixed")
-public class ContactResource extends AbstractCollectionSpaceResourceImpl {
+public class ContactResource extends 
+               AbstractMultiPartCollectionSpaceResourceImpl {
 
+    /** The Constant serviceName. */
     private final static String serviceName = "contacts";
+    
+    /** The logger. */
     final Logger logger = LoggerFactory.getLogger(ContactResource.class);
     //FIXME retrieve client type from configuration
+    /** The Constant CLIENT_TYPE. */
     final static ClientType CLIENT_TYPE = ServiceMain.getInstance().getClientType();
 
+    /**
+     * Instantiates a new contact resource.
+     */
     public ContactResource() {
         // do nothing
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getVersionString()
+     */
     @Override
     protected String getVersionString() {
        /** The last change revision. */
@@ -74,27 +88,45 @@ public class ContactResource extends AbstractCollectionSpaceResourceImpl {
        return lastChangeRevision;
     }
     
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getServiceName()
+     */
     @Override
     public String getServiceName() {
         return serviceName;
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.CollectionSpaceResource#getCommonPartClass()
+     */
     @Override
-    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
-        DocumentHandler docHandler = ctx.getDocumentHandler();
-        if (ctx.getInput() != null) {
-            Object obj = ((MultipartServiceContext)ctx).getInputPart(ctx.getCommonPartLabel(), ContactsCommon.class);
-            if (obj != null) {
-                docHandler.setCommonPart((ContactsCommon) obj);
-            }
-        }
-        return docHandler;
+    public Class<ContactsCommon> getCommonPartClass() {
+       return ContactsCommon.class;
     }
+    
+//    @Override
+//    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
+//        DocumentHandler docHandler = ctx.getDocumentHandler();
+//        if (ctx.getInput() != null) {
+//            Object obj = ((MultipartServiceContext)ctx).getInputPart(ctx.getCommonPartLabel(), ContactsCommon.class);
+//            if (obj != null) {
+//                docHandler.setCommonPart((ContactsCommon) obj);
+//            }
+//        }
+//        return docHandler;
+//    }
 
-    @POST
+    /**
+ * Creates the contact.
+ * 
+ * @param input the input
+ * 
+ * @return the response
+ */
+@POST
     public Response createContact(MultipartInput input) {
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getServiceName());
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(input);
             DocumentHandler handler = createDocumentHandler(ctx);
             String csid = getRepositoryClient(ctx).create(ctx, handler);
             //contactObject.setCsid(csid);
@@ -112,6 +144,13 @@ public class ContactResource extends AbstractCollectionSpaceResourceImpl {
         }
     }
 
+    /**
+     * Gets the contact.
+     * 
+     * @param csid the csid
+     * 
+     * @return the contact
+     */
     @GET
     @Path("{csid}")
     public MultipartOutput getContact(
@@ -128,7 +167,7 @@ public class ContactResource extends AbstractCollectionSpaceResourceImpl {
         }
         MultipartOutput result = null;
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).get(ctx, csid, handler);
             result = (MultipartOutput) ctx.getOutput();
@@ -157,12 +196,19 @@ public class ContactResource extends AbstractCollectionSpaceResourceImpl {
         return result;
     }
 
+    /**
+     * Gets the contact list.
+     * 
+     * @param ui the ui
+     * 
+     * @return the contact list
+     */
     @GET
     @Produces("application/xml")
     public ContactsCommonList getContactList(@Context UriInfo ui) {
         ContactsCommonList contactObjectList = new ContactsCommonList();
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).getAll(ctx, handler);
             contactObjectList = (ContactsCommonList) handler.getCommonPartList();
@@ -177,6 +223,14 @@ public class ContactResource extends AbstractCollectionSpaceResourceImpl {
         return contactObjectList;
     }
 
+    /**
+     * Update contact.
+     * 
+     * @param csid the csid
+     * @param theUpdate the the update
+     * 
+     * @return the multipart output
+     */
     @PUT
     @Path("{csid}")
     public MultipartOutput updateContact(
@@ -194,7 +248,7 @@ public class ContactResource extends AbstractCollectionSpaceResourceImpl {
         }
         MultipartOutput result = null;
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(theUpdate, getServiceName());
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(theUpdate);
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).update(ctx, csid, handler);
             result = (MultipartOutput) ctx.getOutput();
@@ -214,6 +268,13 @@ public class ContactResource extends AbstractCollectionSpaceResourceImpl {
         return result;
     }
 
+    /**
+     * Delete contact.
+     * 
+     * @param csid the csid
+     * 
+     * @return the response
+     */
     @DELETE
     @Path("{csid}")
     public Response deleteContact(@PathParam("csid") String csid) {
@@ -229,7 +290,7 @@ public class ContactResource extends AbstractCollectionSpaceResourceImpl {
             throw new WebApplicationException(response);
         }
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             getRepositoryClient(ctx).delete(ctx, csid);
             return Response.status(HttpResponseCodes.SC_OK).build();
         } catch (DocumentNotFoundException dnfe) {
index 549a4cb85c969ce3aa101da9b327c2f78c2f4a78..e3ecb77f5e10ef92a61fd36438d2ab6e121d8258 100644 (file)
@@ -33,12 +33,13 @@ import javax.ws.rs.PUT;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.WebApplicationException;
 import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
 
-import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl;
-import org.collectionspace.services.dimension.DimensionsCommonList.*;
+import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl;
+//import org.collectionspace.services.dimension.DimensionsCommonList.*;
 
 import org.collectionspace.services.common.ClientType;
 import org.collectionspace.services.common.ServiceMain;
@@ -53,20 +54,34 @@ import org.jboss.resteasy.util.HttpResponseCodes;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+/**
+ * The Class DimensionResource.
+ */
 @Path("/dimensions")
 @Consumes("multipart/mixed")
 @Produces("multipart/mixed")
-public class DimensionResource extends AbstractCollectionSpaceResourceImpl {
+public class DimensionResource extends
+               AbstractMultiPartCollectionSpaceResourceImpl {
 
+    /** The Constant serviceName. */
     private final static String serviceName = "dimensions";
+    
+    /** The logger. */
     final Logger logger = LoggerFactory.getLogger(DimensionResource.class);
     //FIXME retrieve client type from configuration
+    /** The Constant CLIENT_TYPE. */
     final static ClientType CLIENT_TYPE = ServiceMain.getInstance().getClientType();
 
+    /**
+     * Instantiates a new dimension resource.
+     */
     public DimensionResource() {
         // do nothing
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getVersionString()
+     */
     @Override
     protected String getVersionString() {
        /** The last change revision. */
@@ -74,27 +89,45 @@ public class DimensionResource extends AbstractCollectionSpaceResourceImpl {
        return lastChangeRevision;
     }
     
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getServiceName()
+     */
     @Override
     public String getServiceName() {
         return serviceName;
     }
 
-    @Override
-    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
-        DocumentHandler docHandler = ctx.getDocumentHandler();
-        if (ctx.getInput() != null) {
-            Object obj = ((MultipartServiceContext)ctx).getInputPart(ctx.getCommonPartLabel(), DimensionsCommon.class);
-            if (obj != null) {
-                docHandler.setCommonPart((DimensionsCommon) obj);
-            }
-        }
-        return docHandler;
+//    @Override
+//    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
+//        DocumentHandler docHandler = ctx.getDocumentHandler();
+//        if (ctx.getInput() != null) {
+//            Object obj = ((MultipartServiceContext)ctx).getInputPart(ctx.getCommonPartLabel(), DimensionsCommon.class);
+//            if (obj != null) {
+//                docHandler.setCommonPart((DimensionsCommon) obj);
+//            }
+//        }
+//        return docHandler;
+//    }
+    
+    /* (non-Javadoc)
+ * @see org.collectionspace.services.common.CollectionSpaceResource#getCommonPartClass()
+ */
+@Override
+    public Class<DimensionsCommon> getCommonPartClass() {
+       return DimensionsCommon.class;
     }
 
+    /**
+     * Creates the dimension.
+     * 
+     * @param input the input
+     * 
+     * @return the response
+     */
     @POST
     public Response createDimension(MultipartInput input) {
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(input);
             DocumentHandler handler = createDocumentHandler(ctx);
             String csid = getRepositoryClient(ctx).create(ctx, handler);
             //dimensionObject.setCsid(csid);
@@ -112,6 +145,13 @@ public class DimensionResource extends AbstractCollectionSpaceResourceImpl {
         }
     }
 
+    /**
+     * Gets the dimension.
+     * 
+     * @param csid the csid
+     * 
+     * @return the dimension
+     */
     @GET
     @Path("{csid}")
     public MultipartOutput getDimension(
@@ -128,7 +168,7 @@ public class DimensionResource extends AbstractCollectionSpaceResourceImpl {
         }
         MultipartOutput result = null;
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).get(ctx, csid, handler);
             result = (MultipartOutput) ctx.getOutput();
@@ -157,12 +197,20 @@ public class DimensionResource extends AbstractCollectionSpaceResourceImpl {
         return result;
     }
 
+    /**
+     * Gets the dimension list.
+     * 
+     * @param ui the ui
+     * 
+     * @return the dimension list
+     */
     @GET
     @Produces("application/xml")
     public DimensionsCommonList getDimensionList(@Context UriInfo ui) {
         DimensionsCommonList dimensionObjectList = new DimensionsCommonList();
+        MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).getAll(ctx, handler);
             dimensionObjectList = (DimensionsCommonList) handler.getCommonPartList();
@@ -177,6 +225,14 @@ public class DimensionResource extends AbstractCollectionSpaceResourceImpl {
         return dimensionObjectList;
     }
 
+    /**
+     * Update dimension.
+     * 
+     * @param csid the csid
+     * @param theUpdate the the update
+     * 
+     * @return the multipart output
+     */
     @PUT
     @Path("{csid}")
     public MultipartOutput updateDimension(
@@ -194,7 +250,7 @@ public class DimensionResource extends AbstractCollectionSpaceResourceImpl {
         }
         MultipartOutput result = null;
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(theUpdate, getServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(theUpdate);
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).update(ctx, csid, handler);
             result = (MultipartOutput) ctx.getOutput();
@@ -214,6 +270,13 @@ public class DimensionResource extends AbstractCollectionSpaceResourceImpl {
         return result;
     }
 
+    /**
+     * Delete dimension.
+     * 
+     * @param csid the csid
+     * 
+     * @return the response
+     */
     @DELETE
     @Path("{csid}")
     public Response deleteDimension(@PathParam("csid") String csid) {
@@ -229,7 +292,7 @@ public class DimensionResource extends AbstractCollectionSpaceResourceImpl {
             throw new WebApplicationException(response);
         }
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             getRepositoryClient(ctx).delete(ctx, csid);
             return Response.status(HttpResponseCodes.SC_OK).build();
         } catch (DocumentNotFoundException dnfe) {
index 8167a2c706eafa88cb5d6798c59eea8418eac3a6..a7be7687cc00fa8de38a5943bb600dead02c3b59 100644 (file)
@@ -36,17 +36,18 @@ 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;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
 
-import org.collectionspace.services.collectionobject.CollectionobjectsCommonList;
-import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl;
+//import org.collectionspace.services.collectionobject.CollectionobjectsCommonList;
+import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl;
 import org.collectionspace.services.common.ClientType;
 import org.collectionspace.services.common.ServiceMain;
 import org.collectionspace.services.common.authorityref.AuthorityRefList;
-import org.collectionspace.services.common.context.MultipartServiceContext;
-import org.collectionspace.services.common.context.MultipartServiceContextFactory;
+//import org.collectionspace.services.common.context.MultipartServiceContext;
+//import org.collectionspace.services.common.context.MultipartServiceContextFactory;
 import org.collectionspace.services.common.context.MultipartServiceContextImpl;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.document.DocumentFilter;
@@ -71,7 +72,8 @@ import org.slf4j.LoggerFactory;
 @Path("/intakes")
 @Consumes("multipart/mixed")
 @Produces("multipart/mixed")
-public class IntakeResource extends AbstractCollectionSpaceResourceImpl {
+public class IntakeResource extends
+               AbstractMultiPartCollectionSpaceResourceImpl {
 
     /** The Constant serviceName. */
     private final static String serviceName = "intakes";
@@ -108,19 +110,27 @@ public class IntakeResource extends AbstractCollectionSpaceResourceImpl {
     }
 
     /* (non-Javadoc)
-     * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#createDocumentHandler(org.collectionspace.services.common.context.ServiceContext)
+     * @see org.collectionspace.services.common.CollectionSpaceResource#getCommonPartClass()
      */
     @Override
-    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
-        DocumentHandler docHandler = ctx.getDocumentHandler();
-        if (ctx.getInput() != null) {
-            Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), IntakesCommon.class);
-            if (obj != null) {
-                docHandler.setCommonPart((IntakesCommon) obj);
-            }
-        }
-        return docHandler;
+    public Class<IntakesCommon> getCommonPartClass() {
+       return IntakesCommon.class;
     }
+    
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#createDocumentHandler(org.collectionspace.services.common.context.ServiceContext)
+     */
+//    @Override
+//    public DocumentHandler createDocumentHandler(ServiceContext<MultipartInput, MultipartOutput> ctx) throws Exception {
+//        DocumentHandler docHandler = ctx.getDocumentHandler();
+//        if (ctx.getInput() != null) {
+//            Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), IntakesCommon.class);
+//            if (obj != null) {
+//                docHandler.setCommonPart((IntakesCommon) obj);
+//            }
+//        }
+//        return docHandler;
+//    }
 
     /**
      * Creates the intake.
@@ -132,7 +142,7 @@ public class IntakeResource extends AbstractCollectionSpaceResourceImpl {
     @POST
     public Response createIntake(MultipartInput input) {
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(input);
             DocumentHandler handler = createDocumentHandler(ctx);
             String csid = getRepositoryClient(ctx).create(ctx, handler);
             //intakeObject.setCsid(csid);
@@ -177,7 +187,7 @@ public class IntakeResource extends AbstractCollectionSpaceResourceImpl {
         }
         MultipartOutput result = null;
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).get(ctx, csid, handler);
             result = (MultipartOutput) ctx.getOutput();
@@ -223,11 +233,12 @@ public class IntakeResource extends AbstractCollectionSpaceResourceImpl {
     public IntakesCommonList getIntakeList(@Context UriInfo ui,
                @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords) {
        IntakesCommonList result = null;
+       MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
        
        if (keywords != null) {
-               result = searchIntakes(keywords);
+               result = searchIntakes(queryParams, keywords);
        } else {
-               result = getIntakeList();
+               result = getIntakeList(queryParams);
        }
  
        return result;
@@ -238,10 +249,10 @@ public class IntakeResource extends AbstractCollectionSpaceResourceImpl {
      * 
      * @return the intake list
      */
-    private IntakesCommonList getIntakeList() {
+    private IntakesCommonList getIntakeList(MultivaluedMap<String, String> queryParams) {
         IntakesCommonList intakeObjectList;
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).getAll(ctx, handler);
             intakeObjectList = (IntakesCommonList) handler.getCommonPartList();
@@ -276,7 +287,8 @@ public class IntakeResource extends AbstractCollectionSpaceResourceImpl {
                @Context UriInfo ui) {
        AuthorityRefList authRefList = null;
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+               MultivaluedMap<String, String> queryParams = ui.getQueryParameters();           
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
             DocumentWrapper<DocumentModel> docWrapper = 
                getRepositoryClient(ctx).getDoc(ctx, csid);
             RemoteDocumentModelHandlerImpl handler 
@@ -305,10 +317,11 @@ public class IntakeResource extends AbstractCollectionSpaceResourceImpl {
      * 
      * @return the intake list
      */
+    @Deprecated
     public IntakesCommonList getIntakeList(List<String> csidList) {
         IntakesCommonList intakeObjectList = new IntakesCommonList();
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).get(ctx, csidList, handler);
             intakeObjectList = (IntakesCommonList) handler.getCommonPartList();
@@ -352,7 +365,7 @@ public class IntakeResource extends AbstractCollectionSpaceResourceImpl {
         }
         MultipartOutput result = null;
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(theUpdate, getServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(theUpdate);
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).update(ctx, csid, handler);
             result = (MultipartOutput) ctx.getOutput();
@@ -398,7 +411,7 @@ public class IntakeResource extends AbstractCollectionSpaceResourceImpl {
             throw new WebApplicationException(response);
         }
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             getRepositoryClient(ctx).delete(ctx, csid);
             return Response.status(HttpResponseCodes.SC_OK).build();
         } catch (UnauthorizedException ue) {
@@ -431,9 +444,11 @@ public class IntakeResource extends AbstractCollectionSpaceResourceImpl {
     @GET
     @Path("/search")    
     @Produces("application/xml")
+    @Deprecated
     public IntakesCommonList keywordsSearchIntakes(@Context UriInfo ui,
                @QueryParam (IQueryManager.SEARCH_TYPE_KEYWORDS) String keywords) {
-       return searchIntakes(keywords);
+       MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
+       return searchIntakes(queryParams, keywords);
     }
        
     /**
@@ -443,16 +458,17 @@ public class IntakeResource extends AbstractCollectionSpaceResourceImpl {
      * 
      * @return the intakes common list
      */
-    private IntakesCommonList searchIntakes(String keywords) {
+    private IntakesCommonList searchIntakes(MultivaluedMap<String, String> queryParams,
+               String keywords) {
        IntakesCommonList intakesObjectList;
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
             DocumentHandler handler = createDocumentHandler(ctx);
 
             // perform a keyword search
             if (keywords != null && !keywords.isEmpty()) {
                String whereClause = QueryManager.createWhereClauseFromKeywords(keywords);
-                   DocumentFilter documentFilter = handler.createDocumentFilter(ctx);
+                   DocumentFilter documentFilter = handler.getDocumentFilter();
                    documentFilter.setWhereClause(whereClause);
                    if (logger.isDebugEnabled()) {
                        logger.debug("The WHERE clause is: " + documentFilter.getWhereClause());
@@ -476,6 +492,5 @@ public class IntakeResource extends AbstractCollectionSpaceResourceImpl {
             throw new WebApplicationException(response);
         }
         return intakesObjectList;
-    }    
-    
+    }
 }
index 766fcbda71fe101a1e2d3ace318c4eda03b3bbc7..79c302bdaa0ca2149c640c46bdf272d2f268e9b1 100644 (file)
@@ -36,11 +36,12 @@ 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;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
 
-import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl;
+import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl;
 import org.collectionspace.services.common.ClientType;
 import org.collectionspace.services.common.ServiceMain;
 import org.collectionspace.services.common.authorityref.AuthorityRefList;
@@ -70,7 +71,8 @@ import org.slf4j.LoggerFactory;
 @Path("/loansin")
 @Consumes("multipart/mixed")
 @Produces("multipart/mixed")
-public class LoaninResource extends AbstractCollectionSpaceResourceImpl {
+public class LoaninResource extends
+               AbstractMultiPartCollectionSpaceResourceImpl {
 
     /** The Constant serviceName. */
     private final static String serviceName = "loansin";
@@ -107,19 +109,27 @@ public class LoaninResource extends AbstractCollectionSpaceResourceImpl {
     }
 
     /* (non-Javadoc)
-     * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#createDocumentHandler(org.collectionspace.services.common.context.ServiceContext)
+     * @see org.collectionspace.services.common.CollectionSpaceResource#getCommonPartClass()
      */
     @Override
-    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
-        DocumentHandler docHandler = ctx.getDocumentHandler();
-        if (ctx.getInput() != null) {
-            Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), LoansinCommon.class);
-            if (obj != null) {
-                docHandler.setCommonPart((LoansinCommon) obj);
-            }
-        }
-        return docHandler;
+    public Class<LoansinCommon> getCommonPartClass() {
+       return LoansinCommon.class;
     }
+    
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#createDocumentHandler(org.collectionspace.services.common.context.ServiceContext)
+     */
+//    @Override
+//    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
+//        DocumentHandler docHandler = ctx.getDocumentHandler();
+//        if (ctx.getInput() != null) {
+//            Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), LoansinCommon.class);
+//            if (obj != null) {
+//                docHandler.setCommonPart((LoansinCommon) obj);
+//            }
+//        }
+//        return docHandler;
+//    }
 
     /**
      * Creates the loanin.
@@ -131,7 +141,7 @@ public class LoaninResource extends AbstractCollectionSpaceResourceImpl {
     @POST
     public Response createLoanin(MultipartInput input) {
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(input);
             DocumentHandler handler = createDocumentHandler(ctx);
             String csid = getRepositoryClient(ctx).create(ctx, handler);
             //loaninObject.setCsid(csid);
@@ -176,7 +186,7 @@ public class LoaninResource extends AbstractCollectionSpaceResourceImpl {
         }
         MultipartOutput result = null;
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).get(ctx, csid, handler);
             result = (MultipartOutput) ctx.getOutput();
@@ -222,11 +232,11 @@ public class LoaninResource extends AbstractCollectionSpaceResourceImpl {
     public LoansinCommonList getLoaninList(@Context UriInfo ui,
                @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords) {
        LoansinCommonList result = null;
-       
+       MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
        if (keywords != null) {
-               result = searchLoansin(keywords);
+               result = searchLoansin(queryParams, keywords);
        } else {
-               result = getLoaninList();
+               result = getLoaninList(queryParams);
        }
  
        return result;
@@ -237,10 +247,10 @@ public class LoaninResource extends AbstractCollectionSpaceResourceImpl {
      * 
      * @return the loanin list
      */
-    private LoansinCommonList getLoaninList() {
+    private LoansinCommonList getLoaninList(MultivaluedMap<String, String> queryParams) {
         LoansinCommonList loaninObjectList;
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).getAll(ctx, handler);
             loaninObjectList = (LoansinCommonList) handler.getCommonPartList();
@@ -275,7 +285,8 @@ public class LoaninResource extends AbstractCollectionSpaceResourceImpl {
                @Context UriInfo ui) {
        AuthorityRefList authRefList = null;
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+               MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
             DocumentWrapper<DocumentModel> docWrapper = 
                getRepositoryClient(ctx).getDoc(ctx, csid);
             RemoteDocumentModelHandlerImpl handler 
@@ -304,10 +315,11 @@ public class LoaninResource extends AbstractCollectionSpaceResourceImpl {
      * 
      * @return the loanin list
      */
+    @Deprecated
     public LoansinCommonList getLoaninList(List<String> csidList) {
         LoansinCommonList loaninObjectList = new LoansinCommonList();
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).get(ctx, csidList, handler);
             loaninObjectList = (LoansinCommonList) handler.getCommonPartList();
@@ -351,7 +363,7 @@ public class LoaninResource extends AbstractCollectionSpaceResourceImpl {
         }
         MultipartOutput result = null;
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(theUpdate, getServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(theUpdate);
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).update(ctx, csid, handler);
             result = (MultipartOutput) ctx.getOutput();
@@ -397,7 +409,7 @@ public class LoaninResource extends AbstractCollectionSpaceResourceImpl {
             throw new WebApplicationException(response);
         }
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             getRepositoryClient(ctx).delete(ctx, csid);
             return Response.status(HttpResponseCodes.SC_OK).build();
         } catch (UnauthorizedException ue) {
@@ -418,23 +430,7 @@ public class LoaninResource extends AbstractCollectionSpaceResourceImpl {
             throw new WebApplicationException(response);
         }
     }
-    
-    /**
-     * Keywords search loansin.
-     * 
-     * @param ui the ui
-     * @param keywords the keywords
-     * 
-     * @return the loansin common list
-     */
-    @GET
-    @Path("/search")    
-    @Produces("application/xml")
-    public LoansinCommonList keywordsSearchLoansin(@Context UriInfo ui,
-               @QueryParam (IQueryManager.SEARCH_TYPE_KEYWORDS) String keywords) {
-       return searchLoansin(keywords);
-    }
-       
+               
     /**
      * Search loansin.
      * 
@@ -442,10 +438,11 @@ public class LoaninResource extends AbstractCollectionSpaceResourceImpl {
      * 
      * @return the loansin common list
      */
-    private LoansinCommonList searchLoansin(String keywords) {
+    private LoansinCommonList searchLoansin(MultivaluedMap<String, String> queryParams,
+               String keywords) {
        LoansinCommonList loansinObjectList;
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
             DocumentHandler handler = createDocumentHandler(ctx);
 
             // perform a keyword search
@@ -475,6 +472,5 @@ public class LoaninResource extends AbstractCollectionSpaceResourceImpl {
             throw new WebApplicationException(response);
         }
         return loansinObjectList;
-    }    
-    
+    }
 }
index 367a4130cf59bff942acefea01a812799626e09f..3b45ff4e6807dd27917d128de61ae7e32e4cb9a0 100644 (file)
@@ -41,11 +41,11 @@ import javax.ws.rs.core.UriInfo;
 
 import org.collectionspace.services.OrgAuthorityJAXBSchema;
 import org.collectionspace.services.OrganizationJAXBSchema;
-import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl;
+import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl;
 import org.collectionspace.services.common.ClientType;
 import org.collectionspace.services.common.ServiceMain;
 import org.collectionspace.services.common.context.MultipartServiceContext;
-import org.collectionspace.services.common.context.MultipartServiceContextFactory;
+//import org.collectionspace.services.common.context.MultipartServiceContextFactory;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.document.BadRequestException;
 import org.collectionspace.services.common.document.DocumentFilter;
@@ -65,22 +65,40 @@ import org.jboss.resteasy.util.HttpResponseCodes;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+/**
+ * The Class OrgAuthorityResource.
+ */
 @Path("/orgauthorities")
 @Consumes("multipart/mixed")
 @Produces("multipart/mixed")
-public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
+public class OrgAuthorityResource extends
+               AbstractMultiPartCollectionSpaceResourceImpl {
 
+    /** The Constant orgAuthorityServiceName. */
     private final static String orgAuthorityServiceName = "orgauthorities";
+    
+    /** The Constant organizationServiceName. */
     private final static String organizationServiceName = "organizations";
+    
+    /** The logger. */
     final Logger logger = LoggerFactory.getLogger(OrgAuthorityResource.class);
     //FIXME retrieve client type from configuration
+    /** The Constant CLIENT_TYPE. */
     final static ClientType CLIENT_TYPE = ServiceMain.getInstance().getClientType();
+    
+    /** The contact resource. */
     private ContactResource contactResource = new ContactResource();
 
+    /**
+     * Instantiates a new org authority resource.
+     */
     public OrgAuthorityResource() {
         // do nothing
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getVersionString()
+     */
     @Override
     protected String getVersionString() {
        /** The last change revision. */
@@ -88,15 +106,36 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
        return lastChangeRevision;
     }
     
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getServiceName()
+     */
     @Override
     public String getServiceName() {
         return orgAuthorityServiceName;
     }
+    
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.CollectionSpaceResource#getCommonPartClass()
+     */
+    @Override
+    public Class<OrgauthoritiesCommon> getCommonPartClass() {
+       return OrgauthoritiesCommon.class;
+    }    
 
+    /**
+     * Gets the item service name.
+     * 
+     * @return the item service name
+     */
     public String getItemServiceName() {
         return organizationServiceName;
     }
 
+    /**
+     * Gets the contact service name.
+     * 
+     * @return the contact service name
+     */
     public String getContactServiceName() {
         return contactResource.getServiceName();
     }
@@ -108,57 +147,103 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
     return ctx;
     }
      */
-    @Override
-    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
-        DocumentHandler docHandler =ctx.getDocumentHandler();
-        if (ctx.getInput() != null) {
-            Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), OrgauthoritiesCommon.class);
-            if (obj != null) {
-                docHandler.setCommonPart((OrgauthoritiesCommon) obj);
-            }
-        }
-        return docHandler;
-    }
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#createDocumentHandler(org.collectionspace.services.common.context.ServiceContext)
+     */
+//    @Override
+//    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
+//        DocumentHandler docHandler =ctx.getDocumentHandler();
+//        if (ctx.getInput() != null) {
+//            Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), OrgauthoritiesCommon.class);
+//            if (obj != null) {
+//                docHandler.setCommonPart((OrgauthoritiesCommon) obj);
+//            }
+//        }
+//        return docHandler;
+//    }
 
+    /**
+     * Creates the item document handler.
+     * 
+     * @param ctx the ctx
+     * @param inAuthority the in authority
+     * 
+     * @return the document handler
+     * 
+     * @throws Exception the exception
+     */
     private DocumentHandler createItemDocumentHandler(
-            ServiceContext ctx,
-            String inAuthority) throws Exception {
-        DocumentHandler docHandler = ctx.getDocumentHandler();
-        ((OrganizationDocumentModelHandler) docHandler).setInAuthority(inAuthority);
-        if (ctx.getInput() != null) {
-            Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(getItemServiceName()),
-                    OrganizationsCommon.class);
-            if (obj != null) {
-                docHandler.setCommonPart((OrganizationsCommon) obj);
-            }
-        }
+               ServiceContext<MultipartInput, MultipartOutput> ctx,
+            String inAuthority) throws Exception {     
+       OrganizationDocumentModelHandler docHandler = (OrganizationDocumentModelHandler)createDocumentHandler(
+                       ctx,
+                       ctx.getCommonPartLabel(getItemServiceName()),
+                       OrganizationsCommon.class);             
+        docHandler.setInAuthority(inAuthority);
+        
+        
+//        ((OrganizationDocumentModelHandler) docHandler).setInAuthority(inAuthority);
+//        if (ctx.getInput() != null) {
+//            Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(getItemServiceName()),
+//                    OrganizationsCommon.class);
+//            if (obj != null) {
+//                docHandler.setCommonPart((OrganizationsCommon) obj);
+//            }
+//        }
+
         return docHandler;
     }
 
+    /**
+     * Creates the contact document handler.
+     * 
+     * @param ctx the ctx
+     * @param inAuthority the in authority
+     * @param inItem the in item
+     * 
+     * @return the document handler
+     * 
+     * @throws Exception the exception
+     */
     private DocumentHandler createContactDocumentHandler(
-            ServiceContext ctx, String inAuthority,
+               ServiceContext<MultipartInput, MultipartOutput> ctx, String inAuthority,
             String inItem) throws Exception {
-        DocumentHandler docHandler = ctx.getDocumentHandler();
-        // Set the inAuthority and inItem values, which specify the
-        // parent authority (e.g. PersonAuthority, OrgAuthority) and the item
-        // (e.g. Person, Organization) with which the Contact is associated.
-        ((ContactDocumentModelHandler) docHandler).setInAuthority(inAuthority);
-        ((ContactDocumentModelHandler) docHandler).setInItem(inItem);
-        if (ctx.getInput() != null) {
-            Object obj = ((MultipartServiceContext) ctx)
-                .getInputPart(ctx.getCommonPartLabel(getContactServiceName()),
-                ContactsCommon.class);
-            if (obj != null) {
-                docHandler.setCommonPart((ContactsCommon) obj);
-            }
-        }
+       
+       ContactDocumentModelHandler docHandler = (ContactDocumentModelHandler)createDocumentHandler(
+                       ctx,
+                       ctx.getCommonPartLabel(getContactServiceName()),
+                       ContactsCommon.class);          
+        docHandler.setInAuthority(inAuthority);
+        docHandler.setInItem(inItem);
+       
+//        DocumentHandler docHandler = ctx.getDocumentHandler();
+//        // Set the inAuthority and inItem values, which specify the
+//        // parent authority (e.g. PersonAuthority, OrgAuthority) and the item
+//        // (e.g. Person, Organization) with which the Contact is associated.
+//        ((ContactDocumentModelHandler) docHandler).setInAuthority(inAuthority);
+//        ((ContactDocumentModelHandler) docHandler).setInItem(inItem);
+//        if (ctx.getInput() != null) {
+//            Object obj = ((MultipartServiceContext) ctx)
+//                .getInputPart(ctx.getCommonPartLabel(getContactServiceName()),
+//                ContactsCommon.class);
+//            if (obj != null) {
+//                docHandler.setCommonPart((ContactsCommon) obj);
+//            }
+//        }
         return docHandler;
     }
 
+    /**
+     * Creates the org authority.
+     * 
+     * @param input the input
+     * 
+     * @return the response
+     */
     @POST
     public Response createOrgAuthority(MultipartInput input) {
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(input);
             DocumentHandler handler = createDocumentHandler(ctx);
             String csid = getRepositoryClient(ctx).create(ctx, handler);
             //orgAuthorityObject.setCsid(csid);
@@ -184,7 +269,13 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
         }
     }
 
-
+    /**
+     * Gets the org authority by name.
+     * 
+     * @param specifier the specifier
+     * 
+     * @return the org authority by name
+     */
     @GET
     @Path("urn:cspace:name({specifier})")
     public MultipartOutput getOrgAuthorityByName(@PathParam("specifier") String specifier) {
@@ -208,7 +299,7 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
         } 
         MultipartOutput result = null;
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             DocumentHandler handler = createDocumentHandler(ctx);
             DocumentFilter myFilter = new DocumentFilter(whereClause, 0, 1);
             handler.setDocumentFilter(myFilter);
@@ -243,6 +334,13 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
         return result;
     }
 
+    /**
+     * Gets the org authority.
+     * 
+     * @param csid the csid
+     * 
+     * @return the org authority
+     */
     @GET
     @Path("{csid}")
     public MultipartOutput getOrgAuthority(@PathParam("csid") String csid) {
@@ -259,7 +357,7 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
         }
         MultipartOutput result = null;
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).get(ctx, csid, handler);
             result = (MultipartOutput) ctx.getOutput();
@@ -292,15 +390,22 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
         return result;
     }
 
+    /**
+     * Gets the org authority list.
+     * 
+     * @param ui the ui
+     * 
+     * @return the org authority list
+     */
     @GET
     @Produces("application/xml")
     public OrgauthoritiesCommonList getOrgAuthorityList(@Context UriInfo ui) {
         OrgauthoritiesCommonList orgAuthorityObjectList = new OrgauthoritiesCommonList();
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
             DocumentHandler handler = createDocumentHandler(ctx);
-            DocumentFilter myFilter = handler.createDocumentFilter(ctx); //new DocumentFilter();
+            DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter();
             myFilter.setPagination(queryParams);
             String nameQ = queryParams.getFirst("refName");
             if (nameQ != null) {
@@ -324,6 +429,14 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
         return orgAuthorityObjectList;
     }
 
+    /**
+     * Update org authority.
+     * 
+     * @param csid the csid
+     * @param theUpdate the the update
+     * 
+     * @return the multipart output
+     */
     @PUT
     @Path("{csid}")
     public MultipartOutput updateOrgAuthority(
@@ -341,7 +454,7 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
         }
         MultipartOutput result = null;
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(theUpdate, getServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(theUpdate);
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).update(ctx, csid, handler);
             result = (MultipartOutput) ctx.getOutput();
@@ -369,6 +482,13 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
         return result;
     }
 
+    /**
+     * Delete org authority.
+     * 
+     * @param csid the csid
+     * 
+     * @return the response
+     */
     @DELETE
     @Path("{csid}")
     public Response deleteOrgAuthority(@PathParam("csid") String csid) {
@@ -384,7 +504,7 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
             throw new WebApplicationException(response);
         }
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             getRepositoryClient(ctx).delete(ctx, csid);
             return Response.status(HttpResponseCodes.SC_OK).build();
         } catch (UnauthorizedException ue) {
@@ -414,7 +534,8 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
     @Path("{csid}/items")
     public Response createOrganization(@PathParam("csid") String parentcsid, MultipartInput input) {
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getItemServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName(),
+                               input);
             DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
             String itemcsid = getRepositoryClient(ctx).create(ctx, handler);
             UriBuilder path = UriBuilder.fromResource(OrgAuthorityResource.class);
@@ -439,6 +560,14 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
         }
     }
 
+    /**
+     * Gets the organization.
+     * 
+     * @param parentcsid the parentcsid
+     * @param itemcsid the itemcsid
+     * 
+     * @return the organization
+     */
     @GET
     @Path("{csid}/items/{itemcsid}")
     public MultipartOutput getOrganization(
@@ -464,7 +593,7 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
         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());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName());
             DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
             getRepositoryClient(ctx).get(ctx, itemcsid, handler);
             // TODO should we assert that the item is in the passed orgAuthority?
@@ -498,6 +627,15 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
         return result;
     }
 
+    /**
+     * Gets the organization list.
+     * 
+     * @param parentcsid the parentcsid
+     * @param partialTerm the partial term
+     * @param ui the ui
+     * 
+     * @return the organization list
+     */
     @GET
     @Path("{csid}/items")
     @Produces("application/xml")
@@ -507,12 +645,13 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
             @Context UriInfo ui) {
         OrganizationsCommonList organizationObjectList = new OrganizationsCommonList();
         try {
+            MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
             // Note that docType defaults to the ServiceName, so we're fine with that.
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getItemServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName(),
+                               queryParams);
             DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
-            MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
-            DocumentFilter myFilter = handler.createDocumentFilter(ctx); //new DocumentFilter();
-            myFilter.setPagination(queryParams);
+            DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter();
+            myFilter.setPagination(queryParams); //FIXME (this is unnecessary since it is already set by "createContactDocumentHandler" method
             myFilter.setWhereClause(OrganizationJAXBSchema.ORGANIZATIONS_COMMON +
                        ":" + OrganizationJAXBSchema.IN_AUTHORITY + "=" +
                        "'" + parentcsid + "'");
@@ -542,6 +681,15 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
         return organizationObjectList;
     }
 
+    /**
+     * Gets the organization list by auth name.
+     * 
+     * @param parentSpecifier the parent specifier
+     * @param partialTerm the partial term
+     * @param ui the ui
+     * 
+     * @return the organization list by auth name
+     */
     @GET
     @Path("urn:cspace:name({specifier})/items")
     @Produces("application/xml")
@@ -551,20 +699,19 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
             @Context UriInfo ui) {
        OrganizationsCommonList personObjectList = new OrganizationsCommonList();
         try {
+            MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
             String whereClause =
                OrgAuthorityJAXBSchema.ORGAUTHORITIES_COMMON+
                ":"+OrgAuthorityJAXBSchema.DISPLAY_NAME+
                "='"+parentSpecifier+"'";
             // Need to get an Authority by name
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
-            String parentcsid = 
-               getRepositoryClient(ctx).findDocCSID(ctx, whereClause);
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
+            String parentcsid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause);
 
-            ctx = MultipartServiceContextFactory.get().createServiceContext(null, getItemServiceName());
+            ctx = createServiceContext(getItemServiceName(), queryParams);
             DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
-            MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
-            DocumentFilter myFilter = handler.createDocumentFilter(ctx);// new DocumentFilter();
-            myFilter.setPagination(queryParams);
+            DocumentFilter myFilter = handler.createDocumentFilter();// new DocumentFilter();
+            myFilter.setPagination(queryParams); //FIXME (this is unnecessary since it is already set by "createContactDocumentHandler" method
 
             // Add the where clause "organizations_common:inAuthority='" + parentcsid + "'"
             myFilter.setWhereClause(OrganizationJAXBSchema.ORGANIZATIONS_COMMON + ":" +
@@ -598,6 +745,15 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
         return personObjectList;
     }
 
+    /**
+     * Update organization.
+     * 
+     * @param parentcsid the parentcsid
+     * @param itemcsid the itemcsid
+     * @param theUpdate the the update
+     * 
+     * @return the multipart output
+     */
     @PUT
     @Path("{csid}/items/{itemcsid}")
     public MultipartOutput updateOrganization(
@@ -624,7 +780,8 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
         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());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName(),
+                               theUpdate);
             DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
             getRepositoryClient(ctx).update(ctx, itemcsid, handler);
             result = (MultipartOutput) ctx.getOutput();
@@ -652,6 +809,14 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
         return result;
     }
 
+    /**
+     * Delete organization.
+     * 
+     * @param parentcsid the parentcsid
+     * @param itemcsid the itemcsid
+     * 
+     * @return the response
+     */
     @DELETE
     @Path("{csid}/items/{itemcsid}")
     public Response deleteOrganization(
@@ -676,7 +841,7 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
         }
         try {
             // Note that we have to create the service context for the Items, not the main service
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getItemServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName());
             getRepositoryClient(ctx).delete(ctx, itemcsid);
             return Response.status(HttpResponseCodes.SC_OK).build();
         } catch (UnauthorizedException ue) {
@@ -711,7 +876,7 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
         try {
             // Note that we have to create the service context and document
             // handler for the Contact service, not the main service.
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getContactServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getContactServiceName(), input);
             DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid);
             String csid = getRepositoryClient(ctx).create(ctx, handler);
             UriBuilder path = UriBuilder.fromResource(OrgAuthorityResource.class);
@@ -739,6 +904,15 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
 
     }
 
+    /**
+     * Gets the contact list.
+     * 
+     * @param parentcsid the parentcsid
+     * @param itemcsid the itemcsid
+     * @param ui the ui
+     * 
+     * @return the contact list
+     */
     @GET
     @Produces({"application/xml"})
     @Path("{parentcsid}/items/{itemcsid}/contacts/")
@@ -748,11 +922,12 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
             @Context UriInfo ui) {
         ContactsCommonList contactObjectList = new ContactsCommonList();
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getContactServiceName());
-            DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid);
             MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
-            DocumentFilter myFilter = handler.createDocumentFilter(ctx); //new DocumentFilter();
-            myFilter.setPagination(queryParams);
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getContactServiceName(),
+                               queryParams);
+            DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid);
+            DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter();
+            myFilter.setPagination(queryParams); //FIXME (this is unnecessary since it is already set by "createContactDocumentHandler" method
             myFilter.setWhereClause(ContactJAXBSchema.CONTACTS_COMMON + ":" +
                 ContactJAXBSchema.IN_AUTHORITY +
                 "='" + parentcsid + "'" +
@@ -779,6 +954,15 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
         return contactObjectList;
     }
 
+    /**
+     * Gets the contact.
+     * 
+     * @param parentcsid the parentcsid
+     * @param itemcsid the itemcsid
+     * @param csid the csid
+     * 
+     * @return the contact
+     */
     @GET
     @Path("{parentcsid}/items/{itemcsid}/contacts/{csid}")
     public MultipartOutput getContact(
@@ -793,7 +977,7 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
         try {
             // Note that we have to create the service context and document
             // handler for the Contact service, not the main service.
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getContactServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getContactServiceName());
             DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid);
             getRepositoryClient(ctx).get(ctx, csid, handler);
             result = (MultipartOutput) ctx.getOutput();
@@ -828,6 +1012,16 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
 
     }
 
+    /**
+     * Update contact.
+     * 
+     * @param parentcsid the parentcsid
+     * @param itemcsid the itemcsid
+     * @param csid the csid
+     * @param theUpdate the the update
+     * 
+     * @return the multipart output
+     */
     @PUT
     @Path("{parentcsid}/items/{itemcsid}/contacts/{csid}")
     public MultipartOutput updateContact(
@@ -864,8 +1058,7 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
         try {
             // Note that we have to create the service context and document
             // handler for the Contact service, not the main service.
-            ServiceContext ctx = MultipartServiceContextFactory.get()
-                .createServiceContext(theUpdate, getContactServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getContactServiceName(), theUpdate);
             DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid);
             getRepositoryClient(ctx).update(ctx, csid, handler);
             result = (MultipartOutput) ctx.getOutput();
@@ -893,6 +1086,15 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
         return result;
     }
 
+    /**
+     * Delete contact.
+     * 
+     * @param parentcsid the parentcsid
+     * @param itemcsid the itemcsid
+     * @param csid the csid
+     * 
+     * @return the response
+     */
     @DELETE
     @Path("{parentcsid}/items/{itemcsid}/contacts/{csid}")
     public Response deleteContact(
@@ -927,8 +1129,7 @@ public class OrgAuthorityResource extends AbstractCollectionSpaceResourceImpl {
         try {
             // Note that we have to create the service context for the
             // Contact service, not the main service.
-            ServiceContext ctx =
-                MultipartServiceContextFactory.get().createServiceContext(null, getContactServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getContactServiceName());
             getRepositoryClient(ctx).delete(ctx, csid);
             return Response.status(HttpResponseCodes.SC_OK).build();
          } catch (UnauthorizedException ue) {
index 8bdf3a9b5eaaebecf9b828e57fb801a42980bfac..71a025cb375e6aeb9c44423bc58a239af18ef2e3 100644 (file)
@@ -23,7 +23,7 @@
  */
 package org.collectionspace.services.person;
 
-import java.net.URI;
+//import java.net.URI;
 import javax.ws.rs.Consumes;
 import javax.ws.rs.DELETE;
 import javax.ws.rs.GET;
@@ -35,7 +35,7 @@ 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.HttpHeaders;
+//import javax.ws.rs.core.HttpHeaders;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
@@ -43,19 +43,19 @@ import javax.ws.rs.core.UriInfo;
 
 import org.collectionspace.services.PersonAuthorityJAXBSchema;
 import org.collectionspace.services.PersonJAXBSchema;
-import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl;
+import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl;
 import org.collectionspace.services.common.ClientType;
 import org.collectionspace.services.common.ServiceMain;
-import org.collectionspace.services.common.context.MultipartServiceContext;
-import org.collectionspace.services.common.context.MultipartServiceContextFactory;
+//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.BadRequestException;
 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.DocumentWrapper;
+//import org.collectionspace.services.common.document.DocumentWrapper;
 import org.collectionspace.services.common.security.UnauthorizedException;
-import org.collectionspace.services.common.vocabulary.RefNameUtils;
+//import org.collectionspace.services.common.vocabulary.RefNameUtils;
 import org.collectionspace.services.common.query.IQueryManager;
 import org.collectionspace.services.contact.ContactResource;
 import org.collectionspace.services.contact.ContactsCommon;
@@ -66,26 +66,44 @@ import org.collectionspace.services.person.nuxeo.PersonDocumentModelHandler;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartInput;
 import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput;
 import org.jboss.resteasy.util.HttpResponseCodes;
-import org.nuxeo.ecm.core.api.DocumentModel;
+//import org.nuxeo.ecm.core.api.DocumentModel;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+/**
+ * The Class PersonAuthorityResource.
+ */
 @Path("/personauthorities")
 @Consumes("multipart/mixed")
 @Produces("multipart/mixed")
-public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl {
+public class PersonAuthorityResource extends
+               AbstractMultiPartCollectionSpaceResourceImpl {
 
+    /** The Constant personAuthorityServiceName. */
     private final static String personAuthorityServiceName = "personauthorities";
+    
+    /** The Constant personServiceName. */
     private final static String personServiceName = "persons";
+    
+    /** The logger. */
     final Logger logger = LoggerFactory.getLogger(PersonAuthorityResource.class);
     //FIXME retrieve client type from configuration
+    /** The Constant CLIENT_TYPE. */
     final static ClientType CLIENT_TYPE = ServiceMain.getInstance().getClientType();
+    
+    /** The contact resource. */
     private ContactResource contactResource = new ContactResource();
 
+    /**
+     * Instantiates a new person authority resource.
+     */
     public PersonAuthorityResource() {
         // do nothing
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getVersionString()
+     */
     @Override
     protected String getVersionString() {
        /** The last change revision. */
@@ -93,70 +111,117 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl
        return lastChangeRevision;
     }
     
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getServiceName()
+     */
     @Override
     public String getServiceName() {
         return personAuthorityServiceName;
     }
 
+    @Override
+    public Class<PersonauthoritiesCommon> getCommonPartClass() {
+       return PersonauthoritiesCommon.class;
+    }
+    
+    /**
+     * Gets the item service name.
+     * 
+     * @return the item service name
+     */
     public String getItemServiceName() {
         return personServiceName;
     }
 
+    /**
+     * Gets the contact service name.
+     * 
+     * @return the contact service name
+     */
     public String getContactServiceName() {
         return contactResource.getServiceName();
     }
 
-    @Override
-    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
-        DocumentHandler docHandler = ctx.getDocumentHandler();
-        if (ctx.getInput() != null) {
-            Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), PersonauthoritiesCommon.class);
-            if (obj != null) {
-                docHandler.setCommonPart((PersonauthoritiesCommon) obj);
-            }
-        }
-        return docHandler;
-    }
+//    @Override
+//    public DocumentHandler createDocumentHandler(ServiceContext<MultipartInput, MultipartOutput> ctx) throws Exception {
+//        DocumentHandler docHandler = ctx.getDocumentHandler();
+//        if (ctx.getInput() != null) {
+//            Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), PersonauthoritiesCommon.class);
+//            if (obj != null) {
+//                docHandler.setCommonPart((PersonauthoritiesCommon) obj);
+//            }
+//        }
+//        return docHandler;
+//    }
 
-    private DocumentHandler createItemDocumentHandler(
-            ServiceContext ctx,
-            String inAuthority) throws Exception {
-        DocumentHandler docHandler = ctx.getDocumentHandler();
-        ((PersonDocumentModelHandler) docHandler).setInAuthority(inAuthority);
-        if (ctx.getInput() != null) {
-            Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(getItemServiceName()),
-                    PersonsCommon.class);
-            if (obj != null) {
-                docHandler.setCommonPart((PersonsCommon) obj);
-            }
-        }
+    /**
+ * Creates the item document handler.
+ * 
+ * @param ctx the ctx
+ * @param inAuthority the in authority
+ * 
+ * @return the document handler
+ * 
+ * @throws Exception the exception
+ */
+    private DocumentHandler createItemDocumentHandler(ServiceContext<MultipartInput, MultipartOutput> ctx,
+            String inAuthority) throws Exception {    
+        PersonDocumentModelHandler docHandler = (PersonDocumentModelHandler)createDocumentHandler(ctx,
+                       ctx.getCommonPartLabel(getItemServiceName()),
+                       PersonsCommon.class);           
+        docHandler.setInAuthority(inAuthority);
+        
         return docHandler;
     }
 
+    /**
+     * Creates the contact document handler.
+     * 
+     * @param ctx the ctx
+     * @param inAuthority the in authority
+     * @param inItem the in item
+     * 
+     * @return the document handler
+     * 
+     * @throws Exception the exception
+     */
     private DocumentHandler createContactDocumentHandler(
-            ServiceContext ctx, String inAuthority,
+               ServiceContext<MultipartInput, MultipartOutput> ctx, String inAuthority,
             String inItem) throws Exception {
-        DocumentHandler docHandler = ctx.getDocumentHandler();
-        // Set the inAuthority and inItem values, which specify the
-        // parent authority (e.g. PersonAuthority, OrgAuthority) and the item
-        // (e.g. Person, Organization) with which the Contact is associated.
-        ((ContactDocumentModelHandler) docHandler).setInAuthority(inAuthority);
-        ((ContactDocumentModelHandler) docHandler).setInItem(inItem);
-        if (ctx.getInput() != null) {
-            Object obj = ((MultipartServiceContext) ctx)
-                .getInputPart(ctx.getCommonPartLabel(getContactServiceName()),
-                ContactsCommon.class);
-            if (obj != null) {
-                docHandler.setCommonPart((ContactsCommon) obj);
-            }
-        }
+       ContactDocumentModelHandler docHandler = (ContactDocumentModelHandler)createDocumentHandler(ctx,
+                       ctx.getCommonPartLabel(getContactServiceName()),
+                       ContactsCommon.class);          
+        docHandler.setInAuthority(inAuthority);
+        docHandler.setInItem(inItem);
+       
+//        DocumentHandler docHandler = ctx.getDocumentHandler();
+//        // Set the inAuthority and inItem values, which specify the
+//        // parent authority (e.g. PersonAuthority, OrgAuthority) and the item
+//        // (e.g. Person, Organization) with which the Contact is associated.
+//        ((ContactDocumentModelHandler) docHandler).setInAuthority(inAuthority);
+//        ((ContactDocumentModelHandler) docHandler).setInItem(inItem);
+//        if (ctx.getInput() != null) {
+//            Object obj = ((MultipartServiceContext) ctx)
+//                .getInputPart(ctx.getCommonPartLabel(getContactServiceName()),
+//                ContactsCommon.class);
+//            if (obj != null) {
+//                docHandler.setCommonPart((ContactsCommon) obj);
+//            }
+//        }
         return docHandler;
     }
 
+    /**
+     * Creates the person authority.
+     * 
+     * @param input the input
+     * 
+     * @return the response
+     */
     @POST
     public Response createPersonAuthority(MultipartInput input) {
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(input);
             DocumentHandler handler = createDocumentHandler(ctx);
             String csid = getRepositoryClient(ctx).create(ctx, handler);
             //personAuthorityObject.setCsid(csid);
@@ -182,6 +247,13 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl
         }
     }
 
+    /**
+     * Gets the person authority by name.
+     * 
+     * @param specifier the specifier
+     * 
+     * @return the person authority by name
+     */
     @GET
     @Path("urn:cspace:name({specifier})")
     public MultipartOutput getPersonAuthorityByName(@PathParam("specifier") String specifier) {
@@ -205,7 +277,7 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl
         } 
         MultipartOutput result = null;
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             DocumentHandler handler = createDocumentHandler(ctx);
             DocumentFilter myFilter = new DocumentFilter(whereClause, 0, 1);
             handler.setDocumentFilter(myFilter);
@@ -240,6 +312,13 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl
         return result;
     }
 
+    /**
+     * Gets the person authority.
+     * 
+     * @param csid the csid
+     * 
+     * @return the person authority
+     */
     @GET
     @Path("{csid}")
     public MultipartOutput getPersonAuthority(@PathParam("csid") String csid) {
@@ -255,7 +334,7 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl
         } 
         MultipartOutput result = null;
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).get(ctx, csid, handler);
             result = (MultipartOutput) ctx.getOutput();
@@ -288,16 +367,23 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl
         return result;
     }
 
+    /**
+     * Gets the person authority list.
+     * 
+     * @param ui the ui
+     * 
+     * @return the person authority list
+     */
     @GET
     @Produces("application/xml")
     public PersonauthoritiesCommonList getPersonAuthorityList(@Context UriInfo ui) {
         PersonauthoritiesCommonList personAuthorityObjectList = new PersonauthoritiesCommonList();
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
             DocumentHandler handler = createDocumentHandler(ctx);
-            DocumentFilter myFilter = handler.createDocumentFilter(ctx); //new DocumentFilter();
-            myFilter.setPagination(queryParams);
+            DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter();
+            myFilter.setPagination(queryParams); //FIXME
             String nameQ = queryParams.getFirst("refName");
             if (nameQ != null) {
                 myFilter.setWhereClause("personauthorities_common:refName='" + nameQ + "'");
@@ -320,6 +406,14 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl
         return personAuthorityObjectList;
     }
 
+    /**
+     * Update person authority.
+     * 
+     * @param csid the csid
+     * @param theUpdate the the update
+     * 
+     * @return the multipart output
+     */
     @PUT
     @Path("{csid}")
     public MultipartOutput updatePersonAuthority(
@@ -337,7 +431,7 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl
         }
         MultipartOutput result = null;
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(theUpdate, getServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(theUpdate);
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).update(ctx, csid, handler);
             result = (MultipartOutput) ctx.getOutput();
@@ -365,6 +459,13 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl
         return result;
     }
 
+    /**
+     * Delete person authority.
+     * 
+     * @param csid the csid
+     * 
+     * @return the response
+     */
     @DELETE
     @Path("{csid}")
     public Response deletePersonAuthority(@PathParam("csid") String csid) {
@@ -380,7 +481,7 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl
             throw new WebApplicationException(response);
         }
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             getRepositoryClient(ctx).delete(ctx, csid);
             return Response.status(HttpResponseCodes.SC_OK).build();
         } catch (UnauthorizedException ue) {
@@ -410,7 +511,7 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl
     @Path("{csid}/items")
     public Response createPerson(@PathParam("csid") String parentcsid, MultipartInput input) {
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getItemServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName(), input);
             DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
             String itemcsid = getRepositoryClient(ctx).create(ctx, handler);
             UriBuilder path = UriBuilder.fromResource(PersonAuthorityResource.class);
@@ -435,6 +536,14 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl
         }
     }
 
+    /**
+     * Gets the person.
+     * 
+     * @param parentcsid the parentcsid
+     * @param itemcsid the itemcsid
+     * 
+     * @return the person
+     */
     @GET
     @Path("{csid}/items/{itemcsid}")
     public MultipartOutput getPerson(
@@ -460,7 +569,7 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl
         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());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName());
             DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
             getRepositoryClient(ctx).get(ctx, itemcsid, handler);
             // TODO should we assert that the item is in the passed personAuthority?
@@ -494,6 +603,15 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl
         return result;
     }
 
+    /**
+     * Gets the person list.
+     * 
+     * @param parentcsid the parentcsid
+     * @param partialTerm the partial term
+     * @param ui the ui
+     * 
+     * @return the person list
+     */
     @GET
     @Path("{csid}/items")
     @Produces("application/xml")
@@ -504,11 +622,12 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl
         PersonsCommonList personObjectList = new PersonsCommonList();
         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);
             MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
-            DocumentFilter myFilter = handler.createDocumentFilter(ctx); //new DocumentFilter();
-            myFilter.setPagination(queryParams);
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName(),
+                               queryParams);
+            DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
+            DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter();
+            myFilter.setPagination(queryParams); //FIXME (this is unnecessary since it is already set by "createContactDocumentHandler" method
 
             // Add the where clause "persons_common:inAuthority='" + parentcsid + "'"
             myFilter.setWhereClause(PersonJAXBSchema.PERSONS_COMMON + ":" +
@@ -542,6 +661,15 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl
         return personObjectList;
     }
 
+    /**
+     * Gets the person list by auth name.
+     * 
+     * @param parentSpecifier the parent specifier
+     * @param partialTerm the partial term
+     * @param ui the ui
+     * 
+     * @return the person list by auth name
+     */
     @GET
     @Path("urn:cspace:name({specifier})/items")
     @Produces("application/xml")
@@ -551,20 +679,20 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl
             @Context UriInfo ui) {
         PersonsCommonList personObjectList = new PersonsCommonList();
         try {
+            MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
             String whereClause =
                PersonAuthorityJAXBSchema.PERSONAUTHORITIES_COMMON+
                ":"+PersonAuthorityJAXBSchema.DISPLAY_NAME+
                "='"+parentSpecifier+"'";
             // Need to get an Authority by name
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
             String parentcsid = 
                getRepositoryClient(ctx).findDocCSID(ctx, whereClause);
 
-            ctx = MultipartServiceContextFactory.get().createServiceContext(null, getItemServiceName());
+            ctx = createServiceContext(getItemServiceName(), queryParams);
             DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
-            MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
-            DocumentFilter myFilter = handler.createDocumentFilter(ctx); //new DocumentFilter();
-            myFilter.setPagination(queryParams);
+            DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter();
+            myFilter.setPagination(queryParams); //FIXME
 
             // Add the where clause "persons_common:inAuthority='" + parentcsid + "'"
             myFilter.setWhereClause(PersonJAXBSchema.PERSONS_COMMON + ":" +
@@ -598,6 +726,15 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl
         return personObjectList;
     }
 
+    /**
+     * Update person.
+     * 
+     * @param parentcsid the parentcsid
+     * @param itemcsid the itemcsid
+     * @param theUpdate the the update
+     * 
+     * @return the multipart output
+     */
     @PUT
     @Path("{csid}/items/{itemcsid}")
     public MultipartOutput updatePerson(
@@ -624,7 +761,8 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl
         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());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName(),
+                               theUpdate);
             DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
             getRepositoryClient(ctx).update(ctx, itemcsid, handler);
             result = (MultipartOutput) ctx.getOutput();
@@ -652,6 +790,14 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl
         return result;
     }
 
+    /**
+     * Delete person.
+     * 
+     * @param parentcsid the parentcsid
+     * @param itemcsid the itemcsid
+     * 
+     * @return the response
+     */
     @DELETE
     @Path("{csid}/items/{itemcsid}")
     public Response deletePerson(
@@ -676,7 +822,7 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl
         }
         try {
             // Note that we have to create the service context for the Items, not the main service
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getItemServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName());
             getRepositoryClient(ctx).delete(ctx, itemcsid);
             return Response.status(HttpResponseCodes.SC_OK).build();
         } catch (UnauthorizedException ue) {
@@ -711,7 +857,7 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl
         try {
             // Note that we have to create the service context and document
             // handler for the Contact service, not the main service.
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getContactServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getContactServiceName(), input);
             DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid);
             String csid = getRepositoryClient(ctx).create(ctx, handler);
             UriBuilder path = UriBuilder.fromResource(PersonAuthorityResource.class);
@@ -739,6 +885,15 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl
         
     }
         
+    /**
+     * Gets the contact list.
+     * 
+     * @param parentcsid the parentcsid
+     * @param itemcsid the itemcsid
+     * @param ui the ui
+     * 
+     * @return the contact list
+     */
     @GET
     @Produces({"application/xml"})
     @Path("{parentcsid}/items/{itemcsid}/contacts/")
@@ -748,11 +903,12 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl
             @Context UriInfo ui) {
         ContactsCommonList contactObjectList = new ContactsCommonList();
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getContactServiceName());
-            DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid);
             MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
-            DocumentFilter myFilter = handler.createDocumentFilter(ctx); //new DocumentFilter();
-            myFilter.setPagination(queryParams);
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getContactServiceName(),
+                               queryParams);
+            DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid);
+            DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter();
+            myFilter.setPagination(queryParams); //FIXME (this is unnecessary since it is already set by "createContactDocumentHandler" method
             myFilter.setWhereClause(ContactJAXBSchema.CONTACTS_COMMON + ":" +
                 ContactJAXBSchema.IN_AUTHORITY +
                 "='" + parentcsid + "'" +
@@ -779,6 +935,15 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl
         return contactObjectList;
     }
 
+    /**
+     * Gets the contact.
+     * 
+     * @param parentcsid the parentcsid
+     * @param itemcsid the itemcsid
+     * @param csid the csid
+     * 
+     * @return the contact
+     */
     @GET
     @Path("{parentcsid}/items/{itemcsid}/contacts/{csid}")
     public MultipartOutput getContact(
@@ -793,7 +958,7 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl
         try {
             // Note that we have to create the service context and document
             // handler for the Contact service, not the main service.
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getContactServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getContactServiceName());
             DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid);
             getRepositoryClient(ctx).get(ctx, csid, handler);
             result = (MultipartOutput) ctx.getOutput();
@@ -828,6 +993,16 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl
 
     }
 
+    /**
+     * Update contact.
+     * 
+     * @param parentcsid the parentcsid
+     * @param itemcsid the itemcsid
+     * @param csid the csid
+     * @param theUpdate the the update
+     * 
+     * @return the multipart output
+     */
     @PUT
     @Path("{parentcsid}/items/{itemcsid}/contacts/{csid}")
     public MultipartOutput updateContact(
@@ -864,8 +1039,8 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl
         try {
             // Note that we have to create the service context and document
             // handler for the Contact service, not the main service.
-            ServiceContext ctx = MultipartServiceContextFactory.get()
-                .createServiceContext(theUpdate, getContactServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getContactServiceName(),
+                               theUpdate);
             DocumentHandler handler = createContactDocumentHandler(ctx, parentcsid, itemcsid);
             getRepositoryClient(ctx).update(ctx, csid, handler);
             result = (MultipartOutput) ctx.getOutput();
@@ -893,6 +1068,15 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl
         return result;
     }
 
+    /**
+     * Delete contact.
+     * 
+     * @param parentcsid the parentcsid
+     * @param itemcsid the itemcsid
+     * @param csid the csid
+     * 
+     * @return the response
+     */
     @DELETE
     @Path("{parentcsid}/items/{itemcsid}/contacts/{csid}")
     public Response deleteContact(
@@ -927,8 +1111,7 @@ public class PersonAuthorityResource extends AbstractCollectionSpaceResourceImpl
         try {
             // Note that we have to create the service context for the
             // Contact service, not the main service.
-            ServiceContext ctx =
-                MultipartServiceContextFactory.get().createServiceContext(null, getContactServiceName());
+               ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getContactServiceName());
             getRepositoryClient(ctx).delete(ctx, csid);
             return Response.status(HttpResponseCodes.SC_OK).build();   
          } catch (UnauthorizedException ue) {
index ae883fb17713ddbed17743966d23ac257b056172..eeaa84c0f114c5d7bd47ae19f071fc9181b73c38 100644 (file)
@@ -42,17 +42,18 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
 
-import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl;
-import org.collectionspace.services.common.context.MultipartServiceContext;
-import org.collectionspace.services.common.context.MultipartServiceContextFactory;
+import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl;
+//import org.collectionspace.services.common.context.MultipartServiceContext;
 import org.collectionspace.services.common.context.ServiceContext;
 import org.collectionspace.services.common.relation.IRelationsManager;
 import org.collectionspace.services.common.document.DocumentNotFoundException;
 import org.collectionspace.services.common.document.DocumentHandler;
 import org.collectionspace.services.common.security.UnauthorizedException;
+
 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;
 
@@ -62,7 +63,8 @@ import org.slf4j.LoggerFactory;
 @Path("/relations")
 @Consumes("multipart/mixed")
 @Produces("multipart/mixed")
-public class NewRelationResource extends AbstractCollectionSpaceResourceImpl {
+public class NewRelationResource extends
+               AbstractMultiPartCollectionSpaceResourceImpl {
 
        /** The Constant serviceName. */
        public final static String serviceName = "relations";
@@ -89,21 +91,29 @@ public class NewRelationResource extends AbstractCollectionSpaceResourceImpl {
        }
 
        /* (non-Javadoc)
-        * @see org.collectionspace.services.common.AbstractCollectionSpaceResource#createDocumentHandler(org.collectionspace.services.common.context.ServiceContext)
+        * @see org.collectionspace.services.common.CollectionSpaceResource#getCommonPartClass()
         */
        @Override
-       public DocumentHandler createDocumentHandler(ServiceContext ctx)
-                       throws Exception {
-               DocumentHandler docHandler = ctx.getDocumentHandler();
-               if (ctx.getInput() != null) {
-                       Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx
-                                       .getCommonPartLabel(), RelationsCommon.class);
-                       if (obj != null) {
-                               docHandler.setCommonPart((RelationsCommon) obj);
-                       }
-               }
-               return docHandler;
-       }
+    public Class<RelationsCommon> getCommonPartClass() {
+       return RelationsCommon.class;
+    }
+       
+       /* (non-Javadoc)
+        * @see org.collectionspace.services.common.AbstractCollectionSpaceResource#createDocumentHandler(org.collectionspace.services.common.context.ServiceContext)
+        */
+//     @Override
+//     public DocumentHandler createDocumentHandler(ServiceContext<MultipartInput, MultipartOutput> ctx)
+//                     throws Exception {
+//             DocumentHandler docHandler = ctx.getDocumentHandler();
+//             if (ctx.getInput() != null) {
+//                     Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx
+//                                     .getCommonPartLabel(), RelationsCommon.class);
+//                     if (obj != null) {
+//                             docHandler.setCommonPart((RelationsCommon) obj);
+//                     }
+//             }
+//             return docHandler;
+//     }
 
        /**
         * Creates the relation.
@@ -114,10 +124,8 @@ public class NewRelationResource extends AbstractCollectionSpaceResourceImpl {
         */
        @POST
        public Response createRelation(MultipartInput input) {
-
                try {
-                       ServiceContext ctx = MultipartServiceContextFactory.get()
-                                       .createServiceContext(input, getServiceName());
+                       ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(input);
                        DocumentHandler handler = createDocumentHandler(ctx);
                        String csid = getRepositoryClient(ctx).create(ctx, handler);
                        UriBuilder path = UriBuilder
@@ -163,8 +171,7 @@ public class NewRelationResource extends AbstractCollectionSpaceResourceImpl {
                }
                MultipartOutput result = null;
                try {
-                       ServiceContext ctx = MultipartServiceContextFactory.get()
-                                       .createServiceContext(null, getServiceName());
+                       ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
                        DocumentHandler handler = createDocumentHandler(ctx);
                        getRepositoryClient(ctx).get(ctx, csid, handler);
                        result = (MultipartOutput) ctx.getOutput();
@@ -406,8 +413,7 @@ public class NewRelationResource extends AbstractCollectionSpaceResourceImpl {
                }
                MultipartOutput result = null;
                try {
-                       ServiceContext ctx = MultipartServiceContextFactory.get()
-                                       .createServiceContext(theUpdate, getServiceName());
+                       ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(theUpdate);
                        DocumentHandler handler = createDocumentHandler(ctx);
                        getRepositoryClient(ctx).update(ctx, csid, handler);
                        result = (MultipartOutput) ctx.getOutput();
@@ -455,8 +461,7 @@ public class NewRelationResource extends AbstractCollectionSpaceResourceImpl {
                        throw new WebApplicationException(response);
                }
                try {
-                       ServiceContext ctx = MultipartServiceContextFactory.get()
-                                       .createServiceContext(null, getServiceName());
+                       ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
                        getRepositoryClient(ctx).delete(ctx, csid);
                        return Response.status(HttpResponseCodes.SC_OK).build();
                } catch (UnauthorizedException ue) {
@@ -493,10 +498,9 @@ public class NewRelationResource extends AbstractCollectionSpaceResourceImpl {
                        String predicate, String objectCsid) throws WebApplicationException {
                RelationsCommonList relationList = new RelationsCommonList();
                try {
-                       ServiceContext ctx = MultipartServiceContextFactory.get()
-                                       .createServiceContext(null, getServiceName());
+                       ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
                        DocumentHandler handler = createDocumentHandler(ctx);
-                       Map propsFromPath = handler.getProperties();
+                       Map<String, Object> propsFromPath = handler.getProperties();
                        propsFromPath.put(IRelationsManager.SUBJECT, subjectCsid);
                        propsFromPath.put(IRelationsManager.PREDICATE, predicate);
                        propsFromPath.put(IRelationsManager.OBJECT, objectCsid);
index 9eedd82986b3ef3fe5f48a366eda17d0bd0bf8ed..5b8a12830badffcc1cf30f1e6424d8c9e19ea0c5 100644 (file)
@@ -40,7 +40,7 @@ import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
 
 import org.collectionspace.services.VocabularyItemJAXBSchema;
-import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl;
+import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl;
 import org.collectionspace.services.common.ClientType;
 import org.collectionspace.services.common.ServiceMain;
 import org.collectionspace.services.common.context.MultipartServiceContext;
@@ -59,21 +59,37 @@ import org.jboss.resteasy.util.HttpResponseCodes;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+/**
+ * The Class VocabularyResource.
+ */
 @Path("/vocabularies")
 @Consumes("multipart/mixed")
 @Produces("multipart/mixed")
-public class VocabularyResource extends AbstractCollectionSpaceResourceImpl {
+public class VocabularyResource extends
+               AbstractMultiPartCollectionSpaceResourceImpl {
 
+    /** The Constant vocabularyServiceName. */
     private final static String vocabularyServiceName = "vocabularies";
+    
+    /** The Constant vocabularyItemServiceName. */
     private final static String vocabularyItemServiceName = "vocabularyitems";
+    
+    /** The logger. */
     final Logger logger = LoggerFactory.getLogger(VocabularyResource.class);
     //FIXME retrieve client type from configuration
+    /** The Constant CLIENT_TYPE. */
     final static ClientType CLIENT_TYPE = ServiceMain.getInstance().getClientType();
 
+    /**
+     * Instantiates a new vocabulary resource.
+     */
     public VocabularyResource() {
         // do nothing
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getVersionString()
+     */
     @Override
     protected String getVersionString() {
         /** The last change revision. */
@@ -81,11 +97,27 @@ public class VocabularyResource extends AbstractCollectionSpaceResourceImpl {
         return lastChangeRevision;
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getServiceName()
+     */
     @Override
     public String getServiceName() {
         return vocabularyServiceName;
     }
 
+    /* (non-Javadoc)
+     * @see org.collectionspace.services.common.CollectionSpaceResource#getCommonPartClass()
+     */
+    @Override
+    public Class<VocabulariesCommon> getCommonPartClass() {
+       return VocabulariesCommon.class;
+    }
+    
+    /**
+     * Gets the item service name.
+     * 
+     * @return the item service name
+     */
     public String getItemServiceName() {
         return vocabularyItemServiceName;
     }
@@ -97,37 +129,60 @@ public class VocabularyResource extends AbstractCollectionSpaceResourceImpl {
     return ctx;
     }
      */
-    @Override
-    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
-        DocumentHandler docHandler = ctx.getDocumentHandler();
-        if (ctx.getInput() != null) {
-            Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), VocabulariesCommon.class);
-            if (obj != null) {
-                docHandler.setCommonPart((VocabulariesCommon) obj);
-            }
-        }
-        return docHandler;
-    }
-
+//    @Override
+//    public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception {
+//        DocumentHandler docHandler = ctx.getDocumentHandler();
+//        if (ctx.getInput() != null) {
+//            Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), VocabulariesCommon.class);
+//            if (obj != null) {
+//                docHandler.setCommonPart((VocabulariesCommon) obj);
+//            }
+//        }
+//        return docHandler;
+//    }
+    
+//    @Override
+//    public DocumentHandler createDocumentHandler(ServiceContext ctx)
+//             throws Exception {
+//        DocumentHandler docHandler = createDocumentHandler(ctx, VocabulariesCommon.class);
+//        return docHandler;
+//    }
+    
+    /**
+     * Creates the item document handler.
+     * 
+     * @param ctx the ctx
+     * @param inVocabulary the in vocabulary
+     * 
+     * @return the document handler
+     * 
+     * @throws Exception the exception
+     */
     private DocumentHandler createItemDocumentHandler(
-            ServiceContext ctx,
-            String inVocabulary) throws Exception {
-        DocumentHandler docHandler = ctx.getDocumentHandler();
-        ((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);
-            }
-        }
+               ServiceContext<MultipartInput, MultipartOutput> ctx,
+            String inVocabulary)
+                       throws Exception {
+       VocabularyItemDocumentModelHandler docHandler;
+       
+       docHandler = (VocabularyItemDocumentModelHandler)createDocumentHandler(ctx,
+                       ctx.getCommonPartLabel(getItemServiceName()),
+                       VocabularyitemsCommon.class);           
+        docHandler.setInVocabulary(inVocabulary);
+
         return docHandler;
     }
 
+    /**
+     * Creates the vocabulary.
+     * 
+     * @param input the input
+     * 
+     * @return the response
+     */
     @POST
     public Response createVocabulary(MultipartInput input) {
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getServiceName());
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(input);
             DocumentHandler handler = createDocumentHandler(ctx);
             String csid = getRepositoryClient(ctx).create(ctx, handler);
             //vocabularyObject.setCsid(csid);
@@ -149,6 +204,13 @@ public class VocabularyResource extends AbstractCollectionSpaceResourceImpl {
         }
     }
 
+    /**
+     * Gets the vocabulary.
+     * 
+     * @param csid the csid
+     * 
+     * @return the vocabulary
+     */
     @GET
     @Path("{csid}")
     public MultipartOutput getVocabulary(@PathParam("csid") String csid) {
@@ -165,7 +227,7 @@ public class VocabularyResource extends AbstractCollectionSpaceResourceImpl {
         }
         MultipartOutput result = null;
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).get(ctx, csid, handler);
             result = (MultipartOutput) ctx.getOutput();
@@ -189,30 +251,40 @@ public class VocabularyResource extends AbstractCollectionSpaceResourceImpl {
                     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 Vocabulary CSID:" + csid + ": was not found.").type(
                     "text/plain").build();
             throw new WebApplicationException(response);
         }
+        
         return result;
     }
 
+    /**
+     * Gets the vocabulary list.
+     * 
+     * @param ui the ui
+     * 
+     * @return the vocabulary list
+     */
     @GET
     @Produces("application/xml")
     public VocabulariesCommonList getVocabularyList(@Context UriInfo ui) {
         VocabulariesCommonList vocabularyObjectList = new VocabulariesCommonList();
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
             MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(queryParams);
             DocumentHandler handler = createDocumentHandler(ctx);
-            DocumentFilter myFilter = handler.createDocumentFilter(ctx); //new DocumentFilter();
-            myFilter.setPagination(queryParams);
+//            DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter();
+            DocumentFilter myFilter = handler.getDocumentFilter();
+//            myFilter.setPagination(queryParams);
             String nameQ = queryParams.getFirst("refName");
             if (nameQ != null) {
                 myFilter.setWhereClause("vocabularies_common:refName='" + nameQ + "'");
             }
-            handler.setDocumentFilter(myFilter);
+//            handler.setDocumentFilter(myFilter);
             getRepositoryClient(ctx).getFiltered(ctx, handler);
             vocabularyObjectList = (VocabulariesCommonList) handler.getCommonPartList();
         } catch (UnauthorizedException ue) {
@@ -230,6 +302,14 @@ public class VocabularyResource extends AbstractCollectionSpaceResourceImpl {
         return vocabularyObjectList;
     }
 
+    /**
+     * Update vocabulary.
+     * 
+     * @param csid the csid
+     * @param theUpdate the the update
+     * 
+     * @return the multipart output
+     */
     @PUT
     @Path("{csid}")
     public MultipartOutput updateVocabulary(
@@ -247,7 +327,7 @@ public class VocabularyResource extends AbstractCollectionSpaceResourceImpl {
         }
         MultipartOutput result = null;
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(theUpdate, getServiceName());
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(theUpdate);
             DocumentHandler handler = createDocumentHandler(ctx);
             getRepositoryClient(ctx).update(ctx, csid, handler);
             result = (MultipartOutput) ctx.getOutput();
@@ -271,6 +351,13 @@ public class VocabularyResource extends AbstractCollectionSpaceResourceImpl {
         return result;
     }
 
+    /**
+     * Delete vocabulary.
+     * 
+     * @param csid the csid
+     * 
+     * @return the response
+     */
     @DELETE
     @Path("{csid}")
     public Response deleteVocabulary(@PathParam("csid") String csid) {
@@ -286,7 +373,7 @@ public class VocabularyResource extends AbstractCollectionSpaceResourceImpl {
             throw new WebApplicationException(response);
         }
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName());
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext();
             getRepositoryClient(ctx).delete(ctx, csid);
             return Response.status(HttpResponseCodes.SC_OK).build();
         } catch (UnauthorizedException ue) {
@@ -316,7 +403,8 @@ public class VocabularyResource extends AbstractCollectionSpaceResourceImpl {
     @Path("{csid}/items")
     public Response createVocabularyItem(@PathParam("csid") String parentcsid, MultipartInput input) {
         try {
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getItemServiceName());
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName(),
+                       input);
             DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
             String itemcsid = getRepositoryClient(ctx).create(ctx, handler);
             UriBuilder path = UriBuilder.fromResource(VocabularyResource.class);
@@ -341,6 +429,14 @@ public class VocabularyResource extends AbstractCollectionSpaceResourceImpl {
         }
     }
 
+    /**
+     * Gets the vocabulary item.
+     * 
+     * @param parentcsid the parentcsid
+     * @param itemcsid the itemcsid
+     * 
+     * @return the vocabulary item
+     */
     @GET
     @Path("{csid}/items/{itemcsid}")
     public MultipartOutput getVocabularyItem(
@@ -366,7 +462,7 @@ public class VocabularyResource extends AbstractCollectionSpaceResourceImpl {
         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());
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName());
             DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
             getRepositoryClient(ctx).get(ctx, itemcsid, handler);
             // TODO should we assert that the item is in the passed vocab?
@@ -400,6 +496,15 @@ public class VocabularyResource extends AbstractCollectionSpaceResourceImpl {
         return result;
     }
 
+    /**
+     * Gets the vocabulary item list.
+     * 
+     * @param parentcsid the parentcsid
+     * @param partialTerm the partial term
+     * @param ui the ui
+     * 
+     * @return the vocabulary item list
+     */
     @GET
     @Path("{csid}/items")
     @Produces("application/xml")
@@ -409,12 +514,14 @@ public class VocabularyResource extends AbstractCollectionSpaceResourceImpl {
             @Context UriInfo ui) {
         VocabularyitemsCommonList vocabularyItemObjectList = new VocabularyitemsCommonList();
         try {
+            MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
             // Note that docType defaults to the ServiceName, so we're fine with that.
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getItemServiceName());
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName(),
+                       queryParams);
             DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
-            MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
-            DocumentFilter myFilter = handler.createDocumentFilter(ctx); //new DocumentFilter();
-            myFilter.setPagination(queryParams);
+//            DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter();
+            DocumentFilter myFilter = handler.getDocumentFilter(); //new DocumentFilter();
+//            myFilter.setPagination(queryParams);
             // "vocabularyitems_common:inVocabulary='" + parentcsid + "'");
             myFilter.setWhereClause(
                     VocabularyItemJAXBSchema.VOCABULARYITEMS_COMMON + ":"
@@ -455,6 +562,15 @@ public class VocabularyResource extends AbstractCollectionSpaceResourceImpl {
         return vocabularyItemObjectList;
     }
 
+    /**
+     * Update vocabulary item.
+     * 
+     * @param parentcsid the parentcsid
+     * @param itemcsid the itemcsid
+     * @param theUpdate the the update
+     * 
+     * @return the multipart output
+     */
     @PUT
     @Path("{csid}/items/{itemcsid}")
     public MultipartOutput updateVocabularyItem(
@@ -481,7 +597,8 @@ public class VocabularyResource extends AbstractCollectionSpaceResourceImpl {
         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());
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName(),
+                       theUpdate);
             DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid);
             getRepositoryClient(ctx).update(ctx, itemcsid, handler);
             result = (MultipartOutput) ctx.getOutput();
@@ -509,6 +626,14 @@ public class VocabularyResource extends AbstractCollectionSpaceResourceImpl {
         return result;
     }
 
+    /**
+     * Delete vocabulary item.
+     * 
+     * @param parentcsid the parentcsid
+     * @param itemcsid the itemcsid
+     * 
+     * @return the response
+     */
     @DELETE
     @Path("{csid}/items/{itemcsid}")
     public Response deleteVocabularyItem(
@@ -533,7 +658,7 @@ public class VocabularyResource extends AbstractCollectionSpaceResourceImpl {
         }
         try {
             // Note that we have to create the service context for the Items, not the main service
-            ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getItemServiceName());
+            ServiceContext<MultipartInput, MultipartOutput> ctx = createServiceContext(getItemServiceName());
             getRepositoryClient(ctx).delete(ctx, itemcsid);
             return Response.status(HttpResponseCodes.SC_OK).build();
         } catch (UnauthorizedException ue) {