From 6dda0097d5bc0e57a199f17bab2f08e6a08eb487 Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Tue, 7 Apr 2009 00:09:04 +0000 Subject: [PATCH] Integrating CollectionObject and Identifier services into Restful Nuxeo prototype. --- .../nuxeo/nuxeo-platform-cs/build.properties | 15 + .../nuxeo/nuxeo-platform-cs/build.xml | 14 + .../3rdparty/nuxeo/nuxeo-platform-cs/pom.xml | 30 ++ .../src/main/resources/META-INF/MANIFEST.MF | 22 + .../resources/OSGI-INF/core-types-contrib.xml | 13 + .../OSGI-INF/deployment-fragment.xml | 408 ++++++++++++++++++ .../resources/OSGI-INF/ecm-types-contrib.xml | 28 ++ .../resources/OSGI-INF/layouts-contrib.xml | 68 +++ .../resources/schemas/collectionobject.xsd | 13 + sandbox/richard/HelloWorld/.classpath | 6 + sandbox/richard/HelloWorld/.project | 23 + .../hello/client/CollectionObjectClient.java | 96 +++++ .../hello/client/CollectionObjectProxy.java | 46 ++ .../src/main/resources/hello.xsd | 35 +- .../HelloWorldNuxeoService/.classpath | 10 + .../HelloWorldNuxeoService/.project | 23 + .../.settings/org.eclipse.jdt.core.prefs | 5 + .../.settings/org.maven.ide.eclipse.prefs | 8 + .../services/CollectionObjectResource.java | 300 +++++++++++++ .../services/HelloworldNuxeoApplication.java | 1 + .../hello/services/IdentifierResource.java | 77 ++++ 21 files changed, 1240 insertions(+), 1 deletion(-) create mode 100644 sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/build.properties create mode 100644 sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/build.xml create mode 100644 sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/pom.xml create mode 100644 sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/src/main/resources/META-INF/MANIFEST.MF create mode 100644 sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/src/main/resources/OSGI-INF/core-types-contrib.xml create mode 100644 sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/src/main/resources/OSGI-INF/deployment-fragment.xml create mode 100644 sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/src/main/resources/OSGI-INF/ecm-types-contrib.xml create mode 100644 sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/src/main/resources/OSGI-INF/layouts-contrib.xml create mode 100644 sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/src/main/resources/schemas/collectionobject.xsd create mode 100644 sandbox/richard/HelloWorld/.classpath create mode 100644 sandbox/richard/HelloWorld/.project create mode 100644 sandbox/richard/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/CollectionObjectClient.java create mode 100644 sandbox/richard/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/CollectionObjectProxy.java create mode 100644 sandbox/richard/HelloWorld/HelloWorldNuxeoService/.classpath create mode 100644 sandbox/richard/HelloWorld/HelloWorldNuxeoService/.project create mode 100644 sandbox/richard/HelloWorld/HelloWorldNuxeoService/.settings/org.eclipse.jdt.core.prefs create mode 100644 sandbox/richard/HelloWorld/HelloWorldNuxeoService/.settings/org.maven.ide.eclipse.prefs create mode 100644 sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/CollectionObjectResource.java create mode 100644 sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/IdentifierResource.java diff --git a/sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/build.properties b/sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/build.properties new file mode 100644 index 000000000..c26799aa9 --- /dev/null +++ b/sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/build.properties @@ -0,0 +1,15 @@ +# Example for Windows +jboss.dir=c:/dev/jboss-4.2.3.GA +# Example for Unix +#jboss.dir=/opt/jboss + +# Which JBoss server config to use +jboss.config=default + +# nuxeo deployment +jboss.nuxeo.ear.dir=${jboss.dir}/server/${jboss.config}/deploy/nuxeo.ear + + +# additional command line parameters for mvn commands +# e.g. to work offline: +#mvn.opts=-o diff --git a/sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/build.xml b/sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/build.xml new file mode 100644 index 000000000..d4e3b266c --- /dev/null +++ b/sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/build.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/pom.xml b/sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/pom.xml new file mode 100644 index 000000000..540859ee7 --- /dev/null +++ b/sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/pom.xml @@ -0,0 +1,30 @@ + + 4.0.0 + + + org.nuxeo.ecm.platform + nuxeo-platform-parent + 5.2-SNAPSHOT + + + nuxeo-platform-collectionspace + jar + Nuxeo CS extensions + + Nuxeo Enterprise Platform: CS extensions + + + + + org.nuxeo.ecm.core + nuxeo-core-schema + + + org.nuxeo.ecm.platform + nuxeo-platform-types-core + + + + diff --git a/sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/src/main/resources/META-INF/MANIFEST.MF b/sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 000000000..91c534186 --- /dev/null +++ b/sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/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.collectionobject;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.collectionobject +Nuxeo-Component: OSGI-INF/core-types-contrib.xml, + OSGI-INF/ecm-types-contrib.xml, + OSGI-INF/layouts-contrib.xml + diff --git a/sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/src/main/resources/OSGI-INF/core-types-contrib.xml b/sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/src/main/resources/OSGI-INF/core-types-contrib.xml new file mode 100644 index 000000000..72aa5ef19 --- /dev/null +++ b/sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/src/main/resources/OSGI-INF/core-types-contrib.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/src/main/resources/OSGI-INF/deployment-fragment.xml b/sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/src/main/resources/OSGI-INF/deployment-fragment.xml new file mode 100644 index 000000000..88b94ffd1 --- /dev/null +++ b/sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/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/sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/src/main/resources/OSGI-INF/ecm-types-contrib.xml b/sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/src/main/resources/OSGI-INF/ecm-types-contrib.xml new file mode 100644 index 000000000..541251f1e --- /dev/null +++ b/sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/src/main/resources/OSGI-INF/ecm-types-contrib.xml @@ -0,0 +1,28 @@ + + + + + + + view_documents + + + heading + collectionobject + + + + + + CollectionObject + + + + + + CollectionObject + + + + + diff --git a/sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/src/main/resources/OSGI-INF/layouts-contrib.xml b/sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/src/main/resources/OSGI-INF/layouts-contrib.xml new file mode 100644 index 000000000..f3db69e49 --- /dev/null +++ b/sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/src/main/resources/OSGI-INF/layouts-contrib.xml @@ -0,0 +1,68 @@ + + + + + + + + + + + + csid + identifier + description + + + + + + + true + + csid + + + + hidden + + + + true + + + + cssClass + + + + + + + + true + + identifier + + + dataInputText + + + + + + + + true + + description + + + dataInputText + + + + + + diff --git a/sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/src/main/resources/schemas/collectionobject.xsd b/sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/src/main/resources/schemas/collectionobject.xsd new file mode 100644 index 000000000..0a126c947 --- /dev/null +++ b/sandbox/richard/3rdparty/nuxeo/nuxeo-platform-cs/src/main/resources/schemas/collectionobject.xsd @@ -0,0 +1,13 @@ + + + + + + + + diff --git a/sandbox/richard/HelloWorld/.classpath b/sandbox/richard/HelloWorld/.classpath new file mode 100644 index 000000000..cad20f7d9 --- /dev/null +++ b/sandbox/richard/HelloWorld/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/sandbox/richard/HelloWorld/.project b/sandbox/richard/HelloWorld/.project new file mode 100644 index 000000000..234cbef57 --- /dev/null +++ b/sandbox/richard/HelloWorld/.project @@ -0,0 +1,23 @@ + + + helloworld + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.maven.ide.eclipse.maven2Nature + + diff --git a/sandbox/richard/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/CollectionObjectClient.java b/sandbox/richard/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/CollectionObjectClient.java new file mode 100644 index 000000000..8e5a7cf9f --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/CollectionObjectClient.java @@ -0,0 +1,96 @@ +package org.collectionspace.hello.client; + +import javax.ws.rs.core.Response; + +import org.collectionspace.hello.CollectionObject; +import org.collectionspace.hello.CollectionObjectList; + +import org.jboss.resteasy.client.ProxyFactory; +import org.jboss.resteasy.plugins.providers.RegisterBuiltin; +import org.jboss.resteasy.client.ClientResponse; +import org.jboss.resteasy.spi.ResteasyProviderFactory; + +/** + * A CollectionObjectClient. + + * @version $Revision:$ + */ +public class CollectionObjectClient { + + private static final String HOST = "http://localhost:8080"; + private static final String URI = "/helloworld/cspace-nuxeo"; + + /** + * + */ + private static final CollectionObjectClient instance = new CollectionObjectClient(); + /** + * + */ + private CollectionObjectProxy collectionObjectProxy; + + /** + * + * Default constructor for CollectionObjectClient class. + * + */ + private CollectionObjectClient() { + ResteasyProviderFactory factory = ResteasyProviderFactory.getInstance(); + RegisterBuiltin.register(factory); + collectionObjectProxy = ProxyFactory.create(CollectionObjectProxy.class, HOST + URI); + } + + /** + * FIXME Comment this + * + * @return + */ + public static CollectionObjectClient getInstance() { + return instance; + } + + /** + * @return + * @see org.collectionspace.hello.client.CollectionObjectProxy#getCollectionObject() + */ + public ClientResponse getCollectionObjectList() { + return collectionObjectProxy.getCollectionObjectList(); + } + + /** + * @param csid + * @return + * @see org.collectionspace.hello.client.CollectionObjectProxy#getCollectionObject(java.lang.String) + */ + public ClientResponse getCollectionObject(String csid) { + return collectionObjectProxy.getCollectionObject(csid); + } + + /** + * @param collectionobject + * @return + * @see org.collectionspace.hello.client.CollectionObjectProxy#createCollectionObject(org.collectionspace.hello.CollectionObject) + */ + public ClientResponse createCollectionObject(CollectionObject collectionObject) { + return collectionObjectProxy.createCollectionObject(collectionObject); + } + + /** + * @param csid + * @param collectionobject + * @return + * @see org.collectionspace.hello.client.CollectionObjectProxy#updateCollectionObject(java.lang.Long, org.collectionspace.hello.CollectionObject) + */ + public ClientResponse updateCollectionObject(String csid, CollectionObject collectionObject) { + return collectionObjectProxy.updateCollectionObject(csid, collectionObject); + } + + /** + * @param csid + * @return + * @see org.collectionspace.hello.client.CollectionObjectProxy#deleteCollectionObject(java.lang.Long) + */ + public ClientResponse deleteCollectionObject(String csid) { + return collectionObjectProxy.deleteCollectionObject(csid); + } +} diff --git a/sandbox/richard/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/CollectionObjectProxy.java b/sandbox/richard/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/CollectionObjectProxy.java new file mode 100644 index 000000000..6097fed14 --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldClient/src/main/java/org/collectionspace/hello/client/CollectionObjectProxy.java @@ -0,0 +1,46 @@ +package org.collectionspace.hello.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.hello.CollectionObject; +import org.collectionspace.hello.CollectionObjectList; +import org.jboss.resteasy.client.ClientResponse; + +/** + * @version $Revision:$ + */ +@Path("/collectionobjects/") +@Produces({"application/xml"}) +@Consumes({"application/xml"}) +public interface CollectionObjectProxy { + + @GET + ClientResponse getCollectionObjectList(); + + //(C)reate + @POST + ClientResponse createCollectionObject(CollectionObject co); + + //(R)ead + @GET + @Path("/{csid}") + ClientResponse getCollectionObject(@PathParam("csid") String csid); + + //(U)pdate + @PUT + @Path("/{csid}") + ClientResponse updateCollectionObject(@PathParam("csid") String csid, CollectionObject co); + + //(D)elete + @DELETE + @Path("/{csid}") + ClientResponse deleteCollectionObject(@PathParam("csid") String csid); +} \ No newline at end of file diff --git a/sandbox/richard/HelloWorld/HelloWorldJaxb/src/main/resources/hello.xsd b/sandbox/richard/HelloWorld/HelloWorldJaxb/src/main/resources/hello.xsd index 64a6b43b4..65d724a57 100644 --- a/sandbox/richard/HelloWorld/HelloWorldJaxb/src/main/resources/hello.xsd +++ b/sandbox/richard/HelloWorld/HelloWorldJaxb/src/main/resources/hello.xsd @@ -59,7 +59,40 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/richard/HelloWorld/HelloWorldNuxeoService/.classpath b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/.classpath new file mode 100644 index 000000000..1d6493d01 --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/.classpath @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/sandbox/richard/HelloWorld/HelloWorldNuxeoService/.project b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/.project new file mode 100644 index 000000000..dde7b1c9d --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/.project @@ -0,0 +1,23 @@ + + + helloworld-nuxeo-service + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.maven.ide.eclipse.maven2Nature + + diff --git a/sandbox/richard/HelloWorld/HelloWorldNuxeoService/.settings/org.eclipse.jdt.core.prefs b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..bf687d53a --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +#Wed Apr 01 10:19:44 PDT 2009 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/sandbox/richard/HelloWorld/HelloWorldNuxeoService/.settings/org.maven.ide.eclipse.prefs b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 000000000..fe1aa9559 --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/.settings/org.maven.ide.eclipse.prefs @@ -0,0 +1,8 @@ +#Wed Apr 01 10:19:28 PDT 2009 +activeProfiles= +eclipse.preferences.version=1 +fullBuildGoals=process-test-resources +includeModules=false +resolveWorkspaceProjects=true +resourceFilterGoals=process-resources resources\:testResources +version=1 diff --git a/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/CollectionObjectResource.java b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/CollectionObjectResource.java new file mode 100644 index 000000000..d861fc89c --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/CollectionObjectResource.java @@ -0,0 +1,300 @@ +package org.collectionspace.hello.services; + +import java.io.ByteArrayInputStream; +import org.collectionspace.hello.services.nuxeo.NuxeoRESTClient; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import java.util.Map; +import javax.ws.rs.DELETE; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.PathParam; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; +import javax.ws.rs.core.UriInfo; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; +import org.collectionspace.hello.*; + + +import org.collectionspace.hello.CollectionObjectList.CollectionObjectListItem; +import org.dom4j.Document; +import org.dom4j.Element; +import org.dom4j.Namespace; +import org.dom4j.io.SAXReader; +import org.restlet.resource.Representation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Path("/collectionobjects") +@Consumes("application/xml") +@Produces("application/xml") +public class CollectionObjectResource { + + final static String NUXEO_WORKSPACE_UID = "776a8787-9d81-41b0-a02c-1ba674638c0a"; + final static String NUXEO_DOCTYPE = "CollectionObject"; + + final Logger logger = LoggerFactory.getLogger(CollectionObjectResource.class); + + public CollectionObjectResource() { + // do nothing + } + + @GET + public CollectionObjectList getCollectionObjectList(@Context UriInfo ui) { + CollectionObjectList p = new CollectionObjectList(); + try{ + List list = p.getCollectionObjectListItem(); + NuxeoRESTClient nxClient = getClient(); + + List pathParams = new ArrayList(); + Map queryParams = new HashMap(); + pathParams = Arrays.asList("default", NUXEO_WORKSPACE_UID, "browse"); + Representation res = nxClient.get(pathParams, queryParams); + SAXReader reader = new SAXReader(); + Document document = reader.read(res.getStream()); + Element root = document.getRootElement(); + for(Iterator i = root.elementIterator(); i.hasNext();){ + Element element = (Element) i.next(); + CollectionObjectListItem pli = new CollectionObjectListItem(); + // + pli.setCsid(element.attributeValue("csid")); + pli.setUri(element.attributeValue("url")); + pli.setIdentifier(element.attributeValue("identifier")); + list.add(pli); + } + + }catch(Exception e){ + e.printStackTrace(); + } + return p; + } + + @POST + public Response createCollectionObject(CollectionObject co) { + + NuxeoRESTClient nxClient = getClient(); + + List pathParams = new ArrayList(); + Map queryParams = new HashMap(); + pathParams.add("default"); + pathParams.add(NUXEO_WORKSPACE_UID); + pathParams.add("createDocument"); + queryParams.put("docType", NUXEO_DOCTYPE); + + queryParams.put("dublincore:title", co.getIdentifier()); + // CollectionObject core values + queryParams.put("collectionobject:csid", Integer.valueOf(1).toString()); + queryParams.put("collectionobject:identifier", co.getIdentifier()); + queryParams.put("collectionobject:description", co.getDescription()); + + ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]); + Representation res = nxClient.post(pathParams, queryParams, bais); + + SAXReader reader = new SAXReader(); + try { + Document document = reader.read(res.getStream()); + Element root = document.getRootElement(); + for (Iterator i = root.elementIterator(); i.hasNext();){ + Element element = (Element) i.next(); + if ("docRef".equals(element.getName())){ + String id = (String) element.getData(); + co.setCsid(id); + } + } + } catch(Exception e){ + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Create failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + + verbose("created collectionobject", co); + UriBuilder path = UriBuilder.fromResource(PersonNuxeoResource.class); + path.path("" + co.getCsid()); + Response response = Response.created(path.build()).build(); + + return response; + } + + @GET + @Path("{csid}") + public CollectionObject getCollectionObject(@PathParam("csid") String csid) { + + CollectionObject co = null; + try { + List pathParams = new ArrayList(); + Map queryParams = new HashMap(); + + pathParams.add("default"); + pathParams.add(csid); + pathParams.add("export"); + queryParams.put("format", "XML"); + + NuxeoRESTClient nxClient = getClient(); + Representation res = nxClient.get(pathParams, queryParams); + + SAXReader reader = new SAXReader(); + Document document = reader.read(res.getStream()); + Element root = document.getRootElement(); + co = new CollectionObject(); + + // TODO: recognize schema thru namespace uri +// Namespace ns = new Namespace("collectionobject", "http://collectionspace.org/collectionobject"); + + Iterator siter = root.elementIterator("schema"); + while (siter.hasNext()) { + + Element schemaElement = siter.next(); + System.err.println("CollectionObject.getCollectionObject() called."); + + //TODO: recognize schema thru namespace uri + if ("collectionobject".equals(schemaElement.attribute("name").getValue())){ + co.setCsid(csid); + Element ele = schemaElement.element("identifier"); + if(ele != null){ + co.setIdentifier((String) ele.getData()); + } + ele = schemaElement.element("description"); + if(ele != null){ + co.setDescription((String) ele.getData()); + } + } + } + + } catch(Exception e){ + e.printStackTrace(); + Response response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + "Get failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + if (co == null) { + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed, the requested CollectionObject CSID:" + csid + ": was not found.").type("text/plain").build(); + throw new WebApplicationException(response); + } + verbose("get collectionobject", co); + + return co; + } + + @PUT + @Path("{csid}") + public CollectionObject updateCollectionObject( + @PathParam("csid") String csid, + CollectionObject update) { + + verbose("updating collectionobject input", update); + + List pathParams = new ArrayList(); + Map queryParams = new HashMap(); + pathParams.add("default"); + pathParams.add(update.getCsid()); + pathParams.add("updateDocumentRestlet"); + + //todo: intelligent merge needed + if(update.getIdentifier() != null){ + queryParams.put("collectionobject:identifier", update.getIdentifier()); + } + + if(update.getDescription() != null){ + queryParams.put("collectionobject:description", update.getDescription()); + } + + NuxeoRESTClient nxClient = getClient(); + Representation res = nxClient.get(pathParams, queryParams); + SAXReader reader = new SAXReader(); + String status = ""; + try { + Document document = reader.read(res.getStream()); + Element root = document.getRootElement(); + for(Iterator i = root.elementIterator(); i.hasNext();){ + Element element = (Element) i.next(); + if("docRef".equals(element.getName())){ + status = (String) element.getData(); + verbose("update collectionobject: response=" + status); + } + + } + } catch(Exception e) { + //FIXME: NOT_FOUND? + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Update failed ").type("text/plain").build(); + throw new WebApplicationException(response); + } + + return update; + } + + @DELETE + @Path("{csid}") + public void deleteCollectionObject(@PathParam("csid") String csid) { + + verbose("deleting collectionobject with csid=" + csid); + + NuxeoRESTClient nxClient = getClient(); + List pathParams = new ArrayList(); + Map queryParams = new HashMap(); + + pathParams.add("default"); + pathParams.add(csid); + pathParams.add("deleteDocumentRestlet"); + Representation res = nxClient.get(pathParams, queryParams); + SAXReader reader = new SAXReader(); + String status = ""; + + try { + Document document = reader.read(res.getStream()); + Element root = document.getRootElement(); + for(Iterator i = root.elementIterator(); i.hasNext();){ + Element element = (Element) i.next(); + if("docRef".equals(element.getName())){ + status = (String) element.getData(); + verbose("delete collectionobject: response=" + status); + } + + } + }catch(Exception e){ + //FIXME: NOT_FOUND? + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Delete failed ").type("text/plain").build(); + throw new WebApplicationException(response); + } + + } + + private void verbose(String msg, CollectionObject co) { + try { + verbose(msg); + JAXBContext jc = JAXBContext.newInstance( + CollectionObject.class); + + Marshaller m = jc.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, + Boolean.TRUE); + m.marshal(co, System.out); + } catch(Exception e){ + e.printStackTrace(); + } + + } + + private NuxeoRESTClient getClient() { + NuxeoRESTClient nxClient = new NuxeoRESTClient("http://127.0.0.1:8080/nuxeo"); + nxClient.setAuthType(NuxeoRESTClient.AUTH_TYPE_BASIC); + nxClient.setBasicAuthentication("Administrator", "Administrator"); + return nxClient; + } + + private void verbose(String msg) { + System.out.println("CollectionObjectResource: " + msg); + } +} diff --git a/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/HelloworldNuxeoApplication.java b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/HelloworldNuxeoApplication.java index 9443764b9..d6b05c691 100644 --- a/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/HelloworldNuxeoApplication.java +++ b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/HelloworldNuxeoApplication.java @@ -10,6 +10,7 @@ public class HelloworldNuxeoApplication extends Application { private Set> empty = new HashSet>(); public HelloworldNuxeoApplication() { + singletons.add(new CollectionObjectResource()); singletons.add(new PersonNuxeoResource()); } diff --git a/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/IdentifierResource.java b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/IdentifierResource.java new file mode 100644 index 000000000..4c4104890 --- /dev/null +++ b/sandbox/richard/HelloWorld/HelloWorldNuxeoService/src/main/java/org/collectionspace/hello/services/IdentifierResource.java @@ -0,0 +1,77 @@ +package org.collectionspace.hello.services; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +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.Response; +import java.util.Map; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicLong; +import javax.ws.rs.core.UriBuilder; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; +import org.collectionspace.hello.Identifier; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Path("/identifiers") +@Consumes("application/xml") +@Produces("application/xml") +public class IdentifierResource { + + final Logger logger = LoggerFactory.getLogger(IdentifierResource.class); + private Map idDB = new ConcurrentHashMap(); + private AtomicLong idCounter = new AtomicLong(); + + public IdentifierResource() { + } + + @POST + public Response createIdentifier(Identifier id) { + if (id.getNamespace() == null) { + id.setNamespace("edu.berkeley"); + } + id.setId(idCounter.incrementAndGet()); + id.setVersion(1); + UUID uuid = UUID.nameUUIDFromBytes(id.getNamespace().getBytes()); + id.setValue(uuid.toString()); + idDB.put(id.getId(), id); + verbose("created Id", id); + UriBuilder path = UriBuilder.fromResource(IdentifierResource.class); + path.path("" + id.getId()); + Response response = Response.created(path.build()).build(); + return response; + } + + @GET + @Path("{id}") + public Identifier getIdentifier(@PathParam("id") Long id) { + Identifier i = idDB.get(id); + if (i == null) { + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "The requested ID was not found.").type("text/plain").build(); + throw new WebApplicationException(response); + } + verbose("get Id", i); + return i; + } + + private void verbose(String msg, Identifier id) { + try { + System.out.println("IdentifierResource : " + msg); + JAXBContext jc = JAXBContext.newInstance(Identifier.class); + Marshaller m = jc.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, + Boolean.TRUE); + m.marshal(id, System.out); + + } catch (Exception e) { + e.printStackTrace(); + } + } +} -- 2.47.3