From 0c73d59f4534feaeb788facaaaea5ac8afaca53b Mon Sep 17 00:00:00 2001 From: Patrick Schmitz Date: Mon, 4 Jan 2010 20:12:59 +0000 Subject: [PATCH] CSPACE-149. Adding basic code for Organization service. Compiles, but testing remains. Not yet added to main builds. --- services/organization/.classpath | 6 + services/organization/.project | 23 + .../.settings/org.eclipse.jdt.core.prefs | 5 + .../.settings/org.maven.ide.eclipse.prefs | 9 + services/organization/3rdparty/.classpath | 6 + services/organization/3rdparty/.project | 23 + .../.settings/org.eclipse.jdt.core.prefs | 5 + .../.settings/org.maven.ide.eclipse.prefs | 9 + services/organization/3rdparty/build.xml | 131 ++ .../nuxeo-platform-cs-organization/.classpath | 9 + .../nuxeo-platform-cs-organization/.project | 23 + .../.settings/org.eclipse.jdt.core.prefs | 5 + .../.settings/org.maven.ide.eclipse.prefs | 9 + .../nuxeo-platform-cs-organization/build.xml | 138 +++ .../nuxeo-platform-cs-organization/pom.xml | 19 + .../src/main/resources/META-INF/MANIFEST.MF | 22 + .../resources/OSGI-INF/core-types-contrib.xml | 23 + .../OSGI-INF/deployment-fragment.xml | 408 +++++++ .../resources/OSGI-INF/ecm-types-contrib.xml | 53 + .../resources/OSGI-INF/layouts-contrib.xml | 112 ++ .../schemas/organizations_common.xsd | 32 + .../schemas/orgauthorities_common.xsd | 31 + services/organization/3rdparty/pom.xml | 23 + services/organization/build.xml | 134 +++ services/organization/client/.classpath | 10 + services/organization/client/.project | 26 + services/organization/client/pom.xml | 111 ++ .../settings/org.eclipse.jdt.core.prefs | 5 + .../settings/org.maven.ide.eclipse.prefs | 9 + .../services/client/OrgAuthorityClient.java | 157 +++ .../services/client/OrgAuthorityProxy.java | 76 ++ .../client/test/OrgAuthorityServiceTest.java | 1058 +++++++++++++++++ .../src/test/resources/log4j.properties | 23 + services/organization/import/.classpath | 8 + services/organization/import/.project | 23 + .../.settings/org.eclipse.jdt.core.prefs | 5 + .../.settings/org.maven.ide.eclipse.prefs | 9 + services/organization/import/build.xml | 60 + services/organization/import/pom.xml | 130 ++ .../importer/OrgAuthorityBaseImport.java | 229 ++++ services/organization/installer/build.xml | 61 + services/organization/jaxb/.classpath | 9 + services/organization/jaxb/.project | 23 + .../jaxb/.settings/org.eclipse.jdt.core.prefs | 5 + .../.settings/org.maven.ide.eclipse.prefs | 9 + services/organization/jaxb/pom.xml | 105 ++ .../services/OrgAuthorityJAXBSchema.java | 17 + .../OrgAuthorityListItemJAXBSchema.java | 9 + .../services/OrganizationJAXBSchema.java | 18 + .../OrganizationListItemJAXBSchema.java | 8 + .../main/resources/organization_common.xsd | 54 + .../main/resources/orgauthority_common.xsd | 70 ++ services/organization/pom.xml | 70 ++ services/organization/sample/.classpath | 6 + services/organization/sample/.project | 23 + .../.settings/org.eclipse.jdt.core.prefs | 5 + .../.settings/org.maven.ide.eclipse.prefs | 9 + services/organization/sample/pom.xml | 14 + .../organization/sample/sample/.classpath | 117 ++ services/organization/sample/sample/.project | 17 + .../.settings/org.eclipse.jdt.core.prefs | 5 + .../.settings/org.maven.ide.eclipse.prefs | 9 + services/organization/sample/sample/pom.xml | 112 ++ .../organization/client/sample/Sample.java | 548 +++++++++ .../collectionspace-client.properties | 6 + .../sample/src/main/resources/log4j.xml | 38 + services/organization/service/.classpath | 10 + services/organization/service/.project | 25 + services/organization/service/pom.xml | 154 +++ .../organization/OrgAuthorityResource.java | 524 ++++++++ .../nuxeo/OrgAuthorityConstants.java | 35 + .../OrgAuthorityDocumentModelHandler.java | 150 +++ .../nuxeo/OrgAuthorityHandlerFactory.java | 56 + .../nuxeo/OrganizationConstants.java | 35 + .../OrganizationDocumentModelHandler.java | 178 +++ .../nuxeo/OrganizationHandlerFactory.java | 56 + 76 files changed, 5787 insertions(+) create mode 100644 services/organization/.classpath create mode 100644 services/organization/.project create mode 100644 services/organization/.settings/org.eclipse.jdt.core.prefs create mode 100644 services/organization/.settings/org.maven.ide.eclipse.prefs create mode 100644 services/organization/3rdparty/.classpath create mode 100644 services/organization/3rdparty/.project create mode 100644 services/organization/3rdparty/.settings/org.eclipse.jdt.core.prefs create mode 100644 services/organization/3rdparty/.settings/org.maven.ide.eclipse.prefs create mode 100644 services/organization/3rdparty/build.xml create mode 100644 services/organization/3rdparty/nuxeo-platform-cs-organization/.classpath create mode 100644 services/organization/3rdparty/nuxeo-platform-cs-organization/.project create mode 100644 services/organization/3rdparty/nuxeo-platform-cs-organization/.settings/org.eclipse.jdt.core.prefs create mode 100644 services/organization/3rdparty/nuxeo-platform-cs-organization/.settings/org.maven.ide.eclipse.prefs create mode 100644 services/organization/3rdparty/nuxeo-platform-cs-organization/build.xml create mode 100644 services/organization/3rdparty/nuxeo-platform-cs-organization/pom.xml create mode 100644 services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/META-INF/MANIFEST.MF create mode 100644 services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/OSGI-INF/core-types-contrib.xml create mode 100644 services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/OSGI-INF/deployment-fragment.xml create mode 100644 services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/OSGI-INF/ecm-types-contrib.xml create mode 100644 services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/OSGI-INF/layouts-contrib.xml create mode 100644 services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/schemas/organizations_common.xsd create mode 100644 services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/schemas/orgauthorities_common.xsd create mode 100644 services/organization/3rdparty/pom.xml create mode 100644 services/organization/build.xml create mode 100644 services/organization/client/.classpath create mode 100644 services/organization/client/.project create mode 100644 services/organization/client/pom.xml create mode 100644 services/organization/client/settings/org.eclipse.jdt.core.prefs create mode 100644 services/organization/client/settings/org.maven.ide.eclipse.prefs create mode 100644 services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClient.java create mode 100644 services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityProxy.java create mode 100644 services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java create mode 100644 services/organization/client/src/test/resources/log4j.properties create mode 100644 services/organization/import/.classpath create mode 100644 services/organization/import/.project create mode 100644 services/organization/import/.settings/org.eclipse.jdt.core.prefs create mode 100644 services/organization/import/.settings/org.maven.ide.eclipse.prefs create mode 100644 services/organization/import/build.xml create mode 100644 services/organization/import/pom.xml create mode 100644 services/organization/import/src/main/java/org/collectionspace/services/organization/importer/OrgAuthorityBaseImport.java create mode 100644 services/organization/installer/build.xml create mode 100644 services/organization/jaxb/.classpath create mode 100644 services/organization/jaxb/.project create mode 100644 services/organization/jaxb/.settings/org.eclipse.jdt.core.prefs create mode 100644 services/organization/jaxb/.settings/org.maven.ide.eclipse.prefs create mode 100644 services/organization/jaxb/pom.xml create mode 100644 services/organization/jaxb/src/main/java/org/collectionspace/services/OrgAuthorityJAXBSchema.java create mode 100644 services/organization/jaxb/src/main/java/org/collectionspace/services/OrgAuthorityListItemJAXBSchema.java create mode 100644 services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationJAXBSchema.java create mode 100644 services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationListItemJAXBSchema.java create mode 100644 services/organization/jaxb/src/main/resources/organization_common.xsd create mode 100644 services/organization/jaxb/src/main/resources/orgauthority_common.xsd create mode 100644 services/organization/pom.xml create mode 100644 services/organization/sample/.classpath create mode 100644 services/organization/sample/.project create mode 100644 services/organization/sample/.settings/org.eclipse.jdt.core.prefs create mode 100644 services/organization/sample/.settings/org.maven.ide.eclipse.prefs create mode 100644 services/organization/sample/pom.xml create mode 100644 services/organization/sample/sample/.classpath create mode 100644 services/organization/sample/sample/.project create mode 100644 services/organization/sample/sample/.settings/org.eclipse.jdt.core.prefs create mode 100644 services/organization/sample/sample/.settings/org.maven.ide.eclipse.prefs create mode 100644 services/organization/sample/sample/pom.xml create mode 100644 services/organization/sample/sample/src/main/java/org/collectionspace/services/organization/client/sample/Sample.java create mode 100644 services/organization/sample/sample/src/main/resources/collectionspace-client.properties create mode 100644 services/organization/sample/sample/src/main/resources/log4j.xml create mode 100644 services/organization/service/.classpath create mode 100644 services/organization/service/.project create mode 100644 services/organization/service/pom.xml create mode 100644 services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java create mode 100644 services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrgAuthorityConstants.java create mode 100644 services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrgAuthorityDocumentModelHandler.java create mode 100644 services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrgAuthorityHandlerFactory.java create mode 100644 services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationConstants.java create mode 100644 services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationDocumentModelHandler.java create mode 100644 services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationHandlerFactory.java diff --git a/services/organization/.classpath b/services/organization/.classpath new file mode 100644 index 000000000..046988541 --- /dev/null +++ b/services/organization/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/services/organization/.project b/services/organization/.project new file mode 100644 index 000000000..a1651b42a --- /dev/null +++ b/services/organization/.project @@ -0,0 +1,23 @@ + + + org.collectionspace.services.organization + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.maven.ide.eclipse.maven2Nature + + diff --git a/services/organization/.settings/org.eclipse.jdt.core.prefs b/services/organization/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..2341888c8 --- /dev/null +++ b/services/organization/.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/organization/.settings/org.maven.ide.eclipse.prefs b/services/organization/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 000000000..95a5ba022 --- /dev/null +++ b/services/organization/.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/organization/3rdparty/.classpath b/services/organization/3rdparty/.classpath new file mode 100644 index 000000000..046988541 --- /dev/null +++ b/services/organization/3rdparty/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/services/organization/3rdparty/.project b/services/organization/3rdparty/.project new file mode 100644 index 000000000..6e3bacab0 --- /dev/null +++ b/services/organization/3rdparty/.project @@ -0,0 +1,23 @@ + + + org.collectionspace.services.organization.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/organization/3rdparty/.settings/org.eclipse.jdt.core.prefs b/services/organization/3rdparty/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..4956ebcc9 --- /dev/null +++ b/services/organization/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/organization/3rdparty/.settings/org.maven.ide.eclipse.prefs b/services/organization/3rdparty/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 000000000..93b6f8a66 --- /dev/null +++ b/services/organization/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/organization/3rdparty/build.xml b/services/organization/3rdparty/build.xml new file mode 100644 index 000000000..2b77792fa --- /dev/null +++ b/services/organization/3rdparty/build.xml @@ -0,0 +1,131 @@ + + + + organization service 3rdparty + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/organization/3rdparty/nuxeo-platform-cs-organization/.classpath b/services/organization/3rdparty/nuxeo-platform-cs-organization/.classpath new file mode 100644 index 000000000..9757920d7 --- /dev/null +++ b/services/organization/3rdparty/nuxeo-platform-cs-organization/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/services/organization/3rdparty/nuxeo-platform-cs-organization/.project b/services/organization/3rdparty/nuxeo-platform-cs-organization/.project new file mode 100644 index 000000000..48d5893b9 --- /dev/null +++ b/services/organization/3rdparty/nuxeo-platform-cs-organization/.project @@ -0,0 +1,23 @@ + + + org.collectionspace.services.organization.3rdparty.nuxeo + Organization 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/organization/3rdparty/nuxeo-platform-cs-organization/.settings/org.eclipse.jdt.core.prefs b/services/organization/3rdparty/nuxeo-platform-cs-organization/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..82d33d354 --- /dev/null +++ b/services/organization/3rdparty/nuxeo-platform-cs-organization/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +#Tue Oct 06 13:26:44 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/organization/3rdparty/nuxeo-platform-cs-organization/.settings/org.maven.ide.eclipse.prefs b/services/organization/3rdparty/nuxeo-platform-cs-organization/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 000000000..552ddbfcf --- /dev/null +++ b/services/organization/3rdparty/nuxeo-platform-cs-organization/.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/organization/3rdparty/nuxeo-platform-cs-organization/build.xml b/services/organization/3rdparty/nuxeo-platform-cs-organization/build.xml new file mode 100644 index 000000000..f3161e1cb --- /dev/null +++ b/services/organization/3rdparty/nuxeo-platform-cs-organization/build.xml @@ -0,0 +1,138 @@ + + + + organization nuxeo document type + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/organization/3rdparty/nuxeo-platform-cs-organization/pom.xml b/services/organization/3rdparty/nuxeo-platform-cs-organization/pom.xml new file mode 100644 index 000000000..20f4a3b3f --- /dev/null +++ b/services/organization/3rdparty/nuxeo-platform-cs-organization/pom.xml @@ -0,0 +1,19 @@ + + + org.collectionspace.services + nuxeo-platform-collectionspace + 1.0 + + + 4.0.0 + org.collectionspace.services + 1.0 + org.collectionspace.services.organization.3rdparty.nuxeo + jar + services.organization.3rdparty.nuxeo + + Organization Nuxeo Document Type + + diff --git a/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/META-INF/MANIFEST.MF b/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 000000000..8113da6c1 --- /dev/null +++ b/services/organization/3rdparty/nuxeo-platform-cs-organization/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.organization;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.organization +Nuxeo-Component: OSGI-INF/core-types-contrib.xml, + OSGI-INF/ecm-types-contrib.xml, + OSGI-INF/layouts-contrib.xml + diff --git a/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/OSGI-INF/core-types-contrib.xml b/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/OSGI-INF/core-types-contrib.xml new file mode 100644 index 000000000..7e1f0fec5 --- /dev/null +++ b/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/OSGI-INF/core-types-contrib.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/OSGI-INF/deployment-fragment.xml b/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/OSGI-INF/deployment-fragment.xml new file mode 100644 index 000000000..8bbdd72b6 --- /dev/null +++ b/services/organization/3rdparty/nuxeo-platform-cs-organization/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/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/OSGI-INF/ecm-types-contrib.xml b/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/OSGI-INF/ecm-types-contrib.xml new file mode 100644 index 000000000..c29c8f898 --- /dev/null +++ b/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/OSGI-INF/ecm-types-contrib.xml @@ -0,0 +1,53 @@ + + + + + + + view_documents + + + heading + csorgauthority + + + + + + OrgAuthority + + + + + + OrgAuthority + + + + + + + + + view_documents + + + heading + organization + + + + + + Organization + + + + + + Organization + + + + + diff --git a/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/OSGI-INF/layouts-contrib.xml b/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/OSGI-INF/layouts-contrib.xml new file mode 100644 index 000000000..daacbfd75 --- /dev/null +++ b/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/OSGI-INF/layouts-contrib.xml @@ -0,0 +1,112 @@ + + + + + + + + + + + + displayName + refName + vocabType + + + + + + + true + + displayName + + + dataInputText + + + + + + + + true + + refName + + + dataInputText + + + + + + + + true + + vocabType + + + dataInputText + + + + + + + + + + + + + displayName + refName + inAuthority + + + + + + + true + + displayName + + + dataInputText + + + + + + + + true + + refName + + + dataInputText + + + + + + + + true + + inAuthority + + + dataInputText + + + + + diff --git a/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/schemas/organizations_common.xsd b/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/schemas/organizations_common.xsd new file mode 100644 index 000000000..a15057748 --- /dev/null +++ b/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/schemas/organizations_common.xsd @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + diff --git a/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/schemas/orgauthorities_common.xsd b/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/schemas/orgauthorities_common.xsd new file mode 100644 index 000000000..a1238c77b --- /dev/null +++ b/services/organization/3rdparty/nuxeo-platform-cs-organization/src/main/resources/schemas/orgauthorities_common.xsd @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + diff --git a/services/organization/3rdparty/pom.xml b/services/organization/3rdparty/pom.xml new file mode 100644 index 000000000..d790b56f8 --- /dev/null +++ b/services/organization/3rdparty/pom.xml @@ -0,0 +1,23 @@ + + + + org.collectionspace.services.organization + org.collectionspace.services + 1.0 + + 4.0.0 + org.collectionspace.services + 1.0 + org.collectionspace.services.organization.3rdparty + pom + services.organization.3rdparty + + 3rd party build for organization service + + + + nuxeo-platform-cs-organization + + diff --git a/services/organization/build.xml b/services/organization/build.xml new file mode 100644 index 000000000..1b8d8fcdc --- /dev/null +++ b/services/organization/build.xml @@ -0,0 +1,134 @@ + + + + organization service + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/organization/client/.classpath b/services/organization/client/.classpath new file mode 100644 index 000000000..425cd1620 --- /dev/null +++ b/services/organization/client/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/services/organization/client/.project b/services/organization/client/.project new file mode 100644 index 000000000..3b636e056 --- /dev/null +++ b/services/organization/client/.project @@ -0,0 +1,26 @@ + + + org.collectionspace.services.organization.client + + + org.collectionspace.services.client + org.collectionspace.services.common + org.collectionspace.services.organization.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/organization/client/pom.xml b/services/organization/client/pom.xml new file mode 100644 index 000000000..f375194d3 --- /dev/null +++ b/services/organization/client/pom.xml @@ -0,0 +1,111 @@ + + + + + org.collectionspace.services.organization + org.collectionspace.services + 1.0 + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.organization.client + 1.0 + services.organization.client + + + + + org.slf4j + slf4j-api + test + + + org.slf4j + slf4j-log4j12 + test + + + org.collectionspace.services + org.collectionspace.services.organization.jaxb + 1.0 + + + org.collectionspace.services + org.collectionspace.services.client + 1.0 + + + + org.testng + testng + 5.6 + + + org.slf4j + slf4j-api + 1.5.2 + + + org.slf4j + slf4j-log4j12 + 1.5.2 + + + org.jboss.resteasy + resteasy-jaxrs + 1.0.2.GA + + + + tjws + webserver + + + + + org.jboss.resteasy + resteasy-jaxb-provider + 1.0.2.GA + + + org.jboss.resteasy + resteasy-multipart-provider + 1.0.2.GA + + + commons-httpclient + commons-httpclient + 3.1 + + + + + collectionspace-services-organization-client + + + org.apache.maven.plugins + maven-surefire-plugin + + + + log4j.configuration + file:target/test-classes/log4j.properties + + + + + + maven-compiler-plugin + 2.0.2 + + 1.6 + 1.6 + + + + + + diff --git a/services/organization/client/settings/org.eclipse.jdt.core.prefs b/services/organization/client/settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..0b4dbbea4 --- /dev/null +++ b/services/organization/client/settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +#Mon Oct 05 17:07:09 PDT 2009 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/services/organization/client/settings/org.maven.ide.eclipse.prefs b/services/organization/client/settings/org.maven.ide.eclipse.prefs new file mode 100644 index 000000000..93b6f8a66 --- /dev/null +++ b/services/organization/client/settings/org.maven.ide.eclipse.prefs @@ -0,0 +1,9 @@ +#Fri Sep 11 17:00:30 PDT 2009 +activeProfiles= +eclipse.preferences.version=1 +fullBuildGoals=process-test-resources +includeModules=false +resolveWorkspaceProjects=true +resourceFilterGoals=process-resources resources\:testResources +skipCompilerPlugin=true +version=1 diff --git a/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClient.java b/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClient.java new file mode 100644 index 000000000..669fd1622 --- /dev/null +++ b/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityClient.java @@ -0,0 +1,157 @@ +package org.collectionspace.services.client; + +import javax.ws.rs.core.Response; + +import org.collectionspace.services.organization.OrgauthoritiesCommonList; +import org.collectionspace.services.organization.OrganizationsCommonList; +import org.collectionspace.services.client.OrgAuthorityProxy; + +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; + +/** + * A OrgAuthorityClient. + + * @version $Revision:$ + */ +public class OrgAuthorityClient extends BaseServiceClient { + + /* (non-Javadoc) + * @see org.collectionspace.services.client.BaseServiceClient#getServicePathComponent() + */ + @Override + public String getServicePathComponent() { + return "orgauthorities"; + } + + public String getItemCommonPartName() { + return getCommonPartName("organizations"); + } + + /** + * + */ + private static final OrgAuthorityClient instance = new OrgAuthorityClient(); + /** + * + */ + private OrgAuthorityProxy orgAuthorityProxy; + + /** + * + * Default constructor for OrgAuthorityClient class. + * + */ + public OrgAuthorityClient() { + ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance(); + RegisterBuiltin.register(factory); + orgAuthorityProxy = ProxyFactory.create(OrgAuthorityProxy.class, getBaseURL()); + } + + /** + * FIXME Comment this + * + * @return + */ + public static OrgAuthorityClient getInstance() { + return instance; + } + + /** + * @return + * @see org.collectionspace.services.client.OrgAuthorityProxy#readList() + */ + public ClientResponse readList() { + return orgAuthorityProxy.readList(); + } + + /** + * @param csid + * @return + * @see org.collectionspace.services.client.OrgAuthorityProxy#read(java.lang.String) + */ + + public ClientResponse read(String csid) { + return orgAuthorityProxy.read(csid); + } + + /** + * @param orgAuthority + * @return + * @see org.collectionspace.services.client.OrgAuthorityProxy#createOrgAuthority(org.collectionspace.hello.OrgAuthority) + */ + public ClientResponse create(MultipartOutput multipart) { + return orgAuthorityProxy.create(multipart); + } + + /** + * @param csid + * @param orgAuthority + * @return + * @see org.collectionspace.services.client.OrgAuthorityProxy#updateOrgAuthority(java.lang.Long, org.collectionspace.hello.OrgAuthority) + */ + public ClientResponse update(String csid, MultipartOutput multipart) { + return orgAuthorityProxy.update(csid, multipart); + + } + + /** + * @param csid + * @return + * @see org.collectionspace.services.client.OrgAuthorityProxy#deleteOrgAuthority(java.lang.Long) + */ + public ClientResponse delete(String csid) { + return orgAuthorityProxy.delete(csid); + } + + /** + * @return + * @see org.collectionspace.services.client.OrgAuthorityProxy#readItemList() + */ + public ClientResponse readItemList(String vcsid) { + return orgAuthorityProxy.readItemList(vcsid); + } + + /** + * @param csid + * @return + * @see org.collectionspace.services.client.OrgAuthorityProxy#read(java.lang.String) + */ + + public ClientResponse readItem(String vcsid, String csid) { + return orgAuthorityProxy.readItem(vcsid, csid); + } + + /** + * @param orgAuthority + * @return + * @see org.collectionspace.services.client.OrgAuthorityProxy#createOrgAuthority(org.collectionspace.hello.OrgAuthority) + */ + public ClientResponse createItem(String vcsid, MultipartOutput multipart) { + return orgAuthorityProxy.createItem(vcsid, multipart); + } + + /** + * @param csid + * @param orgAuthority + * @return + * @see org.collectionspace.services.client.OrgAuthorityProxy#updateOrgAuthority(java.lang.Long, org.collectionspace.hello.OrgAuthority) + */ + public ClientResponse updateItem(String vcsid, String csid, MultipartOutput multipart) { + return orgAuthorityProxy.updateItem(vcsid, csid, multipart); + + } + + /** + * @param csid + * @return + * @see org.collectionspace.services.client.OrgAuthorityProxy#deleteOrgAuthority(java.lang.Long) + */ + public ClientResponse deleteItem(String vcsid, String csid) { + return orgAuthorityProxy.deleteItem(vcsid, csid); + } +} diff --git a/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityProxy.java b/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityProxy.java new file mode 100644 index 000000000..269836db3 --- /dev/null +++ b/services/organization/client/src/main/java/org/collectionspace/services/client/OrgAuthorityProxy.java @@ -0,0 +1,76 @@ +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.organization.OrgauthoritiesCommonList; +import org.collectionspace.services.organization.OrganizationsCommonList; +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("/orgauthorities/") +@Produces({"multipart/mixed"}) +@Consumes({"multipart/mixed"}) +public interface OrgAuthorityProxy { + + // List Orgauthorities + @GET + @Produces({"application/xml"}) + ClientResponse readList(); + + //(C)reate + @POST + ClientResponse create(MultipartOutput multipart); + + //(R)ead + @GET + @Path("/{csid}") + ClientResponse read(@PathParam("csid") String csid); + + //(U)pdate + @PUT + @Path("/{csid}") + ClientResponse update(@PathParam("csid") String csid, MultipartOutput multipart); + + //(D)elete + @DELETE + @Path("/{csid}") + ClientResponse delete(@PathParam("csid") String csid); + + // List Items + @GET + @Produces({"application/xml"}) + @Path("/{vcsid}/items/") + ClientResponse readItemList(@PathParam("vcsid") String vcsid); + + //(C)reate Item + @POST + @Path("/{vcsid}/items/") + ClientResponse createItem(@PathParam("vcsid") String vcsid, MultipartOutput multipart); + + //(R)ead + @GET + @Path("/{vcsid}/items/{csid}") + ClientResponse readItem(@PathParam("vcsid") String vcsid, @PathParam("csid") String csid); + + //(U)pdate + @PUT + @Path("/{vcsid}/items/{csid}") + ClientResponse updateItem(@PathParam("vcsid") String vcsid, @PathParam("csid") String csid, MultipartOutput multipart); + + //(D)elete + @DELETE + @Path("/{vcsid}/items/{csid}") + ClientResponse deleteItem(@PathParam("vcsid") String vcsid, @PathParam("csid") String csid); +} diff --git a/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java b/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java new file mode 100644 index 000000000..d5f8dad96 --- /dev/null +++ b/services/organization/client/src/test/java/org/collectionspace/services/client/test/OrgAuthorityServiceTest.java @@ -0,0 +1,1058 @@ +/** + * 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.client.OrgAuthorityClient; +import org.collectionspace.services.organization.OrgauthoritiesCommon; +import org.collectionspace.services.organization.OrgauthoritiesCommonList; +import org.collectionspace.services.organization.OrganizationsCommon; +import org.collectionspace.services.organization.OrganizationsCommonList; + +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; + +/** + * OrgAuthorityServiceTest, carries out tests against a + * deployed and running OrgAuthority Service. + * + * $LastChangedRevision: 753 $ + * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $ + */ +public class OrgAuthorityServiceTest extends AbstractServiceTest { + + private final Logger logger = + LoggerFactory.getLogger(OrgAuthorityServiceTest.class); + + // Instance variables specific to this test. + private OrgAuthorityClient client = new OrgAuthorityClient(); + final String SERVICE_PATH_COMPONENT = "orgauthorities"; + final String ITEM_SERVICE_PATH_COMPONENT = "items"; + private String knownResourceId = null; + private String knownResourceRefName = null; + private String knownItemResourceId = null; + private List allResourceIdsCreated = new ArrayList(); + private Map allResourceItemIdsCreated = + new HashMap(); + + protected String createRefName(String displayName) { + return displayName.replaceAll("\\W", ""); + } + + // --------------------------------------------------------------- + // CRUD tests : CREATE tests + // --------------------------------------------------------------- + // Success outcomes + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class) + public void create(String testName) throws Exception { + + // Perform setup, such as initializing the type of service request + // (e.g. CREATE, DELETE), its valid and expected status codes, and + // its associated HTTP method name (e.g. POST, DELETE). + setupCreate(testName); + + // Submit the request to the service and store the response. + String identifier = createIdentifier(); + String displayName = "displayName-" + identifier; + String refName = createRefName(displayName); + String typeName = "vocabType-" + identifier; + MultipartOutput multipart = + createOrgAuthorityInstance(displayName, refName, typeName); + ClientResponse res = client.create(multipart); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + // + // Specifically: + // Does it fall within the set of valid status codes? + // Does it exactly match the expected status code? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Store the refname from the first resource created + // for additional tests below. + knownResourceRefName = refName; + + // Store the ID returned from the first resource created + // for additional tests below. + if (knownResourceId == null){ + knownResourceId = extractId(res); + if (logger.isDebugEnabled()) { + logger.debug(testName + ": knownResourceId=" + knownResourceId); + } + } + // Store the IDs from every resource created by tests, + // so they can be deleted after tests have been run. + allResourceIdsCreated.add(extractId(res)); + + } + + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"create"}) + public void createItem(String testName) { + setupCreate(testName); + + knownItemResourceId = createItemInOrgAuthority(knownResourceId); + if(logger.isDebugEnabled()){ + logger.debug(testName + ": knownItemResourceId=" + knownItemResourceId); + } + } + + private String createItemInOrgAuthority(String vcsid) { + + final String testName = "createItemInOrgAuthority"; + if(logger.isDebugEnabled()){ + logger.debug(testName + ":..."); + } + + // Submit the request to the service and store the response. + String identifier = createIdentifier(); + String refName = createRefName(identifier); + MultipartOutput multipart = createOrganizationInstance(vcsid, identifier, refName); + ClientResponse res = client.createItem(vcsid, 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); + + // Store the ID returned from the first item resource created + // for additional tests below. + if (knownItemResourceId == null){ + knownItemResourceId = extractId(res); + 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. + // + // Item resource IDs are unique, so these are used as keys; + // the non-unique IDs of their parents are stored as associated values. + allResourceItemIdsCreated.put(extractId(res), vcsid); + + return extractId(res); + } + + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"create", "createItem"}) + public void createList(String testName) throws Exception { + for (int i = 0; i < 3; i++) { + create(testName); + // Add 3 items to each orgauthority + for (int j = 0; j < 3; j++) { + createItem(testName); + } + } + } + + // Failure outcomes + // Placeholders until the three tests below can be uncommented. + // See Issue CSPACE-401. + @Override + public void createWithEmptyEntityBody(String testName) throws Exception { + } + + @Override + public void createWithMalformedXml(String testName) throws Exception { + } + + @Override + public void createWithWrongXmlSchema(String testName) throws Exception { + } + + /* + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"create", "testSubmitRequest"}) + public void createWithEmptyEntityBody(String testName) throws Exception { + + // Perform setup. + setupCreateWithEmptyEntityBody(testName); + + // Submit the request to the service and store the response. + String method = REQUEST_TYPE.httpMethodName(); + String url = getServiceRootURL(); + String mediaType = MediaType.APPLICATION_XML; + final String entity = ""; + int statusCode = submitRequest(method, url, mediaType, entity); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()) { + logger.debug(testName + ": url=" + url + + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"create", "testSubmitRequest"}) + public void createWithMalformedXml(String testName) throws Exception { + + // Perform setup. + setupCreateWithMalformedXml(testName); + + // Submit the request to the service and store the response. + String method = REQUEST_TYPE.httpMethodName(); + String url = getServiceRootURL(); + String mediaType = MediaType.APPLICATION_XML; + final String entity = MALFORMED_XML_DATA; // Constant from base class. + int statusCode = submitRequest(method, url, mediaType, entity); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": url=" + url + + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"create", "testSubmitRequest"}) + public void createWithWrongXmlSchema(String testName) throws Exception { + + // Perform setup. + setupCreateWithWrongXmlSchema(testName); + + // Submit the request to the service and store the response. + String method = REQUEST_TYPE.httpMethodName(); + String url = getServiceRootURL(); + String mediaType = MediaType.APPLICATION_XML; + final String entity = WRONG_XML_SCHEMA_DATA; + int statusCode = submitRequest(method, url, mediaType, entity); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": url=" + url + + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + */ + + // --------------------------------------------------------------- + // CRUD tests : READ tests + // --------------------------------------------------------------- + // Success outcomes + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"create"}) + public void read(String testName) throws Exception { + + // Perform setup. + setupRead(); + + // Submit the request to the service and store the response. + ClientResponse res = client.read(knownResourceId); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + 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(); + OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input, + client.getCommonPartName(), OrgauthoritiesCommon.class); + Assert.assertNotNull(orgAuthority); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + /* + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"read"}) + public void readByName(String testName) throws Exception { + + // Perform setup. + setupRead(); + + // Submit the request to the service and store the response. + ClientResponse res = client.read(knownResourceId); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + 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(); + OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input, + client.getCommonPartName(), OrgauthoritiesCommon.class); + Assert.assertNotNull(orgAuthority); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + */ + + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"createItem", "read"}) + public void readItem(String testName) throws Exception { + + // Perform setup. + setupRead(testName); + + // Submit the request to the service and store the response. + 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 organization. + MultipartInput input = (MultipartInput) res.getEntity(); + OrganizationsCommon organization = (OrganizationsCommon) extractPart(input, + client.getItemCommonPartName(), OrganizationsCommon.class); + Assert.assertNotNull(organization); + + } + + // Failure outcomes + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"read"}) + public void readNonExistent(String testName) { + + // Perform setup. + setupReadNonExistent(testName); + + // Submit the request to the service and store the response. + ClientResponse res = client.read(NON_EXISTENT_ID); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"readItem", "readNonExistent"}) + public void readItemNonExistent(String testName) { + + // Perform setup. + setupReadNonExistent(testName); + + // Submit the request to the service and store the response. + 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 + + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"createList", "read"}) + public void readList(String testName) throws Exception { + + // Perform setup. + setupReadList(testName); + + // Submit the request to the service and store the response. + ClientResponse res = client.readList(); + OrgauthoritiesCommonList 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.getOrgauthorityListItem(); + int i = 0; + for (OrgauthoritiesCommonList.OrgauthorityListItem 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); + i++; + } + } + } + + @Test(dependsOnMethods = {"createList", "readItem"}) + public void readItemList() { + readItemList(knownResourceId); + } + + private void readItemList(String vcsid) { + + final String testName = "readItemList"; + + // Perform setup. + setupReadList(testName); + + // Submit the request to the service and store the response. + ClientResponse res = + client.readItemList(vcsid); + OrganizationsCommonList 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.getOrganizationListItem(); + int i = 0; + for (OrganizationsCommonList.OrganizationListItem item : items) { + logger.debug(" " + testName + ": list-item[" + i + "] csid=" + + item.getCsid()); + 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 + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"read"}) + public void update(String testName) throws Exception { + + // Perform setup. + setupUpdate(testName); + + // Retrieve the contents of a resource to update. + 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 OrgAuthority to update with ID: " + knownResourceId); + } + MultipartInput input = (MultipartInput) res.getEntity(); + OrgauthoritiesCommon orgAuthority = (OrgauthoritiesCommon) extractPart(input, + client.getCommonPartName(), OrgauthoritiesCommon.class); + Assert.assertNotNull(orgAuthority); + + // Update the contents of this resource. + orgAuthority.setDisplayName("updated-" + orgAuthority.getDisplayName()); + orgAuthority.setVocabType("updated-" + orgAuthority.getVocabType()); + if(logger.isDebugEnabled()){ + logger.debug("to be updated OrgAuthority"); + logger.debug(objectAsXmlString(orgAuthority, OrgauthoritiesCommon.class)); + } + + // Submit the updated resource to the service and store the response. + MultipartOutput output = new MultipartOutput(); + OutputPart commonPart = output.addPart(orgAuthority, 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("update: 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(); + OrgauthoritiesCommon updatedOrgAuthority = + (OrgauthoritiesCommon) extractPart(input, + client.getCommonPartName(), OrgauthoritiesCommon.class); + Assert.assertNotNull(updatedOrgAuthority); + + // Verify that the updated resource received the correct data. + Assert.assertEquals(updatedOrgAuthority.getDisplayName(), + orgAuthority.getDisplayName(), + "Data in updated object did not match submitted data."); + } + + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"readItem", "update"}) + public void updateItem(String testName) throws Exception { + + // Perform setup. + setupUpdate(testName); + + 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 Organization to update with ID: " + + knownItemResourceId + + " in OrgAuthority: " + knownResourceId ); + } + MultipartInput input = (MultipartInput) res.getEntity(); + OrganizationsCommon organization = (OrganizationsCommon) extractPart(input, + client.getItemCommonPartName(), OrganizationsCommon.class); + Assert.assertNotNull(organization); + + // Update the contents of this resource. + organization.setDisplayName("updated-" + organization.getDisplayName()); + if(logger.isDebugEnabled()){ + logger.debug("to be updated Organization"); + logger.debug(objectAsXmlString(organization, + OrganizationsCommon.class)); + } + + // Submit the updated resource to the service and store the response. + MultipartOutput output = new MultipartOutput(); + OutputPart commonPart = output.addPart(organization, 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("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(); + OrganizationsCommon updatedOrganization = + (OrganizationsCommon) extractPart(input, + client.getItemCommonPartName(), OrganizationsCommon.class); + Assert.assertNotNull(updatedOrganization); + + // Verify that the updated resource received the correct data. + Assert.assertEquals(updatedOrganization.getDisplayName(), + organization.getDisplayName(), + "Data in updated Organization did not match submitted data."); + } + + // Failure outcomes + // Placeholders until the three tests below can be uncommented. + // See Issue CSPACE-401. + @Override + public void updateWithEmptyEntityBody(String testName) throws Exception { + } + + @Override + public void updateWithMalformedXml(String testName) throws Exception { + } + + @Override + public void updateWithWrongXmlSchema(String testName) throws Exception { + } + + /* + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"create", "update", "testSubmitRequest"}) + public void updateWithEmptyEntityBody(String testName) throws Exception { + + // Perform setup. + setupUpdateWithEmptyEntityBody(testName); + + // Submit the request to the service and store the response. + String method = REQUEST_TYPE.httpMethodName(); + String url = getResourceURL(knownResourceId); + String mediaType = MediaType.APPLICATION_XML; + final String entity = ""; + int statusCode = submitRequest(method, url, mediaType, entity); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": url=" + url + + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"create", "update", "testSubmitRequest"}) + public void updateWithMalformedXml(String testName) throws Exception { + + // Perform setup. + setupUpdateWithMalformedXml(testName); + + // Submit the request to the service and store the response. + String method = REQUEST_TYPE.httpMethodName(); + String url = getResourceURL(knownResourceId); + String mediaType = MediaType.APPLICATION_XML; + final String entity = MALFORMED_XML_DATA; + int statusCode = submitRequest(method, url, mediaType, entity); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": url=" + url + + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"create", "update", "testSubmitRequest"}) + public void updateWithWrongXmlSchema(String testName) throws Exception { + + // Perform setup. + setupUpdateWithWrongXmlSchema(testName); + + // Submit the request to the service and store the response. + String method = REQUEST_TYPE.httpMethodName(); + String url = getResourceURL(knownResourceId); + String mediaType = MediaType.APPLICATION_XML; + final String entity = WRONG_XML_SCHEMA_DATA; + int statusCode = submitRequest(method, url, mediaType, entity); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug("updateWithWrongXmlSchema: url=" + url + + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + */ + + + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"update", "testSubmitRequest"}) + public void updateNonExistent(String testName) throws Exception { + + // Perform setup. + setupUpdateNonExistent(testName); + + // Submit the request to the service and store the response. + // Note: The ID used in this 'create' call may be arbitrary. + // The only relevant ID may be the one used in update(), below. + + // The only relevant ID may be the one used in update(), below. + MultipartOutput multipart = createOrgAuthorityInstance(NON_EXISTENT_ID); + ClientResponse res = + client.update(NON_EXISTENT_ID, multipart); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + 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. + + // The only relevant ID may be the one used in update(), below. + MultipartOutput multipart = createOrganizationInstance( + knownResourceId, NON_EXISTENT_ID, createRefName(NON_EXISTENT_ID)); + 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 + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"create", "readList", "testSubmitRequest", "update"}) + public void delete(String testName) throws Exception { + + // Perform setup. + setupDelete(testName); + + // Submit the request to the service and store the response. + 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); + } + + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"createItem", "readItemList", "testItemSubmitRequest", + "updateItem"}) + public void deleteItem(String testName) throws Exception { + + // Perform setup. + setupDelete(testName); + + // Submit the request to the service and store the response. + 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("delete: status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + + // Failure outcomes + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"delete"}) + public void deleteNonExistent(String testName) throws Exception { + + // Perform setup. + setupDeleteNonExistent(testName); + + // Submit the request to the service and store the response. + ClientResponse res = client.delete(NON_EXISTENT_ID); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"deleteItem"}) + public void deleteNonExistentItem(String testName) { + + // Perform setup. + setupDeleteNonExistent(testName); + + // Submit the request to the service and store the response. + 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(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() { + + if (logger.isDebugEnabled()) { + logger.debug("Cleaning up temporary resources created for testing ..."); + } + // Clean up organization resources. + String orgAuthorityResourceId; + String organizationResourceId; + for (Map.Entry entry : allResourceItemIdsCreated.entrySet()) { + organizationResourceId = entry.getKey(); + orgAuthorityResourceId = entry.getValue(); + // Note: Any non-success responses are ignored and not reported. + ClientResponse res = + client.deleteItem(orgAuthorityResourceId, organizationResourceId); + } + // Clean up orgAuthority resources. + for (String resourceId : allResourceIdsCreated) { + // Note: Any non-success responses are ignored and not reported. + ClientResponse res = client.delete(resourceId); + } + + } + + // --------------------------------------------------------------- + // Utility methods used by tests above + // --------------------------------------------------------------- + @Override + public String getServicePathComponent() { + return SERVICE_PATH_COMPONENT; + } + + public String getItemServicePathComponent() { + return ITEM_SERVICE_PATH_COMPONENT; + } + + /** + * Returns the root URL for a service. + * + * This URL consists of a base URL for all services, followed by + * a path component for the owning orgAuthority, followed by the + * path component for the items. + * + * @return The root URL for a service. + */ + protected String getItemServiceRootURL(String parentResourceIdentifier) { + return getResourceURL(parentResourceIdentifier) + "/" + getItemServicePathComponent(); + } + + /** + * Returns the URL of a specific resource managed by a service, and + * designated by an identifier (such as a universally unique ID, or UUID). + * + * @param resourceIdentifier An identifier (such as a UUID) for a resource. + * + * @return The URL of a specific resource managed by a service. + */ + protected String getItemResourceURL(String parentResourceIdentifier, String resourceIdentifier) { + return getItemServiceRootURL(parentResourceIdentifier) + "/" + resourceIdentifier; + } + + private MultipartOutput createOrgAuthorityInstance(String identifier) { + String displayName = "displayName-" + identifier; + String refName = createRefName(displayName); + String typeName = "vocabType-" + identifier; + return createOrgAuthorityInstance( + displayName, refName,typeName ); + } + + private MultipartOutput createOrgAuthorityInstance( + String displayName, String refName, String vocabType) { + OrgauthoritiesCommon orgAuthority = new OrgauthoritiesCommon(); + orgAuthority.setDisplayName(displayName); + if(refName!=null) + orgAuthority.setRefName(refName); + orgAuthority.setVocabType(vocabType); + MultipartOutput multipart = new MultipartOutput(); + OutputPart commonPart = multipart.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", client.getCommonPartName()); + + if(logger.isDebugEnabled()) { + logger.debug("to be created, orgAuthority common"); + logger.debug(objectAsXmlString(orgAuthority, OrgauthoritiesCommon.class)); + } + return multipart; + } + + private MultipartOutput createOrganizationInstance(String inOrgAuthority, + String displayName, String refName) { + OrganizationsCommon organization = new OrganizationsCommon(); + organization.setDisplayName(displayName); + if(refName!=null) + organization.setRefName(refName); + MultipartOutput multipart = new MultipartOutput(); + OutputPart commonPart = multipart.addPart(organization, + MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", client.getItemCommonPartName()); + + if(logger.isDebugEnabled()){ + logger.debug("to be created, organization common"); + logger.debug(objectAsXmlString(organization, + OrganizationsCommon.class)); + } + + return multipart; + } +} diff --git a/services/organization/client/src/test/resources/log4j.properties b/services/organization/client/src/test/resources/log4j.properties new file mode 100644 index 000000000..18c510350 --- /dev/null +++ b/services/organization/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/organization/import/.classpath b/services/organization/import/.classpath new file mode 100644 index 000000000..199bbbbdb --- /dev/null +++ b/services/organization/import/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/services/organization/import/.project b/services/organization/import/.project new file mode 100644 index 000000000..245a8c24f --- /dev/null +++ b/services/organization/import/.project @@ -0,0 +1,23 @@ + + + org.collectionspace.services.organization.importer + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.maven.ide.eclipse.maven2Nature + + diff --git a/services/organization/import/.settings/org.eclipse.jdt.core.prefs b/services/organization/import/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..8bc35048b --- /dev/null +++ b/services/organization/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/organization/import/.settings/org.maven.ide.eclipse.prefs b/services/organization/import/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 000000000..fd8796b9b --- /dev/null +++ b/services/organization/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/organization/import/build.xml b/services/organization/import/build.xml new file mode 100644 index 000000000..001ca5ded --- /dev/null +++ b/services/organization/import/build.xml @@ -0,0 +1,60 @@ + + + + organization service + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/organization/import/pom.xml b/services/organization/import/pom.xml new file mode 100644 index 000000000..2cc38214e --- /dev/null +++ b/services/organization/import/pom.xml @@ -0,0 +1,130 @@ + + + + + org.collectionspace.services + org.collectionspace.services.organization + 1.0 + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.organization.importer + 1.0 + services.organization.importer + + + + + org.collectionspace.services + org.collectionspace.services.organization.jaxb + 1.0 + + + org.collectionspace.services + org.collectionspace.services.client + 1.0 + + + org.collectionspace.services + org.collectionspace.services.organization.client + 1.0 + + + + + org.slf4j + slf4j-api + 1.5.2 + + + + org.jboss.resteasy + resteasy-jaxrs + 1.0.2.GA + + + + tjws + webserver + + + + + org.jboss.resteasy + resteasy-jaxb-provider + 1.0.2.GA + + + org.jboss.resteasy + resteasy-multipart-provider + 1.0.2.GA + + + commons-httpclient + commons-httpclient + 3.1 + + + + + collectionspace-services-organization-importer + + + org.apache.maven.plugins + maven-assembly-plugin + + + + attached + + package + + + jar-with-dependencies + + + + org.collectionspace.services.organization.importer.OrgAuthorityBaseImport + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + + log4j.configuration + file:target/test-classes/log4j.properties + + + + + + maven-compiler-plugin + 2.0.2 + + 1.6 + 1.6 + + + + + + diff --git a/services/organization/import/src/main/java/org/collectionspace/services/organization/importer/OrgAuthorityBaseImport.java b/services/organization/import/src/main/java/org/collectionspace/services/organization/importer/OrgAuthorityBaseImport.java new file mode 100644 index 000000000..f01658c2c --- /dev/null +++ b/services/organization/import/src/main/java/org/collectionspace/services/organization/importer/OrgAuthorityBaseImport.java @@ -0,0 +1,229 @@ +/** + * 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.organization.importer; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +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.client.OrgAuthorityClient; +import org.collectionspace.services.client.test.ServiceRequestType; +import org.collectionspace.services.organization.OrgauthoritiesCommon; +import org.collectionspace.services.organization.OrganizationsCommon; +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; + +/** + * OrgAuthorityServiceTest, carries out tests against a + * deployed and running OrgAuthority Service. + * + * $LastChangedRevision: 753 $ + * $LastChangedDate: 2009-09-23 11:03:36 -0700 (Wed, 23 Sep 2009) $ + */ +public class OrgAuthorityBaseImport { + private static final Logger logger = + LoggerFactory.getLogger(OrgAuthorityBaseImport.class); + + // Instance variables specific to this test. + private OrgAuthorityClient client = new OrgAuthorityClient(); + final String SERVICE_PATH_COMPONENT = "orgauthorities"; + final String ITEM_SERVICE_PATH_COMPONENT = "items"; + + public void createOrgAuthority(String orgAuthorityName, List enumValues ) { + + // 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 orgAuthority: \"" + orgAuthorityName +"\""); + } + MultipartOutput multipart = createOrgAuthorityInstance(orgAuthorityName, + createRefName(orgAuthorityName), "enum"); + ClientResponse res = client.create(multipart); + + int statusCode = res.getStatus(); + + if(!REQUEST_TYPE.isValidStatusCode(statusCode)) { + throw new RuntimeException("Could not create enumeration: \""+orgAuthorityName + +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + } + if(statusCode != EXPECTED_STATUS_CODE) { + throw new RuntimeException("Unexpected Status when creating enumeration: \"" + +orgAuthorityName +"\", Status:"+ statusCode); + } + + // Store the ID returned from this create operation + // for additional tests below. + String newOrgAuthorityId = extractId(res); + if(logger.isDebugEnabled()){ + logger.debug("Import: Created orgAuthorityulary: \"" + orgAuthorityName +"\" ID:" + +newOrgAuthorityId ); + } + for(String itemName : enumValues){ + createItemInOrgAuthority(newOrgAuthorityId, orgAuthorityName, itemName, createRefName(itemName)); + } + } + + private String createItemInOrgAuthority(String vcsid, String orgAuthorityName, String itemName, String refName) { + // 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 Item: \""+itemName+"\" in orgAuthorityulary: \"" + orgAuthorityName +"\""); + } + MultipartOutput multipart = createOrganizationInstance(itemName, refName); + ClientResponse res = client.createItem(vcsid, multipart); + + int statusCode = res.getStatus(); + + if(!REQUEST_TYPE.isValidStatusCode(statusCode)) { + throw new RuntimeException("Could not create Item: \""+itemName + +"\" in orgAuthority: \"" + orgAuthorityName + +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + } + if(statusCode != EXPECTED_STATUS_CODE) { + throw new RuntimeException("Unexpected Status when creating Item: \""+itemName + +"\" in orgAuthority: \"" + orgAuthorityName +"\", Status:"+ statusCode); + } + + return extractId(res); + } + + // --------------------------------------------------------------- + // Utility methods used by tests above + // --------------------------------------------------------------- + + private MultipartOutput createOrgAuthorityInstance( + String displayName, String refName, String vocabType) { + OrgauthoritiesCommon orgAuthority = new OrgauthoritiesCommon(); + orgAuthority.setDisplayName(displayName); + orgAuthority.setRefName(refName); + orgAuthority.setVocabType(vocabType); + MultipartOutput multipart = new MultipartOutput(); + OutputPart commonPart = multipart.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", client.getCommonPartName()); + + if(logger.isDebugEnabled()){ + logger.debug("to be created, orgAuthority common ", + orgAuthority, OrgauthoritiesCommon.class); + } + + return multipart; + } + + private MultipartOutput createOrganizationInstance( + String displayName, String refName) { + OrganizationsCommon organization = new OrganizationsCommon(); + organization.setDisplayName(displayName); + organization.setRefName(refName); + MultipartOutput multipart = new MultipartOutput(); + OutputPart commonPart = multipart.addPart(organization, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", client.getItemCommonPartName()); + + if(logger.isDebugEnabled()){ + logger.debug("to be created, organization common ", organization, OrganizationsCommon.class); + } + + return multipart; + } + + + /** + * 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. + */ + protected String invalidStatusCodeMessage(ServiceRequestType requestType, int statusCode) { + return "Status code '" + statusCode + "' in response is NOT within the expected set: " + + requestType.validStatusCodesAsString(); + } + + protected 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; + } + + protected String createRefName(String displayName) { + return displayName.replaceAll("\\W", ""); + } + + public static void main(String[] args) { + + BasicConfigurator.configure(); + logger.info("OrgAuthorityBaseImport starting..."); + + OrgAuthorityBaseImport oabi = new OrgAuthorityBaseImport(); + final String acquisitionMethodsOrgAuthorityName = "Acquisition Methods"; + final String entryMethodsOrgAuthorityName = "Entry Methods"; + final String entryReasonsOrgAuthorityName = "Entry Reasons"; + final String responsibleDeptsOrgAuthorityName = "Responsible Departments"; + + List acquisitionMethodsEnumValues = + Arrays.asList("Gift","Purchase","Exchange","Transfer","Treasure"); + List entryMethodsEnumValues = + Arrays.asList("In person","Post","Found on doorstep"); + List entryReasonsEnumValues = + Arrays.asList("Enquiry","Commission","Loan"); + List respDeptNamesEnumValues = + Arrays.asList("Antiquities","Architecture and Design","Decorative Arts", + "Ethnography","Herpetology","Media and Performance Art", + "Paintings and Sculpture","Paleobotany","Photographs", + "Prints and Drawings"); + + oabi.createOrgAuthority(acquisitionMethodsOrgAuthorityName, acquisitionMethodsEnumValues); + oabi.createOrgAuthority(entryMethodsOrgAuthorityName, entryMethodsEnumValues); + oabi.createOrgAuthority(entryReasonsOrgAuthorityName, entryReasonsEnumValues); + oabi.createOrgAuthority(responsibleDeptsOrgAuthorityName, respDeptNamesEnumValues); + + logger.info("OrgAuthorityBaseImport complete."); + } +} diff --git a/services/organization/installer/build.xml b/services/organization/installer/build.xml new file mode 100644 index 000000000..250fa2a51 --- /dev/null +++ b/services/organization/installer/build.xml @@ -0,0 +1,61 @@ + + + + organization service + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/organization/jaxb/.classpath b/services/organization/jaxb/.classpath new file mode 100644 index 000000000..fef07b28f --- /dev/null +++ b/services/organization/jaxb/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/services/organization/jaxb/.project b/services/organization/jaxb/.project new file mode 100644 index 000000000..4e8829944 --- /dev/null +++ b/services/organization/jaxb/.project @@ -0,0 +1,23 @@ + + + org.collectionspace.services.organization.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/organization/jaxb/.settings/org.eclipse.jdt.core.prefs b/services/organization/jaxb/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..0b4dbbea4 --- /dev/null +++ b/services/organization/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/organization/jaxb/.settings/org.maven.ide.eclipse.prefs b/services/organization/jaxb/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 000000000..528843671 --- /dev/null +++ b/services/organization/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/organization/jaxb/pom.xml b/services/organization/jaxb/pom.xml new file mode 100644 index 000000000..22259af53 --- /dev/null +++ b/services/organization/jaxb/pom.xml @@ -0,0 +1,105 @@ + + + + + org.collectionspace.services.organization + org.collectionspace.services + 1.0 + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.organization.jaxb + 1.0 + services.organization.jaxb + + + + com.sun.xml.bind + jaxb-impl + 2.0.2 + + + org.jvnet.jaxb2-commons + property-listener-injector + 1.0 + + + org.jvnet.jaxb2_commons + runtime + 0.4.1.4 + + + + collectionspace-services-organization-jaxb + install + + + org.jvnet.jaxb2.maven2 + maven-jaxb2-plugin + + + + generate + + + + + + + javax.activation + activation + 1.1 + + + com.sun.xml.bind + jaxb-impl + 2.1.2 + + + + + -XtoString + -Xinject-listener-code + + + + + + + org.jvnet.jaxb2_commons + + basic + 0.4.1 + + + + org.jvnet.jaxb2-commons + + + property-listener-injector + + 1.0 + + + + + + + + maven-compiler-plugin + 2.0.2 + + 1.6 + 1.6 + + + + + + diff --git a/services/organization/jaxb/src/main/java/org/collectionspace/services/OrgAuthorityJAXBSchema.java b/services/organization/jaxb/src/main/java/org/collectionspace/services/OrgAuthorityJAXBSchema.java new file mode 100644 index 000000000..ad674843b --- /dev/null +++ b/services/organization/jaxb/src/main/java/org/collectionspace/services/OrgAuthorityJAXBSchema.java @@ -0,0 +1,17 @@ +/** + * + */ +package org.collectionspace.services; + +/** + * @author pschmitz + * + */ +public interface OrgAuthorityJAXBSchema { + 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/organization/jaxb/src/main/java/org/collectionspace/services/OrgAuthorityListItemJAXBSchema.java b/services/organization/jaxb/src/main/java/org/collectionspace/services/OrgAuthorityListItemJAXBSchema.java new file mode 100644 index 000000000..d326dc9ff --- /dev/null +++ b/services/organization/jaxb/src/main/java/org/collectionspace/services/OrgAuthorityListItemJAXBSchema.java @@ -0,0 +1,9 @@ +package org.collectionspace.services; + +public interface OrgAuthorityListItemJAXBSchema { + 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/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationJAXBSchema.java b/services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationJAXBSchema.java new file mode 100644 index 000000000..67ae42287 --- /dev/null +++ b/services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationJAXBSchema.java @@ -0,0 +1,18 @@ +/** + * + */ +package org.collectionspace.services; + +/** + * @author pschmitz + * + */ +public interface OrganizationJAXBSchema { + final static String DISPLAY_NAME = "displayName"; + final static String REF_NAME = "refName"; + final static String CSID = "csid"; + final static String LONG_NAME = "longName"; + final static String DESCRIPTION = "description"; +} + + diff --git a/services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationListItemJAXBSchema.java b/services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationListItemJAXBSchema.java new file mode 100644 index 000000000..86653cf18 --- /dev/null +++ b/services/organization/jaxb/src/main/java/org/collectionspace/services/OrganizationListItemJAXBSchema.java @@ -0,0 +1,8 @@ +package org.collectionspace.services; + +public interface OrganizationListItemJAXBSchema { + 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/organization/jaxb/src/main/resources/organization_common.xsd b/services/organization/jaxb/src/main/resources/organization_common.xsd new file mode 100644 index 000000000..3104fbd37 --- /dev/null +++ b/services/organization/jaxb/src/main/resources/organization_common.xsd @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/organization/jaxb/src/main/resources/orgauthority_common.xsd b/services/organization/jaxb/src/main/resources/orgauthority_common.xsd new file mode 100644 index 000000000..8859e2617 --- /dev/null +++ b/services/organization/jaxb/src/main/resources/orgauthority_common.xsd @@ -0,0 +1,70 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/organization/pom.xml b/services/organization/pom.xml new file mode 100644 index 000000000..06a65c2aa --- /dev/null +++ b/services/organization/pom.xml @@ -0,0 +1,70 @@ + + + + org.collectionspace.services.main + org.collectionspace.services + 1.0 + + 4.0.0 + org.collectionspace.services + 1.0 + org.collectionspace.services.organization + pom + services.organization + + + jaxb + service + 3rdparty + client + import + sample + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.5 + 1.5 + + + + org.apache.maven.plugins + maven-site-plugin + + /usr/bin/unzip -o > err.txt + + + + org.apache.maven.plugins + maven-war-plugin + 2.0.1 + + WEB-INF/lib/*.jar + + + true + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.0.2 + + 1.6 + 1.6 + + + + + + diff --git a/services/organization/sample/.classpath b/services/organization/sample/.classpath new file mode 100644 index 000000000..d8f291998 --- /dev/null +++ b/services/organization/sample/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/services/organization/sample/.project b/services/organization/sample/.project new file mode 100644 index 000000000..9c027e0c8 --- /dev/null +++ b/services/organization/sample/.project @@ -0,0 +1,23 @@ + + + org.collectionspace.services.organization.samples + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.maven.ide.eclipse.maven2Nature + + diff --git a/services/organization/sample/.settings/org.eclipse.jdt.core.prefs b/services/organization/sample/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..9fa2bf3ac --- /dev/null +++ b/services/organization/sample/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +#Mon Nov 23 11:54:01 PST 2009 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 +org.eclipse.jdt.core.compiler.compliance=1.4 +org.eclipse.jdt.core.compiler.source=1.3 diff --git a/services/organization/sample/.settings/org.maven.ide.eclipse.prefs b/services/organization/sample/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 000000000..e3f71bde4 --- /dev/null +++ b/services/organization/sample/.settings/org.maven.ide.eclipse.prefs @@ -0,0 +1,9 @@ +#Mon Nov 23 11:53:50 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/organization/sample/pom.xml b/services/organization/sample/pom.xml new file mode 100644 index 000000000..9a991a1d1 --- /dev/null +++ b/services/organization/sample/pom.xml @@ -0,0 +1,14 @@ + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.organization.client.samples + pom + 1.0 + organization.client.samples + + + sample + + + diff --git a/services/organization/sample/sample/.classpath b/services/organization/sample/sample/.classpath new file mode 100644 index 000000000..c7613edd3 --- /dev/null +++ b/services/organization/sample/sample/.classpath @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/organization/sample/sample/.project b/services/organization/sample/sample/.project new file mode 100644 index 000000000..86c07bf67 --- /dev/null +++ b/services/organization/sample/sample/.project @@ -0,0 +1,17 @@ + + org.collectionspace.services.organization.client.sample + + + + + org.eclipse.jdt.core.javabuilder + + + org.maven.ide.eclipse.maven2Builder + + + + org.maven.ide.eclipse.maven2Nature + org.eclipse.jdt.core.javanature + + diff --git a/services/organization/sample/sample/.settings/org.eclipse.jdt.core.prefs b/services/organization/sample/sample/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..8ee16c274 --- /dev/null +++ b/services/organization/sample/sample/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +#Fri Oct 02 14:55:57 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/organization/sample/sample/.settings/org.maven.ide.eclipse.prefs b/services/organization/sample/sample/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 000000000..0624c1a1a --- /dev/null +++ b/services/organization/sample/sample/.settings/org.maven.ide.eclipse.prefs @@ -0,0 +1,9 @@ +#Wed Sep 16 16:14: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/organization/sample/sample/pom.xml b/services/organization/sample/sample/pom.xml new file mode 100644 index 000000000..03ef7c52e --- /dev/null +++ b/services/organization/sample/sample/pom.xml @@ -0,0 +1,112 @@ + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.organization.client.sample + jar + 1.0 + organization.client.sample + + + + org.collectionspace.services + org.collectionspace.services.organization.jaxb + 1.0 + + + org.collectionspace.services + org.collectionspace.services.client + 1.0 + + + org.collectionspace.services + org.collectionspace.services.organization.client + 1.0 + + + + + + libs-releases-local + libs-releases-local + http://source.collectionspace.org:8081/artifactory/libs-releases-local + + true + + + false + + + + + libs-snapshots-local + libs-snapshots-local + http://source.collectionspace.org:8081/artifactory/libs-snapshots-local + + false + + + true + + + + collectionspace-releases + collectionspace-releases + http://source.collectionspace.org:8081/artifactory/public-nuxeo + + true + + + false + + + + collectionspace-snapshots + collectionspace-snapshots + http://source.collectionspace.org:8081/artifactory/public-snapshot-nuxeo + + false + + + true + + + + + + organization-client-sample + + + org.apache.maven.plugins + maven-assembly-plugin + + + + attached + + package + + + jar-with-dependencies + + + + org.collectionspace.services.organization.client.sample.Sample + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.6 + 1.6 + + + + + + diff --git a/services/organization/sample/sample/src/main/java/org/collectionspace/services/organization/client/sample/Sample.java b/services/organization/sample/sample/src/main/java/org/collectionspace/services/organization/client/sample/Sample.java new file mode 100644 index 000000000..cc9d7bb24 --- /dev/null +++ b/services/organization/sample/sample/src/main/java/org/collectionspace/services/organization/client/sample/Sample.java @@ -0,0 +1,548 @@ +/** + * 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.organization.client.sample; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +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.client.OrgAuthorityClient; +import org.collectionspace.services.client.test.ServiceRequestType; +import org.collectionspace.services.organization.OrgauthoritiesCommon; +import org.collectionspace.services.organization.OrgauthoritiesCommonList; +import org.collectionspace.services.organization.OrganizationsCommon; +import org.collectionspace.services.organization.OrganizationsCommonList; +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.InputPart; +import org.jboss.resteasy.plugins.providers.multipart.OutputPart; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * OrgAuthority Sample, carries out tests against a + * deployed and running OrgAuthority Service. + * + * $LastChangedRevision: 1055 $ + * $LastChangedDate: 2009-12-09 12:25:15 -0800 (Wed, 09 Dec 2009) $ + */ +public class Sample { + private static final Logger logger = + LoggerFactory.getLogger(Sample.class); + + // Instance variables specific to this test. + private OrgAuthorityClient client = new OrgAuthorityClient(); + final String SERVICE_PATH_COMPONENT = "organizations"; + final String ITEM_SERVICE_PATH_COMPONENT = "items"; + + + // --------------------------------------------------------------- + // Create + // --------------------------------------------------------------- + + public void createEnumeration(String orgAuthName, List enumValues ) { + + // Expected status code: 201 Created + int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode(); + // Type of service request being tested + ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE; + + logger.info("Import: Create orgAuthority: \"" + orgAuthName +"\""); + MultipartOutput multipart = createOrgAuthorityInstance(orgAuthName, + createRefName(orgAuthName), "enum"); + ClientResponse res = client.create(multipart); + + int statusCode = res.getStatus(); + + if(!REQUEST_TYPE.isValidStatusCode(statusCode)) { + throw new RuntimeException("Could not create enumeration: \""+orgAuthName + +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + } + if(statusCode != EXPECTED_STATUS_CODE) { + throw new RuntimeException("Unexpected Status when creating enumeration: \"" + +orgAuthName +"\", Status:"+ statusCode); + } + + // Store the ID returned from this create operation + // for additional tests below. + String newOrgAuthId = extractId(res); + logger.info("Import: Created orgAuthority: \"" + orgAuthName +"\" ID:" + +newOrgAuthId ); + + // Add items to the orgAuthority + for(String itemName : enumValues){ + createItemInOrgAuth(newOrgAuthId, orgAuthName, itemName, createRefName(itemName)); + } + + } + + private String createItemInOrgAuth(String vcsid, String orgAuthName, String itemName, String refName) { + // Expected status code: 201 Created + int EXPECTED_STATUS_CODE = Response.Status.CREATED.getStatusCode(); + // Type of service request being tested + ServiceRequestType REQUEST_TYPE = ServiceRequestType.CREATE; + + logger.info("Import: Create Item: \""+itemName+"\" in orgAuthority: \"" + orgAuthName +"\""); + MultipartOutput multipart = createOrganizationInstance(itemName, refName); + ClientResponse res = client.createItem(vcsid, multipart); + + int statusCode = res.getStatus(); + + if(!REQUEST_TYPE.isValidStatusCode(statusCode)) { + throw new RuntimeException("Could not create Item: \""+itemName + +"\" in orgAuthority: \"" + orgAuthName + +"\" "+ invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + } + if(statusCode != EXPECTED_STATUS_CODE) { + throw new RuntimeException("Unexpected Status when creating Item: \""+itemName + +"\" in orgAuthority: \"" + orgAuthName +"\", Status:"+ statusCode); + } + + return extractId(res); + } + + + // --------------------------------------------------------------- + // Read + // --------------------------------------------------------------- + + private OrgauthoritiesCommonList readOrgAuthorities() { + + // Expected status code: 200 OK + int EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode(); + // Type of service request being tested + ServiceRequestType REQUEST_TYPE = ServiceRequestType.READ; + + // Submit the request to the service and store the response. + ClientResponse res = client.readList(); + OrgauthoritiesCommonList list = res.getEntity(); + + int statusCode = res.getStatus(); + if(!REQUEST_TYPE.isValidStatusCode(statusCode)) { + throw new RuntimeException("Could not read list of orgAuthorities: " + + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + } + if(statusCode != EXPECTED_STATUS_CODE) { + throw new RuntimeException("Unexpected Status when reading " + + "list of orgAuthorities, Status:"+ statusCode); + } + + return list; + } + + private List readOrgAuthorityIds(OrgauthoritiesCommonList list) { + + List ids = new ArrayList(); + List orgAuthorities = + list.getOrgauthorityListItem(); + for (OrgauthoritiesCommonList.OrgauthorityListItem orgAuthority : orgAuthorities) { + ids.add(orgAuthority.getCsid()); + } + return ids; + } + + private OrgauthoritiesCommon readOrgAuthority(String orgAuthId) { + + // Expected status code: 200 OK + int EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode(); + // Type of service request being tested + ServiceRequestType REQUEST_TYPE = ServiceRequestType.READ; + + // Submit the request to the service and store the response. + OrgauthoritiesCommon orgAuthority = null; + try { + ClientResponse res = client.read(orgAuthId); + int statusCode = res.getStatus(); + if(!REQUEST_TYPE.isValidStatusCode(statusCode)) { + throw new RuntimeException("Could not read orgAuthority" + + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + } + if(statusCode != EXPECTED_STATUS_CODE) { + throw new RuntimeException("Unexpected Status when reading " + + "orgAuthority, Status:"+ statusCode); + } + MultipartInput input = (MultipartInput) res.getEntity(); + orgAuthority = (OrgauthoritiesCommon) extractPart(input, + client.getCommonPartName(), OrgauthoritiesCommon.class); + } catch (Exception e) { + throw new RuntimeException("Could not read orgAuthority: ", e); + } + + return orgAuthority; + } + + private OrganizationsCommonList readItemsInOrgAuth(String orgAuthId) { + + // Expected status code: 200 OK + int EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode(); + // Type of service request being tested + ServiceRequestType REQUEST_TYPE = ServiceRequestType.READ; + + // Submit the request to the service and store the response. + ClientResponse res = + client.readItemList(orgAuthId); + OrganizationsCommonList list = res.getEntity(); + + int statusCode = res.getStatus(); + + if(!REQUEST_TYPE.isValidStatusCode(statusCode)) { + throw new RuntimeException("Could not read items in orgAuthority: " + + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + } + if(statusCode != EXPECTED_STATUS_CODE) { + throw new RuntimeException("Unexpected Status when reading " + + "items in orgAuthority, Status:"+ statusCode); + } + + return list; + } + + private List readOrganizationIds(OrganizationsCommonList list) { + + List ids = new ArrayList(); + List items = + list.getOrganizationListItem(); + for (OrganizationsCommonList.OrganizationListItem item : items) { + ids.add(item.getCsid()); + } + return ids; + } + + // --------------------------------------------------------------- + // Delete + // --------------------------------------------------------------- + + private void deleteOrgAuthority(String vcsid) { + // Expected status code: 200 OK + int EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode(); + // Type of service request being tested + ServiceRequestType REQUEST_TYPE = ServiceRequestType.DELETE; + + ClientResponse res = client.delete(vcsid); + int statusCode = res.getStatus(); + + if(!REQUEST_TYPE.isValidStatusCode(statusCode)) { + throw new RuntimeException("Could not delete orgAuthority: " + + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + } + if(statusCode != EXPECTED_STATUS_CODE) { + throw new RuntimeException("Unexpected Status when deleting " + + "orgAuthority, Status:"+ statusCode); + } + } + + private void deleteAllOrgAuthorities() { + List ids = readOrgAuthorityIds(readOrgAuthorities()); + for (String id : ids) { + deleteOrgAuthority(id); + } + } + + private void deleteOrganization(String vcsid, String itemcsid) { + // Expected status code: 200 OK + int EXPECTED_STATUS_CODE = Response.Status.OK.getStatusCode(); + // Type of service request being tested + ServiceRequestType REQUEST_TYPE = ServiceRequestType.DELETE; + + ClientResponse res = client.deleteItem(vcsid, itemcsid); + int statusCode = res.getStatus(); + + if(!REQUEST_TYPE.isValidStatusCode(statusCode)) { + throw new RuntimeException("Could not delete orgAuthority item: " + + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + } + if(statusCode != EXPECTED_STATUS_CODE) { + throw new RuntimeException("Unexpected Status when deleting " + + "orgAuthority item, Status:"+ statusCode); + } + } + + private void deleteAllItemsForOrgAuth(String orgAuthId) { + List itemIds = readOrganizationIds(readItemsInOrgAuth(orgAuthId)); + for (String itemId : itemIds) { + deleteOrganization(orgAuthId, itemId); + } + } + + // --------------------------------------------------------------- + // Utility methods used by tests above + // --------------------------------------------------------------- + + private MultipartOutput createOrgAuthorityInstance( + String displayName, String refName, String vocabType) { + OrgauthoritiesCommon orgAuthority = new OrgauthoritiesCommon(); + orgAuthority.setDisplayName(displayName); + orgAuthority.setRefName(refName); + orgAuthority.setVocabType(vocabType); + MultipartOutput multipart = new MultipartOutput(); + OutputPart commonPart = multipart.addPart(orgAuthority, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", client.getCommonPartName()); + + if(logger.isDebugEnabled()){ + logger.debug("to be created, orgAuthority common ", + orgAuthority, OrgauthoritiesCommon.class); + } + + return multipart; + } + + private MultipartOutput createOrganizationInstance( + String displayName, String refName) { + OrganizationsCommon organization = new OrganizationsCommon(); + organization.setDisplayName(displayName); + organization.setRefName(refName); + MultipartOutput multipart = new MultipartOutput(); + OutputPart commonPart = multipart.addPart(organization, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", client.getItemCommonPartName()); + + if(logger.isDebugEnabled()){ + logger.debug("to be created, organization common ", organization, OrganizationsCommon.class); + } + + return multipart; + } + + // Retrieve individual fields of orgAuthority records. + + private String displayAllOrgAuthorities(OrgauthoritiesCommonList list) { + StringBuffer sb = new StringBuffer(); + List orgAuthorities = + list.getOrgauthorityListItem(); + int i = 0; + for (OrgauthoritiesCommonList.OrgauthorityListItem orgAuthority : orgAuthorities) { + sb.append("orgAuthority [" + i + "]" + "\n"); + sb.append(displayOrgAuthorityDetails(orgAuthority)); + i++; + } + return sb.toString(); + } + + private String displayOrgAuthorityDetails( + OrgauthoritiesCommonList.OrgauthorityListItem orgAuthority) { + StringBuffer sb = new StringBuffer(); + sb.append("displayName=" + orgAuthority.getDisplayName() + "\n"); + sb.append("vocabType=" + orgAuthority.getVocabType() + "\n"); + // sb.append("csid=" + orgAuthority.getCsid() + "\n"); + sb.append("URI=" + orgAuthority.getUri() + "\n"); + return sb.toString(); + } + + // Retrieve individual fields of organization records. + + private String displayAllOrganizations(OrganizationsCommonList list) { + StringBuffer sb = new StringBuffer(); + List items = + list.getOrganizationListItem(); + int i = 0; + for (OrganizationsCommonList.OrganizationListItem item : items) { + sb.append("organization [" + i + "]" + "\n"); + sb.append(displayOrganizationDetails(item)); + i++; + } + return sb.toString(); + } + + private String displayOrganizationDetails( + OrganizationsCommonList.OrganizationListItem item) { + StringBuffer sb = new StringBuffer(); + sb.append("csid=" + item.getCsid() + "\n"); + sb.append("displayName=" + item.getDisplayName() + "\n"); + // sb.append("URI=" + item.getUri() + "\n"); + return sb.toString(); + } + + private Object extractPart(MultipartInput input, String label, + Class clazz) throws Exception { + Object obj = null; + for(InputPart part : input.getParts()){ + String partLabel = part.getHeaders().getFirst("label"); + if(label.equalsIgnoreCase(partLabel)){ + String partStr = part.getBodyAsString(); + if(logger.isDebugEnabled()){ + logger.debug("extracted part str=\n" + partStr); + } + obj = part.getBody(clazz, null); + if(logger.isDebugEnabled()){ + logger.debug("extracted part obj=\n", obj, clazz); + } + break; + } + } + return obj; + } + + /** + * 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. + */ + protected String invalidStatusCodeMessage(ServiceRequestType requestType, int statusCode) { + return "Status code '" + statusCode + "' in response is NOT within the expected set: " + + requestType.validStatusCodesAsString(); + } + + protected String extractId(ClientResponse res) { + MultivaluedMap mvm = res.getMetadata(); + String uri = (String) ((ArrayList) mvm.get("Location")).get(0); + if(logger.isDebugEnabled()){ + logger.info("extractId:uri=" + uri); + } + String[] segments = uri.split("/"); + String id = segments[segments.length - 1]; + if(logger.isDebugEnabled()){ + logger.debug("id=" + id); + } + return id; + } + + protected String createRefName(String displayName) { + return displayName.replaceAll("\\W", ""); + } + + public static void main(String[] args) { + + // Configure logging. + BasicConfigurator.configure(); + + logger.info("OrgAuthority Sample starting..."); + + Sample vbi = new Sample(); + OrgauthoritiesCommonList orgAuthorities; + List orgAuthIds; + String details = ""; + + // Optionally delete all orgAuthorities and organizations. + + boolean ENABLE_DELETE_ALL = false; + if (ENABLE_DELETE_ALL) { + + logger.info("Deleting all organizations and orgAuthorities ..."); + + // For each orgAuthority ... + orgAuthorities = vbi.readOrgAuthorities(); + orgAuthIds = vbi.readOrgAuthorityIds(orgAuthorities); + for (String orgAuthId : orgAuthIds) { + logger.info("Deleting all organizations for orgAuthority ..."); + vbi.deleteAllItemsForOrgAuth(orgAuthId); + logger.info("Deleting orgAuthority ..."); + vbi.deleteOrgAuthority(orgAuthId); + } + + logger.info("Reading orgAuthorities after deletion ..."); + orgAuthorities = vbi.readOrgAuthorities(); + details = vbi.displayAllOrgAuthorities(orgAuthorities); + logger.info(details); + + logger.info("Reading items in each orgAuthority after deletion ..."); + orgAuthIds = vbi.readOrgAuthorityIds(orgAuthorities); + for (String orgAuthId : orgAuthIds) { + OrganizationsCommonList items = vbi.readItemsInOrgAuth(orgAuthId); + details = vbi.displayAllOrganizations(items); + logger.info(details); + } + + } + + // Create new authorities, each populated with organizations. + + /* + final String acquisitionMethodsVocabName = "Acquisition Methods"; + final String entryMethodsVocabName = "Entry Methods"; + final String entryReasonsVocabName = "Entry Reasons"; + final String responsibleDeptsVocabName = "Responsible Departments"; + + List acquisitionMethodsEnumValues = + Arrays.asList("Gift","Purchase","Exchange","Transfer","Treasure"); + List entryMethodsEnumValues = + Arrays.asList("In person","Post","Found on doorstep"); + List entryReasonsEnumValues = + Arrays.asList("Enquiry","Commission","Loan"); + List respDeptNamesEnumValues = + Arrays.asList("Antiquities","Architecture and Design","Decorative Arts", + "Ethnography","Herpetology","Media and Performance Art", + "Paintings and Sculpture","Paleobotany","Photographs", + "Prints and Drawings"); + + vbi.createEnumeration(acquisitionMethodsVocabName, acquisitionMethodsEnumValues); + vbi.createEnumeration(entryMethodsVocabName, entryMethodsEnumValues); + vbi.createEnumeration(entryReasonsVocabName, entryReasonsEnumValues); + vbi.createEnumeration(responsibleDeptsVocabName, respDeptNamesEnumValues); + */ + + logger.info("OrgAuthority Sample complete."); + + logger.info("Reading orgAuthorities and items ..."); + // Get a list of orgAuthorities. + orgAuthorities = vbi.readOrgAuthorities(); + // For each orgAuthority ... + for (OrgauthoritiesCommonList.OrgauthorityListItem + orgAuthority : orgAuthorities.getOrgauthorityListItem()) { + // Get its display name. + logger.info(orgAuthority.getDisplayName()); + // Get a list of the organizations in this orgAuthority. + OrganizationsCommonList items = + vbi.readItemsInOrgAuth(orgAuthority.getCsid()); + // For each organization ... + for (OrganizationsCommonList.OrganizationListItem + item : items.getOrganizationListItem()) { + // Get its display name. + logger.info(" " + item.getDisplayName()); + } + } + + // Sample alternate methods of reading all orgAuthorities and + // organizations separately. + boolean RUN_ADDITIONAL_SAMPLES = false; + if (RUN_ADDITIONAL_SAMPLES) { + + logger.info("Reading all orgAuthorities ..."); + details = vbi.displayAllOrgAuthorities(orgAuthorities); + logger.info(details); + + logger.info("Reading all organizations ..."); + orgAuthIds = vbi.readOrgAuthorityIds(orgAuthorities); + for (String orgAuthId : orgAuthIds) { + OrganizationsCommonList items = vbi.readItemsInOrgAuth(orgAuthId); + details = vbi.displayAllOrganizations(items); + logger.info(details); + } + + } + + } + +} diff --git a/services/organization/sample/sample/src/main/resources/collectionspace-client.properties b/services/organization/sample/sample/src/main/resources/collectionspace-client.properties new file mode 100644 index 000000000..429b9f6fe --- /dev/null +++ b/services/organization/sample/sample/src/main/resources/collectionspace-client.properties @@ -0,0 +1,6 @@ +#url of the collectionspace server +cspace.url=http://localhost:8180/cspace-services/ +cspace.ssl=false +cspace.auth=false +cspace.user=test +cspace.password=test \ No newline at end of file diff --git a/services/organization/sample/sample/src/main/resources/log4j.xml b/services/organization/sample/sample/src/main/resources/log4j.xml new file mode 100644 index 000000000..2e9dd00c1 --- /dev/null +++ b/services/organization/sample/sample/src/main/resources/log4j.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/organization/service/.classpath b/services/organization/service/.classpath new file mode 100644 index 000000000..425cd1620 --- /dev/null +++ b/services/organization/service/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/services/organization/service/.project b/services/organization/service/.project new file mode 100644 index 000000000..d7542a34a --- /dev/null +++ b/services/organization/service/.project @@ -0,0 +1,25 @@ + + + org.collectionspace.services.organization.service + + + org.collectionspace.services.common + org.collectionspace.services.organization.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/organization/service/pom.xml b/services/organization/service/pom.xml new file mode 100644 index 000000000..a307e2ad0 --- /dev/null +++ b/services/organization/service/pom.xml @@ -0,0 +1,154 @@ + + + + + org.collectionspace.services.organization + org.collectionspace.services + 1.0 + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.organization.service + jar + 1.0 + services.organization.service + + + + org.collectionspace.services + org.collectionspace.services.common + 1.0 + + + org.collectionspace.services + org.collectionspace.services.organization.jaxb + 1.0 + + + org.slf4j + slf4j-api + + + org.slf4j + slf4j-log4j12 + + + 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 + 1.0.2.GA + + + tjws + webserver + + + + + org.jboss.resteasy + resteasy-jaxb-provider + 1.0.2.GA + + + org.jboss.resteasy + resteasy-multipart-provider + 1.0.2.GA + + + + + + org.nuxeo.ecm.core + nuxeo-core-api + ${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-organization + + + org.codehaus.mojo + jboss-maven-plugin + + ${jboss.dir} + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.6 + 1.6 + + + + + + diff --git a/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java b/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java new file mode 100644 index 000000000..4f8ddb8a7 --- /dev/null +++ b/services/organization/service/src/main/java/org/collectionspace/services/organization/OrgAuthorityResource.java @@ -0,0 +1,524 @@ +/** + * 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.organization; + +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.WebApplicationException; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; +import javax.ws.rs.core.UriInfo; + +import org.collectionspace.services.common.AbstractCollectionSpaceResource; +import org.collectionspace.services.common.ClientType; +import org.collectionspace.services.common.ServiceMain; +import org.collectionspace.services.common.context.MultipartServiceContext; +import org.collectionspace.services.common.context.MultipartServiceContextFactory; +import org.collectionspace.services.common.context.ServiceContext; +import org.collectionspace.services.common.document.DocumentFilter; +import org.collectionspace.services.common.document.DocumentHandler; +import org.collectionspace.services.common.document.DocumentNotFoundException; +import org.collectionspace.services.common.security.UnauthorizedException; +import org.collectionspace.services.organization.nuxeo.OrgAuthorityHandlerFactory; +import org.collectionspace.services.organization.nuxeo.OrganizationDocumentModelHandler; +import org.collectionspace.services.organization.nuxeo.OrganizationHandlerFactory; +import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; +import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; +import org.jboss.resteasy.util.HttpResponseCodes; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Path("/orgauthorities") +@Consumes("multipart/mixed") +@Produces("multipart/mixed") +public class OrgAuthorityResource extends AbstractCollectionSpaceResource { + + private final static String orgAuthorityServiceName = "orgauthorities"; + private final static String organizationServiceName = "organizations"; + final Logger logger = LoggerFactory.getLogger(OrgAuthorityResource.class); + //FIXME retrieve client type from configuration + final static ClientType CLIENT_TYPE = ServiceMain.getInstance().getClientType(); + + public OrgAuthorityResource() { + // do nothing + } + + @Override + public String getServiceName() { + return orgAuthorityServiceName; + } + + public String getItemServiceName() { + return organizationServiceName; + } + + /* + public RemoteServiceContext createItemServiceContext(MultipartInput input) throws Exception { + RemoteServiceContext ctx = new RemoteServiceContextImpl(getItemServiceName()); + ctx.setInput(input); + return ctx; + } + */ + @Override + public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception { + DocumentHandler docHandler = OrgAuthorityHandlerFactory.getInstance().getHandler( + ctx.getRepositoryClientType().toString()); + docHandler.setServiceContext(ctx); + if (ctx.getInput() != null) { + Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(), OrgauthoritiesCommon.class); + if (obj != null) { + docHandler.setCommonPart((OrgauthoritiesCommon) obj); + } + } + return docHandler; + } + + private DocumentHandler createItemDocumentHandler( + ServiceContext ctx, + String inOrgAuthority) throws Exception { + DocumentHandler docHandler = OrganizationHandlerFactory.getInstance().getHandler( + ctx.getRepositoryClientType().toString()); + docHandler.setServiceContext(ctx); + ((OrganizationDocumentModelHandler) docHandler).setInOrgAuthority(inOrgAuthority); + if (ctx.getInput() != null) { + Object obj = ((MultipartServiceContext) ctx).getInputPart(ctx.getCommonPartLabel(getItemServiceName()), + OrganizationsCommon.class); + if (obj != null) { + docHandler.setCommonPart((OrganizationsCommon) obj); + } + } + return docHandler; + } + + @POST + public Response createOrgAuthority(MultipartInput input) { + try { + ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getServiceName()); + DocumentHandler handler = createDocumentHandler(ctx); + String csid = getRepositoryClient(ctx).create(ctx, handler); + //orgAuthorityObject.setCsid(csid); + UriBuilder path = UriBuilder.fromResource(OrgAuthorityResource.class); + path.path("" + csid); + Response response = Response.created(path.build()).build(); + return response; + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Create failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("Caught exception in createOrgAuthority", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + } + + @GET + @Path("{csid}") + public MultipartOutput getOrgAuthority(@PathParam("csid") String csid) { + String idValue = null; + if (csid == null) { + logger.error("getOrgAuthority: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "get failed on OrgAuthority csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + if (logger.isDebugEnabled()) { + logger.debug("getOrgAuthority with path(id)=" + csid); + } + MultipartOutput result = null; + try { + ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName()); + DocumentHandler handler = createDocumentHandler(ctx); + getRepositoryClient(ctx).get(ctx, csid, handler); + result = (MultipartOutput) ctx.getOutput(); + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (DocumentNotFoundException dnfe) { + if (logger.isDebugEnabled()) { + logger.debug("getOrgAuthority", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed on OrgAuthority csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("getOrgAuthority", 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 OrgAuthority CSID:" + csid + ": was not found.").type( + "text/plain").build(); + throw new WebApplicationException(response); + } + return result; + } + + @GET + @Produces("application/xml") + public OrgauthoritiesCommonList getOrgAuthorityList(@Context UriInfo ui) { + OrgauthoritiesCommonList orgAuthorityObjectList = new OrgauthoritiesCommonList(); + try { + ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName()); + MultivaluedMap queryParams = ui.getQueryParameters(); + DocumentHandler handler = createDocumentHandler(ctx); + DocumentFilter myFilter = + DocumentFilter.CreatePaginatedDocumentFilter(queryParams); + String nameQ = queryParams.getFirst("refName"); + if (nameQ != null) { + myFilter.setWhereClause("orgauthorities_common:refName='" + nameQ + "'"); + } + handler.setDocumentFilter(myFilter); + getRepositoryClient(ctx).getFiltered(ctx, handler); + orgAuthorityObjectList = (OrgauthoritiesCommonList) 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 getOrgAuthorityList", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + return orgAuthorityObjectList; + } + + @PUT + @Path("{csid}") + public MultipartOutput updateOrgAuthority( + @PathParam("csid") String csid, + MultipartInput theUpdate) { + if (logger.isDebugEnabled()) { + logger.debug("updateOrgAuthority with csid=" + csid); + } + if (csid == null || "".equals(csid)) { + logger.error("updateOrgAuthority: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "update failed on OrgAuthority csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + MultipartOutput result = null; + try { + ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(theUpdate, getServiceName()); + DocumentHandler handler = createDocumentHandler(ctx); + getRepositoryClient(ctx).update(ctx, csid, handler); + result = (MultipartOutput) ctx.getOutput(); + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Update failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (DocumentNotFoundException dnfe) { + if (logger.isDebugEnabled()) { + logger.debug("caugth exception in updateOrgAuthority", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Update failed on OrgAuthority csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + return result; + } + + @DELETE + @Path("{csid}") + public Response deleteOrgAuthority(@PathParam("csid") String csid) { + + if (logger.isDebugEnabled()) { + logger.debug("deleteOrgAuthority with csid=" + csid); + } + if (csid == null || "".equals(csid)) { + logger.error("deleteOrgAuthority: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "delete failed on OrgAuthority csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + try { + ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName()); + getRepositoryClient(ctx).delete(ctx, csid); + return Response.status(HttpResponseCodes.SC_OK).build(); + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Delete failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (DocumentNotFoundException dnfe) { + if (logger.isDebugEnabled()) { + logger.debug("caught exception in deleteOrgAuthority", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Delete failed on OrgAuthority 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); + } + + } + + /************************************************************************* + * Organization parts - this is a sub-resource of OrgAuthority + *************************************************************************/ + @POST + @Path("{csid}/items") + public Response createOrganization(@PathParam("csid") String parentcsid, MultipartInput input) { + try { + ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getItemServiceName()); + DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); + String itemcsid = getRepositoryClient(ctx).create(ctx, handler); + UriBuilder path = UriBuilder.fromResource(OrgAuthorityResource.class); + path.path(parentcsid + "/items/" + itemcsid); + Response response = Response.created(path.build()).build(); + return response; + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Create failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("Caught exception in createOrganization", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Create failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + } + + @GET + @Path("{csid}/items/{itemcsid}") + public MultipartOutput getOrganization( + @PathParam("csid") String parentcsid, + @PathParam("itemcsid") String itemcsid) { + if (logger.isDebugEnabled()) { + logger.debug("getOrganization with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid); + } + if (parentcsid == null || "".equals(parentcsid)) { + logger.error("getOrganization: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "get failed on Organization csid=" + parentcsid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + if (itemcsid == null || "".equals(itemcsid)) { + logger.error("getOrganization: missing itemcsid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "get failed on Organization 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 = MultipartServiceContextFactory.get().createServiceContext(null, getItemServiceName()); + DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); + getRepositoryClient(ctx).get(ctx, itemcsid, handler); + // TODO should we assert that the item is in the passed orgAuthority? + 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("getOrganization", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed on Organization csid=" + itemcsid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("getOrganization", 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 Organization CSID:" + itemcsid + ": was not found.").type( + "text/plain").build(); + throw new WebApplicationException(response); + } + return result; + } + + @GET + @Path("{csid}/items") + @Produces("application/xml") + public OrganizationsCommonList getOrganizationList( + @PathParam("csid") String parentcsid, + @Context UriInfo ui) { + OrganizationsCommonList organizationObjectList = new OrganizationsCommonList(); + try { + // Note that docType defaults to the ServiceName, so we're fine with that. + ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getItemServiceName()); + DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); + MultivaluedMap queryParams = ui.getQueryParameters(); + DocumentFilter myFilter = + DocumentFilter.CreatePaginatedDocumentFilter(queryParams); + myFilter.setWhereClause( + "organizations_common:inOrgAuthority='" + parentcsid + "'"); + handler.setDocumentFilter(myFilter); + getRepositoryClient(ctx).getFiltered(ctx, handler); + organizationObjectList = (OrganizationsCommonList) 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 getOrganizationList", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + return organizationObjectList; + } + + @PUT + @Path("{csid}/items/{itemcsid}") + public MultipartOutput updateOrganization( + @PathParam("csid") String parentcsid, + @PathParam("itemcsid") String itemcsid, + MultipartInput theUpdate) { + if (logger.isDebugEnabled()) { + logger.debug("updateOrganization with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid); + } + if (parentcsid == null || "".equals(parentcsid)) { + logger.error("updateOrganization: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "update failed on Organization parentcsid=" + parentcsid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + if (itemcsid == null || "".equals(itemcsid)) { + logger.error("updateOrganization: missing itemcsid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "update failed on Organization=" + 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 = MultipartServiceContextFactory.get().createServiceContext(theUpdate, getItemServiceName()); + DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); + getRepositoryClient(ctx).update(ctx, itemcsid, handler); + result = (MultipartOutput) ctx.getOutput(); + } catch (UnauthorizedException ue) { + Response response = Response.status( + Response.Status.UNAUTHORIZED).entity("Update failed reason " + ue.getErrorReason()).type("text/plain").build(); + throw new WebApplicationException(response); + } catch (DocumentNotFoundException dnfe) { + if (logger.isDebugEnabled()) { + logger.debug("caugth exception in updateOrganization", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Update failed on Organization 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 + @Path("{csid}/items/{itemcsid}") + public Response deleteOrganization( + @PathParam("csid") String parentcsid, + @PathParam("itemcsid") String itemcsid) { + if (logger.isDebugEnabled()) { + logger.debug("deleteOrganization with parentcsid=" + parentcsid + " and itemcsid=" + itemcsid); + } + if (parentcsid == null || "".equals(parentcsid)) { + logger.error("deleteOrganization: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "delete failed on Organization parentcsid=" + parentcsid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + if (itemcsid == null || "".equals(itemcsid)) { + logger.error("deleteOrganization: missing itemcsid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "delete failed on Organization=" + 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(null, 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 deleteOrganization", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Delete failed on Organization 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/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrgAuthorityConstants.java b/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrgAuthorityConstants.java new file mode 100644 index 000000000..c21bbe958 --- /dev/null +++ b/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrgAuthorityConstants.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.organization.nuxeo; + +/** + * OrgAuthorityConstants processes CollectionObject document + * + */ +public class OrgAuthorityConstants { + + public final static String NUXEO_DOCTYPE = "OrgAuthority"; + public final static String NUXEO_SCHEMA_NAME = "orgauthority"; + public final static String NUXEO_DC_TITLE = "CollectionSpace-OrgAuthority"; +} diff --git a/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrgAuthorityDocumentModelHandler.java b/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrgAuthorityDocumentModelHandler.java new file mode 100644 index 000000000..4be73cd44 --- /dev/null +++ b/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrgAuthorityDocumentModelHandler.java @@ -0,0 +1,150 @@ +/** + * 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.organization.nuxeo; + +import java.util.Iterator; +import java.util.List; + +import org.collectionspace.services.OrgAuthorityJAXBSchema; +import org.collectionspace.services.common.document.DocumentHandler.Action; +import org.collectionspace.services.common.document.DocumentWrapper; +import org.collectionspace.services.organization.OrgauthoritiesCommon; +import org.collectionspace.services.organization.OrgauthoritiesCommonList; +import org.collectionspace.services.organization.OrgauthoritiesCommonList.OrgauthorityListItem; + +import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandler; +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; + +/** + * OrgAuthorityDocumentModelHandler + * + * $LastChangedRevision: $ + * $LastChangedDate: $ + */ +public class OrgAuthorityDocumentModelHandler + extends RemoteDocumentModelHandler { + + private final Logger logger = LoggerFactory.getLogger(OrgAuthorityDocumentModelHandler.class); + /** + * orgAuthority is used to stash JAXB object to use when handle is called + * for Action.CREATE, Action.UPDATE or Action.GET + */ + private OrgauthoritiesCommon orgAuthority; + /** + * orgAuthorityList is stashed when handle is called + * for ACTION.GET_ALL + */ + private OrgauthoritiesCommonList orgAuthorityList; + + @Override + public void prepare(Action action) throws Exception { + //no specific action needed + } + + /** + * getCommonPart get associated orgAuthority + * @return + */ + @Override + public OrgauthoritiesCommon getCommonPart() { + return orgAuthority; + } + + /** + * setCommonPart set associated orgAuthority + * @param orgAuthority + */ + @Override + public void setCommonPart(OrgauthoritiesCommon orgAuthority) { + this.orgAuthority = orgAuthority; + } + + /** + * getCommonPartList get associated orgAuthority (for index/GET_ALL) + * @return + */ + @Override + public OrgauthoritiesCommonList getCommonPartList() { + return orgAuthorityList; + } + + @Override + public void setCommonPartList(OrgauthoritiesCommonList orgAuthorityList) { + this.orgAuthorityList = orgAuthorityList; + } + + @Override + public OrgauthoritiesCommon extractCommonPart(DocumentWrapper wrapDoc) + throws Exception { + throw new UnsupportedOperationException(); + } + + @Override + public void fillCommonPart(OrgauthoritiesCommon orgAuthorityObject, DocumentWrapper wrapDoc) throws Exception { + throw new UnsupportedOperationException(); + } + + @Override + public OrgauthoritiesCommonList extractCommonPartList(DocumentWrapper wrapDoc) throws Exception { + DocumentModelList docList = wrapDoc.getWrappedObject(); + + OrgauthoritiesCommonList coList = new OrgauthoritiesCommonList(); + List list = coList.getOrgauthorityListItem(); + + //FIXME: iterating over a long list of documents is not a long term + //strategy...need to change to more efficient iterating in future + Iterator iter = docList.iterator(); + while(iter.hasNext()){ + DocumentModel docModel = iter.next(); + OrgauthorityListItem ilistItem = new OrgauthorityListItem(); + ilistItem.setDisplayName((String) docModel.getProperty(getServiceContext().getCommonPartLabel(), + OrgAuthorityJAXBSchema.DISPLAY_NAME)); + ilistItem.setRefName((String) docModel.getProperty(getServiceContext().getCommonPartLabel(), + OrgAuthorityJAXBSchema.REF_NAME)); + ilistItem.setVocabType((String) docModel.getProperty(getServiceContext().getCommonPartLabel(), + OrgAuthorityJAXBSchema.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 OrgAuthorityConstants.NUXEO_SCHEMA_NAME + ":" + prop; + } +} + diff --git a/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrgAuthorityHandlerFactory.java b/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrgAuthorityHandlerFactory.java new file mode 100644 index 000000000..b85cec657 --- /dev/null +++ b/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrgAuthorityHandlerFactory.java @@ -0,0 +1,56 @@ +/** + * 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.organization.nuxeo; + +import org.collectionspace.services.common.ClientType; +import org.collectionspace.services.common.document.DocumentHandler; +import org.collectionspace.services.common.document.DocumentHandlerFactory; + + +/** + * OrgAuthorityHandlerFactory creates handlers for organization based + * on type of Nuxeo client used + * + * $LastChangedRevision: $ + * $LastChangedDate: $ + */ +public class OrgAuthorityHandlerFactory implements DocumentHandlerFactory { + + private static final OrgAuthorityHandlerFactory self = new OrgAuthorityHandlerFactory(); + + private OrgAuthorityHandlerFactory() { + } + + public static OrgAuthorityHandlerFactory getInstance() { + return self; + } + + @Override + public DocumentHandler getHandler(String clientType) { + if(ClientType.JAVA.toString().equals(clientType)){ + return new OrgAuthorityDocumentModelHandler(); + } + throw new IllegalArgumentException("Not supported client=" + clientType); + } +} diff --git a/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationConstants.java b/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationConstants.java new file mode 100644 index 000000000..e292fcbd1 --- /dev/null +++ b/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationConstants.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.organization.nuxeo; + +/** + * OrganizationConstants processes CollectionObject document + * + */ +public class OrganizationConstants { + + public final static String NUXEO_DOCTYPE = "Organization"; + public final static String NUXEO_SCHEMA_NAME = "organization"; + public final static String NUXEO_DC_TITLE = "CollectionSpace-Organization"; +} diff --git a/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationDocumentModelHandler.java b/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationDocumentModelHandler.java new file mode 100644 index 000000000..4276f4317 --- /dev/null +++ b/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationDocumentModelHandler.java @@ -0,0 +1,178 @@ +/** + * 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.organization.nuxeo; + +import java.util.Iterator; +import java.util.List; + +import org.collectionspace.services.OrganizationJAXBSchema; +import org.collectionspace.services.common.document.DocumentWrapper; +import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandler; +import org.collectionspace.services.nuxeo.util.NuxeoUtils; +import org.collectionspace.services.organization.OrganizationsCommon; +import org.collectionspace.services.organization.OrganizationsCommonList; +import org.collectionspace.services.organization.OrganizationsCommonList.OrganizationListItem; +import org.nuxeo.ecm.core.api.DocumentModel; +import org.nuxeo.ecm.core.api.DocumentModelList; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * OrganizationDocumentModelHandler + * + * $LastChangedRevision: $ + * $LastChangedDate: $ + */ +public class OrganizationDocumentModelHandler + extends RemoteDocumentModelHandler { + + private final Logger logger = LoggerFactory.getLogger(OrganizationDocumentModelHandler.class); + /** + * organization is used to stash JAXB object to use when handle is called + * for Action.CREATE, Action.UPDATE or Action.GET + */ + private OrganizationsCommon organization; + /** + * organizationList is stashed when handle is called + * for ACTION.GET_ALL + */ + private OrganizationsCommonList organizationList; + + /** + * inOrgAuthority is the parent OrgAuthority for this context + */ + private String inOrgAuthority; + + public String getInOrgAuthority() { + return inOrgAuthority; + } + + public void setInOrgAuthority(String inOrgAuthority) { + this.inOrgAuthority = inOrgAuthority; + } + + @Override + public void prepare(Action action) throws Exception { + //no specific action needed + } + + /** + * getCommonPart get associated organization + * @return + */ + @Override + public OrganizationsCommon getCommonPart() { + return organization; + } + + /** + * setCommonPart set associated organization + * @param organization + */ + @Override + public void setCommonPart(OrganizationsCommon organization) { + this.organization = organization; + } + + /** + * getCommonPartList get associated organization (for index/GET_ALL) + * @return + */ + @Override + public OrganizationsCommonList getCommonPartList() { + return organizationList; + } + + @Override + public void setCommonPartList(OrganizationsCommonList organizationList) { + this.organizationList = organizationList; + } + + @Override + public OrganizationsCommon extractCommonPart(DocumentWrapper wrapDoc) + throws Exception { + throw new UnsupportedOperationException(); + } + + @Override + public void fillCommonPart(OrganizationsCommon organizationObject, DocumentWrapper wrapDoc) throws Exception { + throw new UnsupportedOperationException(); + } + + @Override + public OrganizationsCommonList extractCommonPartList(DocumentWrapper wrapDoc) + throws Exception { + OrganizationsCommonList coList = new OrganizationsCommonList(); + try{ + DocumentModelList docList = (DocumentModelList) wrapDoc.getWrappedObject(); + + List list = + coList.getOrganizationListItem(); + + //FIXME: iterating over a long list of documents is not a long term + //strategy...need to change to more efficient iterating in future + Iterator iter = docList.iterator(); + while(iter.hasNext()){ + DocumentModel docModel = iter.next(); + OrganizationListItem ilistItem = new OrganizationListItem(); + ilistItem.setDisplayName( + (String) docModel.getProperty(getServiceContext().getCommonPartLabel("organizations"), + OrganizationJAXBSchema.DISPLAY_NAME)); + ilistItem.setRefName( + (String) docModel.getProperty(getServiceContext().getCommonPartLabel("organizations"), + OrganizationJAXBSchema.REF_NAME)); + /* + * These are not currently included in the listing - only in the details + ilistItem.setLongName( + (String) docModel.getProperty(getServiceContext().getCommonPartLabel("organizations"), + OrganizationJAXBSchema.LONG_NAME)); + ilistItem.setDescription( + (String) docModel.getProperty(getServiceContext().getCommonPartLabel("organizations"), + OrganizationJAXBSchema.DESCRIPTION)); + */ + String id = NuxeoUtils.extractId(docModel.getPathAsString()); + ilistItem.setUri("/organizations/"+inOrgAuthority+"/items/" + id); + ilistItem.setCsid(id); + list.add(ilistItem); + } + }catch(Exception e){ + if(logger.isDebugEnabled()){ + logger.debug("Caught exception in extractCommonPartList", e); + } + throw e; + } + return coList; + } + + /** + * getQProperty converts the given property to qualified schema property + * @param prop + * @return + */ + @Override + public String getQProperty(String prop) { + return OrganizationConstants.NUXEO_SCHEMA_NAME + ":" + prop; + } +} + diff --git a/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationHandlerFactory.java b/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationHandlerFactory.java new file mode 100644 index 000000000..d756258c0 --- /dev/null +++ b/services/organization/service/src/main/java/org/collectionspace/services/organization/nuxeo/OrganizationHandlerFactory.java @@ -0,0 +1,56 @@ +/** + * 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.organization.nuxeo; + +import org.collectionspace.services.common.ClientType; +import org.collectionspace.services.common.document.DocumentHandler; +import org.collectionspace.services.common.document.DocumentHandlerFactory; + + +/** + * OrganizationHandlerFactory creates handlers for organization based + * on type of Nuxeo client used + * + * $LastChangedRevision: $ + * $LastChangedDate: $ + */ +public class OrganizationHandlerFactory implements DocumentHandlerFactory { + + private static final OrganizationHandlerFactory self = new OrganizationHandlerFactory(); + + private OrganizationHandlerFactory() { + } + + public static OrganizationHandlerFactory getInstance() { + return self; + } + + @Override + public DocumentHandler getHandler(String clientType) { + if(ClientType.JAVA.toString().equals(clientType)){ + return new OrganizationDocumentModelHandler(); + } + throw new IllegalArgumentException("Not supported client=" + clientType); + } +} -- 2.47.3