From de4b69009c060f7e9f7a3920318f322352a7ab93 Mon Sep 17 00:00:00 2001 From: Patrick Schmitz Date: Wed, 7 Oct 2009 23:07:59 +0000 Subject: [PATCH] CSPACE-451 Have basics of the Vocabulary service working. Vocabulary Items still in progress, but I wanted to do an interim checkin. --- services/JaxRsServiceProvider/pom.xml | 5 + .../CollectionSpaceJaxRsApplication.java | 2 + services/build.xml | 3 + services/common/.classpath | 2 +- .../src/main/config/tenant-bindings.xml | 28 + services/vocabulary/3rdparty/.classpath | 6 + services/vocabulary/3rdparty/.project | 23 + .../.settings/org.maven.ide.eclipse.prefs | 9 + services/vocabulary/3rdparty/build.xml | 125 +++++ .../src/main/resources/META-INF/MANIFEST.MF | 22 + .../resources/OSGI-INF/core-types-contrib.xml | 23 + .../OSGI-INF/deployment-fragment.xml | 408 ++++++++++++++ .../resources/OSGI-INF/ecm-types-contrib.xml | 53 ++ .../resources/OSGI-INF/layouts-contrib.xml | 84 +++ .../src/main/resources/schemas/README.txt | 4 + .../resources/schemas/vocabularies-common.xsd | 18 + .../schemas/vocabularyitems-common.xsd | 17 + services/vocabulary/3rdparty/pom.xml | 23 + .../.settings/org.eclipse.jdt.core.prefs | 5 + .../.settings/org.maven.ide.eclipse.prefs | 9 + .../services/client/VocabularyClient.java | 97 ++++ .../services/client/VocabularyProxy.java | 48 ++ .../client/test/VocabularyServiceTest.java | 530 ++++++++++++++++++ .../src/test/resources/log4j.properties | 23 + .../services/VocabularyItemJAXBSchema.java | 15 + .../VocabularyItemListItemJAXBSchema.java | 7 + .../services/VocabularyJAXBSchema.java | 15 + .../VocabularyListItemJAXBSchema.java | 8 + .../src/main/resources/vocabulary-common.xsd | 53 ++ services/vocabulary/pom.xml | 3 + services/vocabulary/service/.classpath | 2 + services/vocabulary/service/pom.xml | 5 + .../services/vocabulary/VocabResource.java | 100 ---- .../vocabulary/VocabularyResource.java | 243 ++++++++ 34 files changed, 1917 insertions(+), 101 deletions(-) create mode 100644 services/vocabulary/3rdparty/.classpath create mode 100644 services/vocabulary/3rdparty/.project create mode 100644 services/vocabulary/3rdparty/.settings/org.maven.ide.eclipse.prefs create mode 100644 services/vocabulary/3rdparty/build.xml create mode 100644 services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/META-INF/MANIFEST.MF create mode 100644 services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/OSGI-INF/core-types-contrib.xml create mode 100644 services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/OSGI-INF/deployment-fragment.xml create mode 100644 services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/OSGI-INF/ecm-types-contrib.xml create mode 100644 services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/OSGI-INF/layouts-contrib.xml create mode 100644 services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/README.txt create mode 100644 services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/vocabularies-common.xsd create mode 100644 services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/vocabularyitems-common.xsd create mode 100644 services/vocabulary/3rdparty/pom.xml create mode 100644 services/vocabulary/client/.settings/org.eclipse.jdt.core.prefs create mode 100644 services/vocabulary/client/.settings/org.maven.ide.eclipse.prefs create mode 100644 services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClient.java create mode 100644 services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyProxy.java create mode 100644 services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java create mode 100644 services/vocabulary/client/src/test/resources/log4j.properties create mode 100644 services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyItemJAXBSchema.java create mode 100644 services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyItemListItemJAXBSchema.java create mode 100644 services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyJAXBSchema.java create mode 100644 services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyListItemJAXBSchema.java create mode 100644 services/vocabulary/jaxb/src/main/resources/vocabulary-common.xsd delete mode 100644 services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabResource.java create mode 100644 services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java diff --git a/services/JaxRsServiceProvider/pom.xml b/services/JaxRsServiceProvider/pom.xml index 66e6c6fff..5fdb4a388 100644 --- a/services/JaxRsServiceProvider/pom.xml +++ b/services/JaxRsServiceProvider/pom.xml @@ -42,6 +42,11 @@ org.collectionspace.services.acquisition.service 1.0 + + org.collectionspace.services + org.collectionspace.services.vocabulary.service + 1.0 + org.collectionspace.services org.collectionspace.services.relation.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 1651aef32..199cc8061 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 @@ -6,6 +6,7 @@ import org.collectionspace.services.intake.IntakeResource; ////import org.collectionspace.services.relation.RelationResource; import org.collectionspace.services.relation.NewRelationResource; import org.collectionspace.services.acquisition.AcquisitionResource; +import org.collectionspace.services.vocabulary.VocabularyResource; //import org.collectionspace.services.query.QueryResource; import javax.ws.rs.core.Application; @@ -25,6 +26,7 @@ public class CollectionSpaceJaxRsApplication extends Application { singletons.add(new AcquisitionResource()); // singletons.add(new RelationResource()); singletons.add(new NewRelationResource()); + singletons.add(new VocabularyResource()); // singletons.add(new QueryResource()); // singletons.add(new DomainIdentifierResource()); // singletons.add(new PingResource()); diff --git a/services/build.xml b/services/build.xml index 074c796e0..fe66659d0 100644 --- a/services/build.xml +++ b/services/build.xml @@ -113,6 +113,7 @@ + @@ -121,6 +122,7 @@ + @@ -139,6 +141,7 @@ + diff --git a/services/common/.classpath b/services/common/.classpath index d6a971966..4c2d7084d 100644 --- a/services/common/.classpath +++ b/services/common/.classpath @@ -4,7 +4,7 @@ - + diff --git a/services/common/src/main/config/tenant-bindings.xml b/services/common/src/main/config/tenant-bindings.xml index 2e3d3e861..9355c744a 100644 --- a/services/common/src/main/config/tenant-bindings.xml +++ b/services/common/src/main/config/tenant-bindings.xml @@ -79,6 +79,34 @@ + + + nuxeo-java + + + + + + + + + + + + + + + + nuxeo-java diff --git a/services/vocabulary/3rdparty/.classpath b/services/vocabulary/3rdparty/.classpath new file mode 100644 index 000000000..046988541 --- /dev/null +++ b/services/vocabulary/3rdparty/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/services/vocabulary/3rdparty/.project b/services/vocabulary/3rdparty/.project new file mode 100644 index 000000000..b3274cfa9 --- /dev/null +++ b/services/vocabulary/3rdparty/.project @@ -0,0 +1,23 @@ + + + org.collectionspace.services.project.3rdparty + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.maven.ide.eclipse.maven2Nature + + diff --git a/services/vocabulary/3rdparty/.settings/org.maven.ide.eclipse.prefs b/services/vocabulary/3rdparty/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 000000000..93b6f8a66 --- /dev/null +++ b/services/vocabulary/3rdparty/.settings/org.maven.ide.eclipse.prefs @@ -0,0 +1,9 @@ +#Fri Sep 11 17:00:30 PDT 2009 +activeProfiles= +eclipse.preferences.version=1 +fullBuildGoals=process-test-resources +includeModules=false +resolveWorkspaceProjects=true +resourceFilterGoals=process-resources resources\:testResources +skipCompilerPlugin=true +version=1 diff --git a/services/vocabulary/3rdparty/build.xml b/services/vocabulary/3rdparty/build.xml new file mode 100644 index 000000000..4222b92e2 --- /dev/null +++ b/services/vocabulary/3rdparty/build.xml @@ -0,0 +1,125 @@ + + + + vocabulary service 3rdparty + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/META-INF/MANIFEST.MF b/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 000000000..dc2b0b1ee --- /dev/null +++ b/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/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.vocabulary;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.vocabulary +Nuxeo-Component: OSGI-INF/core-types-contrib.xml, + OSGI-INF/ecm-types-contrib.xml, + OSGI-INF/layouts-contrib.xml + diff --git a/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/OSGI-INF/core-types-contrib.xml b/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/OSGI-INF/core-types-contrib.xml new file mode 100644 index 000000000..7521aa8f4 --- /dev/null +++ b/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/OSGI-INF/core-types-contrib.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/OSGI-INF/deployment-fragment.xml b/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/OSGI-INF/deployment-fragment.xml new file mode 100644 index 000000000..88b94ffd1 --- /dev/null +++ b/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/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/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/OSGI-INF/ecm-types-contrib.xml b/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/OSGI-INF/ecm-types-contrib.xml new file mode 100644 index 000000000..2d36a8f18 --- /dev/null +++ b/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/OSGI-INF/ecm-types-contrib.xml @@ -0,0 +1,53 @@ + + + + + + + view_documents + + + heading + csvocabulary + + + + + + Vocabulary + + + + + + Vocabulary + + + + + + + + + view_documents + + + heading + vocabularyitem + + + + + + VocabularyItem + + + + + + VocabularyItem + + + + + diff --git a/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/OSGI-INF/layouts-contrib.xml b/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/OSGI-INF/layouts-contrib.xml new file mode 100644 index 000000000..166b39d35 --- /dev/null +++ b/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/OSGI-INF/layouts-contrib.xml @@ -0,0 +1,84 @@ + + + + + + + + + + + + displayName + vocabType + + + + + + + true + + displayName + + + dataInputText + + + + + + + + true + + vocabType + + + dataInputText + + + + + + + + + + + + + displayName + inVocabulary + + + + + + + true + + displayName + + + dataInputText + + + + + + + + true + + inVocabulary + + + dataInputText + + + + + diff --git a/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/README.txt b/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/README.txt new file mode 100644 index 000000000..63bcc64a4 --- /dev/null +++ b/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/README.txt @@ -0,0 +1,4 @@ +The schema file here should be generated from the one defined for JAXB in: +{root, e.g., trunk}\services\vocabulary\jaxb\src\main\resources\vocabulary-common.xsd + +Soon, we should do this with a tool (XSLT). \ No newline at end of file diff --git a/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/vocabularies-common.xsd b/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/vocabularies-common.xsd new file mode 100644 index 000000000..7e642feaa --- /dev/null +++ b/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/vocabularies-common.xsd @@ -0,0 +1,18 @@ + + + + + + + + + + + + diff --git a/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/vocabularyitems-common.xsd b/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/vocabularyitems-common.xsd new file mode 100644 index 000000000..8b0d443d4 --- /dev/null +++ b/services/vocabulary/3rdparty/nuxeo-platform-cs-vocabulary/src/main/resources/schemas/vocabularyitems-common.xsd @@ -0,0 +1,17 @@ + + + + + + + + + + + diff --git a/services/vocabulary/3rdparty/pom.xml b/services/vocabulary/3rdparty/pom.xml new file mode 100644 index 000000000..dd59afb53 --- /dev/null +++ b/services/vocabulary/3rdparty/pom.xml @@ -0,0 +1,23 @@ + + + + org.collectionspace.services.vocabulary + org.collectionspace.services + 1.0 + + 4.0.0 + org.collectionspace.services + 1.0 + org.collectionspace.services.vocabulary.3rdparty + pom + services.vocabulary.3rdparty + + 3rd party build for vocabulary service + + + + nuxeo-platform-cs-vocabulary + + diff --git a/services/vocabulary/client/.settings/org.eclipse.jdt.core.prefs b/services/vocabulary/client/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..0b4dbbea4 --- /dev/null +++ b/services/vocabulary/client/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +#Mon Oct 05 17:07:09 PDT 2009 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/services/vocabulary/client/.settings/org.maven.ide.eclipse.prefs b/services/vocabulary/client/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 000000000..93b6f8a66 --- /dev/null +++ b/services/vocabulary/client/.settings/org.maven.ide.eclipse.prefs @@ -0,0 +1,9 @@ +#Fri Sep 11 17:00:30 PDT 2009 +activeProfiles= +eclipse.preferences.version=1 +fullBuildGoals=process-test-resources +includeModules=false +resolveWorkspaceProjects=true +resourceFilterGoals=process-resources resources\:testResources +skipCompilerPlugin=true +version=1 diff --git a/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClient.java b/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClient.java new file mode 100644 index 000000000..50cd35212 --- /dev/null +++ b/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyClient.java @@ -0,0 +1,97 @@ +package org.collectionspace.services.client; + +import javax.ws.rs.core.Response; + +import org.collectionspace.services.vocabulary.VocabulariesCommonList; + +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; + +/** + * A VocabularyClient. + + * @version $Revision:$ + */ +public class VocabularyClient extends BaseServiceClient { + + + /** + * + */ + private static final VocabularyClient instance = new VocabularyClient(); + /** + * + */ + private VocabularyProxy vocabularyProxy; + + /** + * + * Default constructor for VocabularyClient class. + * + */ + public VocabularyClient() { + ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance(); + RegisterBuiltin.register(factory); + vocabularyProxy = ProxyFactory.create(VocabularyProxy.class, getBaseURL()); + } + + /** + * FIXME Comment this + * + * @return + */ + public static VocabularyClient getInstance() { + return instance; + } + + /** + * @return + * @see org.collectionspace.hello.client.VocabularyProxy#getVocabulary() + */ + public ClientResponse readList() { + return vocabularyProxy.readList(); + } + + /** + * @param csid + * @return + * @see org.collectionspace.hello.client.VocabularyProxy#getVocabulary(java.lang.String) + */ + + public ClientResponse read(String csid) { + return vocabularyProxy.read(csid); + } + + /** + * @param vocabulary + * @return + * @see org.collectionspace.hello.client.VocabularyProxy#createVocabulary(org.collectionspace.hello.Vocabulary) + */ + public ClientResponse create(MultipartOutput multipart) { + return vocabularyProxy.create(multipart); + } + + /** + * @param csid + * @param vocabulary + * @return + * @see org.collectionspace.hello.client.VocabularyProxy#updateVocabulary(java.lang.Long, org.collectionspace.hello.Vocabulary) + */ + public ClientResponse update(String csid, MultipartOutput multipart) { + return vocabularyProxy.update(csid, multipart); + + } + + /** + * @param csid + * @return + * @see org.collectionspace.hello.client.VocabularyProxy#deleteVocabulary(java.lang.Long) + */ + public ClientResponse delete(String csid) { + return vocabularyProxy.delete(csid); + } +} diff --git a/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyProxy.java b/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyProxy.java new file mode 100644 index 000000000..4b293363a --- /dev/null +++ b/services/vocabulary/client/src/main/java/org/collectionspace/services/client/VocabularyProxy.java @@ -0,0 +1,48 @@ +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.vocabulary.VocabulariesCommonList; +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("/vocabularies/") +@Produces({"multipart/mixed"}) +@Consumes({"multipart/mixed"}) +public interface VocabularyProxy { + + @GET + @Produces({"application/xml"}) + ClientResponse readList(); + + //(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); +} diff --git a/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java b/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java new file mode 100644 index 000000000..5a079653a --- /dev/null +++ b/services/vocabulary/client/src/test/java/org/collectionspace/services/client/test/VocabularyServiceTest.java @@ -0,0 +1,530 @@ +/** + * 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.List; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.collectionspace.services.client.VocabularyClient; +import org.collectionspace.services.vocabulary.VocabulariesCommon; +import org.collectionspace.services.vocabulary.VocabulariesCommonList; + +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.Test; + +/** + * VocabularyServiceTest, carries out tests against a + * deployed and running Vocabulary Service. + * + * $LastChangedRevision: 753 $ + * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $ + */ +public class VocabularyServiceTest extends AbstractServiceTest { + + // Instance variables specific to this test. + private VocabularyClient client = new VocabularyClient(); + final String SERVICE_PATH_COMPONENT = "vocabularies"; + private String knownResourceId = null; + + // --------------------------------------------------------------- + // CRUD tests : CREATE tests + // --------------------------------------------------------------- + // Success outcomes + @Override + @Test + public void create() { + + // 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(); + + // Submit the request to the service and store the response. + String identifier = createIdentifier(); + + MultipartOutput multipart = createVocabularyInstance(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? + verbose("create: status = " + statusCode); + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Store the ID returned from this create operation + // for additional tests below. + knownResourceId = extractId(res); + verbose("create: knownResourceId=" + knownResourceId); + } + + @Override + @Test(dependsOnMethods = {"create"}) + public void createList() { + for(int i = 0; i < 3; i++){ + create(); + } + } + + // Failure outcomes + // Placeholders until the three tests below can be uncommented. + // See Issue CSPACE-401. + public void createWithEmptyEntityBody() { + } + + public void createWithMalformedXml() { + } + + public void createWithWrongXmlSchema() { + } + + /* + @Override + @Test(dependsOnMethods = {"create", "testSubmitRequest"}) + public void createWithEmptyEntityBody() { + + // Perform setup. + setupCreateWithEmptyEntityBody(); + + // 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)? + verbose("createWithEmptyEntityBody url=" + url + " status=" + statusCode); + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + + @Override + @Test(dependsOnMethods = {"create", "testSubmitRequest"}) + public void createWithMalformedXml() { + + // Perform setup. + setupCreateWithMalformedXml(); + + // 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)? + verbose("createWithMalformedXml url=" + url + " status=" + statusCode); + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + + @Override + @Test(dependsOnMethods = {"create", "testSubmitRequest"}) + public void createWithWrongXmlSchema() { + + // Perform setup. + setupCreateWithWrongXmlSchema(); + + // 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)? + verbose("createWithWrongSchema 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(dependsOnMethods = {"create"}) + public void read() { + + // Perform setup. + setupRead(); + + // Submit the request to the service and store the response. + ClientResponse res = client.read(knownResourceId); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + verbose("read: status = " + statusCode); + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + //FIXME: remove the following try catch once Aron fixes signatures + try{ + MultipartInput input = (MultipartInput) res.getEntity(); + VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input, + getCommonPartName(), VocabulariesCommon.class); + Assert.assertNotNull(vocabulary); + }catch(Exception e){ + throw new RuntimeException(e); + } + } + + // Failure outcomes + @Override + @Test(dependsOnMethods = {"read"}) + public void readNonExistent() { + + // Perform setup. + setupReadNonExistent(); + + // Submit the request to the service and store the response. + 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)? + verbose("readNonExistent: status = " + res.getStatus()); + 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(dependsOnMethods = {"read"}) + public void readList() { + + // Perform setup. + setupReadList(); + + // Submit the request to the service and store the response. + ClientResponse res = client.readList(); + VocabulariesCommonList list = res.getEntity(); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + verbose("readList: status = " + res.getStatus()); + 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.getVocabularyListItem(); + int i = 0; + for(VocabulariesCommonList.VocabularyListItem item : items){ + verbose("readList: list-item[" + i + "] csid=" + + item.getCsid()); + verbose("readList: list-item[" + i + "] displayName=" + + item.getDisplayName()); + verbose("readList: list-item[" + i + "] URI=" + + item.getUri()); + i++; + } + } + + } + + // Failure outcomes + // None at present. + // --------------------------------------------------------------- + // CRUD tests : UPDATE tests + // --------------------------------------------------------------- + // Success outcomes + @Override + @Test(dependsOnMethods = {"read"}) + public void update() { + + // Perform setup. + setupUpdate(); + + try{ //ideally, just remove try-catch and let the exception bubble up + // Retrieve an existing resource that we can update. + ClientResponse res = + client.read(knownResourceId); + verbose("update: read status = " + res.getStatus()); + Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); + + verbose("got object to update with ID: " + knownResourceId); + MultipartInput input = (MultipartInput) res.getEntity(); + VocabulariesCommon vocabulary = (VocabulariesCommon) extractPart(input, + getCommonPartName(), VocabulariesCommon.class); + Assert.assertNotNull(vocabulary); + + // Update the content of this resource. + vocabulary.setDisplayName("updated-" + vocabulary.getDisplayName()); + vocabulary.setVocabType("updated-" + vocabulary.getVocabType()); + verbose("to be updated object", vocabulary, VocabulariesCommon.class); + // Submit the request to the service and store the response. + MultipartOutput output = new MultipartOutput(); + OutputPart commonPart = output.addPart(vocabulary, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", getCommonPartName()); + + res = client.update(knownResourceId, output); + int statusCode = res.getStatus(); + // Check the status code of the response: does it match the expected response(s)? + verbose("update: status = " + res.getStatus()); + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + + input = (MultipartInput) res.getEntity(); + VocabulariesCommon updatedVocabulary = + (VocabulariesCommon) extractPart(input, + getCommonPartName(), VocabulariesCommon.class); + Assert.assertNotNull(updatedVocabulary); + + Assert.assertEquals(updatedVocabulary.getDisplayName(), + vocabulary.getDisplayName(), + "Data in updated object did not match submitted data."); + }catch(Exception e){ + e.printStackTrace(); + } + } + + // Failure outcomes + // Placeholders until the three tests below can be uncommented. + // See Issue CSPACE-401. + public void updateWithEmptyEntityBody() { + } + + public void updateWithMalformedXml() { + } + + public void updateWithWrongXmlSchema() { + } + + /* + @Override + @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"}) + public void updateWithEmptyEntityBody() { + + // Perform setup. + setupUpdateWithEmptyEntityBody(); + + // 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)? + verbose("updateWithEmptyEntityBody url=" + url + " status=" + statusCode); + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + + @Override + @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"}) + public void updateWithMalformedXml() { + + // Perform setup. + setupUpdateWithMalformedXml(); + + // 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)? + verbose("updateWithMalformedXml: url=" + url + " status=" + statusCode); + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + + @Override + @Test(dependsOnMethods = {"create", "update", "testSubmitRequest"}) + public void updateWithWrongXmlSchema() { + + // Perform setup. + setupUpdateWithWrongXmlSchema(); + + // 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)? + verbose("updateWithWrongSchema: url=" + url + " status=" + statusCode); + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + */ + @Override + @Test(dependsOnMethods = {"update", "testSubmitRequest"}) + public void updateNonExistent() { + + // Perform setup. + setupUpdateNonExistent(); + + // 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. + + // The only relevant ID may be the one used in update(), below. + MultipartOutput multipart = createVocabularyInstance(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)? + verbose("updateNonExistent: status = " + res.getStatus()); + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + + // --------------------------------------------------------------- + // CRUD tests : DELETE tests + // --------------------------------------------------------------- + // Success outcomes + @Override + @Test(dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"}) + public void delete() { + + // Perform setup. + setupDelete(); + + // Submit the request to the service and store the response. + ClientResponse res = client.delete(knownResourceId); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + verbose("delete: status = " + res.getStatus()); + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + + // Failure outcomes + @Override + @Test(dependsOnMethods = {"delete"}) + public void deleteNonExistent() { + + // Perform setup. + setupDeleteNonExistent(); + + // Submit the request to the service and store the response. + 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)? + verbose("deleteNonExistent: status = " + res.getStatus()); + 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_CODE = 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)? + verbose("testSubmitRequest: url=" + url + " status=" + statusCode); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + } + + // --------------------------------------------------------------- + // Utility methods used by tests above + // --------------------------------------------------------------- + @Override + public String getServicePathComponent() { + return SERVICE_PATH_COMPONENT; + } + + private MultipartOutput createVocabularyInstance(String identifier) { + return createVocabularyInstance( + "displayName-" + identifier, + "vocabType-" + identifier); + } + + private MultipartOutput createVocabularyInstance(String displayName, String vocabType) { + VocabulariesCommon vocabulary = new VocabulariesCommon(); + vocabulary.setDisplayName(displayName); + vocabulary.setVocabType(vocabType); + MultipartOutput multipart = new MultipartOutput(); + OutputPart commonPart = multipart.addPart(vocabulary, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", getCommonPartName()); + + verbose("to be created, vocabulary common ", vocabulary, VocabulariesCommon.class); + + return multipart; + } +} diff --git a/services/vocabulary/client/src/test/resources/log4j.properties b/services/vocabulary/client/src/test/resources/log4j.properties new file mode 100644 index 000000000..18c510350 --- /dev/null +++ b/services/vocabulary/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/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyItemJAXBSchema.java b/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyItemJAXBSchema.java new file mode 100644 index 000000000..c0c3038e0 --- /dev/null +++ b/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyItemJAXBSchema.java @@ -0,0 +1,15 @@ +/** + * + */ +package org.collectionspace.services; + +/** + * @author pschmitz + * + */ +public interface VocabularyItemJAXBSchema { + final static String DISPLAY_NAME = "displayName"; + final static String IN_VOCABULARY = "inVocabulary"; +} + + diff --git a/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyItemListItemJAXBSchema.java b/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyItemListItemJAXBSchema.java new file mode 100644 index 000000000..f5f947b4c --- /dev/null +++ b/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyItemListItemJAXBSchema.java @@ -0,0 +1,7 @@ +package org.collectionspace.services; + +public interface VocabularyItemListItemJAXBSchema { + final static String DISPLAY_NAME = "displayName"; + final static String CSID = "csid"; + final static String URI = "url"; +} diff --git a/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyJAXBSchema.java b/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyJAXBSchema.java new file mode 100644 index 000000000..fa90ed4ad --- /dev/null +++ b/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyJAXBSchema.java @@ -0,0 +1,15 @@ +/** + * + */ +package org.collectionspace.services; + +/** + * @author pschmitz + * + */ +public interface VocabularyJAXBSchema { + final static String DISPLAY_NAME = "displayName"; + final static String VOCAB_TYPE = "vocabType"; +} + + diff --git a/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyListItemJAXBSchema.java b/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyListItemJAXBSchema.java new file mode 100644 index 000000000..eae544106 --- /dev/null +++ b/services/vocabulary/jaxb/src/main/java/org/collectionspace/services/VocabularyListItemJAXBSchema.java @@ -0,0 +1,8 @@ +package org.collectionspace.services; + +public interface VocabularyListItemJAXBSchema { + final static String DISPLAY_NAME = "displayName"; + final static String VOCAB_TYPE = "vocabType"; + final static String CSID = "csid"; + final static String URI = "url"; +} diff --git a/services/vocabulary/jaxb/src/main/resources/vocabulary-common.xsd b/services/vocabulary/jaxb/src/main/resources/vocabulary-common.xsd new file mode 100644 index 000000000..0af81ee58 --- /dev/null +++ b/services/vocabulary/jaxb/src/main/resources/vocabulary-common.xsd @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/vocabulary/pom.xml b/services/vocabulary/pom.xml index 316d79b5e..7486fc97b 100644 --- a/services/vocabulary/pom.xml +++ b/services/vocabulary/pom.xml @@ -13,7 +13,10 @@ services.vocabulary + jaxb service + 3rdparty + client diff --git a/services/vocabulary/service/.classpath b/services/vocabulary/service/.classpath index a374a40f8..c641afdb9 100644 --- a/services/vocabulary/service/.classpath +++ b/services/vocabulary/service/.classpath @@ -2,6 +2,8 @@ + + diff --git a/services/vocabulary/service/pom.xml b/services/vocabulary/service/pom.xml index de80035b1..0323438f3 100644 --- a/services/vocabulary/service/pom.xml +++ b/services/vocabulary/service/pom.xml @@ -20,6 +20,11 @@ org.collectionspace.services.common 1.0 + + org.collectionspace.services + org.collectionspace.services.vocabulary.jaxb + 1.0 + org.slf4j slf4j-api diff --git a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabResource.java b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabResource.java deleted file mode 100644 index f8c8a02ef..000000000 --- a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabResource.java +++ /dev/null @@ -1,100 +0,0 @@ -/** - * 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.vocabulary; - -import javax.ws.rs.Consumes; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.DELETE; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.PathParam; -import javax.ws.rs.WebApplicationException; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.UriBuilder; -import javax.ws.rs.core.UriInfo; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.Marshaller; - -import org.collectionspace.services.common.vocabulary.VocabManager; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@Path("/vocab") -@Consumes("application/xml") -@Produces("application/xml") -public class VocabResource { - - public final static String SERVICE_NAME = "vocab"; - final Logger logger = LoggerFactory.getLogger(VocabResource.class); - - public VocabResource() { - // do nothing - } - - @GET - @Path("{csid}") - public void getVocab( - @PathParam("csid") String csid) { - if(logger.isDebugEnabled()){ - verbose("getVocab with csid=" + csid); - } - if(csid == null || "".equals(csid)){ - logger.error("getVocab: missing csid!"); - Response response = Response.status(Response.Status.BAD_REQUEST).entity( - "get failed on getVocab csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - - try { - // - // An example call to the Vocabulary manager - // - VocabManager.exampleMethod("someParam"); - } catch(Exception e){ - if(logger.isDebugEnabled()){ - logger.debug("getVocab", e); - } - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed on vocab csid=" + csid).type( - "text/plain").build(); - throw new WebApplicationException(response); - } - - // an example of how to send a failed message - if(false){ - Response response = Response.status(Response.Status.NOT_FOUND).entity( - "Get failed, the requested CSID:" + csid + ": was not found.").type( - "text/plain").build(); - throw new WebApplicationException(response); - } - } - - private void verbose(String msg) { - System.out.println("VocabResource. " + msg); - } -} diff --git a/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java new file mode 100644 index 000000000..cf7b7e276 --- /dev/null +++ b/services/vocabulary/service/src/main/java/org/collectionspace/services/vocabulary/VocabularyResource.java @@ -0,0 +1,243 @@ +/** + * 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.vocabulary; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.DELETE; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.PathParam; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; +import javax.ws.rs.core.UriInfo; + +import org.collectionspace.services.common.AbstractCollectionSpaceResource; +import org.collectionspace.services.vocabulary.nuxeo.VocabularyHandlerFactory; +import org.collectionspace.services.common.ClientType; +import org.collectionspace.services.common.ServiceMain; +import org.collectionspace.services.common.context.RemoteServiceContext; +import org.collectionspace.services.common.context.ServiceContext; +import org.collectionspace.services.common.repository.DocumentNotFoundException; +import org.collectionspace.services.common.repository.DocumentHandler; +import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; +import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; +import org.jboss.resteasy.util.HttpResponseCodes; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Path("/vocabularies") +@Consumes("multipart/mixed") +@Produces("multipart/mixed") +public class VocabularyResource extends AbstractCollectionSpaceResource { + + private final static String serviceName = "vocabularies"; + final Logger logger = LoggerFactory.getLogger(VocabularyResource.class); + //FIXME retrieve client type from configuration + final static ClientType CLIENT_TYPE = ServiceMain.getInstance().getClientType(); + + public VocabularyResource() { + // do nothing + } + + @Override + public String getServiceName() { + return serviceName; + } + + @Override + public DocumentHandler createDocumentHandler(RemoteServiceContext ctx) throws Exception { + DocumentHandler docHandler = VocabularyHandlerFactory.getInstance().getHandler( + ctx.getRepositoryClientType().toString()); + docHandler.setServiceContext(ctx); + if(ctx.getInput() != null){ + Object obj = ctx.getInputPart(ctx.getCommonPartLabel(), VocabulariesCommon.class); + if(obj != null){ + docHandler.setCommonPart((VocabulariesCommon) obj); + } + } + return docHandler; + } + + @POST + public Response createVocabulary(MultipartInput input) { + try{ + RemoteServiceContext ctx = createServiceContext(input); + DocumentHandler handler = createDocumentHandler(ctx); + String csid = getRepositoryClient(ctx).create(ctx, handler); + //vocabularyObject.setCsid(csid); + UriBuilder path = UriBuilder.fromResource(VocabularyResource.class); + path.path("" + csid); + Response response = Response.created(path.build()).build(); + return response; + }catch(Exception e){ + if(logger.isDebugEnabled()){ + logger.debug("Caught exception in createVocabulary", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + } + + @GET + @Path("{csid}") + public MultipartOutput getVocabulary( + @PathParam("csid") String csid) { + if(logger.isDebugEnabled()){ + logger.debug("getVocabulary with csid=" + csid); + } + if(csid == null || "".equals(csid)){ + logger.error("getVocabulary: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "get failed on Vocabulary csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + MultipartOutput result = null; + try{ + RemoteServiceContext ctx = createServiceContext(null); + DocumentHandler handler = createDocumentHandler(ctx); + getRepositoryClient(ctx).get(ctx, csid, handler); + result = ctx.getOutput(); + }catch(DocumentNotFoundException dnfe){ + if(logger.isDebugEnabled()){ + logger.debug("getVocabulary", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed on Vocabulary csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + }catch(Exception e){ + if(logger.isDebugEnabled()){ + logger.debug("getVocabulary", 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 Vocabulary CSID:" + csid + ": was not found.").type( + "text/plain").build(); + throw new WebApplicationException(response); + } + return result; + } + + @GET + @Produces("application/xml") + public VocabulariesCommonList getVocabularyList(@Context UriInfo ui) { + VocabulariesCommonList vocabularyObjectList = new VocabulariesCommonList(); + try{ + RemoteServiceContext ctx = createServiceContext(null); + DocumentHandler handler = createDocumentHandler(ctx); + getRepositoryClient(ctx).getAll(ctx, handler); + vocabularyObjectList = (VocabulariesCommonList) handler.getCommonPartList(); + }catch(Exception e){ + if(logger.isDebugEnabled()){ + logger.debug("Caught exception in getVocabularyList", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + return vocabularyObjectList; + } + + @PUT + @Path("{csid}") + public MultipartOutput updateVocabulary( + @PathParam("csid") String csid, + MultipartInput theUpdate) { + if(logger.isDebugEnabled()){ + logger.debug("updateVocabulary with csid=" + csid); + } + if(csid == null || "".equals(csid)){ + logger.error("updateVocabulary: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "update failed on Vocabulary csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + MultipartOutput result = null; + try{ + RemoteServiceContext ctx = createServiceContext(theUpdate); + DocumentHandler handler = createDocumentHandler(ctx); + getRepositoryClient(ctx).update(ctx, csid, handler); + result = ctx.getOutput(); + }catch(DocumentNotFoundException dnfe){ + if(logger.isDebugEnabled()){ + logger.debug("caugth exception in updateVocabulary", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Update failed on Vocabulary 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 + @Path("{csid}") + public Response deleteVocabulary(@PathParam("csid") String csid) { + + if(logger.isDebugEnabled()){ + logger.debug("deleteVocabulary with csid=" + csid); + } + if(csid == null || "".equals(csid)){ + logger.error("deleteVocabulary: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "delete failed on Vocabulary csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + try{ + ServiceContext ctx = createServiceContext(null); + getRepositoryClient(ctx).delete(ctx, csid); + return Response.status(HttpResponseCodes.SC_OK).build(); + }catch(DocumentNotFoundException dnfe){ + if(logger.isDebugEnabled()){ + logger.debug("caught exception in deleteVocabulary", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Delete failed on Vocabulary 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); + } + + } +} -- 2.47.3