From: Aron Roberts Date: Sat, 12 Dec 2009 01:54:50 +0000 (+0000) Subject: CSPACE-114: Initial check-in of the Contact service. This is an initial check-in... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=837cebb9333af7895ab3d7b98b30eee0971fa4f6;p=tmp%2Fjakarta-migration.git CSPACE-114: Initial check-in of the Contact service. This is an initial check-in, to get its code into the SVN repository for further work. The service currently implements only a subset of three fields of the Address Information group of the Contact Information Schema. It is not yet integrated with the top-level project Maven and Ant build files. Its document type has not yet been tested in Nuxeo, nor have client tests of the service yet been run. --- diff --git a/services/contact/3rdparty/build.xml b/services/contact/3rdparty/build.xml new file mode 100644 index 000000000..8df56d79d --- /dev/null +++ b/services/contact/3rdparty/build.xml @@ -0,0 +1,125 @@ + + + + contact service 3rdparty + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/contact/3rdparty/nuxeo-platform-cs-contact/build.xml b/services/contact/3rdparty/nuxeo-platform-cs-contact/build.xml new file mode 100644 index 000000000..982de5fb5 --- /dev/null +++ b/services/contact/3rdparty/nuxeo-platform-cs-contact/build.xml @@ -0,0 +1,134 @@ + + + + contact nuxeo document type + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/contact/3rdparty/nuxeo-platform-cs-contact/pom.xml b/services/contact/3rdparty/nuxeo-platform-cs-contact/pom.xml new file mode 100644 index 000000000..1f1d2ddf6 --- /dev/null +++ b/services/contact/3rdparty/nuxeo-platform-cs-contact/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.contact.3rdparty.nuxeo + jar + services.contact.3rdparty.nuxeo + + Contact Nuxeo Document Type + + diff --git a/services/contact/3rdparty/nuxeo-platform-cs-contact/src/main/resources/META-INF/MANIFEST.MF b/services/contact/3rdparty/nuxeo-platform-cs-contact/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 000000000..1e07ceba7 --- /dev/null +++ b/services/contact/3rdparty/nuxeo-platform-cs-contact/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.contact;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.contact +Nuxeo-Component: OSGI-INF/core-types-contrib.xml, + OSGI-INF/ecm-types-contrib.xml, + OSGI-INF/layouts-contrib.xml + diff --git a/services/contact/3rdparty/nuxeo-platform-cs-contact/src/main/resources/OSGI-INF/core-types-contrib.xml b/services/contact/3rdparty/nuxeo-platform-cs-contact/src/main/resources/OSGI-INF/core-types-contrib.xml new file mode 100644 index 000000000..7a4993769 --- /dev/null +++ b/services/contact/3rdparty/nuxeo-platform-cs-contact/src/main/resources/OSGI-INF/core-types-contrib.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/services/contact/3rdparty/nuxeo-platform-cs-contact/src/main/resources/OSGI-INF/deployment-fragment.xml b/services/contact/3rdparty/nuxeo-platform-cs-contact/src/main/resources/OSGI-INF/deployment-fragment.xml new file mode 100644 index 000000000..88b94ffd1 --- /dev/null +++ b/services/contact/3rdparty/nuxeo-platform-cs-contact/src/main/resources/OSGI-INF/deployment-fragment.xml @@ -0,0 +1,408 @@ + + + + + + ${bundle.fileName} + + + + + nuxeo.war + /nuxeo + + + + + + + + + + + + Seam Context Filter + /ws/FileManageWS + + + + Seam Context Filter + /DocumentManagerWS + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #{currentServerLocation.name}/#{currentTabAction.label} + + + + Create new document in #{currentDocument.name} + + + + Create new document in #{currentDocument.name} + + + + breadcrumb=command.user_dashboard + + + + breadcrumb=command.manageMembers + + + + breadcrumb=command.manageMembers + + + + breadcrumb=title.vocabularies + + + + breadcrumb=command.advancedSearch + + + + + + en + en_GB + en_US + fr + de + es + it + ar + ru + ja + vn + + + messages + + + + config/addWorkspace.jpdl.xml + + + + + + generic_error_page + /generic_error_page.xhtml + + + + + generic_message_page + /generic_message_page.xhtml + + + + + home + /nxstartup.xhtml + + + + + user_login + /login.xhtml + + + + + user_logout + /logout.xhtml + + + + + view_servers + /view_servers.xhtml + + + + + + + view_domains + /view_domains.xhtml + + + + + select_document_type + /select_document_type.xhtml + + + + + create_document + /create_document.xhtml + + + + + edit_document + /edit_document.xhtml + + + + + view_documents + /view_documents.xhtml + + + + + create_file + /create_file.xhtml + + + + + create_workspace_wizard + /createWorkspaceWizard.xhtml + + + + + send_email + /document_email.xhtml + + + + + + view_workspaces + /view_workspaces.xhtml + + + + + + create_domain + /create_domain.xhtml + + + + + + edit_domain + /edit_domain.xhtml + + + + + + create_workspace + /create_workspace.xhtml + + + + + + edit_workspace + /edit_workspace.xhtml + + + + + + + members_management + /members_management.xhtml + + + + + view_users + /view_users.xhtml + + + + + view_many_users + /view_many_users.xhtml + + + + + edit_user + /edit_user.xhtml + + + + + edit_user_password + /edit_user_password.xhtml + + + + + view_user + /view_user.xhtml + + + + + create_user + /create_user.xhtml + + + + + view_groups + /view_groups.xhtml + + + + + view_group + /view_group.xhtml + + + + + edit_group + /edit_group.xhtml + + + + + create_group + /create_group.xhtml + + + + + view_vocabularies + /view_vocabularies.xhtml + + + + + view_vocabulary + /view_vocabulary.xhtml + + + + + + + search_form + /search/search_form.xhtml + + + + + search_results_nxql + /search/search_results_nxql.xhtml + + + + + search_results_advanced + + /search/search_results_advanced.xhtml + + + + + + search_results_simple + /search/search_results_simple.xhtml + + + + + + + clipboard + /incl/clipboard.xhtml + + + + + user_dashboard + /user_dashboard.xhtml + + + + + select_workspace_template + /select_workspace_template.xhtml + + + + + pdf_generation_error + /pdf_generation_error.xhtml + + + + + mass_edit + /massedit_documents.xhtml + + + + + mass_edit_confirm + /massedit_documents_preview.xhtml + + + + + + diff --git a/services/contact/3rdparty/nuxeo-platform-cs-contact/src/main/resources/OSGI-INF/ecm-types-contrib.xml b/services/contact/3rdparty/nuxeo-platform-cs-contact/src/main/resources/OSGI-INF/ecm-types-contrib.xml new file mode 100644 index 000000000..e7aed9620 --- /dev/null +++ b/services/contact/3rdparty/nuxeo-platform-cs-contact/src/main/resources/OSGI-INF/ecm-types-contrib.xml @@ -0,0 +1,28 @@ + + + + + + + view_documents + + + heading + contact + + + + + + Contact + + + + + + Contact + + + + + diff --git a/services/contact/3rdparty/nuxeo-platform-cs-contact/src/main/resources/OSGI-INF/layouts-contrib.xml b/services/contact/3rdparty/nuxeo-platform-cs-contact/src/main/resources/OSGI-INF/layouts-contrib.xml new file mode 100644 index 000000000..b5e35d5ee --- /dev/null +++ b/services/contact/3rdparty/nuxeo-platform-cs-contact/src/main/resources/OSGI-INF/layouts-contrib.xml @@ -0,0 +1,59 @@ + + + + + + + + + + + + addressText + postcode + addressType + + + + + + + true + + addressText + + + dataInputText + + + + + + + + true + + postcode + + + dataInputText + + + + + + + + true + + addressType + + + dataInputText + + + + + + diff --git a/services/contact/3rdparty/nuxeo-platform-cs-contact/src/main/resources/schemas/dimensions_common.xsd b/services/contact/3rdparty/nuxeo-platform-cs-contact/src/main/resources/schemas/dimensions_common.xsd new file mode 100644 index 000000000..fe852862c --- /dev/null +++ b/services/contact/3rdparty/nuxeo-platform-cs-contact/src/main/resources/schemas/dimensions_common.xsd @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + diff --git a/services/contact/3rdparty/pom.xml b/services/contact/3rdparty/pom.xml new file mode 100644 index 000000000..22963b2fe --- /dev/null +++ b/services/contact/3rdparty/pom.xml @@ -0,0 +1,23 @@ + + + + org.collectionspace.services.contact + org.collectionspace.services + 1.0 + + 4.0.0 + org.collectionspace.services + 1.0 + org.collectionspace.services.contact.3rdparty + pom + services.contact.3rdparty + + 3rd party build for contact service + + + + nuxeo-platform-cs-contact + + diff --git a/services/contact/build.xml b/services/contact/build.xml new file mode 100644 index 000000000..3e035731e --- /dev/null +++ b/services/contact/build.xml @@ -0,0 +1,122 @@ + + + + contact service + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/contact/client/pom.xml b/services/contact/client/pom.xml new file mode 100644 index 000000000..f6628ff72 --- /dev/null +++ b/services/contact/client/pom.xml @@ -0,0 +1,111 @@ + + + + + org.collectionspace.services.contact + org.collectionspace.services + 1.0 + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.contact.client + 1.0 + services.contact.client + + + + + org.slf4j + slf4j-api + test + + + org.slf4j + slf4j-log4j12 + test + + + org.collectionspace.services + org.collectionspace.services.contact.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-contact-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/contact/client/src/main/java/org/collectionspace/services/client/ContactClient.java b/services/contact/client/src/main/java/org/collectionspace/services/client/ContactClient.java new file mode 100644 index 000000000..464badc39 --- /dev/null +++ b/services/contact/client/src/main/java/org/collectionspace/services/client/ContactClient.java @@ -0,0 +1,123 @@ +/** + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + * + * http://www.collectionspace.org + * http://wiki.collectionspace.org + * + * Copyright (c) 2009 Regents of the University of California + * + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + * + * You may obtain a copy of the ECL 2.0 License at + * https://source.collectionspace.org/collection-space/LICENSE.txt + */ +package org.collectionspace.services.client; + +import javax.ws.rs.core.Response; + +import org.collectionspace.services.common.context.ServiceContext; +import org.collectionspace.services.contact.ContactsCommonList; + +import org.jboss.resteasy.client.ProxyFactory; +import org.jboss.resteasy.plugins.providers.RegisterBuiltin; +import org.jboss.resteasy.client.ClientResponse; +import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; +import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; +import org.jboss.resteasy.spi.ResteasyProviderFactory; + +/** + * ContactClient.java + * + * $LastChangedRevision: $ + * $LastChangedDate: $ + */ + +public class ContactClient extends BaseServiceClient { + + /* (non-Javadoc) + * @see org.collectionspace.services.client.BaseServiceClient#getServicePathComponent() + */ + public String getServicePathComponent() { + return "contacts"; + } + + /** + * + */ + private static final ContactClient instance = new ContactClient(); + + /** + * + */ + private ContactProxy contactProxy; + + /** + * + * Default constructor for ContactClient class. + * + */ + public ContactClient() { + ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance(); + RegisterBuiltin.register(factory); + contactProxy = ProxyFactory.create(ContactProxy.class, getBaseURL()); + } + + /** + * FIXME Comment this + * + * @return + */ + public static ContactClient getInstance() { + return instance; + } + + /** + * @return + * @see org.collectionspace.services.client.Contact#getContact() + */ + public ClientResponse readList() { + return contactProxy.readList(); + } + + /** + * @param csid + * @return + * @see org.collectionspace.services.client.Contact#getContact(java.lang.String) + */ + + public ClientResponse read(String csid) { + return contactProxy.read(csid); + } + + /** + * @param contact + * @return + * @see org.collectionspace.services.client.Contact#createContact(org.collectionspace.services.Contact) + */ + public ClientResponse create(MultipartOutput multipart) { + return contactProxy.create(multipart); + } + + /** + * @param csid + * @param contact + * @return + * @see org.collectionspace.services.client.Contact#updateContact(java.lang.Long, org.collectionspace.services.Contact) + */ + public ClientResponse update(String csid, MultipartOutput multipart) { + return contactProxy.update(csid, multipart); + + } + + /** + * @param csid + * @return + * @see org.collectionspace.services.client.Contact#deleteContact(java.lang.Long) + */ + public ClientResponse delete(String csid) { + return contactProxy.delete(csid); + } +} diff --git a/services/contact/client/src/main/java/org/collectionspace/services/client/ContactProxy.java b/services/contact/client/src/main/java/org/collectionspace/services/client/ContactProxy.java new file mode 100644 index 000000000..99cf4b104 --- /dev/null +++ b/services/contact/client/src/main/java/org/collectionspace/services/client/ContactProxy.java @@ -0,0 +1,48 @@ +package org.collectionspace.services.client; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Response; + +import org.collectionspace.services.contact.ContactsCommonList; +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("/contacts/") +@Produces({"multipart/mixed"}) +@Consumes({"multipart/mixed"}) +public interface ContactProxy { + + @GET + @Produces({"application/xml"}) + ClientResponse readList(); + + //(C)reate + @POST + ClientResponse create(MultipartOutput multipart); + + //(R)ead + @GET + @Path("/{csid}") + ClientResponse read(@PathParam("csid") String csid); + + //(U)pdate + @PUT + @Path("/{csid}") + ClientResponse update(@PathParam("csid") String csid, MultipartOutput multipart); + + //(D)elete + @DELETE + @Path("/{csid}") + ClientResponse delete(@PathParam("csid") String csid); +} diff --git a/services/contact/client/src/test/java/org/collectionspace/services/client/test/ContactServiceTest.java b/services/contact/client/src/test/java/org/collectionspace/services/client/test/ContactServiceTest.java new file mode 100644 index 000000000..a1c9b5f17 --- /dev/null +++ b/services/contact/client/src/test/java/org/collectionspace/services/client/test/ContactServiceTest.java @@ -0,0 +1,601 @@ +/** + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + * + * http://www.collectionspace.org + * http://wiki.collectionspace.org + * + * Copyright © 2009 Regents of the University of California + * + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + * + * You may obtain a copy of the ECL 2.0 License at + * https://source.collectionspace.org/collection-space/LICENSE.txt + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.client.test; + +import java.util.List; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +import org.collectionspace.services.client.ContactClient; +import org.collectionspace.services.contact.ContactsCommon; +import org.collectionspace.services.contact.ContactsCommonList; + +import org.jboss.resteasy.client.ClientResponse; + +import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; +import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; +import org.jboss.resteasy.plugins.providers.multipart.OutputPart; +import org.testng.Assert; +import org.testng.annotations.Test; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * ContactServiceTest, carries out tests against a + * deployed and running Contact Service. + * + * $LastChangedRevision: 917 $ + * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $ + */ +public class ContactServiceTest extends AbstractServiceTest { + + private final Logger logger = + LoggerFactory.getLogger(ContactServiceTest.class); + + // Instance variables specific to this test. + private ContactClient client = new ContactClient(); + final String SERVICE_PATH_COMPONENT = "contacts"; + private String knownResourceId = null; + + // --------------------------------------------------------------- + // 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(); + + MultipartOutput multipart = createContactInstance(identifier); + ClientResponse res = client.create(multipart); + + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + // + // Specifically: + // Does it fall within the set of valid status codes? + // Does it exactly match the expected status code? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + // Store the ID returned from this create operation + // for additional tests below. + knownResourceId = extractId(res); + if(logger.isDebugEnabled()){ + logger.debug(testName + ": knownResourceId=" + knownResourceId); + } + } + + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"create"}) + public void createList(String testName) throws Exception { + for(int i = 0; i < 3; i++){ + create(testName); + } + } + + // Failure outcomes + // Placeholders until the three tests below can be uncommented. + // See Issue CSPACE-401. + @Override + public void createWithEmptyEntityBody(String testName) throws Exception { + } + + @Override + public void createWithMalformedXml(String testName) throws Exception { + } + + @Override + public void createWithWrongXmlSchema(String testName) throws Exception { + } + + /* + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"create", "testSubmitRequest"}) + public void createWithEmptyEntityBody(String testName) throws Exception { + + // Perform setup. + setupCreateWithEmptyEntityBody(testName); + + // Submit the request to the service and store the response. + String method = REQUEST_TYPE.httpMethodName(); + String url = getServiceRootURL(); + String mediaType = MediaType.APPLICATION_XML; + final String entity = ""; + int statusCode = submitRequest(method, url, mediaType, entity); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug("createWithEmptyEntityBody url=" + url + + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"create", "testSubmitRequest"}) + public void createWithMalformedXml(String testName) throws Exception { + + // Perform setup. + setupCreateWithMalformedXml(testName); + + // Submit the request to the service and store the response. + String method = REQUEST_TYPE.httpMethodName(); + String url = getServiceRootURL(); + String mediaType = MediaType.APPLICATION_XML; + final String entity = MALFORMED_XML_DATA; // Constant from base class. + int statusCode = submitRequest(method, url, mediaType, entity); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": url=" + url + + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"create", "testSubmitRequest"}) + public void createWithWrongXmlSchema(String testName) throws Exception { + + // Perform setup. + setupCreateWithWrongXmlSchema(testName); + + // Submit the request to the service and store the response. + String method = REQUEST_TYPE.httpMethodName(); + String url = getServiceRootURL(); + String mediaType = MediaType.APPLICATION_XML; + final String entity = WRONG_XML_SCHEMA_DATA; + int statusCode = submitRequest(method, url, mediaType, entity); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": url=" + url + + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + */ + + // --------------------------------------------------------------- + // CRUD tests : READ tests + // --------------------------------------------------------------- + // Success outcomes + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"create"}) + public void read(String testName) throws Exception { + + // Perform setup. + setupRead(testName); + + // 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); + + MultipartInput input = (MultipartInput) res.getEntity(); + ContactsCommon contact = (ContactsCommon) extractPart(input, + client.getCommonPartName(), ContactsCommon.class); + Assert.assertNotNull(contact); + } + + // Failure outcomes + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"read"}) + public void readNonExistent(String testName) throws Exception { + + // 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); + } + + // --------------------------------------------------------------- + // CRUD tests : READ_LIST tests + // --------------------------------------------------------------- + // Success outcomes + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"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(); + ContactsCommonList 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.getContactListItem(); + int i = 0; + for(ContactsCommonList.ContactListItem item : items){ + logger.debug(testName + ": list-item[" + i + "] csid=" + + item.getCsid()); + logger.debug(testName + ": list-item[" + i + "] objectNumber=" + + item.getAddressText()); + 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); + + ClientResponse res = + client.read(knownResourceId); + if(logger.isDebugEnabled()){ + logger.debug(testName + ": read status = " + res.getStatus()); + } + Assert.assertEquals(res.getStatus(), EXPECTED_STATUS_CODE); + + if(logger.isDebugEnabled()){ + logger.debug("got object to update with ID: " + knownResourceId); + } + MultipartInput input = (MultipartInput) res.getEntity(); + ContactsCommon contact = (ContactsCommon) extractPart(input, + client.getCommonPartName(), ContactsCommon.class); + Assert.assertNotNull(contact); + + // Update the content of this resource. + contact.setAddressText("updated-" + contact.getAddressText()); + contact.setPostcode("updated-" + contact.getPostcode()); + if(logger.isDebugEnabled()){ + logger.debug("to be updated object"); + logger.debug(objectAsXmlString(contact, ContactsCommon.class)); + } + // Submit the request to the service and store the response. + MultipartOutput output = new MultipartOutput(); + OutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", client.getCommonPartName()); + + res = client.update(knownResourceId, output); + int statusCode = res.getStatus(); + // Check the status code of the response: does it match the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + + + input = (MultipartInput) res.getEntity(); + ContactsCommon updatedContact = + (ContactsCommon) extractPart(input, + client.getCommonPartName(), ContactsCommon.class); + Assert.assertNotNull(updatedContact); + + Assert.assertEquals(updatedContact.getPostcode(), + contact.getPostcode(), + "Data in updated object did not match submitted data."); + + } + + // Failure outcomes + // Placeholders until the three tests below can be uncommented. + // See Issue CSPACE-401. + @Override + public void updateWithEmptyEntityBody(String testName) throws Exception{ + } + @Override + public void updateWithMalformedXml(String testName) throws Exception { + } + @Override + public void updateWithWrongXmlSchema(String testName) throws Exception { + } + + /* + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"create", "update", "testSubmitRequest"}) + public void updateWithEmptyEntityBody(String testName) throws Exception { + + // Perform setup. + setupUpdateWithEmptyEntityBody(testName); + + // Submit the request to the service and store the response. + String method = REQUEST_TYPE.httpMethodName(); + String url = getResourceURL(knownResourceId); + String mediaType = MediaType.APPLICATION_XML; + final String entity = ""; + int statusCode = submitRequest(method, url, mediaType, entity); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": url=" + url + + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"create", "update", "testSubmitRequest"}) + public void updateWithMalformedXml(String testName) throws Exception { + + // Perform setup. + setupUpdateWithMalformedXml(testName); + + // Submit the request to the service and store the response. + String method = REQUEST_TYPE.httpMethodName(); + String url = getResourceURL(knownResourceId); + String mediaType = MediaType.APPLICATION_XML; + final String entity = MALFORMED_XML_DATA; + int statusCode = submitRequest(method, url, mediaType, entity); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": url=" + url + + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + + @Override + @Test(dataProvider="testName", dataProviderClass=AbstractServiceTest.class, + dependsOnMethods = {"create", "update", "testSubmitRequest"}) + public void updateWithWrongXmlSchema(String testName) throws Exception { + + // Perform setup. + setupUpdateWithWrongXmlSchema(testName); + + // Submit the request to the service and store the response. + String method = REQUEST_TYPE.httpMethodName(); + String url = getResourceURL(knownResourceId); + String mediaType = MediaType.APPLICATION_XML; + final String entity = WRONG_XML_SCHEMA_DATA; + int statusCode = submitRequest(method, url, mediaType, entity); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": url=" + url + + " status=" + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + */ + + @Override + @Test(dataProvider="testName", dataProviderClass=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 = createContactInstance(NON_EXISTENT_ID); + ClientResponse res = + client.update(NON_EXISTENT_ID, multipart); + int statusCode = res.getStatus(); + + // Check the status code of the response: does it match + // the expected response(s)? + if(logger.isDebugEnabled()){ + logger.debug(testName + ": status = " + statusCode); + } + Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), + invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); + Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + } + + // --------------------------------------------------------------- + // CRUD tests : DELETE tests + // --------------------------------------------------------------- + // Success outcomes + @Override + @Test(dataProvider="testName", dataProviderClass=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); + } + + // 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); + } + + // --------------------------------------------------------------- + // 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); + + } + + // --------------------------------------------------------------- + // Utility methods used by tests above + // --------------------------------------------------------------- + @Override + public String getServicePathComponent() { + return SERVICE_PATH_COMPONENT; + } + + private MultipartOutput createContactInstance(String identifier) { + return createContactInstance( + "addressText-" + identifier, + "postcode-" + identifier, + "addressType-" + identifier); + } + + private MultipartOutput createContactInstance(String addressText, + String postcode, String addressType) { + ContactsCommon contact = new ContactsCommon(); + contact.setAddressText(addressText); + contact.setPostcode(postcode); + contact.setAddressType(addressType); + MultipartOutput multipart = new MultipartOutput(); + OutputPart commonPart = + multipart.addPart(contact, MediaType.APPLICATION_XML_TYPE); + commonPart.getHeaders().add("label", client.getCommonPartName()); + + if(logger.isDebugEnabled()){ + logger.debug("to be created, contact common"); + logger.debug(objectAsXmlString(contact, ContactsCommon.class)); + } + + return multipart; + } +} diff --git a/services/contact/client/src/test/resources/log4j.properties b/services/contact/client/src/test/resources/log4j.properties new file mode 100644 index 000000000..148a3e865 --- /dev/null +++ b/services/contact/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/contact/jaxb/pom.xml b/services/contact/jaxb/pom.xml new file mode 100644 index 000000000..8c51c0ded --- /dev/null +++ b/services/contact/jaxb/pom.xml @@ -0,0 +1,102 @@ + + + + + org.collectionspace.services.contact + org.collectionspace.services + 1.0 + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.contact.jaxb + 1.0 + services.contact.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-contact-jaxb + install + + + org.jvnet.jaxb2.maven2 + maven-jaxb2-plugin + + + + generate + + + + + + + javax.activation + activation + 1.1 + + + com.sun.xml.bind + jaxb-impl + 2.1.9 + + + + + -XtoString + -Xinject-listener-code + + + + + + + org.jvnet.jaxb2_commons + + basic + 0.4.1 + + + + org.jvnet.jaxb2-commons + + + property-listener-injector + + 1.0 + + + + + + + maven-compiler-plugin + 2.0.2 + + 1.6 + 1.6 + + + + + + diff --git a/services/contact/jaxb/src/main/java/org/collectionspace/services/contact/ContactJAXBSchema.java b/services/contact/jaxb/src/main/java/org/collectionspace/services/contact/ContactJAXBSchema.java new file mode 100644 index 000000000..b6beefa2e --- /dev/null +++ b/services/contact/jaxb/src/main/java/org/collectionspace/services/contact/ContactJAXBSchema.java @@ -0,0 +1,15 @@ +/** + * + */ +package org.collectionspace.services.contact; + +/** + * + */ +public interface ContactJAXBSchema { + final static String ADDRESS_TEXT = "addressText"; + final static String POSTCODE = "postcode"; + final static String ADDRESS_TYPE = "addressType"; +} + + diff --git a/services/contact/jaxb/src/main/java/org/collectionspace/services/contact/ContactListItemJAXBSchema.java b/services/contact/jaxb/src/main/java/org/collectionspace/services/contact/ContactListItemJAXBSchema.java new file mode 100644 index 000000000..ff5699f13 --- /dev/null +++ b/services/contact/jaxb/src/main/java/org/collectionspace/services/contact/ContactListItemJAXBSchema.java @@ -0,0 +1,10 @@ +package org.collectionspace.services.contact; + +public interface ContactListItemJAXBSchema { + // TODO Revisit which information unit(s) should be returned + // in each entry, in a list of contact information. + // Should this be addressText or some other unit(s)? + final static String ADDRESS_TEXT = "addressText"; + final static String CSID = "csid"; + final static String URI = "url"; +} diff --git a/services/contact/jaxb/src/main/resources/contacts-common.xsd b/services/contact/jaxb/src/main/resources/contacts-common.xsd new file mode 100644 index 000000000..32cc81929 --- /dev/null +++ b/services/contact/jaxb/src/main/resources/contacts-common.xsd @@ -0,0 +1,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/contact/pom.xml b/services/contact/pom.xml new file mode 100644 index 000000000..d4de6595c --- /dev/null +++ b/services/contact/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.contact + pom + services.contact + + + + jaxb + service + 3rdparty + client + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.5 + 1.5 + + + + org.apache.maven.plugins + maven-site-plugin + + /usr/bin/unzip -o > err.txt + + + + org.apache.maven.plugins + maven-war-plugin + 2.0.1 + + WEB-INF/lib/*.jar + + + true + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.0.2 + + 1.6 + 1.6 + + + + + + diff --git a/services/contact/service/pom.xml b/services/contact/service/pom.xml new file mode 100644 index 000000000..f2222de2e --- /dev/null +++ b/services/contact/service/pom.xml @@ -0,0 +1,119 @@ + + + + + org.collectionspace.services.contact + org.collectionspace.services + 1.0 + + + 4.0.0 + org.collectionspace.services + org.collectionspace.services.contact.service + jar + 1.0 + services.contact.service + + + + + + + + org.collectionspace.services + org.collectionspace.services.common + 1.0 + + + org.collectionspace.services + org.collectionspace.services.contact.jaxb + 1.0 + + + + org.testng + testng + 5.6 + + + + + + + + javax.security + jaas + 1.0.01 + provided + + + + dom4j + dom4j + 1.6.1 + provided + + + + + + org.jboss.resteasy + resteasy-jaxrs + 1.0.2.GA + + + tjws + webserver + + + + + org.jboss.resteasy + resteasy-jaxb-provider + 1.0.2.GA + + + org.jboss.resteasy + resteasy-multipart-provider + 1.0.2.GA + + + + + + org.nuxeo.ecm.core + nuxeo-core-api + ${nuxeo.version.1.5} + + + jboss-remoting + jboss + + + + + + + + collectionspace-services-contact + + + org.codehaus.mojo + jboss-maven-plugin + + ${jboss.dir} + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.6 + 1.6 + true + + + + + + diff --git a/services/contact/service/profiles.xml b/services/contact/service/profiles.xml new file mode 100644 index 000000000..347b9df22 --- /dev/null +++ b/services/contact/service/profiles.xml @@ -0,0 +1,4 @@ + + + \ No newline at end of file diff --git a/services/contact/service/src/main/java/org/collectionspace/services/contact/ContactResource.java b/services/contact/service/src/main/java/org/collectionspace/services/contact/ContactResource.java new file mode 100644 index 000000000..3dcd55daf --- /dev/null +++ b/services/contact/service/src/main/java/org/collectionspace/services/contact/ContactResource.java @@ -0,0 +1,246 @@ +/** + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + + * http://www.collectionspace.org + * http://wiki.collectionspace.org + + * Copyright 2009 Regents of the University of California + + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + + * You may obtain a copy of the ECL 2.0 License at + + * https://source.collectionspace.org/collection-space/LICENSE.txt + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.contact; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.DELETE; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.PathParam; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; +import javax.ws.rs.core.UriInfo; + +import org.collectionspace.services.common.AbstractCollectionSpaceResource; +import org.collectionspace.services.contact.ContactsCommonList.*; + +import org.collectionspace.services.contact.nuxeo.ContactHandlerFactory; +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.DocumentNotFoundException; +import org.collectionspace.services.common.document.DocumentHandler; +import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; +import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; +import org.jboss.resteasy.util.HttpResponseCodes; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Path("/contacts") +@Consumes("multipart/mixed") +@Produces("multipart/mixed") +public class ContactResource extends AbstractCollectionSpaceResource { + + private final static String serviceName = "contacts"; + final Logger logger = LoggerFactory.getLogger(ContactResource.class); + //FIXME retrieve client type from configuration + final static ClientType CLIENT_TYPE = ServiceMain.getInstance().getClientType(); + + public ContactResource() { + // do nothing + } + + @Override + public String getServiceName() { + return serviceName; + } + + @Override + public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception { + DocumentHandler docHandler = ContactHandlerFactory.getInstance().getHandler( + ctx.getRepositoryClientType().toString()); + docHandler.setServiceContext(ctx); + if (ctx.getInput() != null) { + Object obj = ((MultipartServiceContext)ctx).getInputPart(ctx.getCommonPartLabel(), ContactsCommon.class); + if (obj != null) { + docHandler.setCommonPart((ContactsCommon) obj); + } + } + return docHandler; + } + + @POST + public Response createContact(MultipartInput input) { + try { + ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(input, getServiceName()); + DocumentHandler handler = createDocumentHandler(ctx); + String csid = getRepositoryClient(ctx).create(ctx, handler); + //contactObject.setCsid(csid); + UriBuilder path = UriBuilder.fromResource(ContactResource.class); + path.path("" + csid); + Response response = Response.created(path.build()).build(); + return response; + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("Caught exception in createContact", 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 getContact( + @PathParam("csid") String csid) { + if (logger.isDebugEnabled()) { + logger.debug("getContact with csid=" + csid); + } + if (csid == null || "".equals(csid)) { + logger.error("getContact: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "Get failed on Contact csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } + MultipartOutput result = null; + try { + ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName()); + DocumentHandler handler = createDocumentHandler(ctx); + getRepositoryClient(ctx).get(ctx, csid, handler); + result = (MultipartOutput) ctx.getOutput(); + } catch (DocumentNotFoundException dnfe) { + if (logger.isDebugEnabled()) { + logger.debug("getContact", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed on Contact csid=" + csid).type( + "text/plain").build(); + throw new WebApplicationException(response); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("getContact", 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 Contact CSID:" + csid + ": was not found.").type( + "text/plain").build(); + throw new WebApplicationException(response); + } + return result; + } + + @GET + @Produces("application/xml") + public ContactsCommonList getContactList(@Context UriInfo ui) { + ContactsCommonList contactObjectList = new ContactsCommonList(); + try { + ServiceContext ctx = MultipartServiceContextFactory.get().createServiceContext(null, getServiceName()); + DocumentHandler handler = createDocumentHandler(ctx); + getRepositoryClient(ctx).getAll(ctx, handler); + contactObjectList = (ContactsCommonList) handler.getCommonPartList(); + } catch (Exception e) { + if (logger.isDebugEnabled()) { + logger.debug("Caught exception in getContactList", e); + } + Response response = Response.status( + Response.Status.INTERNAL_SERVER_ERROR).entity("Index failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + return contactObjectList; + } + + @PUT + @Path("{csid}") + public MultipartOutput updateContact( + @PathParam("csid") String csid, + MultipartInput theUpdate) { + if (logger.isDebugEnabled()) { + logger.debug("updateContact with csid=" + csid); + } + if (csid == null || "".equals(csid)) { + logger.error("updateContact: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "update failed on Contact 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 (DocumentNotFoundException dnfe) { + if (logger.isDebugEnabled()) { + logger.debug("Caught exception in updateContact", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Update failed on Contact 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 deleteContact(@PathParam("csid") String csid) { + + if (logger.isDebugEnabled()) { + logger.debug("deleteContact with csid=" + csid); + } + if (csid == null || "".equals(csid)) { + logger.error("deleteContact: missing csid!"); + Response response = Response.status(Response.Status.BAD_REQUEST).entity( + "Delete failed on Contact 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 (DocumentNotFoundException dnfe) { + if (logger.isDebugEnabled()) { + logger.debug("Caught exception in deleteContact", dnfe); + } + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Delete failed on Contact 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); + } + + } +} diff --git a/services/contact/service/src/main/java/org/collectionspace/services/contact/nuxeo/ContactConstants.java b/services/contact/service/src/main/java/org/collectionspace/services/contact/nuxeo/ContactConstants.java new file mode 100644 index 000000000..66b72044c --- /dev/null +++ b/services/contact/service/src/main/java/org/collectionspace/services/contact/nuxeo/ContactConstants.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.contact.nuxeo; + +/** + * ContactConstants, stores constants related to Contact documents + * + */ +public class ContactConstants { + + public final static String NUXEO_DOCTYPE = "Contact"; + public final static String NUXEO_SCHEMA_NAME = "contact"; + public final static String NUXEO_DC_TITLE = "CollectionSpace-Contact"; +} diff --git a/services/contact/service/src/main/java/org/collectionspace/services/contact/nuxeo/ContactDocumentModelHandler.java b/services/contact/service/src/main/java/org/collectionspace/services/contact/nuxeo/ContactDocumentModelHandler.java new file mode 100644 index 000000000..f809ec108 --- /dev/null +++ b/services/contact/service/src/main/java/org/collectionspace/services/contact/nuxeo/ContactDocumentModelHandler.java @@ -0,0 +1,149 @@ +/** + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + + * http://www.collectionspace.org + * http://wiki.collectionspace.org + + * Copyright 2009 Regents of the University of California + + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + + * You may obtain a copy of the ECL 2.0 License at + + * https://source.collectionspace.org/collection-space/LICENSE.txt + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.contact.nuxeo; + +import java.util.Iterator; +import java.util.List; + +import org.collectionspace.services.contact.ContactJAXBSchema; +import org.collectionspace.services.common.document.DocumentHandler.Action; +import org.collectionspace.services.common.document.DocumentWrapper; +import org.collectionspace.services.contact.ContactsCommon; +import org.collectionspace.services.contact.ContactsCommonList; +import org.collectionspace.services.contact.ContactsCommonList.ContactListItem; + +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; + +/** + * ContactDocumentModelHandler + * + * $LastChangedRevision: $ + * $LastChangedDate: $ + */ +public class ContactDocumentModelHandler + extends RemoteDocumentModelHandler { + + private final Logger logger = LoggerFactory.getLogger(ContactDocumentModelHandler.class); + /** + * contact is used to stash JAXB object to use when handle is called + * for Action.CREATE, Action.UPDATE or Action.GET + */ + private ContactsCommon contact; + /** + * contactList is stashed when handle is called + * for ACTION.GET_ALL + */ + private ContactsCommonList contactList; + + @Override + public void prepare(Action action) throws Exception { + //no specific action needed + } + + /** + * getCommonPart get associated contact + * @return + */ + @Override + public ContactsCommon getCommonPart() { + return contact; + } + + /** + * setCommonPart set associated contact + * @param contact + */ + @Override + public void setCommonPart(ContactsCommon contact) { + this.contact = contact; + } + + /** + * getCommonPartList get associated contact (for index/GET_ALL) + * @return + */ + @Override + public ContactsCommonList getCommonPartList() { + return contactList; + } + + @Override + public void setCommonPartList(ContactsCommonList contactList) { + this.contactList = contactList; + } + + @Override + public ContactsCommon extractCommonPart(DocumentWrapper wrapDoc) + throws Exception { + throw new UnsupportedOperationException(); + } + + @Override + public void fillCommonPart(ContactsCommon contactObject, DocumentWrapper wrapDoc) throws Exception { + throw new UnsupportedOperationException(); + } + + @Override + public ContactsCommonList extractCommonPartList(DocumentWrapper wrapDoc) throws Exception { + DocumentModelList docList = wrapDoc.getWrappedObject(); + + ContactsCommonList coList = new ContactsCommonList(); + List list = coList.getContactListItem(); + + //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(); + ContactListItem clistItem = new ContactListItem(); + // TODO Revisit which information unit(s) should be returned + // in each entry, in a list of contact information. + // Should this be addressText or some other unit(s)? + clistItem.setAddressText((String) docModel.getProperty(getServiceContext().getCommonPartLabel(), + ContactJAXBSchema.ADDRESS_TEXT)); + String id = NuxeoUtils.extractId(docModel.getPathAsString()); + clistItem.setUri(getServiceContextPath() + id); + clistItem.setCsid(id); + list.add(clistItem); + } + + return coList; + } + + /** + * getQProperty converts the given property to qualified schema property + * @param prop + * @return + */ + @Override + public String getQProperty(String prop) { + return ContactConstants.NUXEO_SCHEMA_NAME + ":" + prop; + } +} + diff --git a/services/contact/service/src/main/java/org/collectionspace/services/contact/nuxeo/ContactHandlerFactory.java b/services/contact/service/src/main/java/org/collectionspace/services/contact/nuxeo/ContactHandlerFactory.java new file mode 100644 index 000000000..8a9196996 --- /dev/null +++ b/services/contact/service/src/main/java/org/collectionspace/services/contact/nuxeo/ContactHandlerFactory.java @@ -0,0 +1,55 @@ +/** + * This document is a part of the source code and related artifacts + * for CollectionSpace, an open source collections management system + * for museums and related institutions: + + * http://www.collectionspace.org + * http://wiki.collectionspace.org + + * Copyright 2009 Regents of the University of California + + * Licensed under the Educational Community License (ECL), Version 2.0. + * You may not use this file except in compliance with this License. + + * You may obtain a copy of the ECL 2.0 License at + + * https://source.collectionspace.org/collection-space/LICENSE.txt + + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.collectionspace.services.contact.nuxeo; + +import org.collectionspace.services.common.ClientType; +import org.collectionspace.services.common.document.DocumentHandler; +import org.collectionspace.services.common.document.DocumentHandlerFactory; + +/** + * ContactHandlerFactory creates handlers for contact objects based + * on type of Nuxeo client used + * + * $LastChangedRevision: $ + * $LastChangedDate: $ + */ +public class ContactHandlerFactory implements DocumentHandlerFactory { + + private static final ContactHandlerFactory self = new ContactHandlerFactory(); + + private ContactHandlerFactory() { + } + + public static ContactHandlerFactory getInstance() { + return self; + } + + @Override + public DocumentHandler getHandler(String clientType) { + if(ClientType.JAVA.toString().equals(clientType)){ + return new ContactDocumentModelHandler(); + } + throw new IllegalArgumentException("Not supported client=" + clientType); + } +} diff --git a/services/contact/service/src/test/java/org/collectionspace/services/test/ContactServiceTest.java b/services/contact/service/src/test/java/org/collectionspace/services/test/ContactServiceTest.java new file mode 100644 index 000000000..b65e89bbb --- /dev/null +++ b/services/contact/service/src/test/java/org/collectionspace/services/test/ContactServiceTest.java @@ -0,0 +1,13 @@ +package org.collectionspace.services.test; + +//import org.collectionspace.services.contact.Contact; +//import org.collectionspace.services.contact.ContactList; + +/** + * ContactServiceTest + * + * @version $Revision:$ + */ +public class ContactServiceTest { + //empty +} diff --git a/services/contact/service/src/test/resources/log4j.xml b/services/contact/service/src/test/resources/log4j.xml new file mode 100644 index 000000000..52121cb83 --- /dev/null +++ b/services/contact/service/src/test/resources/log4j.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +