From dfb86aeacc7c17bdfcdee72c92f99d06c2103bc3 Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Fri, 16 Apr 2010 16:54:13 +0000 Subject: [PATCH] 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. --- ...tMultiPartCollectionSpaceResourceImpl.java | 96 ++++++++++++++++ .../context/RemoteServiceContextFactory.java | 108 ++++++++++++++++++ 2 files changed, 204 insertions(+) create mode 100644 services/common/src/main/java/org/collectionspace/services/common/AbstractMultiPartCollectionSpaceResourceImpl.java create mode 100644 services/common/src/main/java/org/collectionspace/services/common/context/RemoteServiceContextFactory.java diff --git a/services/common/src/main/java/org/collectionspace/services/common/AbstractMultiPartCollectionSpaceResourceImpl.java b/services/common/src/main/java/org/collectionspace/services/common/AbstractMultiPartCollectionSpaceResourceImpl.java new file mode 100644 index 000000000..8c1acf1f4 --- /dev/null +++ b/services/common/src/main/java/org/collectionspace/services/common/AbstractMultiPartCollectionSpaceResourceImpl.java @@ -0,0 +1,96 @@ +/** + * AbstractMultiPartCollectionSpaceResourceImpl.java + * + * {Purpose of This Class} + * + * {Other Notes Relating to This Class (Optional)} + * + * $LastChangedBy: $ + * $LastChangedRevision: $ + * $LastChangedDate: $ + * + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + * + * http://www.collectionspace.org + * http://wiki.collectionspace.org + * + * Copyright © 2009 {Contributing Institution} + * + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + * + * You may obtain a copy of the ECL 2.0 License at + * https://source.collectionspace.org/collection-space/LICENSE.txt + */ +package org.collectionspace.services.common; + +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.context.ServiceContextFactory; +import org.collectionspace.services.common.document.DocumentHandler; + +import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; +import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; + +/** + * The Class AbstractMultiPartCollectionSpaceResourceImpl. + */ +public abstract class AbstractMultiPartCollectionSpaceResourceImpl extends + AbstractCollectionSpaceResourceImpl { + + @Override + public ServiceContextFactory getServiceContextFactory() { + return (ServiceContextFactory)MultipartServiceContextFactory.get(); + } + + @Override + public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception { + DocumentHandler docHandler = createDocumentHandler(ctx, ctx.getCommonPartLabel(), + getCommonPartClass()); + return docHandler; + } + + /** + * Creates the document handler. + * + * @param serviceContext the service context + * @param schemaName the schema name + * @param commonClass the common class + * + * @return the document handler + * + * @throws Exception the exception + */ + public DocumentHandler createDocumentHandler(ServiceContext serviceContext, + String schemaName, + Class commonClass) throws Exception { + MultipartServiceContext ctx = (MultipartServiceContext)serviceContext; + Object commonPart = null; + if (ctx.getInput() != null) { + commonPart = ctx.getInputPart(schemaName, commonClass); + } + DocumentHandler docHandler = super.createDocumentHandler(ctx, commonPart); + + return docHandler; + } + + /** + * Creates the document handler. + * + * @param ctx the ctx + * @param commonClass the common class + * + * @return the document handler + * + * @throws Exception the exception + */ + public DocumentHandler createDocumentHandler( + ServiceContext ctx, + Class commonClass) throws Exception { + return createDocumentHandler(ctx, ctx.getCommonPartLabel(), commonClass); + } + +} diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/RemoteServiceContextFactory.java b/services/common/src/main/java/org/collectionspace/services/common/context/RemoteServiceContextFactory.java new file mode 100644 index 000000000..46be9f728 --- /dev/null +++ b/services/common/src/main/java/org/collectionspace/services/common/context/RemoteServiceContextFactory.java @@ -0,0 +1,108 @@ +/** + * RemoteServiceContextFactory.java + * + * {Purpose of This Class} + * + * {Other Notes Relating to This Class (Optional)} + * + * $LastChangedBy: $ + * $LastChangedRevision: $ + * $LastChangedDate: $ + * + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + * + * http://www.collectionspace.org + * http://wiki.collectionspace.org + * + * Copyright © 2009 {Contributing Institution} + * + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + * + * You may obtain a copy of the ECL 2.0 License at + * https://source.collectionspace.org/collection-space/LICENSE.txt + */ +package org.collectionspace.services.common.context; + +import javax.ws.rs.core.MultivaluedMap; + +import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; +import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; + +/** + * A factory for creating RemoteServiceContext objects. + */ +public class RemoteServiceContextFactory + implements ServiceContextFactory{ + + // create a Factory singleton + /** The Constant self. */ + final private static RemoteServiceContextFactory self = new RemoteServiceContextFactory(); + + /** + * Instantiates a new remote service context factory. + */ + private RemoteServiceContextFactory() {} // private constructor + + /** + * Gets the. + * + * @return the remote service context factory + */ + public static RemoteServiceContextFactory get() { + return self; + } + + /* (non-Javadoc) + * @see org.collectionspace.services.common.context.ServiceContextFactory#createServiceContext(java.lang.String) + */ + @Override + public ServiceContext createServiceContext(String serviceName) throws Exception { + RemoteServiceContext ctx = new RemoteServiceContextImpl(serviceName); + return ctx; + } + + /* (non-Javadoc) + * @see org.collectionspace.services.common.context.ServiceContextFactory#createServiceContext(java.lang.String, java.lang.Object) + */ + @Override + public ServiceContext createServiceContext(String serviceName, + IT theInput) throws Exception { + RemoteServiceContext ctx = new RemoteServiceContextImpl(serviceName, theInput); + 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, + IT theInput, + MultivaluedMap queryParams) throws Exception { + ServiceContext ctx = new RemoteServiceContextImpl(serviceName, + theInput, + queryParams); + + return ctx; + } + + @Override + public ServiceContext createServiceContext(String serviceName, + IT input, + MultivaluedMap queryParams, + String documentType, + String entityName) throws Exception { + ServiceContext ctx = createServiceContext( + serviceName, + input, + queryParams); + ctx.setDocumentType(documentType); //persistence unit + ctx.setProperty("entity-name", entityName); + + return ctx; + } + +} -- 2.47.3