From: Richard Millet Date: Fri, 16 Apr 2010 10:10:58 +0000 (+0000) Subject: CSPACE-1349, 1422, 1428, 1469, 1470, 1473: Adding pagination support for default... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=78741b90a09346d410432ab69ee48932b0cf731e;p=tmp%2Fjakarta-migration.git CSPACE-1349, 1422, 1428, 1469, 1470, 1473: Adding pagination support for default page size, making a convention that query params are part of the service context, giving docHandlers a default filter, removing some of the ubiquitous Generics warnings, refactored resource service code to minimize duplicated code and boiler plating. Passes *ALL* current tests and merged with the latest set of sources. --- diff --git a/services/account/service/src/main/java/org/collectionspace/services/account/AccountResource.java b/services/account/service/src/main/java/org/collectionspace/services/account/AccountResource.java index 8c35ff148..b385280fc 100644 --- a/services/account/service/src/main/java/org/collectionspace/services/account/AccountResource.java +++ b/services/account/service/src/main/java/org/collectionspace/services/account/AccountResource.java @@ -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 { + /** 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 getCommonPartClass() { + return AccountsCommon.class; + } - private ServiceContext createServiceContext(T obj) throws Exception { - ServiceContext ctx = new RemoteServiceContextImpl(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 getServiceContextFactory() { + return (ServiceContextFactory)RemoteServiceContextFactory.get(); } + +// private ServiceContext createServiceContext(T obj) throws Exception { +// ServiceContext ctx = new RemoteServiceContextImpl(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 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 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 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 ctx = createServiceContext((AccountsCommon) null, AccountsCommon.class); DocumentHandler handler = createDocumentHandler(ctx); MultivaluedMap 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 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 ctx = createServiceContext((AccountsCommon) null, + AccountsCommon.class); getStorageClient(ctx).delete(ctx, csid); return Response.status(HttpResponseCodes.SC_OK).build(); } catch (UnauthorizedException ue) { diff --git a/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountDocumentHandler.java b/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountDocumentHandler.java index 40907bcd0..e5da7aca0 100644 --- a/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountDocumentHandler.java +++ b/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountDocumentHandler.java @@ -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(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 + } } diff --git a/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountJpaFilter.java b/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountJpaFilter.java index 21d04f781..3e87d65ce 100644 --- a/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountJpaFilter.java +++ b/services/account/service/src/main/java/org/collectionspace/services/account/storage/AccountJpaFilter.java @@ -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 buildWhereForSearch(StringBuilder queryStrBldr) { diff --git a/services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/AcquisitionResource.java b/services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/AcquisitionResource.java index e9b5fb34e..ab6a8c5d7 100644 --- a/services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/AcquisitionResource.java +++ b/services/acquisition/service/src/main/java/org/collectionspace/services/acquisition/AcquisitionResource.java @@ -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 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 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 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 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 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 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 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 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 ctx = createServiceContext(); DocumentWrapper docWrapper = getRepositoryClient(ctx).getDoc(ctx, csid); RemoteDocumentModelHandlerImpl handler diff --git a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/PermissionResource.java b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/PermissionResource.java index 88ccc3970..191353337 100644 --- a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/PermissionResource.java +++ b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/PermissionResource.java @@ -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 { + /** 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 ServiceContext createServiceContext(T obj) throws Exception { - ServiceContext ctx = new RemoteServiceContextImpl(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 getCommonPartClass() { + return Permission.class; } - + + /* (non-Javadoc) + * @see org.collectionspace.services.common.CollectionSpaceResource#getServiceContextFactory() + */ + @Override + public ServiceContextFactory 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 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 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 ctx = createServiceContext(); DocumentHandler handler = createDocumentHandler(ctx); MultivaluedMap 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 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 ctx = createServiceContext(); getStorageClient(ctx).delete(ctx, csid); return Response.status(HttpResponseCodes.SC_OK).build(); } catch (UnauthorizedException ue) { diff --git a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/PermissionRoleSubResource.java b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/PermissionRoleSubResource.java index 2b59ec293..a9c14b968 100644 --- a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/PermissionRoleSubResource.java +++ b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/PermissionRoleSubResource.java @@ -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 { //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 getCommonPartClass() { + return PermissionRole.class; + } + + /* (non-Javadoc) + * @see org.collectionspace.services.common.CollectionSpaceResource#getServiceContextFactory() + */ + @Override + public ServiceContextFactory getServiceContextFactory() { + return RemoteServiceContextFactory.get(); + } - private ServiceContext createServiceContext(T obj, SubjectType subject) throws Exception { - ServiceContext ctx = new RemoteServiceContextImpl(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 createServiceContext(PermissionRole input, + SubjectType subject) throws Exception { + ServiceContext ctx = createServiceContext(input); +// ServiceContext ctx = new RemoteServiceContextImpl(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 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 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 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 ctx = createServiceContext((PermissionRole) null, subject); getStorageClient(ctx).delete(ctx, csid); } } diff --git a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/RoleResource.java b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/RoleResource.java index d36d497f5..73f02d7d7 100644 --- a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/RoleResource.java +++ b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/RoleResource.java @@ -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 ServiceContext createServiceContext(T obj) throws Exception { - ServiceContext ctx = new RemoteServiceContextImpl(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 getCommonPartClass() { + return RoleResource.class; } - + + /* (non-Javadoc) + * @see org.collectionspace.services.common.CollectionSpaceResource#getServiceContextFactory() + */ @Override + public ServiceContextFactory getServiceContextFactory() { + return RemoteServiceContextFactory.get(); + } + + +// private ServiceContext createServiceContext(T obj) throws Exception { +// ServiceContext ctx = new RemoteServiceContextImpl(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 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) { diff --git a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionDocumentHandler.java b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionDocumentHandler.java index cc613fcf8..e525f45bc 100644 --- a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionDocumentHandler.java +++ b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionDocumentHandler.java @@ -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; } diff --git a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionJpaFilter.java b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionJpaFilter.java index e5cae5bcd..807d5f4c1 100644 --- a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionJpaFilter.java +++ b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionJpaFilter.java @@ -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 buildWhereForSearch(StringBuilder queryStrBldr) { diff --git a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionRoleDocumentHandler.java b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionRoleDocumentHandler.java index 8bd86ea50..6151ea07a 100644 --- a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionRoleDocumentHandler.java +++ b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionRoleDocumentHandler.java @@ -174,7 +174,7 @@ public class PermissionRoleDocumentHandler } @Override - public DocumentFilter createDocumentFilter(ServiceContext ctx) { - return new DocumentFilter(); + public DocumentFilter createDocumentFilter() { + return new DocumentFilter(this.getServiceContext()); } } diff --git a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionRoleStorageClient.java b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionRoleStorageClient.java index 20c1b820f..8afa3be31 100644 --- a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionRoleStorageClient.java +++ b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/PermissionRoleStorageClient.java @@ -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; diff --git a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/RoleDocumentHandler.java b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/RoleDocumentHandler.java index c01c204e5..ce4df4031 100644 --- a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/RoleDocumentHandler.java +++ b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/RoleDocumentHandler.java @@ -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; } diff --git a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/RoleJpaFilter.java b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/RoleJpaFilter.java index 7cb44c05d..cc30c603c 100644 --- a/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/RoleJpaFilter.java +++ b/services/authorization-mgt/service/src/main/java/org/collectionspace/services/authorization/storage/RoleJpaFilter.java @@ -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 buildWhereForSearch(StringBuilder queryStrBldr) { diff --git a/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java b/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java index 069db4b2c..643a29481 100644 --- a/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java +++ b/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java @@ -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 getCommonPartClass() { + return CollectionobjectsCommon.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(), +// 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 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 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 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 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 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 ctx = createServiceContext(); DocumentWrapper 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 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()); diff --git a/services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResourceImpl.java b/services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResourceImpl.java index 21ba6ed4d..9ad8bcce7 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResourceImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/AbstractCollectionSpaceResourceImpl.java @@ -26,8 +26,11 @@ package org.collectionspace.services.common; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; +import javax.ws.rs.core.MultivaluedMap; +import org.collectionspace.services.common.context.RemoteServiceContext; 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.repository.RepositoryClientFactory; @@ -37,8 +40,8 @@ import org.collectionspace.services.common.storage.jpa.JpaStorageClientImpl; /** * The Class AbstractCollectionSpaceResource. */ -public abstract class AbstractCollectionSpaceResourceImpl - implements CollectionSpaceResource { +public abstract class AbstractCollectionSpaceResourceImpl + implements CollectionSpaceResource { // Fields for default client factory and client /** The repository client factory. */ @@ -68,7 +71,7 @@ public abstract class AbstractCollectionSpaceResourceImpl * @see org.collectionspace.services.common.CollectionSpaceResource#getRepositoryClient(org.collectionspace.services.common.context.ServiceContext) */ @Override - synchronized public RepositoryClient getRepositoryClient(ServiceContext ctx) { + synchronized public RepositoryClient getRepositoryClient(ServiceContext ctx) { if(repositoryClient != null){ return repositoryClient; } @@ -80,20 +83,208 @@ public abstract class AbstractCollectionSpaceResourceImpl * @see org.collectionspace.services.common.CollectionSpaceResource#getStorageClient(org.collectionspace.services.common.context.ServiceContext) */ @Override - synchronized public StorageClient getStorageClient(ServiceContext ctx) { + synchronized public StorageClient getStorageClient(ServiceContext ctx) { if(storageClient != null) { return storageClient; } storageClient = new JpaStorageClientImpl(); return storageClient; } - + /* (non-Javadoc) * @see org.collectionspace.services.common.CollectionSpaceResource#createDocumentHandler(org.collectionspace.services.common.context.ServiceContext) */ @Override - abstract public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception ; + public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception { + DocumentHandler docHandler = createDocumentHandler(ctx, ctx.getInput()); + return docHandler; + } + + /** + * Creates the document handler. + * + * @param ctx the ctx + * @param commonPart the common part + * + * @return the document handler + * + * @throws Exception the exception + */ + public DocumentHandler createDocumentHandler(ServiceContext ctx, + Object commonPart) throws Exception { + DocumentHandler docHandler = ctx.getDocumentHandler(); + docHandler.setCommonPart(commonPart); + return docHandler; + } + + /** + * Creates the service context. + * + * @return the service context< i t, o t> + * + * @throws Exception the exception + */ + protected ServiceContext createServiceContext() throws Exception { + ServiceContext ctx = createServiceContext(this.getServiceName(), + (IT)null, //inputType + (MultivaluedMap)null, /*queryParams*/ + this.getCommonPartClass()); + return ctx; + } + + /** + * Creates the service context. + * + * @param serviceName the service name + * + * @return the service context< i t, o t> + * + * @throws Exception the exception + */ + protected ServiceContext createServiceContext(String serviceName) throws Exception { + ServiceContext ctx = createServiceContext( + serviceName, + (IT)null, /*input*/ + (MultivaluedMap)null, /*queryParams*/ + (Class)null /*input type's Class*/); + return ctx; + } + /** + * Creates the service context. + * + * @param serviceName the service name + * @param input the input + * + * @return the service context< i t, o t> + * + * @throws Exception the exception + */ + protected ServiceContext createServiceContext(String serviceName, + IT input) throws Exception { + ServiceContext ctx = createServiceContext(serviceName, input, + (MultivaluedMap)null, /*queryParams*/ + (Class)null /*input type's Class*/); + return ctx; + } + + /** + * Creates the service context. + * + * @param serviceName the service name + * @param input the input + * + * @return the service context< i t, o t> + * + * @throws Exception the exception + */ + protected ServiceContext createServiceContext(String serviceName, + MultivaluedMap queryParams) throws Exception { + ServiceContext ctx = createServiceContext(serviceName, + (IT)null, + queryParams, + (Class)null /*input type's Class*/); + return ctx; + } + + /** + * Creates the service context. + * + * @param queryParams the query params + * + * @return the service context< i t, o t> + * + * @throws Exception the exception + */ + protected ServiceContext createServiceContext(MultivaluedMap queryParams) throws Exception { + ServiceContext ctx = createServiceContext( + (IT)null, /*input*/ + queryParams, + (Class)null /*input type's Class*/); + return ctx; + } + + /** + * Creates the service context. + * + * @param input the input + * + * @return the service context< i t, o t> + * + * @throws Exception the exception + */ + protected ServiceContext createServiceContext(IT input) throws Exception { + ServiceContext ctx = createServiceContext( + input, + (Class)null /*input type's Class*/); + return ctx; + } + + /** + * Creates the service context. + * + * @param input the input + * @param theClass the the class + * + * @return the service context + * + * @throws Exception the exception + */ + protected ServiceContext createServiceContext(IT input, Class theClass) throws Exception { + ServiceContext ctx = createServiceContext( + input, + (MultivaluedMap)null, //queryParams, + theClass); + return ctx; + } + + /** + * Creates the service context. + * + * @param input the input + * @param queryParams the query params + * @param theClass the the class + * + * @return the service context< i t, o t> + * + * @throws Exception the exception + */ + protected ServiceContext createServiceContext( + IT input, + MultivaluedMap queryParams, + Class theClass) throws Exception { + return createServiceContext(this.getServiceName(), + input, + queryParams, + theClass); + } + + /** + * Creates the service context. + * + * @param serviceName the service name + * @param input the input + * @param queryParams the query params + * @param theClass the the class + * + * @return the service context< i t, o t> + * + * @throws Exception the exception + */ + private ServiceContext createServiceContext( + String serviceName, + IT input, + MultivaluedMap queryParams, + Class theClass) throws Exception { + ServiceContext ctx = getServiceContextFactory().createServiceContext( + serviceName, + input, + queryParams, + theClass != null ? theClass.getPackage().getName() : null, + theClass != null ? theClass.getName() : null); + return ctx; + } + /** * Gets the version string. * @@ -116,5 +307,4 @@ public abstract class AbstractCollectionSpaceResourceImpl return result; } - } diff --git a/services/common/src/main/java/org/collectionspace/services/common/CollectionSpaceResource.java b/services/common/src/main/java/org/collectionspace/services/common/CollectionSpaceResource.java index 1e6dd4a9c..5fac316cb 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/CollectionSpaceResource.java +++ b/services/common/src/main/java/org/collectionspace/services/common/CollectionSpaceResource.java @@ -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 { /** * 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 ctx); /** * getStorageClient * @param ctx service context */ - public StorageClient getStorageClient(ServiceContext ctx); + public StorageClient getStorageClient(ServiceContext 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 ctx) throws Exception; + + + public ServiceContextFactory getServiceContextFactory(); + } diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java b/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java index 2715a1b1f..b30bf5a0d 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/context/AbstractServiceContextImpl.java @@ -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 implements ServiceContext { + /** The logger. */ final Logger logger = LoggerFactory.getLogger(AbstractServiceContextImpl.class); + + /** The properties. */ Map properties = new HashMap(); + + /** The object part map. */ Map objectPartMap = new HashMap(); + + /** 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 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 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 return schemaName.toLowerCase() + PART_LABEL_SEPERATOR + PART_COMMON_LABEL; } + /* (non-Javadoc) + * @see org.collectionspace.services.common.context.ServiceContext#getPartsMetadata() + */ @Override public Map getPartsMetadata() { if (objectPartMap.size() != 0) { @@ -127,6 +160,13 @@ public abstract class AbstractServiceContextImpl return objectPartMap; } + /** + * Gets the properties for part. + * + * @param partLabel the part label + * + * @return the properties for part + */ public List getPropertiesForPart(String partLabel) { Map partMap = getPartsMetadata(); ObjectPartType part = partMap.get(partLabel); @@ -137,32 +177,68 @@ public abstract class AbstractServiceContextImpl 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 getPropertyValuesForPart(String partLabel, String propName) { List 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 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 getCommonPartProperties() { return getPropertiesForPart(getCommonPartLabel()); } + /** + * Gets the common part property values. + * + * @param propName the prop name + * + * @return the common part property values + */ public List 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 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 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 getProperties() { return properties; } + /* (non-Javadoc) + * @see org.collectionspace.services.common.context.ServiceContext#setProperties(java.util.Map) + */ @Override public void setProperties(Map 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 //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 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 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 return serviceBinding.getDocumentHandler().trim(); } + /* (non-Javadoc) + * @see org.collectionspace.services.common.context.ServiceContext#getValidatorHandlers() + */ @Override public List getValidatorHandlers() throws Exception { if (valHandlers != null) { @@ -318,6 +498,9 @@ public abstract class AbstractServiceContextImpl 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 msg.append("]"); return msg.toString(); } + + @Override + public MultivaluedMap getQueryParams() { + return this.queryParams; + } + + @Override + public void setQueryParams(MultivaluedMap queryParams) { + this.queryParams = queryParams; + } } diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContextFactory.java b/services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContextFactory.java index 98277c254..535b092e5 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContextFactory.java +++ b/services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContextFactory.java @@ -23,7 +23,10 @@ */ 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 { + implements ServiceContextFactory { + /** 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 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 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 createServiceContext(String serviceName, + MultipartInput input, + MultivaluedMap queryParams) + throws Exception { + ServiceContext 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 createServiceContext(String serviceName, + MultipartInput input, + MultivaluedMap queryParams, + String documentType, + String entityName) throws Exception { + return this.createServiceContext(serviceName, input, queryParams); + } } diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContextImpl.java b/services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContextImpl.java index a997a4102..d760ecbf6 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContextImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContextImpl.java @@ -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 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 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(); diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/RemoteServiceContext.java b/services/common/src/main/java/org/collectionspace/services/common/context/RemoteServiceContext.java index 01fed3c86..74a539959 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/context/RemoteServiceContext.java +++ b/services/common/src/main/java/org/collectionspace/services/common/context/RemoteServiceContext.java @@ -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 * @return local service context */ public ServiceContext getLocalContext(String localContextClassName) throws Exception; + + /** + * Gets the query params. + * + * @return the query params + */ + public MultivaluedMap getQueryParams(); + + /** + * Gets the query params. + * + * @return the query params + */ + public void setQueryParams(MultivaluedMap queryParams); } + diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/RemoteServiceContextImpl.java b/services/common/src/main/java/org/collectionspace/services/common/context/RemoteServiceContextImpl.java index 9391805f4..a5e3eafe8 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/context/RemoteServiceContextImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/context/RemoteServiceContextImpl.java @@ -24,6 +24,11 @@ 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 extends AbstractServiceContextImpl implements RemoteServiceContext { + /** 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 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 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 Constructor ctor = ctxClass.getConstructor(java.lang.String.class); ServiceContext ctx = (ServiceContext) ctor.newInstance(getServiceName()); return ctx; - } + } } diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java b/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java index 9cebceadb..f497f4ebe 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java +++ b/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContext.java @@ -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 { * 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 { */ 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 queryParams) throws Exception; /** * getValidatorHandlers returns registered (from binding) validtor handlers @@ -216,7 +230,20 @@ public interface ServiceContext { * @return validation handlers */ public List getValidatorHandlers() throws Exception; - + + /** + * Gets the query params. + * + * @return the query params + */ + public MultivaluedMap getQueryParams(); + + /** + * Sets the query params. + * + * @param queryParams the query params + */ + public void setQueryParams(MultivaluedMap queryParams); } diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContextFactory.java b/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContextFactory.java index ae76e6dd3..49b78493a 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContextFactory.java +++ b/services/common/src/main/java/org/collectionspace/services/common/context/ServiceContextFactory.java @@ -23,21 +23,70 @@ */ package org.collectionspace.services.common.context; +import javax.ws.rs.core.MultivaluedMap; + /** * * ServiceContextFactory creates a service context * */ -public interface ServiceContextFactory { - +public interface ServiceContextFactory { /** - * 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 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 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 createServiceContext(String serviceName, + IT input, + MultivaluedMap 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 createServiceContext( + String serviceName, + IT input, + MultivaluedMap queryParams, + String documentType, + String entityName) throws Exception; } diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandlerImpl.java b/services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandlerImpl.java index 39fb955d8..ef756c263 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandlerImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/AbstractDocumentHandlerImpl.java @@ -76,8 +76,13 @@ public abstract class AbstractDocumentHandlerImpl 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 diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java index 1fd48204e..87f17e593 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentFilter.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.List; import javax.ws.rs.core.MultivaluedMap; import org.collectionspace.services.common.query.IQueryManager; +import org.collectionspace.services.common.context.ServiceContext; //TODO: would be great to not rely on resteasy directly import org.jboss.resteasy.specimpl.MultivaluedMapImpl; @@ -41,7 +42,8 @@ public class DocumentFilter { protected String whereClause; // Filtering clause. Omit the "WHERE". protected int startPage; // Pagination offset for list results protected int pageSize; // Pagination limit for list results - private MultivaluedMap queryParams = new MultivaluedMapImpl(); + private boolean pageSizeDirty = false; // True if default page size explicitly set/overridden + private MultivaluedMap queryParams = null; /** @@ -86,6 +88,16 @@ public class DocumentFilter { } } + /** + * Instantiates a new document filter. + * + * @param ctx the ctx + */ + public DocumentFilter(ServiceContext ctx) { + this.setPageSize(ctx.getServiceBindingPropertyValue( + DocumentFilter.PAGE_SIZE_DEFAULT_PROPERTY)); + } + public DocumentFilter() { this("", 0, defaultPageSize); // Use empty string for easy concatenation } @@ -96,26 +108,36 @@ public class DocumentFilter { this.pageSize = (pageSize > 0) ? pageSize : defaultPageSize; } - public void setPagination(MultivaluedMap queryParams) { - - String startPageStr = null; - String pageSizeStr = null; + /** + * Sets the pagination. + * + * @param queryParams the query params + */ + public void setPagination(MultivaluedMap queryParams) { + // + // Bail if there are no params + // + if (queryParams == null) return; + + // + // Set the page size + // + String pageSizeStr = null; List list = queryParams.remove(PAGE_SIZE_PARAM); if (list != null) { pageSizeStr = list.get(0); } setPageSize(pageSizeStr); + + // + // Set the start page + // + String startPageStr = null; list = queryParams.remove(START_PAGE_PARAM); if (list != null) { startPageStr = list.get(0); } - if (startPageStr != null) { - try { - startPage = Integer.valueOf(startPageStr); - } catch (NumberFormatException e) { - throw new NumberFormatException("Bad value for: " + START_PAGE_PARAM); - } - } + setStartPage(startPageStr); } /** @@ -192,25 +214,50 @@ public class DocumentFilter { public int getPageSize() { return pageSize; } + + public boolean getPageSizeDirty() { + return this.getPageSizeDirty(); + } /** * @param pageSize the max number of items to return for list requests */ public void setPageSize(int pageSize) { this.pageSize = pageSize; + this.pageSizeDirty = true; // page size explicity set/overriden } /** * @param pageSize the max number of items to return for list requests */ public void setPageSize(String pageSizeStr) { + int pageSize = this.defaultPageSize; if (pageSizeStr != null) { try { - pageSize = Integer.valueOf(pageSizeStr); + pageSize = Integer.valueOf(pageSizeStr); } catch (NumberFormatException e) { + //FIXME This should cause a warning in the log file and should result in the + //FIXME page size being set to the default. We don't need to throw an exception here. throw new NumberFormatException("Bad value for: " + PAGE_SIZE_PARAM); } } + + setPageSize(pageSize); + } + + /** + * Sets the start page. + * + * @param startPageStr the new start page + */ + protected void setStartPage(String startPageStr) { + if (startPageStr != null) { + try { + startPage = Integer.valueOf(startPageStr); + } catch (NumberFormatException e) { + throw new NumberFormatException("Bad value for: " + START_PAGE_PARAM); + } + } } /** diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java index 360169c22..4a6467dd2 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentHandler.java @@ -224,7 +224,7 @@ public interface DocumentHandler { * @param properties */ public void setProperties(Map 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 { * @param ctx ServiceContext used to fetch default pagination, etc. * @return */ - public DocumentFilter createDocumentFilter(ServiceContext ctx); + public DocumentFilter createDocumentFilter(); /** * getDocumentFilter diff --git a/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaDocumentFilter.java b/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaDocumentFilter.java index e0d744793..24e6e27fe 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaDocumentFilter.java +++ b/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaDocumentFilter.java @@ -51,11 +51,14 @@ 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); + } } diff --git a/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaStorageClientImpl.java b/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaStorageClientImpl.java index 0203b73e1..dc29738e3 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaStorageClientImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/storage/jpa/JpaStorageClientImpl.java @@ -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; diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java index 005229fb2..ac2c147a5 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/DocumentModelHandler.java @@ -113,13 +113,10 @@ public abstract class DocumentModelHandler @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; } diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoDocumentFilter.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoDocumentFilter.java index fd74a9334..bf9411f82 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoDocumentFilter.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/NuxeoDocumentFilter.java @@ -51,10 +51,14 @@ 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); + } } diff --git a/services/contact/service/src/main/java/org/collectionspace/services/contact/ContactResource.java b/services/contact/service/src/main/java/org/collectionspace/services/contact/ContactResource.java index 9d1eb50d2..0a4d89826 100644 --- a/services/contact/service/src/main/java/org/collectionspace/services/contact/ContactResource.java +++ b/services/contact/service/src/main/java/org/collectionspace/services/contact/ContactResource.java @@ -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 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 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 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 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 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 ctx = createServiceContext(); getRepositoryClient(ctx).delete(ctx, csid); return Response.status(HttpResponseCodes.SC_OK).build(); } catch (DocumentNotFoundException dnfe) { diff --git a/services/dimension/service/src/main/java/org/collectionspace/services/dimension/DimensionResource.java b/services/dimension/service/src/main/java/org/collectionspace/services/dimension/DimensionResource.java index 549a4cb85..e3ecb77f5 100644 --- a/services/dimension/service/src/main/java/org/collectionspace/services/dimension/DimensionResource.java +++ b/services/dimension/service/src/main/java/org/collectionspace/services/dimension/DimensionResource.java @@ -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 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 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 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 queryParams = ui.getQueryParameters(); try { - ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName()); + ServiceContext 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 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 ctx = createServiceContext(); getRepositoryClient(ctx).delete(ctx, csid); return Response.status(HttpResponseCodes.SC_OK).build(); } catch (DocumentNotFoundException dnfe) { diff --git a/services/intake/service/src/main/java/org/collectionspace/services/intake/IntakeResource.java b/services/intake/service/src/main/java/org/collectionspace/services/intake/IntakeResource.java index 8167a2c70..a7be7687c 100644 --- a/services/intake/service/src/main/java/org/collectionspace/services/intake/IntakeResource.java +++ b/services/intake/service/src/main/java/org/collectionspace/services/intake/IntakeResource.java @@ -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 getCommonPartClass() { + return IntakesCommon.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(), 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 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 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 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 queryParams) { IntakesCommonList intakeObjectList; try { - ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName()); + ServiceContext 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 queryParams = ui.getQueryParameters(); + ServiceContext ctx = createServiceContext(queryParams); DocumentWrapper 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 csidList) { IntakesCommonList intakeObjectList = new IntakesCommonList(); try { - ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName()); + ServiceContext 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 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 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 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 queryParams, + String keywords) { IntakesCommonList intakesObjectList; try { - ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName()); + ServiceContext 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; - } - + } } diff --git a/services/loanin/service/src/main/java/org/collectionspace/services/loanin/LoaninResource.java b/services/loanin/service/src/main/java/org/collectionspace/services/loanin/LoaninResource.java index 766fcbda7..79c302bda 100644 --- a/services/loanin/service/src/main/java/org/collectionspace/services/loanin/LoaninResource.java +++ b/services/loanin/service/src/main/java/org/collectionspace/services/loanin/LoaninResource.java @@ -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 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 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 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 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 queryParams) { LoansinCommonList loaninObjectList; try { - ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName()); + ServiceContext 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 queryParams = ui.getQueryParameters(); + ServiceContext ctx = createServiceContext(queryParams); DocumentWrapper 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 csidList) { LoansinCommonList loaninObjectList = new LoansinCommonList(); try { - ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName()); + ServiceContext 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 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 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 queryParams, + String keywords) { LoansinCommonList loansinObjectList; try { - ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName()); + ServiceContext 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; - } - + } } diff --git a/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java b/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java index 367a4130c..3b45ff4e6 100644 --- a/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java +++ b/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java @@ -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 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 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 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 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 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 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 ctx = createServiceContext(); MultivaluedMap 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 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 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 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 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 queryParams = ui.getQueryParameters(); // Note that docType defaults to the ServiceName, so we're fine with that. - ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getItemServiceName()); + ServiceContext ctx = createServiceContext(getItemServiceName(), + queryParams); DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); - MultivaluedMap 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 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 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 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 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 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 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 queryParams = ui.getQueryParameters(); - DocumentFilter myFilter = handler.createDocumentFilter(ctx); //new DocumentFilter(); - myFilter.setPagination(queryParams); + ServiceContext 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 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 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 ctx = createServiceContext(getContactServiceName()); getRepositoryClient(ctx).delete(ctx, csid); return Response.status(HttpResponseCodes.SC_OK).build(); } catch (UnauthorizedException ue) { diff --git a/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java b/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java index 8bdf3a9b5..71a025cb3 100644 --- a/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java +++ b/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java @@ -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 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 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 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 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 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 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 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 ctx = createServiceContext(); MultivaluedMap 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 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 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 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 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 queryParams = ui.getQueryParameters(); - DocumentFilter myFilter = handler.createDocumentFilter(ctx); //new DocumentFilter(); - myFilter.setPagination(queryParams); + ServiceContext 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 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 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 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 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 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 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 queryParams = ui.getQueryParameters(); - DocumentFilter myFilter = handler.createDocumentFilter(ctx); //new DocumentFilter(); - myFilter.setPagination(queryParams); + ServiceContext 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 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 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 ctx = createServiceContext(getContactServiceName()); getRepositoryClient(ctx).delete(ctx, csid); return Response.status(HttpResponseCodes.SC_OK).build(); } catch (UnauthorizedException ue) { diff --git a/services/relation/service/src/main/java/org/collectionspace/services/relation/NewRelationResource.java b/services/relation/service/src/main/java/org/collectionspace/services/relation/NewRelationResource.java index ae883fb17..eeaa84c0f 100644 --- a/services/relation/service/src/main/java/org/collectionspace/services/relation/NewRelationResource.java +++ b/services/relation/service/src/main/java/org/collectionspace/services/relation/NewRelationResource.java @@ -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 getCommonPartClass() { + return RelationsCommon.class; + } + + /* (non-Javadoc) + * @see org.collectionspace.services.common.AbstractCollectionSpaceResource#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(), 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 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 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 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 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 ctx = createServiceContext(); DocumentHandler handler = createDocumentHandler(ctx); - Map propsFromPath = handler.getProperties(); + Map propsFromPath = handler.getProperties(); propsFromPath.put(IRelationsManager.SUBJECT, subjectCsid); propsFromPath.put(IRelationsManager.PREDICATE, predicate); propsFromPath.put(IRelationsManager.OBJECT, objectCsid); diff --git a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java index 9eedd8298..5b8a12830 100644 --- a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java +++ b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java @@ -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 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 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 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 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 queryParams = ui.getQueryParameters(); + ServiceContext 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 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 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 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 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 queryParams = ui.getQueryParameters(); // Note that docType defaults to the ServiceName, so we're fine with that. - ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getItemServiceName()); + ServiceContext ctx = createServiceContext(getItemServiceName(), + queryParams); DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); - MultivaluedMap 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 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 ctx = createServiceContext(getItemServiceName()); getRepositoryClient(ctx).delete(ctx, itemcsid); return Response.status(HttpResponseCodes.SC_OK).build(); } catch (UnauthorizedException ue) {