From: Aron Roberts Date: Sat, 17 Apr 2010 00:10:02 +0000 (+0000) Subject: CSPACE-1292: Initial release of the Loan Out (aka Loans Out) service. Introduces... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=975dff9a68cfc0ab213e89f125d992a0879e62ed;p=tmp%2Fjakarta-migration.git CSPACE-1292: Initial release of the Loan Out (aka Loans Out) service. Introduces a new Nuxeo document type, and thus requires 'ant deploy' and restarting the two JBoss servers. --- diff --git a/services/JaxRsServiceProvider/pom.xml b/services/JaxRsServiceProvider/pom.xml index cc0e8e7be..f4e4f6ab7 100644 --- a/services/JaxRsServiceProvider/pom.xml +++ b/services/JaxRsServiceProvider/pom.xml @@ -90,6 +90,11 @@ org.collectionspace.services.loanin.service ${project.version} + + org.collectionspace.services + org.collectionspace.services.loanout.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 10c7b7554..3bf763ec3 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.collectionobject.CollectionObjectResource; import org.collectionspace.services.id.IDResource; import org.collectionspace.services.intake.IntakeResource; import org.collectionspace.services.loanin.LoaninResource; +import org.collectionspace.services.loanout.LoanoutResource; import org.collectionspace.services.relation.NewRelationResource; import org.collectionspace.services.acquisition.AcquisitionResource; import org.collectionspace.services.dimension.DimensionResource; @@ -67,6 +68,7 @@ public class CollectionSpaceJaxRsApplication extends Application { singletons.add(new IDResource()); singletons.add(new IntakeResource()); singletons.add(new LoaninResource()); + singletons.add(new LoanoutResource()); singletons.add(new AcquisitionResource()); singletons.add(new NewRelationResource()); singletons.add(new VocabularyResource()); diff --git a/services/common/src/main/config/services/tenant-bindings.xml b/services/common/src/main/config/services/tenant-bindings.xml index a2e82ac47..7660a6a3a 100644 --- a/services/common/src/main/config/services/tenant-bindings.xml +++ b/services/common/src/main/config/services/tenant-bindings.xml @@ -151,6 +151,48 @@ + + + + nuxeo-java + + + org.collectionspace.services.loanout.nuxeo.LoanoutDocumentModelHandler + + + org.collectionspace.services.loanout.nuxeo.LoanoutValidatorHandler + + + + + + + + + + + authRefborrower + authRefborrowersContact + authReflendersAuthorizer + authReflendersContact + + + + + + + + + diff --git a/services/loanout/3rdparty/build.xml b/services/loanout/3rdparty/build.xml new file mode 100644 index 000000000..4a351d9c3 --- /dev/null +++ b/services/loanout/3rdparty/build.xml @@ -0,0 +1,127 @@ + + + + loanout service 3rdparty + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/loanout/3rdparty/nuxeo-platform-cs-loanout/build.xml b/services/loanout/3rdparty/nuxeo-platform-cs-loanout/build.xml new file mode 100644 index 000000000..faa723714 --- /dev/null +++ b/services/loanout/3rdparty/nuxeo-platform-cs-loanout/build.xml @@ -0,0 +1,132 @@ + + + + loanout nuxeo document type + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/loanout/3rdparty/nuxeo-platform-cs-loanout/pom.xml b/services/loanout/3rdparty/nuxeo-platform-cs-loanout/pom.xml new file mode 100644 index 000000000..4b2800bc9 --- /dev/null +++ b/services/loanout/3rdparty/nuxeo-platform-cs-loanout/pom.xml @@ -0,0 +1,38 @@ + + + + org.collectionspace.services + org.collectionspace.services.loanout.3rdparty + 0.6-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.loanout.3rdparty.nuxeo + services.loanout.3rdparty.nuxeo + jar + + Loanout Nuxeo Document Type + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + src/main/resources/META-INF/MANIFEST.MF + + ${eclipseVersion} + 2 + + + + + + + + diff --git a/services/loanout/3rdparty/nuxeo-platform-cs-loanout/src/main/resources/META-INF/MANIFEST.MF b/services/loanout/3rdparty/nuxeo-platform-cs-loanout/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 000000000..69f1fdf21 --- /dev/null +++ b/services/loanout/3rdparty/nuxeo-platform-cs-loanout/src/main/resources/META-INF/MANIFEST.MF @@ -0,0 +1,22 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 1 +Bundle-Name: NuxeoCS +Bundle-SymbolicName: org.collectionspace.loanout;singleton:=true +Bundle-Version: 1.0.0 +Bundle-Localization: plugin +Bundle-Vendor: Nuxeo +Require-Bundle: org.nuxeo.runtime, + org.nuxeo.ecm.core.api, + org.nuxeo.ecm.core, + org.nuxeo.ecm.core.api, + org.nuxeo.ecm.platform.types.api, + org.nuxeo.ecm.platform.versioning.api, + org.nuxeo.ecm.platform.ui, + org.nuxeo.ecm.platform.forms.layout.client, + org.nuxeo.ecm.platform.publishing.api, + org.nuxeo.ecm.platform.ws +Provide-Package: org.collectionspace.loanout +Nuxeo-Component: OSGI-INF/core-types-contrib.xml, + OSGI-INF/ecm-types-contrib.xml, + OSGI-INF/layouts-contrib.xml + diff --git a/services/loanout/3rdparty/nuxeo-platform-cs-loanout/src/main/resources/OSGI-INF/core-types-contrib.xml b/services/loanout/3rdparty/nuxeo-platform-cs-loanout/src/main/resources/OSGI-INF/core-types-contrib.xml new file mode 100644 index 000000000..4d4171b0b --- /dev/null +++ b/services/loanout/3rdparty/nuxeo-platform-cs-loanout/src/main/resources/OSGI-INF/core-types-contrib.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/services/loanout/3rdparty/nuxeo-platform-cs-loanout/src/main/resources/OSGI-INF/deployment-fragment.xml b/services/loanout/3rdparty/nuxeo-platform-cs-loanout/src/main/resources/OSGI-INF/deployment-fragment.xml new file mode 100644 index 000000000..88b94ffd1 --- /dev/null +++ b/services/loanout/3rdparty/nuxeo-platform-cs-loanout/src/main/resources/OSGI-INF/deployment-fragment.xml @@ -0,0 +1,408 @@ + + + + + + ${bundle.fileName} + + + + + nuxeo.war + /nuxeo + + + + + + + + + + + + Seam Context Filter + /ws/FileManageWS + + + + Seam Context Filter + /DocumentManagerWS + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #{currentServerLocation.name}/#{currentTabAction.label} + + + + Create new document in #{currentDocument.name} + + + + Create new document in #{currentDocument.name} + + + + breadcrumb=command.user_dashboard + + + + breadcrumb=command.manageMembers + + + + breadcrumb=command.manageMembers + + + + breadcrumb=title.vocabularies + + + + breadcrumb=command.advancedSearch + + + + + + en + en_GB + en_US + fr + de + es + it + ar + ru + ja + vn + + + messages + + + + config/addWorkspace.jpdl.xml + + + + + + generic_error_page + /generic_error_page.xhtml + + + + + generic_message_page + /generic_message_page.xhtml + + + + + home + /nxstartup.xhtml + + + + + user_login + /login.xhtml + + + + + user_logout + /logout.xhtml + + + + + view_servers + /view_servers.xhtml + + + + + + + view_domains + /view_domains.xhtml + + + + + select_document_type + /select_document_type.xhtml + + + + + create_document + /create_document.xhtml + + + + + edit_document + /edit_document.xhtml + + + + + view_documents + /view_documents.xhtml + + + + + create_file + /create_file.xhtml + + + + + create_workspace_wizard + /createWorkspaceWizard.xhtml + + + + + send_email + /document_email.xhtml + + + + + + view_workspaces + /view_workspaces.xhtml + + + + + + create_domain + /create_domain.xhtml + + + + + + edit_domain + /edit_domain.xhtml + + + + + + create_workspace + /create_workspace.xhtml + + + + + + edit_workspace + /edit_workspace.xhtml + + + + + + + members_management + /members_management.xhtml + + + + + view_users + /view_users.xhtml + + + + + view_many_users + /view_many_users.xhtml + + + + + edit_user + /edit_user.xhtml + + + + + edit_user_password + /edit_user_password.xhtml + + + + + view_user + /view_user.xhtml + + + + + create_user + /create_user.xhtml + + + + + view_groups + /view_groups.xhtml + + + + + view_group + /view_group.xhtml + + + + + edit_group + /edit_group.xhtml + + + + + create_group + /create_group.xhtml + + + + + view_vocabularies + /view_vocabularies.xhtml + + + + + view_vocabulary + /view_vocabulary.xhtml + + + + + + + search_form + /search/search_form.xhtml + + + + + search_results_nxql + /search/search_results_nxql.xhtml + + + + + search_results_advanced + + /search/search_results_advanced.xhtml + + + + + + search_results_simple + /search/search_results_simple.xhtml + + + + + + + clipboard + /incl/clipboard.xhtml + + + + + user_dashboard + /user_dashboard.xhtml + + + + + select_workspace_template + /select_workspace_template.xhtml + + + + + pdf_generation_error + /pdf_generation_error.xhtml + + + + + mass_edit + /massedit_documents.xhtml + + + + + mass_edit_confirm + /massedit_documents_preview.xhtml + + + + + + diff --git a/services/loanout/3rdparty/nuxeo-platform-cs-loanout/src/main/resources/OSGI-INF/ecm-types-contrib.xml b/services/loanout/3rdparty/nuxeo-platform-cs-loanout/src/main/resources/OSGI-INF/ecm-types-contrib.xml new file mode 100644 index 000000000..3abdb6d6b --- /dev/null +++ b/services/loanout/3rdparty/nuxeo-platform-cs-loanout/src/main/resources/OSGI-INF/ecm-types-contrib.xml @@ -0,0 +1,28 @@ + + + + + + + view_documents + + + heading + loanout + + + + + + Loanout + + + + + + Loanout + + + + + diff --git a/services/loanout/3rdparty/nuxeo-platform-cs-loanout/src/main/resources/OSGI-INF/layouts-contrib.xml b/services/loanout/3rdparty/nuxeo-platform-cs-loanout/src/main/resources/OSGI-INF/layouts-contrib.xml new file mode 100644 index 000000000..b8405c1d3 --- /dev/null +++ b/services/loanout/3rdparty/nuxeo-platform-cs-loanout/src/main/resources/OSGI-INF/layouts-contrib.xml @@ -0,0 +1,212 @@ + + + + + + + + + + + + + + + loanOutNumber + borrower + borrowersContact + lendersAuthorizer + lendersAuthorizationDate + lendersContact + + + + + + + loanOutDate + loanReturnDate + loanRenewalApplicationDate + specialConditionsOfLoan + loanOutNote + loanPurpose + + + + + + + true + + loanOutNumber + + + dataInputText + + + + + + + + true + + borrower + + + dataInputText + + + + + + + + true + + borrowersContact + + + dataInputText + + + + + + + + true + + lendersAuthorizer + + + dataInputText + + + + + + + + true + + lendersAuthorizationDate + + + dataInputText + + + + + + + + true + + lendersContact + + + dataInputText + + + + + + + + true + + loanOutDate + + + dataInputText + + + + + + + + true + + loanReturnDate + + + dataInputText + + + + + + + + true + + loanRenewalApplicationDate + + + dataInputText + + + + + + + + true + + specialConditionsOfLoan + + + dataInputText + + + + + + + + true + + loanOutNote + + + dataInputText + + + + + + + + true + + loanPurpose + + + dataInputText + + + + + + diff --git a/services/loanout/3rdparty/nuxeo-platform-cs-loanout/src/main/resources/schemas/loansout_common.xsd b/services/loanout/3rdparty/nuxeo-platform-cs-loanout/src/main/resources/schemas/loansout_common.xsd new file mode 100644 index 000000000..beca4809a --- /dev/null +++ b/services/loanout/3rdparty/nuxeo-platform-cs-loanout/src/main/resources/schemas/loansout_common.xsd @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/loanout/3rdparty/pom.xml b/services/loanout/3rdparty/pom.xml new file mode 100644 index 000000000..bdaa4e88f --- /dev/null +++ b/services/loanout/3rdparty/pom.xml @@ -0,0 +1,24 @@ + + + + org.collectionspace.services.loanout + org.collectionspace.services + 0.6-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.loanout.3rdparty + services.loanout.3rdparty + pom + + + 3rd party build for loanout service + + + + nuxeo-platform-cs-loanout + + diff --git a/services/loanout/build.xml b/services/loanout/build.xml new file mode 100644 index 000000000..609b490bd --- /dev/null +++ b/services/loanout/build.xml @@ -0,0 +1,124 @@ + + + + loanout service + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/loanout/client/pom.xml b/services/loanout/client/pom.xml new file mode 100644 index 000000000..f2ebfe1a2 --- /dev/null +++ b/services/loanout/client/pom.xml @@ -0,0 +1,115 @@ + + + + org.collectionspace.services + org.collectionspace.services.loanout + 0.6-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.loanout.client + services.loanout.client + + + + + org.slf4j + slf4j-api + test + + + org.slf4j + slf4j-log4j12 + test + + + + org.collectionspace.services + org.collectionspace.services.jaxb + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.common + true + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.client + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.loanout.jaxb + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.person.client + ${project.version} + + + + org.testng + testng + 5.6 + + + org.jboss.resteasy + resteasy-jaxrs + 1.1.GA + + + + tjws + webserver + + + + + org.jboss.resteasy + resteasy-jaxb-provider + 1.1.GA + + + org.jboss.resteasy + resteasy-multipart-provider + 1.1.GA + + + commons-httpclient + commons-httpclient + 3.1 + + + + + collectionspace-services-loanout-client + + + org.apache.maven.plugins + maven-surefire-plugin + + + + log4j.configuration + file:target/test-classes/log4j.properties + + + + + + maven-compiler-plugin + 2.0.2 + + 1.6 + 1.6 + + + + + diff --git a/services/loanout/client/src/main/java/org/collectionspace/services/client/LoanoutClient.java b/services/loanout/client/src/main/java/org/collectionspace/services/client/LoanoutClient.java new file mode 100644 index 000000000..c78b27af3 --- /dev/null +++ b/services/loanout/client/src/main/java/org/collectionspace/services/client/LoanoutClient.java @@ -0,0 +1,145 @@ +/** + * 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 (c) 2009 Regents of the University of California + * + * 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.client; + +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Response; + +import org.collectionspace.services.common.authorityref.AuthorityRefList; +//import org.collectionspace.services.common.context.ServiceContext; +import org.collectionspace.services.loanout.LoansoutCommonList; + +import org.jboss.resteasy.client.ProxyFactory; +import org.jboss.resteasy.plugins.providers.RegisterBuiltin; +import org.jboss.resteasy.client.ClientResponse; +import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; +import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; +import org.jboss.resteasy.spi.ResteasyProviderFactory; + +/** + * LoanoutClient.java + * + * $LastChangedRevision: $ + * $LastChangedDate: $ + * + */ +public class LoanoutClient extends AbstractServiceClientImpl { + + /* (non-Javadoc) + * @see org.collectionspace.services.client.AbstractServiceClientImpl#getServicePathComponent() + */ + public String getServicePathComponent() { + return "loansout"; + } + /** + * + */ + private static final LoanoutClient instance = new LoanoutClient(); + /** + * + */ + private LoanoutProxy loanoutProxy; + + /** + * + * Default constructor for LoanoutClient class. + * + */ + public LoanoutClient() { + ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance(); + RegisterBuiltin.register(factory); + setProxy(); + } + + /** + * allow to reset proxy as per security needs + */ + public void setProxy() { + if (useAuth()) { + loanoutProxy = ProxyFactory.create(LoanoutProxy.class, + getBaseURL(), getHttpClient()); + } else { + loanoutProxy = ProxyFactory.create(LoanoutProxy.class, + getBaseURL()); + } + } + + /** + * FIXME Comment this + * + * @return + */ + public static LoanoutClient getInstance() { + return instance; + } + + /** + * @return + * @see org.collectionspace.services.client.LoanoutProxy#getLoanout() + */ + public ClientResponse readList() { + return loanoutProxy.readList(); + } + + /** + * @param csid + * @return + * @see org.collectionspace.services.client.LoanoutProxy#getAuthorityRefs(java.lang.String) + */ + public ClientResponse getAuthorityRefs(String csid) { + return loanoutProxy.getAuthorityRefs(csid); + } + + + /** + * @param csid + * @return + * @see org.collectionspace.services.client.LoanoutProxy#getLoanout(java.lang.String) + */ + public ClientResponse read(String csid) { + return loanoutProxy.read(csid); + } + + /** + * @param loanout + * @return + * @see org.collectionspace.services.client.LoanoutProxy#createLoanout(org.collectionspace.hello.Loanout) + */ + public ClientResponse create(MultipartOutput multipart) { + return loanoutProxy.create(multipart); + } + + /** + * @param csid + * @param loanout + * @return + * @see org.collectionspace.services.client.LoanoutProxy#updateLoanout(java.lang.Long, org.collectionspace.hello.Loanout) + */ + public ClientResponse update(String csid, MultipartOutput multipart) { + return loanoutProxy.update(csid, multipart); + + } + + /** + * @param csid + * @return + * @see org.collectionspace.services.client.LoanoutProxy#deleteLoanout(java.lang.Long) + */ + public ClientResponse delete(String csid) { + return loanoutProxy.delete(csid); + } +} diff --git a/services/loanout/client/src/main/java/org/collectionspace/services/client/LoanoutProxy.java b/services/loanout/client/src/main/java/org/collectionspace/services/client/LoanoutProxy.java new file mode 100644 index 000000000..511158142 --- /dev/null +++ b/services/loanout/client/src/main/java/org/collectionspace/services/client/LoanoutProxy.java @@ -0,0 +1,57 @@ +package org.collectionspace.services.client; + +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.core.Response; + +import org.collectionspace.services.common.authorityref.AuthorityRefList; +import org.collectionspace.services.loanout.LoansoutCommonList; +import org.jboss.resteasy.client.ClientResponse; +import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; +import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; + +/** + * @version $Revision:$ + */ +@Path("/loansout/") +@Produces({"multipart/mixed"}) +@Consumes({"multipart/mixed"}) +public interface LoanoutProxy { + + //(C)reate + @POST + ClientResponse create(MultipartOutput multipart); + + //(R)ead + @GET + @Path("/{csid}") + ClientResponse read(@PathParam("csid") String csid); + + //(U)pdate + @PUT + @Path("/{csid}") + ClientResponse update(@PathParam("csid") String csid, MultipartOutput multipart); + + //(D)elete + @DELETE + @Path("/{csid}") + ClientResponse delete(@PathParam("csid") String csid); + + // List + @GET + @Produces({"application/xml"}) + ClientResponse readList(); + + // List Authority References + @GET + @Produces({"application/xml"}) + @Path("/{csid}/authorityrefs/") + ClientResponse getAuthorityRefs(@PathParam("csid") String csid); + +} diff --git a/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutAuthRefsTest.java b/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutAuthRefsTest.java new file mode 100644 index 000000000..d9e4f78d0 --- /dev/null +++ b/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutAuthRefsTest.java @@ -0,0 +1,323 @@ +/** + * 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 Regents of the University of California + * + * 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.client.test; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.collectionspace.services.PersonJAXBSchema; +import org.collectionspace.services.client.LoanoutClient; +import org.collectionspace.services.client.PersonAuthorityClient; +import org.collectionspace.services.client.PersonAuthorityClientUtils; +import org.collectionspace.services.common.authorityref.AuthorityRefList; +import org.collectionspace.services.common.authorityref.AuthorityRefList.AuthorityRefItem; +import org.collectionspace.services.loanout.LoansoutCommon; +import org.collectionspace.services.loanout.LoansoutCommonList; + +import org.jboss.resteasy.client.ClientResponse; + +import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; +import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; +import org.jboss.resteasy.plugins.providers.multipart.OutputPart; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.Test; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * LoanoutAuthRefsTest, carries out Authority References tests against a + * deployed and running Loanout (aka Loans Out) Service. + * + * $LastChangedRevision: 1327 $ + * $LastChangedDate: 2010-02-12 10:35:11 -0800 (Fri, 12 Feb 2010) $ + */ +public class LoanoutAuthRefsTest extends BaseServiceTest { + + private final Logger logger = + LoggerFactory.getLogger(LoanoutAuthRefsTest.class); + + // Instance variables specific to this test. + final String SERVICE_PATH_COMPONENT = "loansout"; + final String PERSON_AUTHORITY_NAME = "TestPersonAuth"; + private String knownResourceId = null; + private List loanoutIdsCreated = new ArrayList(); + private List personIdsCreated = new ArrayList(); + private int CREATED_STATUS = Response.Status.CREATED.getStatusCode(); + private int OK_STATUS = Response.Status.OK.getStatusCode(); + private String personAuthCSID = null; + private String borrowersContactRefName = null; + private String lendersAuthorizerRefName = null; + private String lendersContactRefName = null; + + // FIXME: Can add 'borrower' - likely to be an organization + // authority - as an authRef to tests below, and increase the + // number of expected authRefs to 4. + private final int NUM_AUTH_REFS_EXPECTED = 3; + + // --------------------------------------------------------------- + // CRUD tests : CREATE tests + // --------------------------------------------------------------- + // Success outcomes + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class) + public void createWithAuthRefs(String testName) throws Exception { + + testSetup(CREATED_STATUS, ServiceRequestType.CREATE,testName); + + // Submit the request to the service and store the response. + String identifier = createIdentifier(); + + // Create all the person refs and entities + createPersonRefs(); + + // Create a new Loans In resource. + // + // One or more fields in this resource will be PersonAuthority + // references, and will refer to Person resources by their refNames. + LoanoutClient loanoutClient = new LoanoutClient(); + MultipartOutput multipart = createLoanoutInstance( + "loanOutNumber-" + identifier, + "returnDate-" + identifier, + borrowersContactRefName, + lendersAuthorizerRefName, + lendersContactRefName); + ClientResponse res = loanoutClient.create(multipart); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + // + // Specifically: + // Does it fall within the set of valid status codes? + // Does it exactly match the expected status code? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Store the ID returned from the first resource created + // for additional tests below. + if (knownResourceId == null){ + knownResourceId = extractId(res); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": knownResourceId=" + knownResourceId); + } + } + + // Store the IDs from every resource created by tests, + // so they can be deleted after tests have been run. + loanoutIdsCreated.add(extractId(res)); + } + + protected void createPersonRefs(){ + + PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); + // Create a temporary PersonAuthority resource, and its corresponding + // refName by which it can be identified. + String authRefName = + PersonAuthorityClientUtils.createPersonAuthRefName(PERSON_AUTHORITY_NAME, false); + MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance( + PERSON_AUTHORITY_NAME, authRefName, personAuthClient.getCommonPartName()); + ClientResponse res = personAuthClient.create(multipart); + int statusCode = res.getStatus(); + + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, CREATED_STATUS); + personAuthCSID = extractId(res); + + // Create temporary Person resources, and their corresponding refNames + // by which they can be identified. + borrowersContactRefName = + PersonAuthorityClientUtils.createPersonRefName(authRefName, "Bradley BorrowersContact", true); + personIdsCreated.add(createPerson("Bradley", "BorrowersContact", borrowersContactRefName)); + + lendersAuthorizerRefName = + PersonAuthorityClientUtils.createPersonRefName(authRefName, "Art Lendersauthorizor", true); + personIdsCreated.add(createPerson("Art", "Lendersauthorizor", lendersAuthorizerRefName)); + + lendersContactRefName = + PersonAuthorityClientUtils.createPersonRefName(authRefName, "Larry Lenderscontact", true); + personIdsCreated.add(createPerson("Larry", "Lenderscontact", lendersContactRefName)); + } + + protected String createPerson(String firstName, String surName, String refName ) { + PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); + Map personInfo = new HashMap(); + personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); + personInfo.put(PersonJAXBSchema.SUR_NAME, surName); + MultipartOutput multipart = + PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, + refName, personInfo, personAuthClient.getItemCommonPartName()); + ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); + int statusCode = res.getStatus(); + + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, CREATED_STATUS); + return extractId(res); + } + + // Success outcomes + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + dependsOnMethods = {"createWithAuthRefs"}) + public void readAndCheckAuthRefs(String testName) throws Exception { + + // Perform setup. + testSetup(OK_STATUS, ServiceRequestType.READ,testName); + + // Submit the request to the service and store the response. + LoanoutClient loanoutClient = new LoanoutClient(); + ClientResponse res = loanoutClient.read(knownResourceId); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ".read: status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + MultipartInput input = (MultipartInput) res.getEntity(); + LoansoutCommon loanout = (LoansoutCommon) extractPart(input, + loanoutClient.getCommonPartName(), LoansoutCommon.class); + Assert.assertNotNull(loanout); + if(logger.isDebugEnabled()){ + logger.debug(objectAsXmlString(loanout, LoansoutCommon.class)); + } + // Check a couple of fields + // FIXME + Assert.assertEquals(loanout.getLendersAuthorizer(), lendersAuthorizerRefName); + Assert.assertEquals(loanout.getLendersContact(), lendersContactRefName); + + // Get the auth refs and check them + ClientResponse res2 = + loanoutClient.getAuthorityRefs(knownResourceId); + statusCode = res2.getStatus(); + + if(logger.isDebugEnabled()){ + logger.debug(testName + ".getAuthorityRefs: status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + AuthorityRefList list = res2.getEntity(); + + // Optionally output additional data about list members for debugging. + boolean iterateThroughList = true; + if(iterateThroughList && logger.isDebugEnabled()){ + List items = + list.getAuthorityRefItem(); + int i = 0; + for(AuthorityRefList.AuthorityRefItem item : items){ + logger.debug(testName + ": list-item[" + i + "] Field:" + + item.getSourceField() + "= " + + item.getAuthDisplayName() + + item.getItemDisplayName()); + logger.debug(testName + ": list-item[" + i + "] refName=" + + item.getRefName()); + logger.debug(testName + ": list-item[" + i + "] URI=" + + item.getUri()); + i++; + } + Assert.assertEquals(i, NUM_AUTH_REFS_EXPECTED, "Did not find all authrefs!"); + } + } + + + // --------------------------------------------------------------- + // Cleanup of resources created during testing + // --------------------------------------------------------------- + + /** + * Deletes all resources created by tests, after all tests have been run. + * + * This cleanup method will always be run, even if one or more tests fail. + * For this reason, it attempts to remove all resources created + * at any point during testing, even if some of those resources + * may be expected to be deleted by certain tests. + */ + @AfterClass(alwaysRun=true) + public void cleanUp() { + if (logger.isDebugEnabled()) { + logger.debug("Cleaning up temporary resources created for testing ..."); + } + // Note: Any non-success responses are ignored and not reported. + + PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); + // Delete Person resource(s) (before PersonAuthority resources). + ClientResponse res; + for (String resourceId : personIdsCreated) { + res = personAuthClient.deleteItem(personAuthCSID, resourceId); + } + // Delete PersonAuthority resource(s). + res = personAuthClient.delete(personAuthCSID); + // Delete Loans In resource(s). + LoanoutClient loanoutClient = new LoanoutClient(); + for (String resourceId : loanoutIdsCreated) { + res = loanoutClient.delete(resourceId); + } + } + + // --------------------------------------------------------------- + // Utility methods used by tests above + // --------------------------------------------------------------- + @Override + public String getServicePathComponent() { + return SERVICE_PATH_COMPONENT; + } + + private MultipartOutput createLoanoutInstance(String loanoutNumber, + String returnDate, + String borrowersContact, + String lendersAuthorizer, + String lendersContact) { + LoansoutCommon loanout = new LoansoutCommon(); + loanout.setLoanOutNumber(loanoutNumber); + loanout.setLoanReturnDate(returnDate); + loanout.setBorrowersContact(lendersContact); + loanout.setLendersAuthorizer(lendersAuthorizer); + loanout.setLendersContact(lendersContact); + MultipartOutput multipart = new MultipartOutput(); + OutputPart commonPart = + multipart.addPart(loanout, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", new LoanoutClient().getCommonPartName()); + + if(logger.isDebugEnabled()){ + logger.debug("to be created, loanout common"); + logger.debug(objectAsXmlString(loanout, LoansoutCommon.class)); + } + + return multipart; + } +} diff --git a/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutServiceTest.java b/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutServiceTest.java new file mode 100644 index 000000000..fbfc7f6bd --- /dev/null +++ b/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutServiceTest.java @@ -0,0 +1,642 @@ +/** + * 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 Regents of the University of California + * + * 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.client.test; + +import java.util.ArrayList; +import java.util.List; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.collectionspace.services.client.LoanoutClient; +import org.collectionspace.services.loanout.LoansoutCommon; +import org.collectionspace.services.loanout.LoansoutCommonList; + +import org.jboss.resteasy.client.ClientResponse; + +import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; +import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; +import org.jboss.resteasy.plugins.providers.multipart.OutputPart; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.Test; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * LoanoutServiceTest, carries out tests against a + * deployed and running Loanout (aka Loans Out) Service. + * + * $LastChangedRevision: 1327 $ + * $LastChangedDate: 2010-02-12 10:35:11 -0800 (Fri, 12 Feb 2010) $ + */ +public class LoanoutServiceTest extends AbstractServiceTestImpl { + + private final Logger logger = + LoggerFactory.getLogger(LoanoutServiceTest.class); + + // Instance variables specific to this test. + final String SERVICE_PATH_COMPONENT = "loansout"; + private String knownResourceId = null; + private List allResourceIdsCreated = new ArrayList(); + + // --------------------------------------------------------------- + // CRUD tests : CREATE tests + // --------------------------------------------------------------- + // Success outcomes + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class) + public void create(String testName) throws Exception { + + // Perform setup, such as initializing the type of service request + // (e.g. CREATE, DELETE), its valid and expected status codes, and + // its associated HTTP method name (e.g. POST, DELETE). + setupCreate(testName); + + // Submit the request to the service and store the response. + LoanoutClient client = new LoanoutClient(); + String identifier = createIdentifier(); + MultipartOutput multipart = createLoanoutInstance(identifier); + ClientResponse res = client.create(multipart); + + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + // + // Specifically: + // Does it fall within the set of valid status codes? + // Does it exactly match the expected status code? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Store the ID returned from the first resource created + // for additional tests below. + if (knownResourceId == null){ + knownResourceId = extractId(res); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": knownResourceId=" + knownResourceId); + } + } + + // Store the IDs from every resource created by tests, + // so they can be deleted after tests have been run. + allResourceIdsCreated.add(extractId(res)); + } + + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + dependsOnMethods = {"create"}) + public void createList(String testName) throws Exception { + for(int i = 0; i < 3; i++){ + create(testName); + } + } + + // Failure outcomes + // Placeholders until the three tests below can be uncommented. + // See Issue CSPACE-401. + @Override + public void createWithEmptyEntityBody(String testName) throws Exception { + } + + @Override + public void createWithMalformedXml(String testName) throws Exception { + } + + @Override + public void createWithWrongXmlSchema(String testName) throws Exception { + } + + /* + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"create", "testSubmitRequest"}) + public void createWithEmptyEntityBody(String testName) throws Exception { + + // Perform setup. + setupCreateWithEmptyEntityBody(testName); + + // Submit the request to the service and store the response. + String method = REQUEST_TYPE.httpMethodName(); + String url = getServiceRootURL(); + String mediaType = MediaType.APPLICATION_XML; + final String entity = ""; + int statusCode = submitRequest(method, url, mediaType, entity); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug("createWithEmptyEntityBody url=" + url + + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"create", "testSubmitRequest"}) + public void createWithMalformedXml(String testName) throws Exception { + + // Perform setup. + setupCreateWithMalformedXml(testName); + + // Submit the request to the service and store the response. + String method = REQUEST_TYPE.httpMethodName(); + String url = getServiceRootURL(); + String mediaType = MediaType.APPLICATION_XML; + final String entity = MALFORMED_XML_DATA; // Constant from base class. + int statusCode = submitRequest(method, url, mediaType, entity); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": url=" + url + + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"create", "testSubmitRequest"}) + public void createWithWrongXmlSchema(String testName) throws Exception { + + // Perform setup. + setupCreateWithWrongXmlSchema(testName); + + // Submit the request to the service and store the response. + String method = REQUEST_TYPE.httpMethodName(); + String url = getServiceRootURL(); + String mediaType = MediaType.APPLICATION_XML; + final String entity = WRONG_XML_SCHEMA_DATA; + int statusCode = submitRequest(method, url, mediaType, entity); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": url=" + url + + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + */ + + // --------------------------------------------------------------- + // CRUD tests : READ tests + // --------------------------------------------------------------- + // Success outcomes + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + dependsOnMethods = {"create"}) + public void read(String testName) throws Exception { + + // Perform setup. + setupRead(testName); + + // Submit the request to the service and store the response. + LoanoutClient client = new LoanoutClient(); + ClientResponse res = client.read(knownResourceId); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + MultipartInput input = (MultipartInput) res.getEntity(); + LoansoutCommon loanout = (LoansoutCommon) extractPart(input, + client.getCommonPartName(), LoansoutCommon.class); + Assert.assertNotNull(loanout); + } + + // Failure outcomes + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + dependsOnMethods = {"read"}) + public void readNonExistent(String testName) throws Exception { + + // Perform setup. + setupReadNonExistent(testName); + + // Submit the request to the service and store the response. + LoanoutClient client = new LoanoutClient(); + ClientResponse res = client.read(NON_EXISTENT_ID); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + + // --------------------------------------------------------------- + // CRUD tests : READ_LIST tests + // --------------------------------------------------------------- + // Success outcomes + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + dependsOnMethods = {"createList", "read"}) + public void readList(String testName) throws Exception { + + // Perform setup. + setupReadList(testName); + + // Submit the request to the service and store the response. + LoanoutClient client = new LoanoutClient(); + ClientResponse res = client.readList(); + LoansoutCommonList list = res.getEntity(); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Optionally output additional data about list members for debugging. + boolean iterateThroughList = false; + if(iterateThroughList && logger.isDebugEnabled()){ + List items = + list.getLoanoutListItem(); + int i = 0; + for(LoansoutCommonList.LoanoutListItem item : items){ + logger.debug(testName + ": list-item[" + i + "] csid=" + + item.getCsid()); + logger.debug(testName + ": list-item[" + i + "] loanOutNumber=" + + item.getLoanOutNumber()); + logger.debug(testName + ": list-item[" + i + "] URI=" + + item.getUri()); + i++; + } + } + + } + + // Failure outcomes + // None at present. + // --------------------------------------------------------------- + // CRUD tests : UPDATE tests + // --------------------------------------------------------------- + // Success outcomes + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + dependsOnMethods = {"read"}) + public void update(String testName) throws Exception { + + // Perform setup. + setupUpdate(testName); + + // Retrieve the contents of a resource to update. + LoanoutClient client = new LoanoutClient(); + ClientResponse res = + client.read(knownResourceId); + if(logger.isDebugEnabled()){ + logger.debug(testName + ": read status = " + res.getStatus()); + } + Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); + + if(logger.isDebugEnabled()){ + logger.debug("got object to update with ID: " + knownResourceId); + } + MultipartInput input = (MultipartInput) res.getEntity(); + LoansoutCommon loanout = (LoansoutCommon) extractPart(input, + client.getCommonPartName(), LoansoutCommon.class); + Assert.assertNotNull(loanout); + + // Update the content of this resource. + loanout.setLoanOutNumber("updated-" + loanout.getLoanOutNumber()); + loanout.setLoanReturnDate("updated-" + loanout.getLoanReturnDate()); + if(logger.isDebugEnabled()){ + logger.debug("to be updated object"); + logger.debug(objectAsXmlString(loanout, LoansoutCommon.class)); + } + // Submit the request to the service and store the response. + MultipartOutput output = new MultipartOutput(); + OutputPart commonPart = output.addPart(loanout, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", client.getCommonPartName()); + + res = client.update(knownResourceId, output); + int statusCode = res.getStatus(); + // Check the status code of the response: does it match the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + + input = (MultipartInput) res.getEntity(); + LoansoutCommon updatedLoanout = + (LoansoutCommon) extractPart(input, + client.getCommonPartName(), LoansoutCommon.class); + Assert.assertNotNull(updatedLoanout); + + Assert.assertEquals(updatedLoanout.getLoanReturnDate(), + loanout.getLoanReturnDate(), + "Data in updated object did not match submitted data."); + + } + + // Failure outcomes + // Placeholders until the three tests below can be uncommented. + // See Issue CSPACE-401. + @Override + public void updateWithEmptyEntityBody(String testName) throws Exception{ + } + @Override + public void updateWithMalformedXml(String testName) throws Exception { + } + @Override + public void updateWithWrongXmlSchema(String testName) throws Exception { + } + + /* + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"create", "update", "testSubmitRequest"}) + public void updateWithEmptyEntityBody(String testName) throws Exception { + + // Perform setup. + setupUpdateWithEmptyEntityBody(testName); + + // Submit the request to the service and store the response. + String method = REQUEST_TYPE.httpMethodName(); + String url = getResourceURL(knownResourceId); + String mediaType = MediaType.APPLICATION_XML; + final String entity = ""; + int statusCode = submitRequest(method, url, mediaType, entity); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": url=" + url + + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"create", "update", "testSubmitRequest"}) + public void updateWithMalformedXml(String testName) throws Exception { + + // Perform setup. + setupUpdateWithMalformedXml(testName); + + // Submit the request to the service and store the response. + String method = REQUEST_TYPE.httpMethodName(); + String url = getResourceURL(knownResourceId); + String mediaType = MediaType.APPLICATION_XML; + final String entity = MALFORMED_XML_DATA; + int statusCode = submitRequest(method, url, mediaType, entity); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": url=" + url + + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"create", "update", "testSubmitRequest"}) + public void updateWithWrongXmlSchema(String testName) throws Exception { + + // Perform setup. + setupUpdateWithWrongXmlSchema(testName); + + // Submit the request to the service and store the response. + String method = REQUEST_TYPE.httpMethodName(); + String url = getResourceURL(knownResourceId); + String mediaType = MediaType.APPLICATION_XML; + final String entity = WRONG_XML_SCHEMA_DATA; + int statusCode = submitRequest(method, url, mediaType, entity); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": url=" + url + + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + */ + + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + dependsOnMethods = {"update", "testSubmitRequest"}) + public void updateNonExistent(String testName) throws Exception { + + // Perform setup. + setupUpdateNonExistent(testName); + + // Submit the request to the service and store the response. + // Note: The ID used in this 'create' call may be arbitrary. + // The only relevant ID may be the one used in update(), below. + LoanoutClient client = new LoanoutClient(); + MultipartOutput multipart = createLoanoutInstance(NON_EXISTENT_ID); + ClientResponse res = + client.update(NON_EXISTENT_ID, multipart); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + + // --------------------------------------------------------------- + // CRUD tests : DELETE tests + // --------------------------------------------------------------- + // Success outcomes + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"}) + public void delete(String testName) throws Exception { + + // Perform setup. + setupDelete(testName); + + // Submit the request to the service and store the response. + LoanoutClient client = new LoanoutClient(); + ClientResponse res = client.delete(knownResourceId); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + + // Failure outcomes + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + dependsOnMethods = {"delete"}) + public void deleteNonExistent(String testName) throws Exception { + + // Perform setup. + setupDeleteNonExistent(testName); + + // Submit the request to the service and store the response. + LoanoutClient client = new LoanoutClient(); + ClientResponse res = client.delete(NON_EXISTENT_ID); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + + // --------------------------------------------------------------- + // Utility tests : tests of code used in tests above + // --------------------------------------------------------------- + /** + * Tests the code for manually submitting data that is used by several + * of the methods above. + */ + @Test(dependsOnMethods = {"create", "read"}) + public void testSubmitRequest() { + + // Expected status code: 200 OK + final int EXPECTED_STATUS = Response.Status.OK.getStatusCode(); + + // Submit the request to the service and store the response. + String method = ServiceRequestType.READ.httpMethodName(); + String url = getResourceURL(knownResourceId); + int statusCode = submitRequest(method, url); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug("testSubmitRequest: url=" + url + + " status=" + statusCode); + } + Assert.assertEquals(statusCode, EXPECTED_STATUS); + + } + + // --------------------------------------------------------------- + // Cleanup of resources created during testing + // --------------------------------------------------------------- + + /** + * Deletes all resources created by tests, after all tests have been run. + * + * This cleanup method will always be run, even if one or more tests fail. + * For this reason, it attempts to remove all resources created + * at any point during testing, even if some of those resources + * may be expected to be deleted by certain tests. + */ + @AfterClass(alwaysRun=true) + public void cleanUp() { + if (logger.isDebugEnabled()) { + logger.debug("Cleaning up temporary resources created for testing ..."); + } + LoanoutClient client = new LoanoutClient(); + for (String resourceId : allResourceIdsCreated) { + // Note: Any non-success responses are ignored and not reported. + ClientResponse res = client.delete(resourceId); + } + } + + // --------------------------------------------------------------- + // Utility methods used by tests above + // --------------------------------------------------------------- + @Override + public String getServicePathComponent() { + return SERVICE_PATH_COMPONENT; + } + + private MultipartOutput createLoanoutInstance(String identifier) { + return createLoanoutInstance( + "loanoutNumber-" + identifier, + "returnDate-" + identifier); + } + + private MultipartOutput createLoanoutInstance(String loanOutNumber, + String returnDate) { + LoansoutCommon loanout = new LoansoutCommon(); + loanout.setLoanOutNumber(loanOutNumber); + loanout.setLoanReturnDate(returnDate); + loanout.setBorrower( + "urn:cspace:org.collectionspace.demo:orgauthority:name(TestOrgAuth):organization:name(Northern Climes Museum)'Northern Climes Museum'"); + loanout.setBorrowersContact( + "urn:cspace:org.collectionspace.demo:personauthority:name(TestPersonAuth):person:name(Chris Contact)'Chris Contact'"); + loanout.setLoanPurpose("Allow people in cold climes to share the magic of Surfboards of the 1960s."); + MultipartOutput multipart = new MultipartOutput(); + OutputPart commonPart = + multipart.addPart(loanout, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", new LoanoutClient().getCommonPartName()); + + if(logger.isDebugEnabled()){ + logger.debug("to be created, loanout common"); + logger.debug(objectAsXmlString(loanout, LoansoutCommon.class)); + } + + return multipart; + } +} diff --git a/services/loanout/client/src/test/resources/log4j.properties b/services/loanout/client/src/test/resources/log4j.properties new file mode 100644 index 000000000..18c510350 --- /dev/null +++ b/services/loanout/client/src/test/resources/log4j.properties @@ -0,0 +1,23 @@ +log4j.rootLogger=debug, stdout, R + +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout + +# Pattern to output the caller's file name and line number. +log4j.appender.stdout.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n + +log4j.appender.R=org.apache.log4j.RollingFileAppender +log4j.appender.R.File=target/test-client.log + +log4j.appender.R.MaxFileSize=100KB +# Keep one backup file +log4j.appender.R.MaxBackupIndex=1 + +log4j.appender.R.layout=org.apache.log4j.PatternLayout +log4j.appender.R.layout.ConversionPattern=%d %-5p [%t] [%c:%L] %m%n + +#packages +log4j.logger.org.collectionspace=DEBUG +log4j.logger.org.apache=INFO +log4j.logger.httpclient=INFO +log4j.logger.org.jboss.resteasy=INFO diff --git a/services/loanout/jaxb/pom.xml b/services/loanout/jaxb/pom.xml new file mode 100644 index 000000000..6d5fd0293 --- /dev/null +++ b/services/loanout/jaxb/pom.xml @@ -0,0 +1,42 @@ + + + + org.collectionspace.services.loanout + org.collectionspace.services + 0.6-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.loanout.jaxb + services.loanout.jaxb + + + + com.sun.xml.bind + jaxb-impl + + + org.jvnet.jaxb2-commons + property-listener-injector + + + org.jvnet.jaxb2_commons + runtime + + + + + collectionspace-services-loanout-jaxb + install + + + org.jvnet.jaxb2.maven2 + maven-jaxb2-plugin + + + + + diff --git a/services/loanout/jaxb/src/main/java/org/collectionspace/services/LoanoutJAXBSchema.java b/services/loanout/jaxb/src/main/java/org/collectionspace/services/LoanoutJAXBSchema.java new file mode 100644 index 000000000..0d5bf4709 --- /dev/null +++ b/services/loanout/jaxb/src/main/java/org/collectionspace/services/LoanoutJAXBSchema.java @@ -0,0 +1,30 @@ +/** + * + */ +package org.collectionspace.services; + +public interface LoanoutJAXBSchema { + + final static String LOAN_OUT_NUMBER = "loanOutNumber"; + final static String BORROWER = "borrower"; + final static String BORROWERS_CONTACT = "borrowersContact"; + final static String LENDERS_AUTHORIZER = "lendersAuthorizer"; + final static String LENDERS_AUTHORIZATION_DATE = "lendersAuthorizationDate"; + final static String LENDERS_CONTACT = "lendersContact"; + + /* + * Omitting loaned object status fields in release 0.5.2, + * as these are likely to be repeatable or else + * handled in some alternate way in release 0.7. + */ + // final static String LOANED_OBJECT_STATUS = "loanedObjectStatus"; + // final static String LOANED_OBJECT_STATUS_DATE = "loanedObjectStatusDate"; + // final static String LOANED_OBJECT_STATUS_NOTE = "loanedObjectStatusNote"; + + final static String LOAN_OUT_DATE = "loanOutDate"; + final static String LOAN_RETURN_DATE = "loanReturnDate"; + final static String LOAN_RENEWAL_APPLICATION_DATE = "loanRenewalApplicationDate"; + final static String SPECIAL_CONDITIONS_OF_LOAN = "specialConditionsOfLoan"; + final static String LOAN_OUT_NOTE = "loanOutNote"; + final static String LOAN_PURPOSE = "loanPurpose"; +} diff --git a/services/loanout/jaxb/src/main/java/org/collectionspace/services/LoanoutListItemJAXBSchema.java b/services/loanout/jaxb/src/main/java/org/collectionspace/services/LoanoutListItemJAXBSchema.java new file mode 100644 index 000000000..c49599415 --- /dev/null +++ b/services/loanout/jaxb/src/main/java/org/collectionspace/services/LoanoutListItemJAXBSchema.java @@ -0,0 +1,8 @@ +package org.collectionspace.services; + +public interface LoanoutListItemJAXBSchema { + final static String LOAN_OUT_NUMBER = "loanoutNumber"; + final static String LOAN_RETURN_DATE = "loanReturnDate"; + final static String CSID = "csid"; + final static String URI = "url"; +} diff --git a/services/loanout/jaxb/src/main/resources/loansout-common.xsd b/services/loanout/jaxb/src/main/resources/loansout-common.xsd new file mode 100644 index 000000000..6591ef4d0 --- /dev/null +++ b/services/loanout/jaxb/src/main/resources/loansout-common.xsd @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/loanout/pom.xml b/services/loanout/pom.xml new file mode 100644 index 000000000..675c04964 --- /dev/null +++ b/services/loanout/pom.xml @@ -0,0 +1,69 @@ + + + + + org.collectionspace.services + org.collectionspace.services.main + 0.6-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.loanout + services.loanout + pom + + + jaxb + service + 3rdparty + client + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.5 + 1.5 + + + + org.apache.maven.plugins + maven-site-plugin + + /usr/bin/unzip -o > err.txt + + + + org.apache.maven.plugins + maven-war-plugin + 2.0.1 + + WEB-INF/lib/*.jar + + + true + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.0.2 + + 1.6 + 1.6 + + + + + + diff --git a/services/loanout/service/pom.xml b/services/loanout/service/pom.xml new file mode 100644 index 000000000..545cb44ec --- /dev/null +++ b/services/loanout/service/pom.xml @@ -0,0 +1,138 @@ + + + + + org.collectionspace.services + org.collectionspace.services.loanout + 0.6-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.loanout.service + services.loanout.service + jar + + + + org.collectionspace.services + org.collectionspace.services.common + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.loanout.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-loanout + + + org.codehaus.mojo + jboss-maven-plugin + + ${jboss.dir} + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.6 + 1.6 + true + + + + + + diff --git a/services/loanout/service/profiles.xml b/services/loanout/service/profiles.xml new file mode 100644 index 000000000..347b9df22 --- /dev/null +++ b/services/loanout/service/profiles.xml @@ -0,0 +1,4 @@ + + + \ No newline at end of file diff --git a/services/loanout/service/src/main/java/org/collectionspace/services/loanout/LoanoutResource.java b/services/loanout/service/src/main/java/org/collectionspace/services/loanout/LoanoutResource.java new file mode 100644 index 000000000..6ea529f88 --- /dev/null +++ b/services/loanout/service/src/main/java/org/collectionspace/services/loanout/LoanoutResource.java @@ -0,0 +1,476 @@ +/** + * 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.loanout; + +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.MultivaluedMap; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; +import javax.ws.rs.core.UriInfo; + +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.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 LoanoutResource. + */ +@Path("/loansout") +@Consumes("multipart/mixed") +@Produces("multipart/mixed") +public class LoanoutResource extends + AbstractMultiPartCollectionSpaceResourceImpl { + + /** The Constant serviceName. */ + private final static String serviceName = "loansout"; + + /** The logger. */ + final Logger logger = LoggerFactory.getLogger(LoanoutResource.class); + //FIXME retrieve client type from configuration + /** The Constant CLIENT_TYPE. */ + final static ClientType CLIENT_TYPE = ServiceMain.getInstance().getClientType(); + + /** + * Instantiates a new loanout resource. + */ + public LoanoutResource() { + // 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.CollectionSpaceResource#getCommonPartClass() + */ + @Override + public Class getCommonPartClass() { + return LoansoutCommon.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(), LoansoutCommon.class); +// if (obj != null) { +// docHandler.setCommonPart((LoansoutCommon) obj); +// } +// } +// return docHandler; +// } + + /** + * Creates the loanout. + * + * @param input the input + * + * @return the response + */ + @POST + public Response createLoanout(MultipartInput input) { + try { + ServiceContext ctx = createServiceContext(input); + DocumentHandler handler = createDocumentHandler(ctx); + String csid = getRepositoryClient(ctx).create(ctx, handler); + //loanoutObject.setCsid(csid); + UriBuilder path = UriBuilder.fromResource(LoanoutResource.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 createLoanout", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + } + + /** + * Gets the loanout. + * + * @param csid the csid + * + * @return the loanout + */ + @GET + @Path("{csid}") + public MultipartOutput getLoanout( + @PathParam("csid") String csid) { + if (logger.isDebugEnabled()) { + logger.debug("getLoanout with csid=" + csid); + } + if (csid == null || "".equals(csid)) { + logger.error("getLoanout: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "get failed on Loanout csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + MultipartOutput result = null; + try { + ServiceContext ctx = createServiceContext(); + 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("getLoanout", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed on Loanout csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("getLoanout", 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 Loanout CSID:" + csid + ": was not found.").type( + "text/plain").build(); + throw new WebApplicationException(response); + } + return result; + } + + /** + * Gets the loanout list. + * + * @param ui the ui + * @param keywords the keywords + * + * @return the loanout list + */ + @GET + @Produces("application/xml") + public LoansoutCommonList getLoanoutList(@Context UriInfo ui, + @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords) { + LoansoutCommonList result = null; + MultivaluedMap queryParams = ui.getQueryParameters(); + if (keywords != null) { + result = searchLoansout(queryParams, keywords); + } else { + result = getLoanoutList(queryParams); + } + + return result; + } + + /** + * Gets the loanout list. + * + * @return the loanout list + */ + private LoansoutCommonList getLoanoutList(MultivaluedMap queryParams) { + LoansoutCommonList loanoutObjectList; + try { + ServiceContext ctx = createServiceContext(queryParams); + DocumentHandler handler = createDocumentHandler(ctx); + getRepositoryClient(ctx).getAll(ctx, handler); + loanoutObjectList = (LoansoutCommonList) 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 getLoanoutList", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + return loanoutObjectList; + } + + /** + * 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 { + MultivaluedMap queryParams = ui.getQueryParameters(); + ServiceContext ctx = createServiceContext(queryParams); + 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("Failed to retrieve authority references: 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("Failed to retrieve authority references").type("text/plain").build(); + throw new WebApplicationException(response); + } + return authRefList; + } + + /** + * Gets the loanout list. + * + * @param csidList the csid list + * + * @return the loanout list + */ + @Deprecated + public LoansoutCommonList getLoanoutList(List csidList) { + LoansoutCommonList loanoutObjectList = new LoansoutCommonList(); + try { + ServiceContext ctx = createServiceContext(); + DocumentHandler handler = createDocumentHandler(ctx); + getRepositoryClient(ctx).get(ctx, csidList, handler); + loanoutObjectList = (LoansoutCommonList) 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 getLoanoutList", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + return loanoutObjectList; + } + + /** + * Update loanout. + * + * @param csid the csid + * @param theUpdate the the update + * + * @return the multipart output + */ + @PUT + @Path("{csid}") + public MultipartOutput updateLoanout( + @PathParam("csid") String csid, + MultipartInput theUpdate) { + if (logger.isDebugEnabled()) { + logger.debug("updateLoanout with csid=" + csid); + } + if (csid == null || "".equals(csid)) { + logger.error("updateLoanout: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "update failed on Loanout csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + MultipartOutput result = null; + try { + ServiceContext ctx = createServiceContext(theUpdate); + 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 updateLoanout", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Update failed on Loanout 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 loanout. + * + * @param csid the csid + * + * @return the response + */ + @DELETE + @Path("{csid}") + public Response deleteLoanout(@PathParam("csid") String csid) { + + if (logger.isDebugEnabled()) { + logger.debug("deleteLoanout with csid=" + csid); + } + if (csid == null || "".equals(csid)) { + logger.error("deleteLoanout: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "delete failed on Loanout csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + try { + ServiceContext ctx = createServiceContext(); + 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 deleteLoanout", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Delete failed on Loanout 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); + } + } + + /** + * Search loansout. + * + * @param keywords the keywords + * + * @return the loansout common list + */ + private LoansoutCommonList searchLoansout(MultivaluedMap queryParams, + String keywords) { + LoansoutCommonList loansoutObjectList; + try { + 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.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); + } + loansoutObjectList = (LoansoutCommonList) 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 Loansout", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + return loansoutObjectList; + } +} diff --git a/services/loanout/service/src/main/java/org/collectionspace/services/loanout/nuxeo/LoanoutConstants.java b/services/loanout/service/src/main/java/org/collectionspace/services/loanout/nuxeo/LoanoutConstants.java new file mode 100644 index 000000000..8bdecb773 --- /dev/null +++ b/services/loanout/service/src/main/java/org/collectionspace/services/loanout/nuxeo/LoanoutConstants.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.loanout.nuxeo; + +/** + * LoanoutConstants specifies constants for the Loans Out service + * + */ +public class LoanoutConstants { + + public final static String NUXEO_DOCTYPE = "Loanout"; + public final static String NUXEO_SCHEMA_NAME = "loanout"; + public final static String NUXEO_DC_TITLE = "CollectionSpace-Loanout"; +} diff --git a/services/loanout/service/src/main/java/org/collectionspace/services/loanout/nuxeo/LoanoutDocumentModelHandler.java b/services/loanout/service/src/main/java/org/collectionspace/services/loanout/nuxeo/LoanoutDocumentModelHandler.java new file mode 100644 index 000000000..a14ce2a07 --- /dev/null +++ b/services/loanout/service/src/main/java/org/collectionspace/services/loanout/nuxeo/LoanoutDocumentModelHandler.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.loanout.nuxeo; + +import java.util.Iterator; +import java.util.List; + +import org.collectionspace.services.LoanoutJAXBSchema; +import org.collectionspace.services.common.document.DocumentWrapper; +import org.collectionspace.services.loanout.LoansoutCommon; +import org.collectionspace.services.loanout.LoansoutCommonList; +import org.collectionspace.services.loanout.LoansoutCommonList.LoanoutListItem; +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; + +/** + * LoanoutDocumentModelHandler + * + * $LastChangedRevision: $ + * $LastChangedDate: $ + */ +public class LoanoutDocumentModelHandler + extends RemoteDocumentModelHandlerImpl { + + private final Logger logger = LoggerFactory.getLogger(LoanoutDocumentModelHandler.class); + /** + * loanout is used to stash JAXB object to use when handle is called + * for Action.CREATE, Action.UPDATE or Action.GET + */ + private LoansoutCommon loanout; + /** + * loanoutList is stashed when handle is called + * for ACTION.GET_ALL + */ + private LoansoutCommonList loanoutList; + + + /** + * getCommonPart get associated loanout + * @return + */ + @Override + public LoansoutCommon getCommonPart() { + return loanout; + } + + /** + * setCommonPart set associated loanout + * @param loanout + */ + @Override + public void setCommonPart(LoansoutCommon loanout) { + this.loanout = loanout; + } + + /** + * getCommonPartList get associated loanout (for index/GET_ALL) + * @return + */ + @Override + public LoansoutCommonList getCommonPartList() { + return loanoutList; + } + + @Override + public void setCommonPartList(LoansoutCommonList loanoutList) { + this.loanoutList = loanoutList; + } + + @Override + public LoansoutCommon extractCommonPart(DocumentWrapper wrapDoc) + throws Exception { + throw new UnsupportedOperationException(); + } + + @Override + public void fillCommonPart(LoansoutCommon loanoutObject, DocumentWrapper wrapDoc) throws Exception { + throw new UnsupportedOperationException(); + } + + @Override + public LoansoutCommonList extractCommonPartList(DocumentWrapper wrapDoc) throws Exception { + DocumentModelList docList = wrapDoc.getWrappedObject(); + + LoansoutCommonList coList = new LoansoutCommonList(); + List list = coList.getLoanoutListItem(); + + //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(); + LoanoutListItem ilistItem = new LoanoutListItem(); + ilistItem.setLoanOutNumber((String) docModel.getProperty(getServiceContext().getCommonPartLabel(), + LoanoutJAXBSchema.LOAN_OUT_NUMBER)); + ilistItem.setLoanReturnDate((String) docModel.getProperty(getServiceContext().getCommonPartLabel(), + LoanoutJAXBSchema.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 LoanoutConstants.NUXEO_SCHEMA_NAME + ":" + prop; + } + +} + diff --git a/services/loanout/service/src/main/java/org/collectionspace/services/loanout/nuxeo/LoanoutValidatorHandler.java b/services/loanout/service/src/main/java/org/collectionspace/services/loanout/nuxeo/LoanoutValidatorHandler.java new file mode 100644 index 000000000..bb3e18f25 --- /dev/null +++ b/services/loanout/service/src/main/java/org/collectionspace/services/loanout/nuxeo/LoanoutValidatorHandler.java @@ -0,0 +1,18 @@ +package org.collectionspace.services.loanout.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 LoanoutValidatorHandler implements ValidatorHandler { + + @Override + public void validate(Action action, ServiceContext ctx) + throws InvalidDocumentException { + // TODO Auto-generated method stub + System.out.println("LoanoutValidatorHandler executed."); + + } + +} diff --git a/services/loanout/service/src/test/java/org/collectionspace/services/test/LoanoutServiceTest.java b/services/loanout/service/src/test/java/org/collectionspace/services/test/LoanoutServiceTest.java new file mode 100644 index 000000000..f082012e7 --- /dev/null +++ b/services/loanout/service/src/test/java/org/collectionspace/services/test/LoanoutServiceTest.java @@ -0,0 +1,13 @@ +package org.collectionspace.services.test; + +//import org.collectionspace.services.loanout.Loanout; +//import org.collectionspace.services.loanout.LoanoutList; + +/** + * Placeholder for server-side testing of Loan Out service code. + * + * @version $Revision:$ + */ +public class LoanoutServiceTest { + //empty +} diff --git a/services/loanout/service/src/test/resources/log4j.xml b/services/loanout/service/src/test/resources/log4j.xml new file mode 100644 index 000000000..52121cb83 --- /dev/null +++ b/services/loanout/service/src/test/resources/log4j.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/pom.xml b/services/pom.xml index 5bd7c6dd8..4556e2b2f 100644 --- a/services/pom.xml +++ b/services/pom.xml @@ -30,6 +30,7 @@ collectionobject intake loanin + loanout dimension contact JaxRsServiceProvider @@ -291,4 +292,4 @@ - \ No newline at end of file +