From: Aron Roberts Date: Thu, 25 Mar 2010 04:20:55 +0000 (+0000) Subject: CSPACE-1286: Initial, somewhat minimal version of Loans In service. (The service... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=6d3a5483dceb64017339dae86a84cccc3f13e9db;p=tmp%2Fjakarta-migration.git CSPACE-1286: Initial, somewhat minimal version of Loans In service. (The service's module is named 'loanin' for consistency with other system layers.) See the relevant JIRA for tasks remaining. Service is fully functional, but requires completion and adding back of the LoaninAuthRefsTest client test, initially omitted. Would also benefit by using a larger set of fields in example records in client tests, adding convenience JAXB constants and completing the Nuxeo layout for webapp record editing. --- diff --git a/services/JaxRsServiceProvider/pom.xml b/services/JaxRsServiceProvider/pom.xml index 0225c15cb..39dafa866 100644 --- a/services/JaxRsServiceProvider/pom.xml +++ b/services/JaxRsServiceProvider/pom.xml @@ -80,6 +80,11 @@ org.collectionspace.services.intake.service ${project.version} + + org.collectionspace.services + org.collectionspace.services.loanin.service + ${project.version} + org.collectionspace.services org.collectionspace.services.dimension.service diff --git a/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java b/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java index ba0591be5..60cdd95c3 100644 --- a/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java +++ b/services/JaxRsServiceProvider/src/main/java/org/collectionspace/services/jaxrs/CollectionSpaceJaxRsApplication.java @@ -27,6 +27,7 @@ import org.collectionspace.services.account.AccountResource; import org.collectionspace.services.collectionobject.CollectionObjectResource; import org.collectionspace.services.id.IDResource; import org.collectionspace.services.intake.IntakeResource; +import org.collectionspace.services.loanin.LoaninResource; import org.collectionspace.services.relation.NewRelationResource; import org.collectionspace.services.acquisition.AcquisitionResource; import org.collectionspace.services.dimension.DimensionResource; @@ -63,6 +64,7 @@ public class CollectionSpaceJaxRsApplication extends Application { singletons.add(new CollectionObjectResource()); singletons.add(new IDResource()); singletons.add(new IntakeResource()); + singletons.add(new LoaninResource()); singletons.add(new AcquisitionResource()); singletons.add(new NewRelationResource()); singletons.add(new VocabularyResource()); diff --git a/services/build.xml b/services/build.xml index 4b2377044..a2c56c4af 100644 --- a/services/build.xml +++ b/services/build.xml @@ -151,6 +151,7 @@ + @@ -170,6 +171,7 @@ + @@ -196,6 +198,7 @@ + @@ -225,6 +228,7 @@ + --> diff --git a/services/common/src/main/config/services/tenant-bindings.xml b/services/common/src/main/config/services/tenant-bindings.xml index 294577b9b..3a3f6bb0d 100644 --- a/services/common/src/main/config/services/tenant-bindings.xml +++ b/services/common/src/main/config/services/tenant-bindings.xml @@ -109,6 +109,42 @@ + + + + nuxeo-java + + + org.collectionspace.services.loanin.nuxeo.LoaninDocumentModelHandler + + + org.collectionspace.services.loanin.nuxeo.LoaninValidatorHandler + + + + + + + + + + + + + + + + + diff --git a/services/loanin/jaxb/pom.xml b/services/loanin/jaxb/pom.xml new file mode 100644 index 000000000..5f7a2c54c --- /dev/null +++ b/services/loanin/jaxb/pom.xml @@ -0,0 +1,104 @@ + + + + org.collectionspace.services.loanin + org.collectionspace.services + 0.6-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.loanin.jaxb + services.loanin.jaxb + + + + com.sun.xml.bind + jaxb-impl + 2.0.2 + + + org.jvnet.jaxb2-commons + property-listener-injector + 1.0 + + + org.jvnet.jaxb2_commons + runtime + 0.4.1.4 + + + + + collectionspace-services-loanin-jaxb + install + + + org.jvnet.jaxb2.maven2 + maven-jaxb2-plugin + + + + generate + + + + + + + javax.activation + activation + 1.1 + + + com.sun.xml.bind + jaxb-impl + 2.1.9 + + + + + -XtoString + -Xinject-listener-code + + + + + + + org.jvnet.jaxb2_commons + + basic + 0.4.1 + + + + org.jvnet.jaxb2-commons + + + property-listener-injector + + 1.0 + + + + + + + + maven-compiler-plugin + 2.0.2 + + 1.6 + 1.6 + + + + + + diff --git a/services/loanin/jaxb/src/main/java/org/collectionspace/services/LoaninJAXBSchema.java b/services/loanin/jaxb/src/main/java/org/collectionspace/services/LoaninJAXBSchema.java new file mode 100644 index 000000000..be1ddd9e9 --- /dev/null +++ b/services/loanin/jaxb/src/main/java/org/collectionspace/services/LoaninJAXBSchema.java @@ -0,0 +1,11 @@ +/** + * + */ +package org.collectionspace.services; + +public interface LoaninJAXBSchema { + final static String LOAN_IN_NUMBER = "loanInNumber"; + final static String LOAN_RETURN_DATE = "loanReturnDate"; +} + + diff --git a/services/loanin/jaxb/src/main/java/org/collectionspace/services/LoaninListItemJAXBSchema.java b/services/loanin/jaxb/src/main/java/org/collectionspace/services/LoaninListItemJAXBSchema.java new file mode 100644 index 000000000..34285605c --- /dev/null +++ b/services/loanin/jaxb/src/main/java/org/collectionspace/services/LoaninListItemJAXBSchema.java @@ -0,0 +1,8 @@ +package org.collectionspace.services; + +public interface LoaninListItemJAXBSchema { + final static String LOAN_IN_NUMBER = "loaninNumber"; + final static String LOAN_RETURN_DATE = "loanReturnDate"; + final static String CSID = "csid"; + final static String URI = "url"; +} diff --git a/services/loanin/jaxb/src/main/resources/loansin-common.xsd b/services/loanin/jaxb/src/main/resources/loansin-common.xsd new file mode 100644 index 000000000..d4af271a1 --- /dev/null +++ b/services/loanin/jaxb/src/main/resources/loansin-common.xsd @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/loanin/service/pom.xml b/services/loanin/service/pom.xml new file mode 100644 index 000000000..8cfe40bef --- /dev/null +++ b/services/loanin/service/pom.xml @@ -0,0 +1,138 @@ + + + + + org.collectionspace.services + org.collectionspace.services.loanin + 0.6-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.loanin.service + services.loanin.service + jar + + + + org.collectionspace.services + org.collectionspace.services.common + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.loanin.jaxb + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.collectionobject.jaxb + ${project.version} + + + + junit + junit + 4.1 + test + + + org.testng + testng + 5.6 + + + + + + javax.security + jaas + 1.0.01 + provided + + + + dom4j + dom4j + 1.6.1 + provided + + + + + + org.jboss.resteasy + resteasy-jaxrs + 1.0.2.GA + + + tjws + webserver + + + + + org.jboss.resteasy + resteasy-jaxb-provider + 1.0.2.GA + + + org.jboss.resteasy + resteasy-multipart-provider + 1.0.2.GA + + + + + + org.nuxeo.ecm.core + nuxeo-core-api + 1.5.1-SNAPSHOT + + + jboss-remoting + jboss + + + + + + org.restlet + org.restlet + 1.0.7 + + + com.noelios.restlet + com.noelios.restlet.ext.httpclient + 1.0.7 + + + com.noelios.restlet + com.noelios.restlet + 1.0.7 + + + + + collectionspace-services-loanin + + + org.codehaus.mojo + jboss-maven-plugin + + ${jboss.dir} + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.6 + 1.6 + true + + + + + + diff --git a/services/loanin/service/profiles.xml b/services/loanin/service/profiles.xml new file mode 100644 index 000000000..347b9df22 --- /dev/null +++ b/services/loanin/service/profiles.xml @@ -0,0 +1,4 @@ + + + \ No newline at end of file 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 new file mode 100644 index 000000000..38264d551 --- /dev/null +++ b/services/loanin/service/src/main/java/org/collectionspace/services/loanin/LoaninResource.java @@ -0,0 +1,480 @@ +/** + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + + * http://www.collectionspace.org + * http://wiki.collectionspace.org + + * Copyright 2009 University of California at Berkeley + + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + + * You may obtain a copy of the ECL 2.0 License at + + * https://source.collectionspace.org/collection-space/LICENSE.txt + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.loanin; + +import java.util.List; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; +import javax.ws.rs.core.UriInfo; + +import org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl; +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.MultipartServiceContextImpl; +import org.collectionspace.services.common.context.ServiceContext; +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.query.IQueryManager; +import org.collectionspace.services.common.query.QueryManager; +import org.collectionspace.services.common.security.UnauthorizedException; +import org.collectionspace.services.common.vocabulary.RefNameServiceUtils; +import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; +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.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * The Class LoaninResource. + */ +@Path("/loansin") +@Consumes("multipart/mixed") +@Produces("multipart/mixed") +public class LoaninResource extends AbstractCollectionSpaceResourceImpl { + + /** The Constant serviceName. */ + private final static String serviceName = "loansin"; + + /** The logger. */ + final Logger logger = LoggerFactory.getLogger(LoaninResource.class); + //FIXME retrieve client type from configuration + /** The Constant CLIENT_TYPE. */ + final static ClientType CLIENT_TYPE = ServiceMain.getInstance().getClientType(); + + /** + * Instantiates a new loanin resource. + */ + public LoaninResource() { + // do nothing + } + + /* (non-Javadoc) + * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getVersionString() + */ + @Override + protected String getVersionString() { + /** The last change revision. */ + final String lastChangeRevision = "$LastChangedRevision: 1627 $"; + return lastChangeRevision; + } + + /* (non-Javadoc) + * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getServiceName() + */ + @Override + public String getServiceName() { + return serviceName; + } + + /* (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. + * + * @param input the input + * + * @return the response + */ + @POST + public Response createLoanin(MultipartInput input) { + try { + ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getServiceName()); + DocumentHandler handler = createDocumentHandler(ctx); + String csid = getRepositoryClient(ctx).create(ctx, handler); + //loaninObject.setCsid(csid); + UriBuilder path = UriBuilder.fromResource(LoaninResource.class); + path.path("" + csid); + Response response = Response.created(path.build()).build(); + return response; + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Create failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("Caught exception in createLoanin", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + } + + /** + * Gets the loanin. + * + * @param csid the csid + * + * @return the loanin + */ + @GET + @Path("{csid}") + public MultipartOutput getLoanin( + @PathParam("csid") String csid) { + if (logger.isDebugEnabled()) { + logger.debug("getLoanin with csid=" + csid); + } + if (csid == null || "".equals(csid)) { + logger.error("getLoanin: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "get failed on Loanin csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + MultipartOutput result = null; + try { + ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName()); + DocumentHandler handler = createDocumentHandler(ctx); + getRepositoryClient(ctx).get(ctx, csid, handler); + result = (MultipartOutput) ctx.getOutput(); + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (DocumentNotFoundException dnfe) { + if (logger.isDebugEnabled()) { + logger.debug("getLoanin", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed on Loanin csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("getLoanin", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + if (result == null) { + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed, the requested Loanin CSID:" + csid + ": was not found.").type( + "text/plain").build(); + throw new WebApplicationException(response); + } + return result; + } + + /** + * Gets the loanin list. + * + * @param ui the ui + * @param keywords the keywords + * + * @return the loanin list + */ + @GET + @Produces("application/xml") + public LoansinCommonList getLoaninList(@Context UriInfo ui, + @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords) { + LoansinCommonList result = null; + + if (keywords != null) { + result = searchLoansin(keywords); + } else { + result = getLoaninList(); + } + + return result; + } + + /** + * Gets the loanin list. + * + * @return the loanin list + */ + private LoansinCommonList getLoaninList() { + LoansinCommonList loaninObjectList; + try { + ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName()); + DocumentHandler handler = createDocumentHandler(ctx); + getRepositoryClient(ctx).getAll(ctx, handler); + loaninObjectList = (LoansinCommonList) handler.getCommonPartList(); + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("Caught exception in getLoaninList", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + return loaninObjectList; + } + + /** + * Gets the authority refs. + * + * @param csid the csid + * @param ui the ui + * + * @return the authority refs + */ + @GET + @Path("{csid}/authorityrefs") + @Produces("application/xml") + public AuthorityRefList getAuthorityRefs( + @PathParam("csid") String csid, + @Context UriInfo ui) { + AuthorityRefList authRefList = null; + try { + ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName()); + DocumentWrapper docWrapper = + getRepositoryClient(ctx).getDoc(ctx, csid); + RemoteDocumentModelHandlerImpl handler + = (RemoteDocumentModelHandlerImpl)createDocumentHandler(ctx); + List authRefFields = ((MultipartServiceContextImpl)ctx).getCommonPartPropertyValues(RefNameServiceUtils.AUTH_REF_PROP); + authRefList = handler.getAuthorityRefs(docWrapper, authRefFields); + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("Caught exception in getAuthorityRefs", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + return authRefList; + } + + /** + * Gets the loanin list. + * + * @param csidList the csid list + * + * @return the loanin list + */ + public LoansinCommonList getLoaninList(List csidList) { + LoansinCommonList loaninObjectList = new LoansinCommonList(); + try { + ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName()); + DocumentHandler handler = createDocumentHandler(ctx); + getRepositoryClient(ctx).get(ctx, csidList, handler); + loaninObjectList = (LoansinCommonList) handler.getCommonPartList(); + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("Caught exception in getLoaninList", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + return loaninObjectList; + } + + /** + * Update loanin. + * + * @param csid the csid + * @param theUpdate the the update + * + * @return the multipart output + */ + @PUT + @Path("{csid}") + public MultipartOutput updateLoanin( + @PathParam("csid") String csid, + MultipartInput theUpdate) { + if (logger.isDebugEnabled()) { + logger.debug("updateLoanin with csid=" + csid); + } + if (csid == null || "".equals(csid)) { + logger.error("updateLoanin: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "update failed on Loanin csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + MultipartOutput result = null; + try { + ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(theUpdate, getServiceName()); + DocumentHandler handler = createDocumentHandler(ctx); + getRepositoryClient(ctx).update(ctx, csid, handler); + result = (MultipartOutput) ctx.getOutput(); + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Update failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (DocumentNotFoundException dnfe) { + if (logger.isDebugEnabled()) { + logger.debug("caught exception in updateLoanin", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Update failed on Loanin csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + return result; + } + + /** + * Delete loanin. + * + * @param csid the csid + * + * @return the response + */ + @DELETE + @Path("{csid}") + public Response deleteLoanin(@PathParam("csid") String csid) { + + if (logger.isDebugEnabled()) { + logger.debug("deleteLoanin with csid=" + csid); + } + if (csid == null || "".equals(csid)) { + logger.error("deleteLoanin: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "delete failed on Loanin csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + try { + ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName()); + getRepositoryClient(ctx).delete(ctx, csid); + return Response.status(HttpResponseCodes.SC_OK).build(); + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Delete failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (DocumentNotFoundException dnfe) { + if (logger.isDebugEnabled()) { + logger.debug("caught exception in deleteLoanin", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Delete failed on Loanin csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Delete failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + } + + /** + * 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. + * + * @param keywords the keywords + * + * @return the loansin common list + */ + private LoansinCommonList searchLoansin(String keywords) { + LoansinCommonList loansinObjectList; + try { + ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName()); + DocumentHandler handler = createDocumentHandler(ctx); + + // perform a keyword search + if (keywords != null && !keywords.isEmpty()) { + String whereClause = QueryManager.createWhereClauseFromKeywords(keywords); + DocumentFilter documentFilter = handler.getDocumentFilter(); + documentFilter.setWhereClause(whereClause); + if (logger.isDebugEnabled()) { + logger.debug("The WHERE clause is: " + documentFilter.getWhereClause()); + } + getRepositoryClient(ctx).getFiltered(ctx, handler); + } else { + getRepositoryClient(ctx).getAll(ctx, handler); + } + loansinObjectList = (LoansinCommonList) handler.getCommonPartList(); + + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Index failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("Caught exception in search for Loansin", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + return loansinObjectList; + } + +} diff --git a/services/loanin/service/src/main/java/org/collectionspace/services/loanin/nuxeo/LoaninConstants.java b/services/loanin/service/src/main/java/org/collectionspace/services/loanin/nuxeo/LoaninConstants.java new file mode 100644 index 000000000..113c45835 --- /dev/null +++ b/services/loanin/service/src/main/java/org/collectionspace/services/loanin/nuxeo/LoaninConstants.java @@ -0,0 +1,35 @@ +/** + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + + * http://www.collectionspace.org + * http://wiki.collectionspace.org + + * Copyright 2009 University of California at Berkeley + + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + + * You may obtain a copy of the ECL 2.0 License at + + * https://source.collectionspace.org/collection-space/LICENSE.txt + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.loanin.nuxeo; + +/** + * LoaninConstants specifies constants for the Loans In service + * + */ +public class LoaninConstants { + + public final static String NUXEO_DOCTYPE = "Loanin"; + public final static String NUXEO_SCHEMA_NAME = "loanin"; + public final static String NUXEO_DC_TITLE = "CollectionSpace-Loanin"; +} diff --git a/services/loanin/service/src/main/java/org/collectionspace/services/loanin/nuxeo/LoaninDocumentModelHandler.java b/services/loanin/service/src/main/java/org/collectionspace/services/loanin/nuxeo/LoaninDocumentModelHandler.java new file mode 100644 index 000000000..0aebab8a7 --- /dev/null +++ b/services/loanin/service/src/main/java/org/collectionspace/services/loanin/nuxeo/LoaninDocumentModelHandler.java @@ -0,0 +1,143 @@ +/** + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + + * http://www.collectionspace.org + * http://wiki.collectionspace.org + + * Copyright 2009 University of California at Berkeley + + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + + * You may obtain a copy of the ECL 2.0 License at + + * https://source.collectionspace.org/collection-space/LICENSE.txt + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.loanin.nuxeo; + +import java.util.Iterator; +import java.util.List; + +import org.collectionspace.services.LoaninJAXBSchema; +import org.collectionspace.services.common.document.DocumentWrapper; +import org.collectionspace.services.loanin.LoansinCommon; +import org.collectionspace.services.loanin.LoansinCommonList; +import org.collectionspace.services.loanin.LoansinCommonList.LoaninListItem; +import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; +import org.collectionspace.services.nuxeo.util.NuxeoUtils; +import org.nuxeo.ecm.core.api.DocumentModel; +import org.nuxeo.ecm.core.api.DocumentModelList; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * LoaninDocumentModelHandler + * + * $LastChangedRevision: $ + * $LastChangedDate: $ + */ +public class LoaninDocumentModelHandler + extends RemoteDocumentModelHandlerImpl { + + private final Logger logger = LoggerFactory.getLogger(LoaninDocumentModelHandler.class); + /** + * loanin is used to stash JAXB object to use when handle is called + * for Action.CREATE, Action.UPDATE or Action.GET + */ + private LoansinCommon loanin; + /** + * loaninList is stashed when handle is called + * for ACTION.GET_ALL + */ + private LoansinCommonList loaninList; + + + /** + * getCommonPart get associated loanin + * @return + */ + @Override + public LoansinCommon getCommonPart() { + return loanin; + } + + /** + * setCommonPart set associated loanin + * @param loanin + */ + @Override + public void setCommonPart(LoansinCommon loanin) { + this.loanin = loanin; + } + + /** + * getCommonPartList get associated loanin (for index/GET_ALL) + * @return + */ + @Override + public LoansinCommonList getCommonPartList() { + return loaninList; + } + + @Override + public void setCommonPartList(LoansinCommonList loaninList) { + this.loaninList = loaninList; + } + + @Override + public LoansinCommon extractCommonPart(DocumentWrapper wrapDoc) + throws Exception { + throw new UnsupportedOperationException(); + } + + @Override + public void fillCommonPart(LoansinCommon loaninObject, DocumentWrapper wrapDoc) throws Exception { + throw new UnsupportedOperationException(); + } + + @Override + public LoansinCommonList extractCommonPartList(DocumentWrapper wrapDoc) throws Exception { + DocumentModelList docList = wrapDoc.getWrappedObject(); + + LoansinCommonList coList = new LoansinCommonList(); + List list = coList.getLoaninListItem(); + + //FIXME: iterating over a long list of documents is not a long term + //strategy...need to change to more efficient iterating in future + Iterator iter = docList.iterator(); + while(iter.hasNext()){ + DocumentModel docModel = iter.next(); + LoaninListItem ilistItem = new LoaninListItem(); + ilistItem.setLoanInNumber((String) docModel.getProperty(getServiceContext().getCommonPartLabel(), + LoaninJAXBSchema.LOAN_IN_NUMBER)); + ilistItem.setLoanReturnDate((String) docModel.getProperty(getServiceContext().getCommonPartLabel(), + LoaninJAXBSchema.LOAN_RETURN_DATE)); + String id = NuxeoUtils.extractId(docModel.getPathAsString()); + ilistItem.setUri(getServiceContextPath() + id); + ilistItem.setCsid(id); + list.add(ilistItem); + } + + return coList; + } + + /** + * getQProperty converts the given property to qualified schema property + * @param prop + * @return + */ + @Override + public String getQProperty(String prop) { + return LoaninConstants.NUXEO_SCHEMA_NAME + ":" + prop; + } + +} + diff --git a/services/loanin/service/src/main/java/org/collectionspace/services/loanin/nuxeo/LoaninValidatorHandler.java b/services/loanin/service/src/main/java/org/collectionspace/services/loanin/nuxeo/LoaninValidatorHandler.java new file mode 100644 index 000000000..b45fd5116 --- /dev/null +++ b/services/loanin/service/src/main/java/org/collectionspace/services/loanin/nuxeo/LoaninValidatorHandler.java @@ -0,0 +1,18 @@ +package org.collectionspace.services.loanin.nuxeo; + +import org.collectionspace.services.common.context.ServiceContext; +import org.collectionspace.services.common.document.InvalidDocumentException; +import org.collectionspace.services.common.document.ValidatorHandler; +import org.collectionspace.services.common.document.DocumentHandler.Action; + +public class LoaninValidatorHandler implements ValidatorHandler { + + @Override + public void validate(Action action, ServiceContext ctx) + throws InvalidDocumentException { + // TODO Auto-generated method stub + System.out.println("LoaninValidatorHandler executed."); + + } + +} diff --git a/services/loanin/service/src/test/java/org/collectionspace/services/test/LoaninServiceTest.java b/services/loanin/service/src/test/java/org/collectionspace/services/test/LoaninServiceTest.java new file mode 100644 index 000000000..adcf38f03 --- /dev/null +++ b/services/loanin/service/src/test/java/org/collectionspace/services/test/LoaninServiceTest.java @@ -0,0 +1,13 @@ +package org.collectionspace.services.test; + +//import org.collectionspace.services.loanin.Loanin; +//import org.collectionspace.services.loanin.LoaninList; + +/** + * Placeholder for server-side testing of Loan In service code. + * + * @version $Revision:$ + */ +public class LoaninServiceTest { + //empty +} diff --git a/services/loanin/service/src/test/resources/log4j.xml b/services/loanin/service/src/test/resources/log4j.xml new file mode 100644 index 000000000..52121cb83 --- /dev/null +++ b/services/loanin/service/src/test/resources/log4j.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/pom.xml b/services/pom.xml index cefff9c0f..97f102875 100644 --- a/services/pom.xml +++ b/services/pom.xml @@ -28,6 +28,7 @@ id collectionobject intake + loanin dimension contact JaxRsServiceProvider @@ -272,4 +273,4 @@ - \ No newline at end of file +