From 570c6734b27a805fa1e4134a38db2833a0508e82 Mon Sep 17 00:00:00 2001 From: Patrick Schmitz Date: Fri, 21 May 2010 21:25:01 +0000 Subject: [PATCH] CSPACE-1357, CSPACE-131, CSPACE-133 - Adding basic LocationAuthority support. --- services/JaxRsServiceProvider/pom.xml | 5 + .../CollectionSpaceJaxRsApplication.java | 2 + services/build.xml | 3 + .../main/config/services/tenant-bindings.xml | 72 + services/location/.classpath | 6 + services/location/.project | 23 + .../.settings/org.eclipse.jdt.core.prefs | 5 + .../.settings/org.maven.ide.eclipse.prefs | 9 + services/location/3rdparty/.classpath | 6 + services/location/3rdparty/.project | 23 + .../.settings/org.eclipse.jdt.core.prefs | 5 + .../.settings/org.maven.ide.eclipse.prefs | 9 + services/location/3rdparty/build.xml | 131 ++ .../nuxeo-platform-cs-location/.classpath | 7 + .../nuxeo-platform-cs-location/.project | 23 + .../.settings/org.eclipse.jdt.core.prefs | 5 + .../.settings/org.maven.ide.eclipse.prefs | 9 + .../nuxeo-platform-cs-location/build.xml | 149 ++ .../nuxeo-platform-cs-location/pom.xml | 37 + .../src/main/resources/META-INF/MANIFEST.MF | 22 + .../resources/OSGI-INF/core-types-contrib.xml | 25 + .../OSGI-INF/deployment-fragment.xml | 408 +++++ .../resources/OSGI-INF/ecm-types-contrib.xml | 53 + .../resources/OSGI-INF/layouts-contrib.xml | 212 +++ .../schemas/locationauthorities_common.xsd | 31 + .../resources/schemas/locations_common.xsd | 37 + services/location/3rdparty/pom.xml | 23 + services/location/build.xml | 134 ++ services/location/client/.classpath | 10 + services/location/client/.project | 26 + .../.settings/org.eclipse.jdt.core.prefs | 5 + .../.settings/org.maven.ide.eclipse.prefs | 9 + services/location/client/pom.xml | 91 ++ .../client/LocationAuthorityClient.java | 318 ++++ .../client/LocationAuthorityClientUtils.java | 190 +++ .../client/LocationAuthorityProxy.java | 143 ++ .../test/LocationAuthorityServiceTest.java | 1323 +++++++++++++++++ .../src/test/resources/log4j.properties | 23 + services/location/import/.classpath | 8 + services/location/import/.project | 26 + .../.settings/org.eclipse.jdt.core.prefs | 5 + .../.settings/org.maven.ide.eclipse.prefs | 9 + services/location/import/build.xml | 60 + services/location/import/pom.xml | 105 ++ .../importer/LocationAuthorityBaseImport.java | 155 ++ services/location/installer/build.xml | 61 + services/location/jaxb/.classpath | 10 + services/location/jaxb/.project | 23 + .../jaxb/.settings/org.eclipse.jdt.core.prefs | 5 + .../.settings/org.maven.ide.eclipse.prefs | 9 + services/location/jaxb/pom.xml | 47 + .../services/LocationAuthorityJAXBSchema.java | 18 + .../LocationAuthorityListItemJAXBSchema.java | 9 + .../services/LocationJAXBSchema.java | 24 + .../services/LocationListItemJAXBSchema.java | 8 + .../src/main/resources/location_common.xsd | 75 + .../resources/locationauthority_common.xsd | 86 ++ services/location/pom.xml | 33 + services/location/service/.classpath | 7 + services/location/service/.project | 26 + .../.settings/org.eclipse.jdt.core.prefs | 5 + .../.settings/org.maven.ide.eclipse.prefs | 9 + services/location/service/pom.xml | 141 ++ .../location/LocationAuthorityResource.java | 863 +++++++++++ .../nuxeo/LocationAuthorityConstants.java | 35 + ...LocationAuthorityDocumentModelHandler.java | 146 ++ .../location/nuxeo/LocationConstants.java | 35 + .../nuxeo/LocationDocumentModelHandler.java | 265 ++++ .../nuxeo/LocationValidatorHandler.java | 103 ++ .../person/PersonAuthorityResource.java | 4 +- services/pom.xml | 1 + 71 files changed, 6026 insertions(+), 2 deletions(-) create mode 100644 services/location/.classpath create mode 100644 services/location/.project create mode 100644 services/location/.settings/org.eclipse.jdt.core.prefs create mode 100644 services/location/.settings/org.maven.ide.eclipse.prefs create mode 100644 services/location/3rdparty/.classpath create mode 100644 services/location/3rdparty/.project create mode 100644 services/location/3rdparty/.settings/org.eclipse.jdt.core.prefs create mode 100644 services/location/3rdparty/.settings/org.maven.ide.eclipse.prefs create mode 100644 services/location/3rdparty/build.xml create mode 100644 services/location/3rdparty/nuxeo-platform-cs-location/.classpath create mode 100644 services/location/3rdparty/nuxeo-platform-cs-location/.project create mode 100644 services/location/3rdparty/nuxeo-platform-cs-location/.settings/org.eclipse.jdt.core.prefs create mode 100644 services/location/3rdparty/nuxeo-platform-cs-location/.settings/org.maven.ide.eclipse.prefs create mode 100644 services/location/3rdparty/nuxeo-platform-cs-location/build.xml create mode 100644 services/location/3rdparty/nuxeo-platform-cs-location/pom.xml create mode 100644 services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/META-INF/MANIFEST.MF create mode 100644 services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/OSGI-INF/core-types-contrib.xml create mode 100644 services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/OSGI-INF/deployment-fragment.xml create mode 100644 services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/OSGI-INF/ecm-types-contrib.xml create mode 100644 services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/OSGI-INF/layouts-contrib.xml create mode 100644 services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/schemas/locationauthorities_common.xsd create mode 100644 services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/schemas/locations_common.xsd create mode 100644 services/location/3rdparty/pom.xml create mode 100644 services/location/build.xml create mode 100644 services/location/client/.classpath create mode 100644 services/location/client/.project create mode 100644 services/location/client/.settings/org.eclipse.jdt.core.prefs create mode 100644 services/location/client/.settings/org.maven.ide.eclipse.prefs create mode 100644 services/location/client/pom.xml create mode 100644 services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClient.java create mode 100644 services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClientUtils.java create mode 100644 services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityProxy.java create mode 100644 services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java create mode 100644 services/location/client/src/test/resources/log4j.properties create mode 100644 services/location/import/.classpath create mode 100644 services/location/import/.project create mode 100644 services/location/import/.settings/org.eclipse.jdt.core.prefs create mode 100644 services/location/import/.settings/org.maven.ide.eclipse.prefs create mode 100644 services/location/import/build.xml create mode 100644 services/location/import/pom.xml create mode 100644 services/location/import/src/main/java/org/collectionspace/services/location/importer/LocationAuthorityBaseImport.java create mode 100644 services/location/installer/build.xml create mode 100644 services/location/jaxb/.classpath create mode 100644 services/location/jaxb/.project create mode 100644 services/location/jaxb/.settings/org.eclipse.jdt.core.prefs create mode 100644 services/location/jaxb/.settings/org.maven.ide.eclipse.prefs create mode 100644 services/location/jaxb/pom.xml create mode 100644 services/location/jaxb/src/main/java/org/collectionspace/services/LocationAuthorityJAXBSchema.java create mode 100644 services/location/jaxb/src/main/java/org/collectionspace/services/LocationAuthorityListItemJAXBSchema.java create mode 100644 services/location/jaxb/src/main/java/org/collectionspace/services/LocationJAXBSchema.java create mode 100644 services/location/jaxb/src/main/java/org/collectionspace/services/LocationListItemJAXBSchema.java create mode 100644 services/location/jaxb/src/main/resources/location_common.xsd create mode 100644 services/location/jaxb/src/main/resources/locationauthority_common.xsd create mode 100644 services/location/pom.xml create mode 100644 services/location/service/.classpath create mode 100644 services/location/service/.project create mode 100644 services/location/service/.settings/org.eclipse.jdt.core.prefs create mode 100644 services/location/service/.settings/org.maven.ide.eclipse.prefs create mode 100644 services/location/service/pom.xml create mode 100644 services/location/service/src/main/java/org/collectionspace/services/location/LocationAuthorityResource.java create mode 100644 services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationAuthorityConstants.java create mode 100644 services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationAuthorityDocumentModelHandler.java create mode 100644 services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationConstants.java create mode 100644 services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationDocumentModelHandler.java create mode 100644 services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationValidatorHandler.java diff --git a/services/JaxRsServiceProvider/pom.xml b/services/JaxRsServiceProvider/pom.xml index ffbc04ce6..5f21896c0 100644 --- a/services/JaxRsServiceProvider/pom.xml +++ b/services/JaxRsServiceProvider/pom.xml @@ -95,6 +95,11 @@ org.collectionspace.services.loanout.service ${project.version} + + org.collectionspace.services + org.collectionspace.services.location.service + ${project.version} + org.collectionspace.services org.collectionspace.services.movement.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 df2532ee2..b2bf8358d 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 @@ -28,6 +28,7 @@ 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.location.LocationAuthorityResource; import org.collectionspace.services.movement.MovementResource; import org.collectionspace.services.relation.NewRelationResource; import org.collectionspace.services.acquisition.AcquisitionResource; @@ -70,6 +71,7 @@ public class CollectionSpaceJaxRsApplication extends Application { singletons.add(new IntakeResource()); singletons.add(new LoaninResource()); singletons.add(new LoanoutResource()); + singletons.add(new LocationAuthorityResource()); singletons.add(new MovementResource()); singletons.add(new AcquisitionResource()); singletons.add(new NewRelationResource()); diff --git a/services/build.xml b/services/build.xml index 1e67ac988..01869f002 100644 --- a/services/build.xml +++ b/services/build.xml @@ -153,6 +153,7 @@ + @@ -173,6 +174,7 @@ + @@ -204,6 +206,7 @@ + diff --git a/services/common/src/main/config/services/tenant-bindings.xml b/services/common/src/main/config/services/tenant-bindings.xml index 4d547d7ba..aa1b25de4 100644 --- a/services/common/src/main/config/services/tenant-bindings.xml +++ b/services/common/src/main/config/services/tenant-bindings.xml @@ -470,6 +470,78 @@ + + + + nuxeo-java + + + org.collectionspace.services.location.nuxeo.LocationAuthorityDocumentModelHandler + + + + + + + + + + + + + + + + + + + + + nuxeo-java + + + org.collectionspace.services.location.nuxeo.LocationDocumentModelHandler + + + org.collectionspace.services.location.nuxeo.LocationValidatorHandler + + + + + + + + + + + + + + + + + diff --git a/services/location/.classpath b/services/location/.classpath new file mode 100644 index 000000000..046988541 --- /dev/null +++ b/services/location/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/services/location/.project b/services/location/.project new file mode 100644 index 000000000..eba3c0275 --- /dev/null +++ b/services/location/.project @@ -0,0 +1,23 @@ + + + org.collectionspace.services.person + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.maven.ide.eclipse.maven2Nature + + diff --git a/services/location/.settings/org.eclipse.jdt.core.prefs b/services/location/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..2341888c8 --- /dev/null +++ b/services/location/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +#Tue Oct 06 13:26:43 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/location/.settings/org.maven.ide.eclipse.prefs b/services/location/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 000000000..95a5ba022 --- /dev/null +++ b/services/location/.settings/org.maven.ide.eclipse.prefs @@ -0,0 +1,9 @@ +#Fri Sep 11 17:00:29 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/location/3rdparty/.classpath b/services/location/3rdparty/.classpath new file mode 100644 index 000000000..046988541 --- /dev/null +++ b/services/location/3rdparty/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/services/location/3rdparty/.project b/services/location/3rdparty/.project new file mode 100644 index 000000000..a84a0da90 --- /dev/null +++ b/services/location/3rdparty/.project @@ -0,0 +1,23 @@ + + + org.collectionspace.services.person.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/location/3rdparty/.settings/org.eclipse.jdt.core.prefs b/services/location/3rdparty/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..4956ebcc9 --- /dev/null +++ b/services/location/3rdparty/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +#Mon Oct 05 17:07:08 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/location/3rdparty/.settings/org.maven.ide.eclipse.prefs b/services/location/3rdparty/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 000000000..93b6f8a66 --- /dev/null +++ b/services/location/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/location/3rdparty/build.xml b/services/location/3rdparty/build.xml new file mode 100644 index 000000000..fdc140c02 --- /dev/null +++ b/services/location/3rdparty/build.xml @@ -0,0 +1,131 @@ + + + + location service 3rdparty + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/location/3rdparty/nuxeo-platform-cs-location/.classpath b/services/location/3rdparty/nuxeo-platform-cs-location/.classpath new file mode 100644 index 000000000..b61c5d843 --- /dev/null +++ b/services/location/3rdparty/nuxeo-platform-cs-location/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/services/location/3rdparty/nuxeo-platform-cs-location/.project b/services/location/3rdparty/nuxeo-platform-cs-location/.project new file mode 100644 index 000000000..748ad4ef9 --- /dev/null +++ b/services/location/3rdparty/nuxeo-platform-cs-location/.project @@ -0,0 +1,23 @@ + + + org.collectionspace.services.person.3rdparty.nuxeo + Person Nuxeo Document Type + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + + org.maven.ide.eclipse.maven2Nature + org.eclipse.jdt.core.javanature + + diff --git a/services/location/3rdparty/nuxeo-platform-cs-location/.settings/org.eclipse.jdt.core.prefs b/services/location/3rdparty/nuxeo-platform-cs-location/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..2f969717b --- /dev/null +++ b/services/location/3rdparty/nuxeo-platform-cs-location/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +#Tue May 18 21:45:35 PDT 2010 +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/location/3rdparty/nuxeo-platform-cs-location/.settings/org.maven.ide.eclipse.prefs b/services/location/3rdparty/nuxeo-platform-cs-location/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 000000000..552ddbfcf --- /dev/null +++ b/services/location/3rdparty/nuxeo-platform-cs-location/.settings/org.maven.ide.eclipse.prefs @@ -0,0 +1,9 @@ +#Tue Oct 06 13:25:17 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/location/3rdparty/nuxeo-platform-cs-location/build.xml b/services/location/3rdparty/nuxeo-platform-cs-location/build.xml new file mode 100644 index 000000000..c0a26cd3c --- /dev/null +++ b/services/location/3rdparty/nuxeo-platform-cs-location/build.xml @@ -0,0 +1,149 @@ + + + + location nuxeo document type + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/location/3rdparty/nuxeo-platform-cs-location/pom.xml b/services/location/3rdparty/nuxeo-platform-cs-location/pom.xml new file mode 100644 index 000000000..294f213a9 --- /dev/null +++ b/services/location/3rdparty/nuxeo-platform-cs-location/pom.xml @@ -0,0 +1,37 @@ + + + org.collectionspace.services + org.collectionspace.services.location.3rdparty + 0.7-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.location.3rdparty.nuxeo + services.location.3rdparty.nuxeo + jar + + Location Nuxeo Document Type + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + src/main/resources/META-INF/MANIFEST.MF + + ${eclipseVersion} + 2 + + + + + + + + diff --git a/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/META-INF/MANIFEST.MF b/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 000000000..d16df5ae4 --- /dev/null +++ b/services/location/3rdparty/nuxeo-platform-cs-location/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.location;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.location +Nuxeo-Component: OSGI-INF/core-types-contrib.xml, + OSGI-INF/ecm-types-contrib.xml, + OSGI-INF/layouts-contrib.xml + diff --git a/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/OSGI-INF/core-types-contrib.xml b/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/OSGI-INF/core-types-contrib.xml new file mode 100644 index 000000000..beef5a5c9 --- /dev/null +++ b/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/OSGI-INF/core-types-contrib.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/OSGI-INF/deployment-fragment.xml b/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/OSGI-INF/deployment-fragment.xml new file mode 100644 index 000000000..8bbdd72b6 --- /dev/null +++ b/services/location/3rdparty/nuxeo-platform-cs-location/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.orgauthorities + + + + 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_orgauthorities + /view_orgauthorities.xhtml + + + + + view_orgauthority + /view_orgauthority.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/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/OSGI-INF/ecm-types-contrib.xml b/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/OSGI-INF/ecm-types-contrib.xml new file mode 100644 index 000000000..184cd0ae3 --- /dev/null +++ b/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/OSGI-INF/ecm-types-contrib.xml @@ -0,0 +1,53 @@ + + + + + + + view_documents + + + heading + cslocationauthority + + + + + + Locationauthority + + + + + + Locationauthority + + + + + + + + + view_documents + + + heading + location + + + + + + Location + + + + + + Location + + + + + diff --git a/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/OSGI-INF/layouts-contrib.xml b/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/OSGI-INF/layouts-contrib.xml new file mode 100644 index 000000000..6e6c34dc3 --- /dev/null +++ b/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/OSGI-INF/layouts-contrib.xml @@ -0,0 +1,212 @@ + + + + + + + + + + + + displayName + refName + vocabType + + + + + + + true + + displayName + + + dataInputText + + + + + + + + true + + refName + + + dataInputText + + + + + + + + true + + vocabType + + + dataInputText + + + + + + + + + + + + + inAuthority + refName + displayName + displayNameComputed + name + conditionNote + conditionNoteDate + securityNote + locationType + status + + + + + + + true + + inAuthority + + + dataInputText + + + + + + + + true + + refName + + + dataInputText + + + + + + + + true + + displayName + + + dataInputText + + + + + + + + + true + + displayNameComputed + + + dataInputText + + + + + + + + true + + name + + + dataInputText + + + + + + + + true + + conditionNote + + + dataInputText + + + + + + + + true + + conditionNoteDate + + + dataInputText + + + + + + + + true + + securityNote + + + dataInputText + + + + + + + + true + + locationType + + + dataInputText + + + + + + + + true + + status + + + dataInputText + + + + + + diff --git a/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/schemas/locationauthorities_common.xsd b/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/schemas/locationauthorities_common.xsd new file mode 100644 index 000000000..0a1f73678 --- /dev/null +++ b/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/schemas/locationauthorities_common.xsd @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + diff --git a/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/schemas/locations_common.xsd b/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/schemas/locations_common.xsd new file mode 100644 index 000000000..d64d2c15f --- /dev/null +++ b/services/location/3rdparty/nuxeo-platform-cs-location/src/main/resources/schemas/locations_common.xsd @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/location/3rdparty/pom.xml b/services/location/3rdparty/pom.xml new file mode 100644 index 000000000..3c1921f68 --- /dev/null +++ b/services/location/3rdparty/pom.xml @@ -0,0 +1,23 @@ + + + + org.collectionspace.services + org.collectionspace.services.location + 0.7-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.location.3rdparty + services.location.3rdparty + pom + + 3rd party build for location service + + + + nuxeo-platform-cs-location + + diff --git a/services/location/build.xml b/services/location/build.xml new file mode 100644 index 000000000..ce5d33547 --- /dev/null +++ b/services/location/build.xml @@ -0,0 +1,134 @@ + + + + Location Authority service + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/location/client/.classpath b/services/location/client/.classpath new file mode 100644 index 000000000..425cd1620 --- /dev/null +++ b/services/location/client/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/services/location/client/.project b/services/location/client/.project new file mode 100644 index 000000000..ba2d51a96 --- /dev/null +++ b/services/location/client/.project @@ -0,0 +1,26 @@ + + + org.collectionspace.services.person.client + + + org.collectionspace.services.client + org.collectionspace.services.common + org.collectionspace.services.person.jaxb + + + + org.eclipse.jdt.core.javabuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + + org.maven.ide.eclipse.maven2Nature + org.eclipse.jdt.core.javanature + + diff --git a/services/location/client/.settings/org.eclipse.jdt.core.prefs b/services/location/client/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..c97287836 --- /dev/null +++ b/services/location/client/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +#Mon Jan 04 16:43:16 PST 2010 +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/location/client/.settings/org.maven.ide.eclipse.prefs b/services/location/client/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 000000000..ddebb8bf5 --- /dev/null +++ b/services/location/client/.settings/org.maven.ide.eclipse.prefs @@ -0,0 +1,9 @@ +#Mon Jan 04 16:40:35 PST 2010 +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/location/client/pom.xml b/services/location/client/pom.xml new file mode 100644 index 000000000..9a4784e0c --- /dev/null +++ b/services/location/client/pom.xml @@ -0,0 +1,91 @@ + + + + org.collectionspace.services + org.collectionspace.services.location + 0.7-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.location.client + services.location.client + + + + + org.slf4j + slf4j-api + + + org.slf4j + slf4j-log4j12 + + + + 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.location.jaxb + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.client + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.contact.client + ${project.version} + + + + org.testng + testng + 5.6 + + + org.jboss.resteasy + resteasy-jaxrs + + + + tjws + webserver + + + + + org.jboss.resteasy + resteasy-jaxb-provider + + + org.jboss.resteasy + resteasy-multipart-provider + + + commons-httpclient + commons-httpclient + 3.1 + + + + + collectionspace-services-location-client + + + + + diff --git a/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClient.java b/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClient.java new file mode 100644 index 000000000..5f3e77d13 --- /dev/null +++ b/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClient.java @@ -0,0 +1,318 @@ +/** + * LocationAuthorityClient.java + * + * {Purpose of This Class} + * + * {Other Notes Relating to This Class (Optional)} + * + * $LastChangedBy: $ + * $LastChangedRevision: $ + * $LastChangedDate: $ + * + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + * + * http://www.collectionspace.org + * http://wiki.collectionspace.org + * + * Copyright © 2009 {Contributing Institution} + * + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + * + * You may obtain a copy of the ECL 2.0 License at + * https://source.collectionspace.org/collection-space/LICENSE.txt + */ +package org.collectionspace.services.client; + +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Response; + +//import org.collectionspace.services.common.authorityref.AuthorityRefList; +import org.collectionspace.services.common.authorityref.AuthorityRefDocList; +import org.collectionspace.services.contact.ContactsCommonList; +import org.collectionspace.services.location.LocationauthoritiesCommonList; +import org.collectionspace.services.location.LocationsCommonList; +import org.collectionspace.services.client.LocationAuthorityProxy; + +import org.jboss.resteasy.client.ClientResponse; +import org.jboss.resteasy.client.ProxyFactory; +import org.jboss.resteasy.plugins.providers.RegisterBuiltin; +import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; +import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; +import org.jboss.resteasy.spi.ResteasyProviderFactory; + +/** + * The Class LocationAuthorityClient. + */ +public class LocationAuthorityClient extends AbstractServiceClientImpl { + + /* (non-Javadoc) + * @see org.collectionspace.services.client.BaseServiceClient#getServicePathComponent() + */ + @Override + public String getServicePathComponent() { + return "locationauthorities"; + } + + /** + * Gets the item common part name. + * + * @return the item common part name + */ + public String getItemCommonPartName() { + return getCommonPartName("locations"); + } + + /** The location authority proxy. */ +// private static final LocationAuthorityClient instance = new LocationAuthorityClient(); + + /** + * + */ + private LocationAuthorityProxy locationAuthorityProxy; + + /** + * Instantiates a new location authority client. + */ + public LocationAuthorityClient() { + ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance(); + RegisterBuiltin.register(factory); + setProxy(); + } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.CollectionSpaceClient#getProxy() + */ + @Override + public CollectionSpaceProxy getProxy() { + return this.locationAuthorityProxy; + } + + /** + * Sets the proxy. + */ + public void setProxy() { + if (useAuth()) { + locationAuthorityProxy = ProxyFactory.create(LocationAuthorityProxy.class, + getBaseURL(), getHttpClient()); + } else { + locationAuthorityProxy = ProxyFactory.create(LocationAuthorityProxy.class, + getBaseURL()); + } + } + + /** + * Read list. + * + * @return the client response + */ +// public static LocationAuthorityClient getInstance() { +// return instance; +// } + + /** + * @return list + * @see org.collectionspace.services.client.LocationAuthorityProxy#readList() + */ + public ClientResponse readList() { + return locationAuthorityProxy.readList(); + } + + /** + * Read. + * + * @param csid the csid + * @return the client response + */ + public ClientResponse read(String csid) { + return locationAuthorityProxy.read(csid); + } + + /** + * Read by name. + * + * @param name the name + * @return the client response + */ + public ClientResponse readByName(String name) { + return locationAuthorityProxy.readByName(name); + } + + /** + * Creates the. + * + * @param multipart the multipart + * @return the client response + */ + public ClientResponse create(MultipartOutput multipart) { + return locationAuthorityProxy.create(multipart); + } + + /** + * Update. + * + * @param csid the csid + * @param multipart the multipart + * @return the client response + */ + public ClientResponse update(String csid, MultipartOutput multipart) { + return locationAuthorityProxy.update(csid, multipart); + + } + + /** + * Delete. + * + * @param csid the csid + * @return the client response + */ + public ClientResponse delete(String csid) { + return locationAuthorityProxy.delete(csid); + } + + /** + * Read item list. + * + * @param vcsid the vcsid + * @return the client response + */ + public ClientResponse readItemList(String vcsid) { + return locationAuthorityProxy.readItemList(vcsid); + } + + /** + * Gets the referencing objects. + * + * @param parentcsid the parentcsid + * @param csid the csid + * @return the referencing objects + */ + public ClientResponse getReferencingObjects(String parentcsid, String csid) { + return locationAuthorityProxy.getReferencingObjects(parentcsid, csid); + } + + /** + * Read item list for named authority. + * + * @param specifier the specifier + * @return the client response + */ + public ClientResponse readItemListForNamedAuthority(String specifier) { + return locationAuthorityProxy.readItemListForNamedAuthority(specifier); + } + + /** + * Read item. + * + * @param vcsid the vcsid + * @param csid the csid + * @return the client response + */ + public ClientResponse readItem(String vcsid, String csid) { + return locationAuthorityProxy.readItem(vcsid, csid); + } + + /** + * Creates the item. + * + * @param vcsid the vcsid + * @param multipart the multipart + * @return the client response + */ + public ClientResponse createItem(String vcsid, MultipartOutput multipart) { + return locationAuthorityProxy.createItem(vcsid, multipart); + } + + /** + * Update item. + * + * @param vcsid the vcsid + * @param csid the csid + * @param multipart the multipart + * @return the client response + */ + public ClientResponse updateItem(String vcsid, String csid, MultipartOutput multipart) { + return locationAuthorityProxy.updateItem(vcsid, csid, multipart); + + } + + /** + * Delete item. + * + * @param vcsid the vcsid + * @param csid the csid + * @return the client response + */ + public ClientResponse deleteItem(String vcsid, String csid) { + return locationAuthorityProxy.deleteItem(vcsid, csid); + } + + /** + * Creates the contact. + * + * @param parentcsid the parentcsid + * @param itemcsid the itemcsid + * @param multipart the multipart + * @return the client response + */ + public ClientResponse createContact(String parentcsid, + String itemcsid, MultipartOutput multipart) { + return locationAuthorityProxy.createContact(parentcsid, itemcsid, multipart); + } + + /** + * Read contact. + * + * @param parentcsid the parentcsid + * @param itemcsid the itemcsid + * @param csid the csid + * @return the client response + */ + public ClientResponse readContact(String parentcsid, + String itemcsid, String csid) { + return locationAuthorityProxy.readContact(parentcsid, itemcsid, csid); + } + + /** + * Read contact list. + * + * @param parentcsid the parentcsid + * @param itemcsid the itemcsid + * @return the client response + */ + public ClientResponse readContactList(String parentcsid, + String itemcsid) { + return locationAuthorityProxy.readContactList(parentcsid, itemcsid); + } + + /** + * Update contact. + * + * @param parentcsid the parentcsid + * @param itemcsid the itemcsid + * @param csid the csid + * @param multipart the multipart + * @return the client response + */ + public ClientResponse updateContact(String parentcsid, + String itemcsid, String csid, MultipartOutput multipart) { + return locationAuthorityProxy.updateContact(parentcsid, itemcsid, csid, multipart); + } + + /** + * Delete contact. + * + * @param parentcsid the parentcsid + * @param itemcsid the itemcsid + * @param csid the csid + * @return the client response + */ + public ClientResponse deleteContact(String parentcsid, + String itemcsid, String csid) { + return locationAuthorityProxy.deleteContact(parentcsid, + itemcsid, csid); + } + +} diff --git a/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClientUtils.java b/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClientUtils.java new file mode 100644 index 000000000..4919c3795 --- /dev/null +++ b/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityClientUtils.java @@ -0,0 +1,190 @@ +package org.collectionspace.services.client; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; + +import org.collectionspace.services.LocationJAXBSchema; +import org.collectionspace.services.client.test.ServiceRequestType; +import org.collectionspace.services.location.LocationsCommon; +import org.collectionspace.services.location.LocationauthoritiesCommon; +import org.jboss.resteasy.client.ClientResponse; +import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; +import org.jboss.resteasy.plugins.providers.multipart.OutputPart; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class LocationAuthorityClientUtils { + private static final Logger logger = + LoggerFactory.getLogger(LocationAuthorityClientUtils.class); + + public static MultipartOutput createLocationAuthorityInstance( + String displayName, String refName, String headerLabel ) { + LocationauthoritiesCommon locationAuthority = new LocationauthoritiesCommon(); + locationAuthority.setDisplayName(displayName); + locationAuthority.setRefName(refName); + locationAuthority.setVocabType("LocationAuthority"); + MultipartOutput multipart = new MultipartOutput(); + OutputPart commonPart = multipart.addPart(locationAuthority, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", headerLabel); + + if(logger.isDebugEnabled()){ + logger.debug("to be created, locationAuthority common ", + locationAuthority, LocationauthoritiesCommon.class); + } + + return multipart; + } + + public static MultipartOutput createLocationInstance(String inAuthority, + String locationRefName, Map locationInfo, String headerLabel){ + LocationsCommon location = new LocationsCommon(); + location.setInAuthority(inAuthority); + location.setRefName(locationRefName); + String value = null; + value = locationInfo.get(LocationJAXBSchema.DISPLAY_NAME_COMPUTED); + boolean displayNameComputed = (value==null) || value.equalsIgnoreCase("true"); + location.setDisplayNameComputed(displayNameComputed); + if((value = (String)locationInfo.get(LocationJAXBSchema.NAME))!=null) + location.setName(value); + if((value = (String)locationInfo.get(LocationJAXBSchema.CONDITION_NOTE))!=null) + location.setConditionNote(value); + if((value = (String)locationInfo.get(LocationJAXBSchema.CONDITION_NOTE_DATE))!=null) + location.setConditionNoteDate(value); + if((value = (String)locationInfo.get(LocationJAXBSchema.SECURITY_NOTE))!=null) + location.setSecurityNote(value); + if((value = (String)locationInfo.get(LocationJAXBSchema.LOCATION_TYPE))!=null) + location.setLocationType(value); + if((value = (String)locationInfo.get(LocationJAXBSchema.STATUS))!=null) + location.setStatus(value); + MultipartOutput multipart = new MultipartOutput(); + OutputPart commonPart = multipart.addPart(location, + MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", headerLabel); + + if(logger.isDebugEnabled()){ + logger.debug("to be created, location common ", location, LocationsCommon.class); + } + + return multipart; + } + + public static String createItemInAuthority(String vcsid, + String locationAuthorityRefName, Map locationMap, + LocationAuthorityClient client ) { + // Expected status code: 201 Created + int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode(); + // Type of service request being tested + ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE; + + String displayName = locationMap.get(LocationJAXBSchema.DISPLAY_NAME); + String displayNameComputedStr = locationMap.get(LocationJAXBSchema.DISPLAY_NAME_COMPUTED); + boolean displayNameComputed = (displayNameComputedStr==null) || displayNameComputedStr.equalsIgnoreCase("true"); + if( displayName == null ) { + if(!displayNameComputed) { + throw new RuntimeException( + "CreateItem: Must supply a displayName if displayNameComputed is set to false."); + } + displayName = + prepareDefaultDisplayName( + locationMap.get(LocationJAXBSchema.NAME)); + } + + String refName = createLocationRefName(locationAuthorityRefName, displayName, true); + + if(logger.isDebugEnabled()){ + logger.debug("Import: Create Item: \""+displayName + +"\" in locationAuthority: \"" + locationAuthorityRefName +"\""); + } + MultipartOutput multipart = + createLocationInstance( vcsid, refName, + locationMap, client.getItemCommonPartName() ); + ClientResponse res = client.createItem(vcsid, multipart); + + int statusCode = res.getStatus(); + + if(!REQUEST_TYPE.isValidStatusCode(statusCode)) { + throw new RuntimeException("Could not create Item: \""+refName + +"\" in locationAuthority: \"" + locationAuthorityRefName + +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + } + if(statusCode != EXPECTED_STATUS_CODE) { + throw new RuntimeException("Unexpected Status when creating Item: \""+refName + +"\" in locationAuthority: \"" + locationAuthorityRefName +"\", Status:"+ statusCode); + } + + return extractId(res); + } + + public static String createLocationAuthRefName(String locationAuthorityName, boolean withDisplaySuffix) { + String refName = "urn:cspace:org.collectionspace.demo:locationauthority:name(" + +locationAuthorityName+")"; + if(withDisplaySuffix) + refName += "'"+locationAuthorityName+"'"; + return refName; + } + + public static String createLocationRefName( + String locationAuthRefName, String locationName, boolean withDisplaySuffix) { + String refName = locationAuthRefName+":location:name("+locationName+")"; + if(withDisplaySuffix) + refName += "'"+locationName+"'"; + return refName; + } + + public static String extractId(ClientResponse res) { + MultivaluedMap mvm = res.getMetadata(); + String uri = (String) ((ArrayList) mvm.get("Location")).get(0); + if(logger.isDebugEnabled()){ + logger.debug("extractId:uri=" + uri); + } + String[] segments = uri.split("/"); + String id = segments[segments.length - 1]; + if(logger.isDebugEnabled()){ + logger.debug("id=" + id); + } + return id; + } + + /** + * Returns an error message indicating that the status code returned by a + * specific call to a service does not fall within a set of valid status + * codes for that service. + * + * @param serviceRequestType A type of service request (e.g. CREATE, DELETE). + * + * @param statusCode The invalid status code that was returned in the response, + * from submitting that type of request to the service. + * + * @return An error message. + */ + public static String invalidStatusCodeMessage(ServiceRequestType requestType, int statusCode) { + return "Status code '" + statusCode + "' in response is NOT within the expected set: " + + requestType.validStatusCodesAsString(); + } + + + + /** + * Produces a default displayName from the basic name and dates fields. + * @see LocationDocumentModelHandler.prepareDefaultDisplayName() which + * duplicates this logic, until we define a service-general utils package + * that is neither client nor service specific. + * @param name + * @return + */ + public static String prepareDefaultDisplayName( + String name ) { + StringBuilder newStr = new StringBuilder(); + newStr.append(name); + return newStr.toString(); + } + + + +} diff --git a/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityProxy.java b/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityProxy.java new file mode 100644 index 000000000..863265bd0 --- /dev/null +++ b/services/location/client/src/main/java/org/collectionspace/services/client/LocationAuthorityProxy.java @@ -0,0 +1,143 @@ +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.AuthorityRefDocList; +import org.collectionspace.services.contact.ContactsCommonList; +import org.collectionspace.services.location.LocationauthoritiesCommonList; +import org.collectionspace.services.location.LocationsCommonList; +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("/locationauthorities/") +@Produces({"multipart/mixed"}) +@Consumes({"multipart/mixed"}) +public interface LocationAuthorityProxy extends CollectionSpaceProxy { + + // List Locationauthorities + @GET + @Produces({"application/xml"}) + ClientResponse readList(); + + //(C)reate + @POST + ClientResponse create(MultipartOutput multipart); + + //(R)ead + @GET + @Path("/{csid}") + ClientResponse read(@PathParam("csid") String csid); + + //(R)ead by name + @GET + @Path("/urn:cspace:name({name})") + ClientResponse readByName(@PathParam("name") String name); + + //(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 Items + @GET + @Produces({"application/xml"}) + @Path("/{vcsid}/items/") + ClientResponse readItemList(@PathParam("vcsid") String vcsid); + + /** + * @param csid + * @return + * @see org.collectionspace.services.client.IntakeProxy#getAuthorityRefs(java.lang.String) + */ + @GET + @Path("{csid}/items/{itemcsid}/refObjs") + @Produces("application/xml") + ClientResponse getReferencingObjects( + @PathParam("csid") String parentcsid, + @PathParam("itemcsid") String itemcsid); + + // List Items for a named authority + @GET + @Produces({"application/xml"}) + @Path("/urn:cspace:name({specifier})/items/") + ClientResponse readItemListForNamedAuthority(@PathParam("specifier") String specifier); + + //(C)reate Item + @POST + @Path("/{vcsid}/items/") + ClientResponse createItem(@PathParam("vcsid") String vcsid, MultipartOutput multipart); + + //(R)ead Item + @GET + @Path("/{vcsid}/items/{csid}") + ClientResponse readItem(@PathParam("vcsid") String vcsid, @PathParam("csid") String csid); + + //(U)pdate Item + @PUT + @Path("/{vcsid}/items/{csid}") + ClientResponse updateItem(@PathParam("vcsid") String vcsid, @PathParam("csid") String csid, MultipartOutput multipart); + + //(D)elete Item + @DELETE + @Path("/{vcsid}/items/{csid}") + ClientResponse deleteItem(@PathParam("vcsid") String vcsid, @PathParam("csid") String csid); + + // List Contacts + @GET + @Produces({"application/xml"}) + @Path("/{parentcsid}/items/{itemcsid}/contacts/") + ClientResponse readContactList( + @PathParam("parentcsid") String parentcsid, + @PathParam("itemcsid") String itemcsid); + + //(C)reate Contact + @POST + @Path("/{parentcsid}/items/{itemcsid}/contacts/") + ClientResponse createContact( + @PathParam("parentcsid") String parentcsid, + @PathParam("itemcsid") String itemcsid, + MultipartOutput multipart); + + //(R)ead Contact + @GET + @Path("/{parentcsid}/items/{itemcsid}/contacts/{csid}") + ClientResponse readContact( + @PathParam("parentcsid") String parentcsid, + @PathParam("itemcsid") String itemcsid, + @PathParam("csid") String csid); + + //(U)pdate Contact + @PUT + @Path("/{parentcsid}/items/{itemcsid}/contacts/{csid}") + ClientResponse updateContact( + @PathParam("parentcsid") String parentcsid, + @PathParam("itemcsid") String itemcsid, + @PathParam("csid") String csid, + MultipartOutput multipart); + + //(D)elete Contact + @DELETE + @Path("/{parentcsid}/items/{itemcsid}/contacts/{csid}") + ClientResponse deleteContact( + @PathParam("parentcsid") String parentcsid, + @PathParam("itemcsid") String itemcsid, + @PathParam("csid") String csid); + +} diff --git a/services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java b/services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java new file mode 100644 index 000000000..83fd1e9fd --- /dev/null +++ b/services/location/client/src/test/java/org/collectionspace/services/client/test/LocationAuthorityServiceTest.java @@ -0,0 +1,1323 @@ +/** + * 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 + * + * 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.LocationJAXBSchema; +import org.collectionspace.services.client.CollectionSpaceClient; +import org.collectionspace.services.client.ContactClient; +import org.collectionspace.services.client.ContactClientUtils; +import org.collectionspace.services.contact.ContactsCommon; +import org.collectionspace.services.contact.ContactsCommonList; +import org.collectionspace.services.client.LocationAuthorityClient; +import org.collectionspace.services.client.LocationAuthorityClientUtils; +import org.collectionspace.services.jaxb.AbstractCommonList; +import org.collectionspace.services.location.LocationauthoritiesCommon; +import org.collectionspace.services.location.LocationauthoritiesCommonList; +import org.collectionspace.services.location.LocationsCommon; +import org.collectionspace.services.location.LocationsCommonList; +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.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.testng.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.Test; + +/** + * LocationAuthorityServiceTest, carries out tests against a + * deployed and running LocationAuthority Service. + * + * $LastChangedRevision: 753 $ + * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $ + */ +public class LocationAuthorityServiceTest extends AbstractServiceTestImpl { + + /** The logger. */ + private final Logger logger = + LoggerFactory.getLogger(LocationAuthorityServiceTest.class); + + // Instance variables specific to this test. + /** The SERVICE path component. */ + final String SERVICE_PATH_COMPONENT = "locationauthorities"; + + /** The ITEM servicE path component. */ + final String ITEM_SERVICE_PATH_COMPONENT = "items"; + + /** The CONTACT servicE path component. */ + final String CONTACT_SERVICE_PATH_COMPONENT = "contacts"; + + /** The TEST name. */ + final String TEST_NAME = "Shelf 1"; + + /** The TEST conditionNote. */ + final String TEST_CONDITION_NOTE = "Basically clean"; + + /** The TEST death date. */ + final String TEST_CONDITION_NOTE_DATE = "June 11, 1979"; + + /** The TEST securityNote. */ + final String TEST_SECURITY_NOTE = "Kind of safe"; + + /** The TEST location type. */ + // TODO Make loc type be a controlled vocab term. + final String TEST_LOCATION_TYPE = "Shelf"; + + /** The TEST location type. */ + // TODO Make status type be a controlled vocab term. + final String TEST_STATUS = "Approved"; + + /** The known resource id. */ + private String knownResourceId = null; + + /** The known resource display name. */ + private String knownResourceDisplayName = null; + + /** The known resource ref name. */ + private String knownResourceRefName = null; + + /** The known locationType ref name. */ + private String knownLocationTypeRefName = null; + + /** The known item resource id. */ + private String knownItemResourceId = null; + + /** The known contact resource id. */ + private String knownContactResourceId = null; + + /** The n items to create in list. */ + private int nItemsToCreateInList = 3; + + /** The all resource ids created. */ + private List allResourceIdsCreated = new ArrayList(); + + /** The all item resource ids created. */ + private Map allItemResourceIdsCreated = + new HashMap(); + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() + */ + @Override + protected CollectionSpaceClient getClientInstance() { + return new LocationAuthorityClient(); + } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) + */ + @Override + protected AbstractCommonList getAbstractCommonList( + ClientResponse response) { + return response.getEntity(LocationsCommonList.class); + } + + // --------------------------------------------------------------- + // CRUD tests : CREATE tests + // --------------------------------------------------------------- + // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String) + */ + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"create"}) + 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. + LocationAuthorityClient client = new LocationAuthorityClient(); + String identifier = createIdentifier(); + String displayName = "displayName-" + identifier; + String baseRefName = LocationAuthorityClientUtils.createLocationAuthRefName(displayName, false); + String fullRefName = LocationAuthorityClientUtils.createLocationAuthRefName(displayName, true); + MultipartOutput multipart = + LocationAuthorityClientUtils.createLocationAuthorityInstance( + displayName, fullRefName, client.getCommonPartName()); + 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(this.REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(this.REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, this.EXPECTED_STATUS_CODE); + + // Store the refname from the first resource created + // for additional tests below. + knownResourceRefName = baseRefName; + + String newID = LocationAuthorityClientUtils.extractId(res); + // Store the ID returned from the first resource created + // for additional tests below. + if (knownResourceId == null){ + knownResourceId = newID; + knownResourceDisplayName = displayName; + 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(newID); + } + + /** + * Creates the item. + * + * @param testName the test name + */ + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"create"}, dependsOnMethods = {"create"}) + public void createItem(String testName) { + setupCreate(testName); + String newID = createItemInAuthority(knownResourceId, knownResourceRefName); + } + + /** + * Creates the item in authority. + * + * @param vcsid the vcsid + * @param authRefName the auth ref name + * @return the string + */ + private String createItemInAuthority(String vcsid, String authRefName) { + + final String testName = "createItemInAuthority"; + if(logger.isDebugEnabled()){ + logger.debug(testName + ":..."); + } + + // Submit the request to the service and store the response. + LocationAuthorityClient client = new LocationAuthorityClient(); + String identifier = createIdentifier(); + String refName = LocationAuthorityClientUtils.createLocationRefName(authRefName, TEST_NAME, true); + Map shelf1Map = new HashMap(); + // TODO Make loc type and status be controlled vocabs. + shelf1Map.put(LocationJAXBSchema.NAME, TEST_NAME); + shelf1Map.put(LocationJAXBSchema.CONDITION_NOTE, TEST_CONDITION_NOTE); + shelf1Map.put(LocationJAXBSchema.CONDITION_NOTE_DATE, TEST_CONDITION_NOTE_DATE); + shelf1Map.put(LocationJAXBSchema.SECURITY_NOTE, TEST_SECURITY_NOTE); + shelf1Map.put(LocationJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE); + shelf1Map.put(LocationJAXBSchema.STATUS, TEST_STATUS); + MultipartOutput multipart = + LocationAuthorityClientUtils.createLocationInstance(vcsid, refName, shelf1Map, + client.getItemCommonPartName() ); + ClientResponse res = client.createItem(vcsid, multipart); + int statusCode = res.getStatus(); + String newID = LocationAuthorityClientUtils.extractId(res); + + // 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); + + // Store the ID returned from the first item resource created + // for additional tests below. + if (knownItemResourceId == null){ + knownItemResourceId = newID; + if (logger.isDebugEnabled()) { + logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId); + } + } + + // Store the IDs from any item resources created + // by tests, along with the IDs of their parents, so these items + // can be deleted after all tests have been run. + allItemResourceIdsCreated.put(newID, vcsid); + + return newID; + } + + + + // Failure outcomes + + // Placeholders until the three tests below can be uncommented. + // See Issue CSPACE-401. + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithEmptyEntityBody(java.lang.String) + */ + @Override + public void createWithEmptyEntityBody(String testName) throws Exception { + } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithMalformedXml(java.lang.String) + */ + @Override + public void createWithMalformedXml(String testName) throws Exception { + } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createWithWrongXmlSchema(java.lang.String) + */ + @Override + public void createWithWrongXmlSchema(String testName) throws Exception { + } + + + // --------------------------------------------------------------- + // CRUD tests : CREATE LIST tests + // --------------------------------------------------------------- + // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#createList(java.lang.String) + */ + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"createList"}, dependsOnGroups = {"create"}) + public void createList(String testName) throws Exception { + for (int i = 0; i < nItemsToCreateInList; i++) { + create(testName); + } + } + + /** + * Creates the item list. + * + * @param testName the test name + * @throws Exception the exception + */ + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"createList"}, dependsOnMethods = {"createList"}) + public void createItemList(String testName) throws Exception { + // Add items to the initially-created, known parent record. + for (int j = 0; j < nItemsToCreateInList; j++) { + createItem(testName); + } + } + + // --------------------------------------------------------------- + // CRUD tests : READ tests + // --------------------------------------------------------------- + // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String) + */ + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"read"}, dependsOnGroups = {"create"}) + public void read(String testName) throws Exception { + + // Perform setup. + setupRead(); + + // Submit the request to the service and store the response. + LocationAuthorityClient client = new LocationAuthorityClient(); + 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); + //FIXME: remove the following try catch once Aron fixes signatures + try { + MultipartInput input = (MultipartInput) res.getEntity(); + LocationauthoritiesCommon locationAuthority = (LocationauthoritiesCommon) extractPart(input, + client.getCommonPartName(), LocationauthoritiesCommon.class); + Assert.assertNotNull(locationAuthority); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + /** + * Read by name. + * + * @param testName the test name + * @throws Exception the exception + */ + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"read"}, dependsOnGroups = {"create"}) + public void readByName(String testName) throws Exception { + + // Perform setup. + setupRead(); + + // Submit the request to the service and store the response. + LocationAuthorityClient client = new LocationAuthorityClient(); + ClientResponse res = client.readByName(knownResourceDisplayName); + 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); + //FIXME: remove the following try catch once Aron fixes signatures + try { + MultipartInput input = (MultipartInput) res.getEntity(); + LocationauthoritiesCommon locationAuthority = (LocationauthoritiesCommon) extractPart(input, + client.getCommonPartName(), LocationauthoritiesCommon.class); + Assert.assertNotNull(locationAuthority); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + + /** + * Read item. + * + * @param testName the test name + * @throws Exception the exception + */ + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"read"}, dependsOnMethods = {"read"}) + public void readItem(String testName) throws Exception { + + // Perform setup. + setupRead(testName); + + // Submit the request to the service and store the response. + LocationAuthorityClient client = new LocationAuthorityClient(); + ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); + 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); + + // Check whether we've received a location. + MultipartInput input = (MultipartInput) res.getEntity(); + LocationsCommon location = (LocationsCommon) extractPart(input, + client.getItemCommonPartName(), LocationsCommon.class); + Assert.assertNotNull(location); + boolean showFull = true; + if(showFull && logger.isDebugEnabled()){ + logger.debug(testName + ": returned payload:"); + logger.debug(objectAsXmlString(location, LocationsCommon.class)); + } + Assert.assertEquals(location.getInAuthority(), knownResourceId); + + } + + /** + * Verify item display name. + * + * @param testName the test name + * @throws Exception the exception + */ + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + dependsOnMethods = {"readItem", "updateItem"}) + public void verifyItemDisplayName(String testName) throws Exception { + + // Perform setup. + setupUpdate(testName); + + // Submit the request to the service and store the response. + LocationAuthorityClient client = new LocationAuthorityClient(); + ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); + 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); + + // Check whether location has expected displayName. + MultipartInput input = (MultipartInput) res.getEntity(); + LocationsCommon location = (LocationsCommon) extractPart(input, + client.getItemCommonPartName(), LocationsCommon.class); + Assert.assertNotNull(location); + String displayName = location.getDisplayName(); + // Make sure displayName matches computed form + String expectedDisplayName = + LocationAuthorityClientUtils.prepareDefaultDisplayName(TEST_NAME); + Assert.assertNotNull(displayName, expectedDisplayName); + + // Update the shortName and verify the computed name is updated. + location.setCsid(null); + location.setDisplayNameComputed(true); + location.setName("updated-" + TEST_NAME); + expectedDisplayName = + LocationAuthorityClientUtils.prepareDefaultDisplayName("updated-" + TEST_NAME); + + // Submit the updated resource to the service and store the response. + MultipartOutput output = new MultipartOutput(); + OutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", client.getItemCommonPartName()); + res = client.updateItem(knownResourceId, knownItemResourceId, output); + statusCode = res.getStatus(); + + // Check the status code of the response: does it match the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug("updateItem: status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Retrieve the updated resource and verify that its contents exist. + input = (MultipartInput) res.getEntity(); + LocationsCommon updatedLocation = + (LocationsCommon) extractPart(input, + client.getItemCommonPartName(), LocationsCommon.class); + Assert.assertNotNull(updatedLocation); + + // Verify that the updated resource received the correct data. + Assert.assertEquals(updatedLocation.getName(), location.getName(), + "Updated ForeName in Location did not match submitted data."); + // Verify that the updated resource computes the right displayName. + Assert.assertEquals(updatedLocation.getDisplayName(), expectedDisplayName, + "Updated ForeName in Location not reflected in computed DisplayName."); + + // Now Update the displayName, not computed and verify the computed name is overriden. + location.setDisplayNameComputed(false); + expectedDisplayName = "TestName"; + location.setDisplayName(expectedDisplayName); + + // Submit the updated resource to the service and store the response. + output = new MultipartOutput(); + commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", client.getItemCommonPartName()); + res = client.updateItem(knownResourceId, knownItemResourceId, output); + statusCode = res.getStatus(); + + // Check the status code of the response: does it match the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug("updateItem: status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Retrieve the updated resource and verify that its contents exist. + input = (MultipartInput) res.getEntity(); + updatedLocation = + (LocationsCommon) extractPart(input, + client.getItemCommonPartName(), LocationsCommon.class); + Assert.assertNotNull(updatedLocation); + + // Verify that the updated resource received the correct data. + Assert.assertEquals(updatedLocation.isDisplayNameComputed(), false, + "Updated displayNameComputed in Location did not match submitted data."); + // Verify that the updated resource computes the right displayName. + Assert.assertEquals(updatedLocation.getDisplayName(), + expectedDisplayName, + "Updated DisplayName (not computed) in Location not stored."); + } + + /** + * Verify illegal item display name. + * + * @param testName the test name + * @throws Exception the exception + */ + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + dependsOnMethods = {"verifyItemDisplayName"}) + public void verifyIllegalItemDisplayName(String testName) throws Exception { + + // Perform setup. + setupUpdateWithWrongXmlSchema(testName); + + // Submit the request to the service and store the response. + LocationAuthorityClient client = new LocationAuthorityClient(); + ClientResponse res = client.readItem(knownResourceId, knownItemResourceId); + 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, Response.Status.OK.getStatusCode()); + + // Check whether Location has expected displayName. + MultipartInput input = (MultipartInput) res.getEntity(); + LocationsCommon location = (LocationsCommon) extractPart(input, + client.getItemCommonPartName(), LocationsCommon.class); + Assert.assertNotNull(location); + // Try to Update with computed false and no displayName + location.setDisplayNameComputed(false); + location.setDisplayName(null); + + // Submit the updated resource to the service and store the response. + MultipartOutput output = new MultipartOutput(); + OutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", client.getItemCommonPartName()); + res = client.updateItem(knownResourceId, knownItemResourceId, output); + statusCode = res.getStatus(); + + // Check the status code of the response: does it match the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug("updateItem: status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + + + // Failure outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readNonExistent(java.lang.String) + */ + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"read"}, dependsOnMethods = {"read"}) + public void readNonExistent(String testName) { + + // Perform setup. + setupReadNonExistent(testName); + + // Submit the request to the service and store the response. + LocationAuthorityClient client = new LocationAuthorityClient(); + 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); + } + + /** + * Read item non existent. + * + * @param testName the test name + */ + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"read"}, dependsOnMethods = {"readItem"}) + public void readItemNonExistent(String testName) { + + // Perform setup. + setupReadNonExistent(testName); + + // Submit the request to the service and store the response. + LocationAuthorityClient client = new LocationAuthorityClient(); + ClientResponse res = client.readItem(knownResourceId, 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 + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String) + */ + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"readList"}, dependsOnGroups = {"createList", "read"}) + public void readList(String testName) throws Exception { + + // Perform setup. + setupReadList(testName); + + // Submit the request to the service and store the response. + LocationAuthorityClient client = new LocationAuthorityClient(); + ClientResponse res = client.readList(); + LocationauthoritiesCommonList 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.getLocationauthorityListItem(); + int i = 0; + for (LocationauthoritiesCommonList.LocationauthorityListItem item : items) { + String csid = item.getCsid(); + logger.debug(testName + ": list-item[" + i + "] csid=" + + csid); + logger.debug(testName + ": list-item[" + i + "] displayName=" + + item.getDisplayName()); + logger.debug(testName + ": list-item[" + i + "] URI=" + + item.getUri()); + readItemList(csid, null); + i++; + } + } + } + + /** + * Read item list. + */ + @Test(groups = {"readList"}, dependsOnMethods = {"readList"}) + public void readItemList() { + readItemList(knownResourceId, null); + } + + /** + * Read item list by authority name. + */ + @Test(groups = {"readList"}, dependsOnMethods = {"readItemList"}) + public void readItemListByAuthorityName() { + readItemList(null, knownResourceDisplayName); + } + + /** + * Read item list. + * + * @param vcsid the vcsid + * @param name the name + */ + private void readItemList(String vcsid, String name) { + + final String testName = "readItemList"; + + // Perform setup. + setupReadList(testName); + + // Submit the request to the service and store the response. + LocationAuthorityClient client = new LocationAuthorityClient(); + ClientResponse res = null; + if(vcsid!= null) { + res = client.readItemList(vcsid); + } else if(name!= null) { + res = client.readItemListForNamedAuthority(name); + } else { + Assert.fail("readItemList passed null csid and name!"); + } + LocationsCommonList 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); + + List items = + list.getLocationListItem(); + int nItemsReturned = items.size(); + // There will be one item created, associated with a + // known parent resource, by the createItem test. + // + // In addition, there will be 'nItemsToCreateInList' + // additional items created by the createItemList test, + // all associated with the same parent resource. + int nExpectedItems = nItemsToCreateInList + 1; + if(logger.isDebugEnabled()){ + logger.debug(testName + ": Expected " + + nExpectedItems +" items; got: "+nItemsReturned); + } + Assert.assertEquals(nItemsReturned, nExpectedItems); + + int i = 0; + for (LocationsCommonList.LocationListItem item : items) { + Assert.assertTrue((null != item.getRefName()), "Item refName is null!"); + Assert.assertTrue((null != item.getDisplayName()), "Item displayName is null!"); + // Optionally output additional data about list members for debugging. + boolean showDetails = true; + if (showDetails && logger.isDebugEnabled()) { + logger.debug(" " + testName + ": list-item[" + i + "] csid=" + + item.getCsid()); + logger.debug(" " + testName + ": list-item[" + i + "] refName=" + + item.getRefName()); + logger.debug(" " + testName + ": list-item[" + i + "] displayName=" + + item.getDisplayName()); + logger.debug(" " + testName + ": list-item[" + i + "] URI=" + + item.getUri()); + } + i++; + } + } + + + // Failure outcomes + // None at present. + + // --------------------------------------------------------------- + // CRUD tests : UPDATE tests + // --------------------------------------------------------------- + // Success outcomes + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String) + */ + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"update"}, dependsOnGroups = {"read", "readList"}) + public void update(String testName) throws Exception { + + // Perform setup. + setupUpdate(testName); + + // Retrieve the contents of a resource to update. + LocationAuthorityClient client = new LocationAuthorityClient(); + 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 LocationAuthority to update with ID: " + knownResourceId); + } + MultipartInput input = (MultipartInput) res.getEntity(); + LocationauthoritiesCommon locationAuthority = (LocationauthoritiesCommon) extractPart(input, + client.getCommonPartName(), LocationauthoritiesCommon.class); + Assert.assertNotNull(locationAuthority); + + // Update the contents of this resource. + locationAuthority.setDisplayName("updated-" + locationAuthority.getDisplayName()); + locationAuthority.setVocabType("updated-" + locationAuthority.getVocabType()); + if(logger.isDebugEnabled()){ + logger.debug("to be updated LocationAuthority"); + logger.debug(objectAsXmlString(locationAuthority, LocationauthoritiesCommon.class)); + } + + // Submit the updated resource to the service and store the response. + MultipartOutput output = new MultipartOutput(); + OutputPart commonPart = output.addPart(locationAuthority, 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); + + // Retrieve the updated resource and verify that its contents exist. + input = (MultipartInput) res.getEntity(); + LocationauthoritiesCommon updatedLocationAuthority = + (LocationauthoritiesCommon) extractPart(input, + client.getCommonPartName(), LocationauthoritiesCommon.class); + Assert.assertNotNull(updatedLocationAuthority); + + // Verify that the updated resource received the correct data. + Assert.assertEquals(updatedLocationAuthority.getDisplayName(), + locationAuthority.getDisplayName(), + "Data in updated object did not match submitted data."); + } + + /** + * Update item. + * + * @param testName the test name + * @throws Exception the exception + */ + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"update"}, dependsOnMethods = {"update"}) + public void updateItem(String testName) throws Exception { + + // Perform setup. + setupUpdate(testName); + + // Retrieve the contents of a resource to update. + LocationAuthorityClient client = new LocationAuthorityClient(); + ClientResponse res = + client.readItem(knownResourceId, knownItemResourceId); + if(logger.isDebugEnabled()){ + logger.debug(testName + ": read status = " + res.getStatus()); + } + Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); + + if(logger.isDebugEnabled()){ + logger.debug("got Location to update with ID: " + + knownItemResourceId + + " in LocationAuthority: " + knownResourceId ); + } + MultipartInput input = (MultipartInput) res.getEntity(); + LocationsCommon location = (LocationsCommon) extractPart(input, + client.getItemCommonPartName(), LocationsCommon.class); + Assert.assertNotNull(location); + + // Update the contents of this resource. + location.setCsid(null); + location.setName("updated-" + location.getName()); + if(logger.isDebugEnabled()){ + logger.debug("to be updated Location"); + logger.debug(objectAsXmlString(location, + LocationsCommon.class)); + } + + // Submit the updated resource to the service and store the response. + MultipartOutput output = new MultipartOutput(); + OutputPart commonPart = output.addPart(location, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", client.getItemCommonPartName()); + res = client.updateItem(knownResourceId, knownItemResourceId, 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); + + // Retrieve the updated resource and verify that its contents exist. + input = (MultipartInput) res.getEntity(); + LocationsCommon updatedLocation = + (LocationsCommon) extractPart(input, + client.getItemCommonPartName(), LocationsCommon.class); + Assert.assertNotNull(updatedLocation); + + // Verify that the updated resource received the correct data. + Assert.assertEquals(updatedLocation.getName(), location.getName(), + "Data in updated Location did not match submitted data."); + } + + // Failure outcomes + // Placeholders until the three tests below can be uncommented. + // See Issue CSPACE-401. + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithEmptyEntityBody(java.lang.String) + */ + @Override + public void updateWithEmptyEntityBody(String testName) throws Exception { + } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithMalformedXml(java.lang.String) + */ + @Override + public void updateWithMalformedXml(String testName) throws Exception { + } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateWithWrongXmlSchema(java.lang.String) + */ + @Override + public void updateWithWrongXmlSchema(String testName) throws Exception { + } + + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#updateNonExistent(java.lang.String) + */ +@Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"update"}, 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(s) used when creating the request payload may be arbitrary. + // The only relevant ID may be the one used in update(), below. + LocationAuthorityClient client = new LocationAuthorityClient(); + String displayName = "displayName-NON_EXISTENT_ID"; + String fullRefName = LocationAuthorityClientUtils.createLocationAuthRefName(displayName, true); + MultipartOutput multipart = LocationAuthorityClientUtils.createLocationAuthorityInstance( + displayName, fullRefName, client.getCommonPartName()); + 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); + } + + /** + * Update non existent item. + * + * @param testName the test name + * @throws Exception the exception + */ + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"update"}, dependsOnMethods = {"updateItem", "testItemSubmitRequest"}) + public void updateNonExistentItem(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. + LocationAuthorityClient client = new LocationAuthorityClient(); + Map nonexMap = new HashMap(); + nonexMap.put(LocationJAXBSchema.NAME, TEST_NAME); + nonexMap.put(LocationJAXBSchema.LOCATION_TYPE, TEST_LOCATION_TYPE); + nonexMap.put(LocationJAXBSchema.STATUS, TEST_STATUS); + MultipartOutput multipart = + LocationAuthorityClientUtils.createLocationInstance(NON_EXISTENT_ID, + LocationAuthorityClientUtils.createLocationRefName(NON_EXISTENT_ID, NON_EXISTENT_ID, true), nonexMap, + client.getItemCommonPartName() ); + ClientResponse res = + client.updateItem(knownResourceId, 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 + + // Note: delete sub-resources in ascending hierarchical order, + // before deleting their parents. + + /** + * Delete item. + * + * @param testName the test name + * @throws Exception the exception + */ + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + //groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "readListByPartialTerm", "update"}) + groups = {"delete"}, dependsOnGroups = {"create", "read", "readList", "update"}) + public void deleteItem(String testName) throws Exception { + + // Perform setup. + setupDelete(testName); + + if(logger.isDebugEnabled()){ + logger.debug("parentcsid =" + knownResourceId + + " itemcsid = " + knownItemResourceId); + } + + // Submit the request to the service and store the response. + LocationAuthorityClient client = new LocationAuthorityClient(); + ClientResponse res = client.deleteItem(knownResourceId, knownItemResourceId); + 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); + } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#delete(java.lang.String) + */ + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"delete"}, dependsOnMethods = {"deleteItem"}) + public void delete(String testName) throws Exception { + + // Perform setup. + setupDelete(testName); + + if(logger.isDebugEnabled()){ + logger.debug("parentcsid =" + knownResourceId); + } + + // Submit the request to the service and store the response. + LocationAuthorityClient client = new LocationAuthorityClient(); + 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 + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String) + */ + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"delete"}, dependsOnMethods = {"delete"}) + public void deleteNonExistent(String testName) throws Exception { + + // Perform setup. + setupDeleteNonExistent(testName); + + // Submit the request to the service and store the response. + LocationAuthorityClient client = new LocationAuthorityClient(); + 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); + } + + /** + * Delete non existent item. + * + * @param testName the test name + */ + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, + groups = {"delete"}, dependsOnMethods = {"deleteItem"}) + public void deleteNonExistentItem(String testName) { + + // Perform setup. + setupDeleteNonExistent(testName); + + // Submit the request to the service and store the response. + LocationAuthorityClient client = new LocationAuthorityClient(); + ClientResponse res = client.deleteItem(knownResourceId, 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); + + } + + /** + * Test item submit request. + */ + @Test(dependsOnMethods = {"createItem", "readItem", "testSubmitRequest"}) + public void testItemSubmitRequest() { + + // 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 = getItemResourceURL(knownResourceId, knownItemResourceId); + int statusCode = submitRequest(method, url); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug("testItemSubmitRequest: 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() { + String noTest = System.getProperty("noTestCleanup"); + if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { + if (logger.isDebugEnabled()) { + logger.debug("Skipping Cleanup phase ..."); + } + return; + } + if (logger.isDebugEnabled()) { + logger.debug("Cleaning up temporary resources created for testing ..."); + } + String parentResourceId; + String itemResourceId; + // Clean up contact resources. + LocationAuthorityClient client = new LocationAuthorityClient(); + parentResourceId = knownResourceId; + // Clean up item resources. + for (Map.Entry entry : allItemResourceIdsCreated.entrySet()) { + itemResourceId = entry.getKey(); + parentResourceId = entry.getValue(); + // Note: Any non-success responses from the delete operation + // below are ignored and not reported. + ClientResponse res = + client.deleteItem(parentResourceId, itemResourceId); + } + // Clean up parent resources. + for (String resourceId : allResourceIdsCreated) { + // Note: Any non-success responses from the delete operation + // below are ignored and not reported. + ClientResponse res = client.delete(resourceId); + } + } + + // --------------------------------------------------------------- + // Utility methods used by tests above + // --------------------------------------------------------------- + /* (non-Javadoc) + * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent() + */ + @Override + public String getServicePathComponent() { + return SERVICE_PATH_COMPONENT; + } + + /** + * Gets the item service path component. + * + * @return the item service path component + */ + public String getItemServicePathComponent() { + return ITEM_SERVICE_PATH_COMPONENT; + } + + /** + * Returns the root URL for the item service. + * + * This URL consists of a base URL for all services, followed by + * a path component for the owning parent, followed by the + * path component for the items. + * + * @param parentResourceIdentifier An identifier (such as a UUID) for the + * parent authority resource of the relevant item resource. + * + * @return The root URL for the item service. + */ + protected String getItemServiceRootURL(String parentResourceIdentifier) { + return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent(); + } + + /** + * Returns the URL of a specific item resource managed by a service, and + * designated by an identifier (such as a universally unique ID, or UUID). + * + * @param parentResourceIdentifier An identifier (such as a UUID) for the + * parent authority resource of the relevant item resource. + * + * @param itemResourceIdentifier An identifier (such as a UUID) for an + * item resource. + * + * @return The URL of a specific item resource managed by a service. + */ + protected String getItemResourceURL(String parentResourceIdentifier, String itemResourceIdentifier) { + return getItemServiceRootURL(parentResourceIdentifier) + "/" + itemResourceIdentifier; + } + + +} diff --git a/services/location/client/src/test/resources/log4j.properties b/services/location/client/src/test/resources/log4j.properties new file mode 100644 index 000000000..18c510350 --- /dev/null +++ b/services/location/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/location/import/.classpath b/services/location/import/.classpath new file mode 100644 index 000000000..199bbbbdb --- /dev/null +++ b/services/location/import/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/services/location/import/.project b/services/location/import/.project new file mode 100644 index 000000000..ae21be519 --- /dev/null +++ b/services/location/import/.project @@ -0,0 +1,26 @@ + + + org.collectionspace.services.person.importer + + + org.collectionspace.services.client + org.collectionspace.services.common + org.collectionspace.services.person.jaxb + + + + org.eclipse.jdt.core.javabuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.maven.ide.eclipse.maven2Nature + + diff --git a/services/location/import/.settings/org.eclipse.jdt.core.prefs b/services/location/import/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..8bc35048b --- /dev/null +++ b/services/location/import/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +#Tue Nov 10 14:56:23 PST 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/location/import/.settings/org.maven.ide.eclipse.prefs b/services/location/import/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 000000000..fd8796b9b --- /dev/null +++ b/services/location/import/.settings/org.maven.ide.eclipse.prefs @@ -0,0 +1,9 @@ +#Tue Nov 10 14:56:18 PST 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/location/import/build.xml b/services/location/import/build.xml new file mode 100644 index 000000000..1b691286e --- /dev/null +++ b/services/location/import/build.xml @@ -0,0 +1,60 @@ + + + + location service + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/location/import/pom.xml b/services/location/import/pom.xml new file mode 100644 index 000000000..c760f8e0b --- /dev/null +++ b/services/location/import/pom.xml @@ -0,0 +1,105 @@ + + + + org.collectionspace.services + org.collectionspace.services.location + 0.7-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.location.importer + services.location.importer + + + + + org.slf4j + slf4j-api + 1.5.2 + + + + + org.collectionspace.services + org.collectionspace.services.location.jaxb + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.client + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.location.client + ${project.version} + + + + org.jboss.resteasy + resteasy-jaxrs + + + + tjws + webserver + + + + + org.jboss.resteasy + resteasy-jaxb-provider + + + org.jboss.resteasy + resteasy-multipart-provider + + + commons-httpclient + commons-httpclient + 3.1 + + + + + collectionspace-services-location-importer + + + org.apache.maven.plugins + maven-assembly-plugin + + + + attached + + package + + + jar-with-dependencies + + + + org.collectionspace.services.location.importer.LocationAuthorityBaseImport + + + + + + + + + + diff --git a/services/location/import/src/main/java/org/collectionspace/services/location/importer/LocationAuthorityBaseImport.java b/services/location/import/src/main/java/org/collectionspace/services/location/importer/LocationAuthorityBaseImport.java new file mode 100644 index 000000000..4b2b703f3 --- /dev/null +++ b/services/location/import/src/main/java/org/collectionspace/services/location/importer/LocationAuthorityBaseImport.java @@ -0,0 +1,155 @@ +/** + * 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 + * + * 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.location.importer; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; + +import org.apache.log4j.BasicConfigurator; +import org.collectionspace.services.LocationJAXBSchema; +import org.collectionspace.services.client.LocationAuthorityClient; +import org.collectionspace.services.client.LocationAuthorityClientUtils; +import org.collectionspace.services.client.test.ServiceRequestType; +import org.collectionspace.services.location.LocationauthoritiesCommon; +import org.collectionspace.services.location.LocationauthoritiesCommonList; +import org.collectionspace.services.location.LocationsCommon; +import org.collectionspace.services.location.LocationsCommonList; +import org.jboss.resteasy.client.ClientResponse; +import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; +import org.jboss.resteasy.plugins.providers.multipart.OutputPart; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * LocationAuthorityServiceTest, carries out tests against a + * deployed and running LocationAuthority Service. + * + * $LastChangedRevision: 753 $ + * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $ + */ +public class LocationAuthorityBaseImport { + private static final Logger logger = + LoggerFactory.getLogger(LocationAuthorityBaseImport.class); + + // Instance variables specific to this test. + private LocationAuthorityClient client = new LocationAuthorityClient(); + + public void createLocationAuthority(String locationAuthorityName, + List> locationMaps ) { + + // Expected status code: 201 Created + int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode(); + // Type of service request being tested + ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE; + + if(logger.isDebugEnabled()){ + logger.debug("Import: Create locationAuthority: \"" + locationAuthorityName +"\""); + } + String baseLocationRefName = + LocationAuthorityClientUtils.createLocationAuthRefName(locationAuthorityName, false); + String fullLocationRefName = + LocationAuthorityClientUtils.createLocationAuthRefName(locationAuthorityName, true); + MultipartOutput multipart = + LocationAuthorityClientUtils.createLocationAuthorityInstance( + locationAuthorityName, fullLocationRefName, client.getCommonPartName()); + ClientResponse res = client.create(multipart); + + int statusCode = res.getStatus(); + + if(!REQUEST_TYPE.isValidStatusCode(statusCode)) { + throw new RuntimeException("Could not create enumeration: \""+locationAuthorityName + +"\" "+ LocationAuthorityClientUtils.invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + } + if(statusCode != EXPECTED_STATUS_CODE) { + throw new RuntimeException("Unexpected Status when creating enumeration: \"" + +locationAuthorityName +"\", Status:"+ statusCode); + } + + // Store the ID returned from this create operation + // for additional tests below. + String newLocationAuthorityId = LocationAuthorityClientUtils.extractId(res); + if(logger.isDebugEnabled()){ + logger.debug("Import: Created locationAuthorityulary: \"" + locationAuthorityName +"\" ID:" + +newLocationAuthorityId ); + } + for(Map locationMap : locationMaps){ + LocationAuthorityClientUtils.createItemInAuthority( + newLocationAuthorityId, baseLocationRefName, locationMap, client); + } + } + + public static void main(String[] args) { + + BasicConfigurator.configure(); + logger.info("LocationAuthorityBaseImport starting..."); + + LocationAuthorityBaseImport pabi = new LocationAuthorityBaseImport(); + final String demoLocationAuthorityName = "Demo Location Authority"; + + /* Strings are: + shortName, longName, nameAdditions, contactName, + foundingDate, dissolutionDate, foundingPlace, function, description + */ + Map johnWayneMap = new HashMap(); + johnWayneMap.put(LocationJAXBSchema.FORE_NAME, "John"); + johnWayneMap.put(LocationJAXBSchema.SUR_NAME, "Wayne"); + johnWayneMap.put(LocationJAXBSchema.GENDER, "male"); + johnWayneMap.put(LocationJAXBSchema.BIRTH_DATE, "May 26, 1907"); + johnWayneMap.put(LocationJAXBSchema.BIRTH_PLACE, "Winterset, Iowa"); + johnWayneMap.put(LocationJAXBSchema.DEATH_DATE, "June 11, 1979"); + johnWayneMap.put(LocationJAXBSchema.BIO_NOTE, "born Marion Robert Morrison and better" + + "known by his stage name John Wayne, was an American film actor, director " + + "and producer. He epitomized rugged masculinity and has become an enduring " + + "American icon. He is famous for his distinctive voice, walk and height. " + + "He was also known for his conservative political views and his support in " + + "the 1950s for anti-communist positions."); + Map patrickSchmitzMap = new HashMap(); + patrickSchmitzMap.put(LocationJAXBSchema.FORE_NAME, "Patrick"); + patrickSchmitzMap.put(LocationJAXBSchema.SUR_NAME, "Schmitz"); + patrickSchmitzMap.put(LocationJAXBSchema.GENDER, "male"); + patrickSchmitzMap.put(LocationJAXBSchema.BIRTH_DATE, "7/15/1960"); + patrickSchmitzMap.put(LocationJAXBSchema.BIRTH_PLACE, "MI"); + Map janeDoeMap = new HashMap(); + janeDoeMap.put(LocationJAXBSchema.FORE_NAME, "Jane"); + janeDoeMap.put(LocationJAXBSchema.SUR_NAME, "Doe"); + janeDoeMap.put(LocationJAXBSchema.GENDER, "female"); + janeDoeMap.put(LocationJAXBSchema.BIRTH_DATE, "7/04/1901"); + janeDoeMap.put(LocationJAXBSchema.DEATH_DATE, "4/01/1999"); + janeDoeMap.put(LocationJAXBSchema.BIRTH_PLACE, "Anytown, USA"); + janeDoeMap.put(LocationJAXBSchema.BIRTH_PLACE, "Nowheresville, USA"); + List> locationsMaps = + Arrays.asList(johnWayneMap, patrickSchmitzMap, janeDoeMap ); + + pabi.createLocationAuthority(demoLocationAuthorityName, locationsMaps); + + logger.info("LocationAuthorityBaseImport complete."); + } +} diff --git a/services/location/installer/build.xml b/services/location/installer/build.xml new file mode 100644 index 000000000..3f8be51d8 --- /dev/null +++ b/services/location/installer/build.xml @@ -0,0 +1,61 @@ + + + + location service + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/location/jaxb/.classpath b/services/location/jaxb/.classpath new file mode 100644 index 000000000..425cd1620 --- /dev/null +++ b/services/location/jaxb/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/services/location/jaxb/.project b/services/location/jaxb/.project new file mode 100644 index 000000000..27c00a817 --- /dev/null +++ b/services/location/jaxb/.project @@ -0,0 +1,23 @@ + + + org.collectionspace.services.person.jaxb + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + + org.maven.ide.eclipse.maven2Nature + org.eclipse.jdt.core.javanature + + diff --git a/services/location/jaxb/.settings/org.eclipse.jdt.core.prefs b/services/location/jaxb/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..0b4dbbea4 --- /dev/null +++ b/services/location/jaxb/.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/location/jaxb/.settings/org.maven.ide.eclipse.prefs b/services/location/jaxb/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 000000000..528843671 --- /dev/null +++ b/services/location/jaxb/.settings/org.maven.ide.eclipse.prefs @@ -0,0 +1,9 @@ +#Mon Oct 05 17:07:08 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/location/jaxb/pom.xml b/services/location/jaxb/pom.xml new file mode 100644 index 000000000..c1c00d6a5 --- /dev/null +++ b/services/location/jaxb/pom.xml @@ -0,0 +1,47 @@ + + + + org.collectionspace.services + org.collectionspace.services.location + 0.7-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.location.jaxb + services.location.jaxb + + + + com.sun.xml.bind + jaxb-impl + + + org.jvnet.jaxb2-commons + property-listener-injector + + + org.jvnet.jaxb2_commons + runtime + + + org.collectionspace.services + org.collectionspace.services.jaxb + ${project.version} + + + + + collectionspace-services-location-jaxb + install + + + org.jvnet.jaxb2.maven2 + maven-jaxb2-plugin + + + + + diff --git a/services/location/jaxb/src/main/java/org/collectionspace/services/LocationAuthorityJAXBSchema.java b/services/location/jaxb/src/main/java/org/collectionspace/services/LocationAuthorityJAXBSchema.java new file mode 100644 index 000000000..134e3193b --- /dev/null +++ b/services/location/jaxb/src/main/java/org/collectionspace/services/LocationAuthorityJAXBSchema.java @@ -0,0 +1,18 @@ +/** + * + */ +package org.collectionspace.services; + +/** + * @author pschmitz + * + */ +public interface LocationAuthorityJAXBSchema { + final static String LOCATIONAUTHORITIES_COMMON = "locationauthorities_common"; + final static String DISPLAY_NAME = "displayName"; + final static String REF_NAME = "refName"; + final static String VOCAB_TYPE = "vocabType"; + final static String CSID = "csid"; +} + + diff --git a/services/location/jaxb/src/main/java/org/collectionspace/services/LocationAuthorityListItemJAXBSchema.java b/services/location/jaxb/src/main/java/org/collectionspace/services/LocationAuthorityListItemJAXBSchema.java new file mode 100644 index 000000000..fe6ce9091 --- /dev/null +++ b/services/location/jaxb/src/main/java/org/collectionspace/services/LocationAuthorityListItemJAXBSchema.java @@ -0,0 +1,9 @@ +package org.collectionspace.services; + +public interface LocationAuthorityListItemJAXBSchema { + final static String DISPLAY_NAME = "displayName"; + final static String REF_NAME = "refName"; + final static String VOCAB_TYPE = "vocabType"; + final static String CSID = "csid"; + final static String URI = "url"; +} diff --git a/services/location/jaxb/src/main/java/org/collectionspace/services/LocationJAXBSchema.java b/services/location/jaxb/src/main/java/org/collectionspace/services/LocationJAXBSchema.java new file mode 100644 index 000000000..7b7e70c46 --- /dev/null +++ b/services/location/jaxb/src/main/java/org/collectionspace/services/LocationJAXBSchema.java @@ -0,0 +1,24 @@ +/** + * + */ +package org.collectionspace.services; + +/** + * @author pschmitz + * + */ +public interface LocationJAXBSchema { + final static String LOCATIONS_COMMON = "locations_common"; + final static String CSID = "csid"; + final static String IN_AUTHORITY = "inAuthority"; + final static String REF_NAME = "refName"; + final static String DISPLAY_NAME = "displayName"; + final static String DISPLAY_NAME_COMPUTED = "displayNameComputed"; + final static String NAME = "name"; + final static String CONDITION_NOTE = "conditionNote"; + final static String CONDITION_NOTE_DATE = "conditionNoteDate"; + final static String SECURITY_NOTE = "securityNote"; + final static String LOCATION_TYPE = "locationType"; + final static String STATUS = "status"; +} + diff --git a/services/location/jaxb/src/main/java/org/collectionspace/services/LocationListItemJAXBSchema.java b/services/location/jaxb/src/main/java/org/collectionspace/services/LocationListItemJAXBSchema.java new file mode 100644 index 000000000..75d494f63 --- /dev/null +++ b/services/location/jaxb/src/main/java/org/collectionspace/services/LocationListItemJAXBSchema.java @@ -0,0 +1,8 @@ +package org.collectionspace.services; + +public interface LocationListItemJAXBSchema { + final static String DISPLAY_NAME = "displayName"; + final static String REF_NAME = "refName"; + final static String CSID = "csid"; + final static String URI = "url"; +} diff --git a/services/location/jaxb/src/main/resources/location_common.xsd b/services/location/jaxb/src/main/resources/location_common.xsd new file mode 100644 index 000000000..f4fa8bee5 --- /dev/null +++ b/services/location/jaxb/src/main/resources/location_common.xsd @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/location/jaxb/src/main/resources/locationauthority_common.xsd b/services/location/jaxb/src/main/resources/locationauthority_common.xsd new file mode 100644 index 000000000..83547ffdb --- /dev/null +++ b/services/location/jaxb/src/main/resources/locationauthority_common.xsd @@ -0,0 +1,86 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/location/pom.xml b/services/location/pom.xml new file mode 100644 index 000000000..a549912dd --- /dev/null +++ b/services/location/pom.xml @@ -0,0 +1,33 @@ + + + + org.collectionspace.services + org.collectionspace.services.main + 0.7-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.location + services.location + pom + + + jaxb + service + 3rdparty + client + + + + + samples + + import + + + + + + + diff --git a/services/location/service/.classpath b/services/location/service/.classpath new file mode 100644 index 000000000..83343792e --- /dev/null +++ b/services/location/service/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/services/location/service/.project b/services/location/service/.project new file mode 100644 index 000000000..290bda033 --- /dev/null +++ b/services/location/service/.project @@ -0,0 +1,26 @@ + + + org.collectionspace.services.person.service + + + org.collectionspace.services.common + org.collectionspace.services.jaxb + org.collectionspace.services.person.jaxb + + + + org.eclipse.jdt.core.javabuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + + org.maven.ide.eclipse.maven2Nature + org.eclipse.jdt.core.javanature + + diff --git a/services/location/service/.settings/org.eclipse.jdt.core.prefs b/services/location/service/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..588ea278c --- /dev/null +++ b/services/location/service/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +#Mon Jan 04 16:43:19 PST 2010 +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/location/service/.settings/org.maven.ide.eclipse.prefs b/services/location/service/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 000000000..ddebb8bf5 --- /dev/null +++ b/services/location/service/.settings/org.maven.ide.eclipse.prefs @@ -0,0 +1,9 @@ +#Mon Jan 04 16:40:35 PST 2010 +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/location/service/pom.xml b/services/location/service/pom.xml new file mode 100644 index 000000000..f3f1ae47b --- /dev/null +++ b/services/location/service/pom.xml @@ -0,0 +1,141 @@ + + + + org.collectionspace.services + org.collectionspace.services.location + 0.7-SNAPSHOT + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.location.service + services.location.service + jar + + + + org.slf4j + slf4j-api + + + org.slf4j + slf4j-log4j12 + + + + org.collectionspace.services + org.collectionspace.services.common + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.location.jaxb + ${project.version} + + + org.collectionspace.services + org.collectionspace.services.contact.service + ${project.version} + + + + junit + junit + 4.1 + test + + + org.testng + testng + 5.6 + + + + + commons-beanutils + commons-beanutils + 1.6.1 + + + + commons-logging + commons-logging + 1.1 + + + + + + javax.security + jaas + 1.0.01 + provided + + + + dom4j + dom4j + 1.6.1 + provided + + + + + + org.jboss.resteasy + resteasy-jaxrs + + + tjws + webserver + + + + + org.jboss.resteasy + resteasy-jaxb-provider + + + org.jboss.resteasy + resteasy-multipart-provider + + + + + + org.nuxeo.ecm.core + nuxeo-core-api + ${nuxeo.version.1.5} + + + 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-location + + + + + diff --git a/services/location/service/src/main/java/org/collectionspace/services/location/LocationAuthorityResource.java b/services/location/service/src/main/java/org/collectionspace/services/location/LocationAuthorityResource.java new file mode 100644 index 000000000..e71af43d7 --- /dev/null +++ b/services/location/service/src/main/java/org/collectionspace/services/location/LocationAuthorityResource.java @@ -0,0 +1,863 @@ +/** + * 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.location; + +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.LocationAuthorityJAXBSchema; +import org.collectionspace.services.LocationJAXBSchema; +import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl; +import org.collectionspace.services.common.ClientType; +import org.collectionspace.services.common.ServiceMain; +import org.collectionspace.services.common.authorityref.AuthorityRefDocList; +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.ServiceBindingUtils; +import org.collectionspace.services.common.context.ServiceContext; +import org.collectionspace.services.common.document.BadRequestException; +import org.collectionspace.services.common.document.DocumentException; +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.repository.RepositoryClient; +import org.collectionspace.services.common.security.UnauthorizedException; +import org.collectionspace.services.common.vocabulary.RefNameServiceUtils; +import org.collectionspace.services.common.vocabulary.RefNameUtils; +import org.collectionspace.services.common.query.IQueryManager; +import org.collectionspace.services.contact.ContactResource; +import org.collectionspace.services.contact.ContactsCommon; +import org.collectionspace.services.contact.ContactsCommonList; +import org.collectionspace.services.contact.ContactJAXBSchema; +import org.collectionspace.services.contact.nuxeo.ContactDocumentModelHandler; +import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; +import org.collectionspace.services.location.nuxeo.LocationDocumentModelHandler; +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 LocationAuthorityResource. + */ +@Path("/locationauthorities") +@Consumes("multipart/mixed") +@Produces("multipart/mixed") +public class LocationAuthorityResource extends + AbstractMultiPartCollectionSpaceResourceImpl { + + /** The Constant locationAuthorityServiceName. */ + private final static String locationAuthorityServiceName = "locationauthorities"; + + /** The Constant locationServiceName. */ + private final static String locationServiceName = "locations"; + + /** The logger. */ + final Logger logger = LoggerFactory.getLogger(LocationAuthorityResource.class); + //FIXME retrieve client type from configuration + /** The Constant CLIENT_TYPE. */ + final static ClientType CLIENT_TYPE = ServiceMain.getInstance().getClientType(); + + /** + * Instantiates a new location authority resource. + */ + public LocationAuthorityResource() { + // do nothing + } + + /* (non-Javadoc) + * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getVersionString() + */ + @Override + protected String getVersionString() { + /** The last change revision. */ + final String lastChangeRevision = "$LastChangedRevision: 1850 $"; + return lastChangeRevision; + } + + /* (non-Javadoc) + * @see org.collectionspace.services.common.AbstractCollectionSpaceResourceImpl#getServiceName() + */ + @Override + public String getServiceName() { + return locationAuthorityServiceName; + } + + @Override + public Class getCommonPartClass() { + return LocationauthoritiesCommon.class; + } + + /** + * Gets the item service name. + * + * @return the item service name + */ + public String getItemServiceName() { + return locationServiceName; + } + + /** + * Creates the item document handler. + * + * @param ctx the ctx + * @param inAuthority the in authority + * + * @return the document handler + * + * @throws Exception the exception + */ + private DocumentHandler createItemDocumentHandler(ServiceContext ctx, + String inAuthority) throws Exception { + LocationDocumentModelHandler docHandler = (LocationDocumentModelHandler)createDocumentHandler(ctx, + ctx.getCommonPartLabel(getItemServiceName()), + LocationsCommon.class); + docHandler.setInAuthority(inAuthority); + + return docHandler; + } + + /** + * Creates the location authority. + * + * @param input the input + * + * @return the response + */ + @POST + public Response createLocationAuthority(MultipartInput input) { + try { + ServiceContext ctx = createServiceContext(input); + DocumentHandler handler = createDocumentHandler(ctx); + String csid = getRepositoryClient(ctx).create(ctx, handler); + //locationAuthorityObject.setCsid(csid); + UriBuilder path = UriBuilder.fromResource(LocationAuthorityResource.class); + path.path("" + csid); + Response response = Response.created(path.build()).build(); + return response; + } catch (BadRequestException bre) { + Response response = Response.status( + Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(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 createLocationAuthority", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + } + + /** + * Gets the location authority by name. + * + * @param specifier the specifier + * + * @return the location authority by name + */ + @GET + @Path("urn:cspace:name({specifier})") + public MultipartOutput getLocationAuthorityByName(@PathParam("specifier") String specifier) { + if (specifier == null) { + logger.error("getLocationAuthority: missing name!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "get failed on LocationAuthority (missing specifier)").type( + "text/plain").build(); + throw new WebApplicationException(response); + } + String whereClause = + LocationAuthorityJAXBSchema.LOCATIONAUTHORITIES_COMMON+ + ":"+LocationAuthorityJAXBSchema.DISPLAY_NAME+ + "='"+specifier+"'"; + // We only get a single doc - if there are multiple, + // it is an error in use. + + if (logger.isDebugEnabled()) { + logger.debug("getLocationAuthority with name=" + specifier); + } + MultipartOutput result = null; + try { + ServiceContext ctx = createServiceContext(); + DocumentHandler handler = createDocumentHandler(ctx); + DocumentFilter myFilter = new DocumentFilter(whereClause, 0, 1); + handler.setDocumentFilter(myFilter); + getRepositoryClient(ctx).get(ctx, 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("getLocationAuthority", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed on LocationAuthority spec=" + specifier).type( + "text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("getLocationAuthority", 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 LocationAuthority spec:" + specifier + ": was not found.").type( + "text/plain").build(); + throw new WebApplicationException(response); + } + return result; + } + + /** + * Gets the entities referencing this Location instance. The service type + * can be passed as a query param "type", and must match a configured type + * for the service bindings. If not set, the type defaults to + * ServiceBindingUtils.SERVICE_TYPE_PROCEDURE. + * + * @param csid the parent csid + * @param itemcsid the location csid + * @param ui the ui + * + * @return the info for the referencing objects + */ + @GET + @Path("{csid}/items/{itemcsid}/refObjs") + @Produces("application/xml") + public AuthorityRefDocList getReferencingObjects( + @PathParam("csid") String parentcsid, + @PathParam("itemcsid") String itemcsid, + @Context UriInfo ui) { + AuthorityRefDocList authRefDocList = null; + if (logger.isDebugEnabled()) { + logger.debug("getReferencingObjects with parentcsid=" + + parentcsid + " and itemcsid=" + itemcsid); + } + if (parentcsid == null || "".equals(parentcsid) + || itemcsid == null || "".equals(itemcsid)) { + logger.error("getLocation: missing parentcsid or itemcsid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "get failed on Location with parentcsid=" + + parentcsid + " and itemcsid=" + itemcsid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + try { + // Note that we have to create the service context for the Items, not the main service + ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(getItemServiceName()); + DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); + RepositoryClient repoClient = getRepositoryClient(ctx); + DocumentFilter myFilter = handler.createDocumentFilter(); + MultivaluedMap queryParams = ui.getQueryParameters(); + myFilter.setPagination(queryParams); + String serviceType = ServiceBindingUtils.SERVICE_TYPE_PROCEDURE; + List list = queryParams.remove(ServiceBindingUtils.SERVICE_TYPE_PROP); + if (list != null) { + serviceType = list.get(0); + } + DocumentWrapper docWrapper = repoClient.getDoc(ctx, itemcsid); + DocumentModel docModel = docWrapper.getWrappedObject(); + String refName = (String)docModel.getPropertyValue(LocationJAXBSchema.REF_NAME); + + authRefDocList = RefNameServiceUtils.getAuthorityRefDocs(ctx, repoClient, + serviceType, refName, + myFilter.getPageSize(), myFilter.getStartPage(), true ); + } 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("getReferencingObjects", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "GetReferencingObjects failed with parentcsid=" + + parentcsid + " and itemcsid=" + itemcsid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { // Includes DocumentException + if (logger.isDebugEnabled()) { + logger.debug("GetReferencingObjects", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Get failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + if (authRefDocList == null) { + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed, the requested Location CSID:" + itemcsid + ": was not found.").type( + "text/plain").build(); + throw new WebApplicationException(response); + } + return authRefDocList; + } + + @GET + @Path("{csid}") + public MultipartOutput getLocationAuthority(@PathParam("csid") String csid) { + if (csid == null) { + logger.error("getLocationAuthority: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "get failed on LocationAuthority csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + if (logger.isDebugEnabled()) { + logger.debug("getLocationAuthority with path(id)=" + csid); + } + 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("getLocationAuthority", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed on LocationAuthority csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("getLocationAuthority", 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 LocationAuthority CSID:" + csid + ": was not found.").type( + "text/plain").build(); + throw new WebApplicationException(response); + } + return result; + } + + /** + * Gets the location authority list. + * + * @param ui the ui + * + * @return the location authority list + */ + @GET + @Produces("application/xml") + public LocationauthoritiesCommonList getLocationAuthorityList(@Context UriInfo ui) { + LocationauthoritiesCommonList locationAuthorityObjectList = new LocationauthoritiesCommonList(); + try { + ServiceContext ctx = createServiceContext(); + MultivaluedMap queryParams = ui.getQueryParameters(); + DocumentHandler handler = createDocumentHandler(ctx); + DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter(); + myFilter.setPagination(queryParams); //FIXME + String nameQ = queryParams.getFirst("refName"); + if (nameQ != null) { + myFilter.setWhereClause("locationauthorities_common:refName='" + nameQ + "'"); + } + handler.setDocumentFilter(myFilter); + getRepositoryClient(ctx).getFiltered(ctx, handler); + locationAuthorityObjectList = (LocationauthoritiesCommonList) 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 getLocationAuthorityList", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + return locationAuthorityObjectList; + } + + /** + * Update location authority. + * + * @param csid the csid + * @param theUpdate the the update + * + * @return the multipart output + */ + @PUT + @Path("{csid}") + public MultipartOutput updateLocationAuthority( + @PathParam("csid") String csid, + MultipartInput theUpdate) { + if (logger.isDebugEnabled()) { + logger.debug("updateLocationAuthority with csid=" + csid); + } + if (csid == null || "".equals(csid)) { + logger.error("updateLocationAuthority: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "update failed on LocationAuthority 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 (BadRequestException bre) { + Response response = Response.status( + Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } 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("caugth exception in updateLocationAuthority", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Update failed on LocationAuthority 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 location authority. + * + * @param csid the csid + * + * @return the response + */ + @DELETE + @Path("{csid}") + public Response deleteLocationAuthority(@PathParam("csid") String csid) { + + if (logger.isDebugEnabled()) { + logger.debug("deleteLocationAuthority with csid=" + csid); + } + if (csid == null || "".equals(csid)) { + logger.error("deleteLocationAuthority: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "delete failed on LocationAuthority 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 deleteLocationAuthority", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Delete failed on LocationAuthority 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); + } + + } + + /************************************************************************* + * Location parts - this is a sub-resource of LocationAuthority + *************************************************************************/ + @POST + @Path("{csid}/items") + public Response createLocation(@PathParam("csid") String parentcsid, MultipartInput input) { + try { + ServiceContext ctx = createServiceContext(getItemServiceName(), input); + DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); + String itemcsid = getRepositoryClient(ctx).create(ctx, handler); + UriBuilder path = UriBuilder.fromResource(LocationAuthorityResource.class); + path.path(parentcsid + "/items/" + itemcsid); + Response response = Response.created(path.build()).build(); + return response; + } catch (BadRequestException bre) { + Response response = Response.status( + Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(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 createLocation", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + } + + /** + * Gets the location. + * + * @param parentcsid the parentcsid + * @param itemcsid the itemcsid + * + * @return the location + */ + @GET + @Path("{csid}/items/{itemcsid}") + public MultipartOutput getLocation( + @PathParam("csid") String parentcsid, + @PathParam("itemcsid") String itemcsid) { + if (logger.isDebugEnabled()) { + logger.debug("getLocation with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid); + } + if (parentcsid == null || "".equals(parentcsid) + || itemcsid == null || "".equals(itemcsid)) { + logger.error("getLocation: missing parentcsid or itemcsid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "get failed on Location with parentcsid=" + + parentcsid + " and itemcsid=" + itemcsid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + MultipartOutput result = null; + try { + // Note that we have to create the service context for the Items, not the main service + ServiceContext ctx = createServiceContext(getItemServiceName()); + DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); + getRepositoryClient(ctx).get(ctx, itemcsid, handler); + // TODO should we assert that the item is in the passed locationAuthority? + 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("getLocation", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed on Location csid=" + itemcsid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("getLocation", 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 Location CSID:" + itemcsid + ": was not found.").type( + "text/plain").build(); + throw new WebApplicationException(response); + } + return result; + } + + /** + * Gets the location list. + * + * @param parentcsid the parentcsid + * @param partialTerm the partial term + * @param ui the ui + * + * @return the location list + */ + @GET + @Path("{csid}/items") + @Produces("application/xml") + public LocationsCommonList getLocationList( + @PathParam("csid") String parentcsid, + @QueryParam (IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm, + @Context UriInfo ui) { + LocationsCommonList locationObjectList = new LocationsCommonList(); + try { + // Note that docType defaults to the ServiceName, so we're fine with that. + MultivaluedMap queryParams = ui.getQueryParameters(); + ServiceContext ctx = createServiceContext(getItemServiceName(), + queryParams); + DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); + DocumentFilter myFilter = handler.getDocumentFilter(); + + // Add the where clause "locations_common:inAuthority='" + parentcsid + "'" + myFilter.setWhereClause(LocationJAXBSchema.LOCATIONS_COMMON + ":" + + LocationJAXBSchema.IN_AUTHORITY + "='" + parentcsid + "'"); + + // AND locations_common:displayName LIKE '%partialTerm%' + if (partialTerm != null && !partialTerm.isEmpty()) { + String ptClause = + LocationJAXBSchema.LOCATIONS_COMMON + ":" + + LocationJAXBSchema.DISPLAY_NAME + + " LIKE " + + "'%" + partialTerm + "%'"; + myFilter.appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND); + } + getRepositoryClient(ctx).getFiltered(ctx, handler); + locationObjectList = (LocationsCommonList) 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 getLocationList", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + return locationObjectList; + } + + + /** + * Gets the location list by auth name. + * + * @param parentSpecifier the parent specifier + * @param partialTerm the partial term + * @param ui the ui + * + * @return the location list by auth name + */ + @GET + @Path("urn:cspace:name({specifier})/items") + @Produces("application/xml") + public LocationsCommonList getLocationListByAuthName( + @PathParam("specifier") String parentSpecifier, + @QueryParam (IQueryManager.SEARCH_TYPE_PARTIALTERM) String partialTerm, + @Context UriInfo ui) { + LocationsCommonList locationObjectList = new LocationsCommonList(); + try { + MultivaluedMap queryParams = ui.getQueryParameters(); + String whereClause = + LocationAuthorityJAXBSchema.LOCATIONAUTHORITIES_COMMON+ + ":"+LocationAuthorityJAXBSchema.DISPLAY_NAME+ + "='"+parentSpecifier+"'"; + // Need to get an Authority by name + ServiceContext ctx = createServiceContext(queryParams); + String parentcsid = + getRepositoryClient(ctx).findDocCSID(ctx, whereClause); + + ctx = createServiceContext(getItemServiceName(), queryParams); + DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); + DocumentFilter myFilter = handler.createDocumentFilter(); //new DocumentFilter(); + myFilter.setPagination(queryParams); //FIXME + + // Add the where clause "locations_common:inAuthority='" + parentcsid + "'" + myFilter.setWhereClause(LocationJAXBSchema.LOCATIONS_COMMON + ":" + + LocationJAXBSchema.IN_AUTHORITY + "='" + parentcsid + "'"); + + // AND locations_common:displayName LIKE '%partialTerm%' + if (partialTerm != null && !partialTerm.isEmpty()) { + String ptClause = // "AND " + + LocationJAXBSchema.LOCATIONS_COMMON + ":" + + LocationJAXBSchema.DISPLAY_NAME + + " LIKE " + + "'%" + partialTerm + "%'"; + myFilter.appendWhereClause(ptClause, "AND"); + } + + handler.setDocumentFilter(myFilter); + getRepositoryClient(ctx).getFiltered(ctx, handler); + locationObjectList = (LocationsCommonList) 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 getLocationList", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + return locationObjectList; + } + + /** + * Update location. + * + * @param parentcsid the parentcsid + * @param itemcsid the itemcsid + * @param theUpdate the the update + * + * @return the multipart output + */ + @PUT + @Path("{csid}/items/{itemcsid}") + public MultipartOutput updateLocation( + @PathParam("csid") String parentcsid, + @PathParam("itemcsid") String itemcsid, + MultipartInput theUpdate) { + if (logger.isDebugEnabled()) { + logger.debug("updateLocation with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid); + } + if (parentcsid == null || "".equals(parentcsid)) { + logger.error("updateLocation: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "update failed on Location parentcsid=" + parentcsid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + if (itemcsid == null || "".equals(itemcsid)) { + logger.error("updateLocation: missing itemcsid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "update failed on Location=" + itemcsid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + MultipartOutput result = null; + try { + // Note that we have to create the service context for the Items, not the main service + ServiceContext ctx = createServiceContext(getItemServiceName(), + theUpdate); + DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); + getRepositoryClient(ctx).update(ctx, itemcsid, handler); + result = (MultipartOutput) ctx.getOutput(); + } catch (BadRequestException bre) { + Response response = Response.status( + Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } 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 updateLocation", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Update failed on Location csid=" + itemcsid).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 location. + * + * @param parentcsid the parentcsid + * @param itemcsid the itemcsid + * + * @return the response + */ + @DELETE + @Path("{csid}/items/{itemcsid}") + public Response deleteLocation( + @PathParam("csid") String parentcsid, + @PathParam("itemcsid") String itemcsid) { + if (logger.isDebugEnabled()) { + logger.debug("deleteLocation with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid); + } + if (parentcsid == null || "".equals(parentcsid)) { + logger.error("deleteLocation: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "delete failed on Location parentcsid=" + parentcsid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + if (itemcsid == null || "".equals(itemcsid)) { + logger.error("deleteLocation: missing itemcsid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "delete failed on Location=" + itemcsid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + try { + // Note that we have to create the service context for the Items, not the main service + ServiceContext ctx = createServiceContext(getItemServiceName()); + getRepositoryClient(ctx).delete(ctx, itemcsid); + 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 deleteLocation", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Delete failed on Location itemcsid=" + itemcsid).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); + } + + } + +} diff --git a/services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationAuthorityConstants.java b/services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationAuthorityConstants.java new file mode 100644 index 000000000..68bf2f956 --- /dev/null +++ b/services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationAuthorityConstants.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.location.nuxeo; + +/** + * LocationAuthorityConstants processes CollectionObject document + * + */ +public class LocationAuthorityConstants { + + public final static String NUXEO_DOCTYPE = "LocationAuthority"; + public final static String NUXEO_SCHEMA_NAME = "locationauthority"; + public final static String NUXEO_DC_TITLE = "CollectionSpace-LocationAuthority"; +} diff --git a/services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationAuthorityDocumentModelHandler.java b/services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationAuthorityDocumentModelHandler.java new file mode 100644 index 000000000..9a8b46c43 --- /dev/null +++ b/services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationAuthorityDocumentModelHandler.java @@ -0,0 +1,146 @@ +/** + * 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.location.nuxeo; + +import java.util.Iterator; +import java.util.List; + +import org.collectionspace.services.LocationAuthorityJAXBSchema; +import org.collectionspace.services.common.document.DocumentHandler.Action; +import org.collectionspace.services.common.document.DocumentFilter; +import org.collectionspace.services.common.document.DocumentWrapper; +import org.collectionspace.services.location.LocationauthoritiesCommon; +import org.collectionspace.services.location.LocationauthoritiesCommonList; +import org.collectionspace.services.location.LocationauthoritiesCommonList.LocationauthorityListItem; + +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; + +/** + * LocationAuthorityDocumentModelHandler + * + * $LastChangedRevision: $ + * $LastChangedDate: $ + */ +public class LocationAuthorityDocumentModelHandler + extends RemoteDocumentModelHandlerImpl { + + private final Logger logger = LoggerFactory.getLogger(LocationAuthorityDocumentModelHandler.class); + /** + * locationAuthority is used to stash JAXB object to use when handle is called + * for Action.CREATE, Action.UPDATE or Action.GET + */ + private LocationauthoritiesCommon locationAuthority; + /** + * locationAuthorityList is stashed when handle is called + * for ACTION.GET_ALL + */ + private LocationauthoritiesCommonList locationAuthorityList; + + + /** + * getCommonPart get associated locationAuthority + * @return + */ + @Override + public LocationauthoritiesCommon getCommonPart() { + return locationAuthority; + } + + /** + * setCommonPart set associated locationAuthority + * @param locationAuthority + */ + @Override + public void setCommonPart(LocationauthoritiesCommon locationAuthority) { + this.locationAuthority = locationAuthority; + } + + /** + * getCommonPartList get associated locationAuthority (for index/GET_ALL) + * @return + */ + @Override + public LocationauthoritiesCommonList getCommonPartList() { + return locationAuthorityList; + } + + @Override + public void setCommonPartList(LocationauthoritiesCommonList locationAuthorityList) { + this.locationAuthorityList = locationAuthorityList; + } + + @Override + public LocationauthoritiesCommon extractCommonPart(DocumentWrapper wrapDoc) + throws Exception { + throw new UnsupportedOperationException(); + } + + @Override + public void fillCommonPart(LocationauthoritiesCommon locationAuthorityObject, DocumentWrapper wrapDoc) throws Exception { + throw new UnsupportedOperationException(); + } + + @Override + public LocationauthoritiesCommonList extractCommonPartList(DocumentWrapper wrapDoc) throws Exception { + LocationauthoritiesCommonList coList = extractPagingInfo(new LocationauthoritiesCommonList(), + wrapDoc); + + //FIXME: iterating over a long list of documents is not a long term + //strategy...need to change to more efficient iterating in future + List list = coList.getLocationauthorityListItem(); + Iterator iter = wrapDoc.getWrappedObject().iterator(); + while(iter.hasNext()){ + DocumentModel docModel = iter.next(); + LocationauthorityListItem ilistItem = new LocationauthorityListItem(); + ilistItem.setDisplayName((String) docModel.getProperty(getServiceContext().getCommonPartLabel(), + LocationAuthorityJAXBSchema.DISPLAY_NAME)); + ilistItem.setRefName((String) docModel.getProperty(getServiceContext().getCommonPartLabel(), + LocationAuthorityJAXBSchema.REF_NAME)); + ilistItem.setVocabType((String) docModel.getProperty(getServiceContext().getCommonPartLabel(), + LocationAuthorityJAXBSchema.VOCAB_TYPE)); + 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 LocationAuthorityConstants.NUXEO_SCHEMA_NAME + ":" + prop; + } +} + diff --git a/services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationConstants.java b/services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationConstants.java new file mode 100644 index 000000000..2f3f1bedd --- /dev/null +++ b/services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationConstants.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.location.nuxeo; + +/** + * LocationConstants processes CollectionObject document + * + */ +public class LocationConstants { + + public final static String NUXEO_DOCTYPE = "Location"; + public final static String NUXEO_SCHEMA_NAME = "location"; + public final static String NUXEO_DC_TITLE = "CollectionSpace-Location"; +} diff --git a/services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationDocumentModelHandler.java b/services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationDocumentModelHandler.java new file mode 100644 index 000000000..53de3e74a --- /dev/null +++ b/services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationDocumentModelHandler.java @@ -0,0 +1,265 @@ +/** + * 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.location.nuxeo; + +import java.util.Iterator; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import org.collectionspace.services.LocationJAXBSchema; +import org.collectionspace.services.common.document.DocumentFilter; +import org.collectionspace.services.common.document.DocumentWrapper; +import org.collectionspace.services.common.service.ObjectPartType; +import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; +import org.collectionspace.services.nuxeo.util.NuxeoUtils; +import org.collectionspace.services.location.LocationsCommon; +import org.collectionspace.services.location.LocationsCommonList; +import org.collectionspace.services.location.LocationsCommonList.LocationListItem; +import org.nuxeo.ecm.core.api.DocumentModel; +import org.nuxeo.ecm.core.api.DocumentModelList; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * LocationDocumentModelHandler + * + * $LastChangedRevision: $ + * $LastChangedDate: $ + */ +/** + * @author pschmitz + * + */ +public class LocationDocumentModelHandler + extends RemoteDocumentModelHandlerImpl { + + /** The logger. */ + private final Logger logger = LoggerFactory.getLogger(LocationDocumentModelHandler.class); + /** + * Common part schema label + */ + private static final String COMMON_PART_LABEL = "locations_common"; + + /** + * location is used to stash JAXB object to use when handle is called + * for Action.CREATE, Action.UPDATE or Action.GET + */ + private LocationsCommon location; + /** + * locationList is stashed when handle is called + * for ACTION.GET_ALL + */ + private LocationsCommonList locationList; + + /** + * inAuthority is the parent OrgAuthority for this context + */ + private String inAuthority; + + /** + * Gets the in authority. + * + * @return the in authority + */ + public String getInAuthority() { + return inAuthority; + } + + /** + * Sets the in authority. + * + * @param inAuthority the new in authority + */ + public void setInAuthority(String inAuthority) { + this.inAuthority = inAuthority; + } + + + /* (non-Javadoc) + * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleCreate(org.collectionspace.services.common.document.DocumentWrapper) + */ + @Override + public void handleCreate(DocumentWrapper wrapDoc) throws Exception { + // first fill all the parts of the document + super.handleCreate(wrapDoc); + handleDisplayName(wrapDoc.getWrappedObject()); + } + + /* (non-Javadoc) + * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#handleUpdate(org.collectionspace.services.common.document.DocumentWrapper) + */ + @Override + public void handleUpdate(DocumentWrapper wrapDoc) throws Exception { + super.handleUpdate(wrapDoc); + handleDisplayName(wrapDoc.getWrappedObject()); + } + + /** + * Handle display name. + * + * @param docModel the doc model + * @throws Exception the exception + */ + private void handleDisplayName(DocumentModel docModel) throws Exception { + String commonPartLabel = getServiceContext().getCommonPartLabel("locations"); + Boolean displayNameComputed = (Boolean) docModel.getProperty(commonPartLabel, + LocationJAXBSchema.DISPLAY_NAME_COMPUTED); + if (displayNameComputed) { + String displayName = prepareDefaultDisplayName( + (String)docModel.getProperty(commonPartLabel, LocationJAXBSchema.NAME )); + docModel.setProperty(commonPartLabel, LocationJAXBSchema.DISPLAY_NAME, + displayName); + } + } + + /** + * Produces a default displayName from the basic name and dates fields. + * @see LocationAuthorityClientUtils.prepareDefaultDisplayName() which + * duplicates this logic, until we define a service-general utils package + * that is neither client nor service specific. + * @param foreName + * @param middleName + * @param surName + * @param birthDate + * @param deathDate + * @return + * @throws Exception + */ + private static String prepareDefaultDisplayName( + String name ) throws Exception { + StringBuilder newStr = new StringBuilder(); + newStr.append(name); + return newStr.toString(); + } + + /** + * getCommonPart get associated location + * @return + */ + @Override + public LocationsCommon getCommonPart() { + return location; + } + + /** + * setCommonPart set associated location + * @param location + */ + @Override + public void setCommonPart(LocationsCommon location) { + this.location = location; + } + + /** + * getCommonPartList get associated location (for index/GET_ALL) + * @return + */ + @Override + public LocationsCommonList getCommonPartList() { + return locationList; + } + + /* (non-Javadoc) + * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPartList(java.lang.Object) + */ + @Override + public void setCommonPartList(LocationsCommonList locationList) { + this.locationList = locationList; + } + + /* (non-Javadoc) + * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#extractPart(org.nuxeo.ecm.core.api.DocumentModel, java.lang.String, org.collectionspace.services.common.service.ObjectPartType) + */ + @Override + protected Map extractPart(DocumentModel docModel, String schema, ObjectPartType partMeta) + throws Exception { + Map unQObjectProperties = super.extractPart(docModel, schema, partMeta); + + // Add the CSID to the common part + if (partMeta.getLabel().equalsIgnoreCase(COMMON_PART_LABEL)) { + String csid = NuxeoUtils.extractId(docModel.getPathAsString()); + unQObjectProperties.put("csid", csid); + } + + return unQObjectProperties; + } + + /* (non-Javadoc) + * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper) + */ + @Override + public LocationsCommon extractCommonPart(DocumentWrapper wrapDoc) + throws Exception { + throw new UnsupportedOperationException(); + } + + /* (non-Javadoc) + * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper) + */ + @Override + public void fillCommonPart(LocationsCommon locationObject, DocumentWrapper wrapDoc) throws Exception { + throw new UnsupportedOperationException(); + } + + /* (non-Javadoc) + * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper) + */ + @Override + public LocationsCommonList extractCommonPartList( + DocumentWrapper wrapDoc) throws Exception { + LocationsCommonList coList = extractPagingInfo(new LocationsCommonList(), wrapDoc); + List list = coList.getLocationListItem(); + Iterator iter = wrapDoc.getWrappedObject().iterator(); + String commonPartLabel = getServiceContext().getCommonPartLabel( + "locations"); + while (iter.hasNext()) { + DocumentModel docModel = iter.next(); + LocationListItem ilistItem = new LocationListItem(); + ilistItem.setDisplayName((String) docModel.getProperty( + commonPartLabel, LocationJAXBSchema.DISPLAY_NAME)); + ilistItem.setRefName((String) docModel.getProperty(commonPartLabel, + LocationJAXBSchema.REF_NAME)); + String id = NuxeoUtils.extractId(docModel.getPathAsString()); + ilistItem.setUri("/locationauthorities/" + inAuthority + "/items/" + + 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 LocationConstants.NUXEO_SCHEMA_NAME + ":" + prop; + } +} + diff --git a/services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationValidatorHandler.java b/services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationValidatorHandler.java new file mode 100644 index 000000000..50b2c4db2 --- /dev/null +++ b/services/location/service/src/main/java/org/collectionspace/services/location/nuxeo/LocationValidatorHandler.java @@ -0,0 +1,103 @@ +/** + * 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. + *//** + * 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. + */ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.collectionspace.services.location.nuxeo; + +import org.collectionspace.services.location.LocationsCommon; +import org.collectionspace.services.common.context.MultipartServiceContext; +import org.collectionspace.services.common.context.ServiceContext; +import org.collectionspace.services.common.document.DocumentHandler.Action; +import org.collectionspace.services.common.document.InvalidDocumentException; +import org.collectionspace.services.common.document.ValidatorHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * + * @author + */ +public class LocationValidatorHandler implements ValidatorHandler { + + final Logger logger = LoggerFactory.getLogger(LocationValidatorHandler.class); + + @Override + public void validate(Action action, ServiceContext ctx) + throws InvalidDocumentException { + if(logger.isDebugEnabled()) { + logger.debug("validate() action=" + action.name()); + } + try { + MultipartServiceContext mctx = (MultipartServiceContext) ctx; + LocationsCommon location = (LocationsCommon) mctx.getInputPart(mctx.getCommonPartLabel(), + LocationsCommon.class); + String msg = ""; + boolean invalid = false; + if(!location.isDisplayNameComputed() && (location.getDisplayName()==null)) { + invalid = true; + msg += "displayName must be non-null if displayNameComputed is false!"; + } + /* + if(action.equals(Action.CREATE)) { + //create specific validation here + } else if(action.equals(Action.UPDATE)) { + //update specific validation here + } + */ + + if (invalid) { + logger.error(msg); + throw new InvalidDocumentException(msg); + } + } catch (InvalidDocumentException ide) { + throw ide; + } catch (Exception e) { + throw new InvalidDocumentException(e); + } + } +} diff --git a/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java b/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java index 0c40909cc..7815fe6b1 100644 --- a/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java +++ b/services/person/service/src/main/java/org/collectionspace/services/person/PersonAuthorityResource.java @@ -686,13 +686,13 @@ public class PersonAuthorityResource extends // AND persons_common:displayName LIKE '%partialTerm%' if (partialTerm != null && !partialTerm.isEmpty()) { - String ptClause = "AND " + + String ptClause = PersonJAXBSchema.PERSONS_COMMON + ":" + PersonJAXBSchema.DISPLAY_NAME + " LIKE " + "'%" + partialTerm + "%'"; // handler.getDocumentFilter().appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND); - handler.getDocumentFilter().appendWhereClause(ptClause, ""); + handler.getDocumentFilter().appendWhereClause(ptClause, IQueryManager.SEARCH_QUALIFIER_AND); } getRepositoryClient(ctx).getFiltered(ctx, handler); diff --git a/services/pom.xml b/services/pom.xml index 70f7a8a51..936eac0ce 100644 --- a/services/pom.xml +++ b/services/pom.xml @@ -32,6 +32,7 @@ intake loanin loanout + location movement dimension contact -- 2.47.3