From 9c5d3608541fac36634804bde31ac4e523979a05 Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Tue, 15 Feb 2011 23:40:22 +0000 Subject: [PATCH] CSPACE-3574: Merging Plain Old XML payload work into trunk. --- .../nuxeo-platform-cs-blob/.classpath | 12 +- .../3rdparty/nuxeo-platform-cs-blob/.project | 12 +- services/blob/client/.classpath | 317 ++++++++++++++++- services/blob/client/.project | 18 +- .../services/client/BlobClient.java | 34 +- .../services/client/BlobProxy.java | 14 +- .../client/test/BlobAuthRefsTest.java | 37 +- .../services/client/test/BlobServiceTest.java | 53 +-- services/blob/jaxb/.classpath | 37 +- services/blob/jaxb/.project | 10 +- .../.settings/org.maven.ide.eclipse.prefs | 8 +- services/blob/service/.classpath | 319 ++++++++++++++++- services/blob/service/.project | 19 +- services/blob/service/pom.xml | 6 + .../services/blob/BlobResource.java | 30 +- services/client/.classpath | 224 +++++++++++- services/client/.project | 11 +- services/client/pom.xml | 7 + .../client/AbstractServiceClientImpl.java | 38 ++- .../client/CollectionSpaceClient.java | 2 + .../client/CollectionSpaceClientUtils.java | 23 ++ .../services/client/PayloadInputPart.java | 36 ++ .../services/client/PayloadOutputPart.java | 48 +++ .../services/client/PayloadPart.java | 77 +++++ .../services/client/PoxPayload.java | 304 +++++++++++++++++ .../services/client/PoxPayloadIn.java | 51 +++ .../services/client/PoxPayloadOut.java | 174 ++++++++++ .../services/client/TestServiceClient.java | 5 + .../client/test/AbstractServiceTestImpl.java | 10 + .../services/client/test/BaseServiceTest.java | 95 ++---- services/common/.classpath | 322 +++++++++++++++++- services/common/.project | 17 +- .../.settings/org.maven.ide.eclipse.prefs | 4 +- services/common/pom.xml | 4 +- ...tMultiPartCollectionSpaceResourceImpl.java | 23 +- .../services/common/ResourceBase.java | 73 ++-- .../services/common/blob/BlobUtil.java | 8 +- .../context/MultipartServiceContext.java | 30 +- .../MultipartServiceContextFactory.java | 20 +- .../context/MultipartServiceContextImpl.java | 120 +++---- .../common/document/DocumentUtils.java | 63 ++-- .../services/common/query/QueryContext.java | 8 +- .../common/vocabulary/AuthorityResource.java | 87 ++--- .../java/RemoteDocumentModelHandlerImpl.java | 47 +-- ...RemoteSubItemDocumentModelHandlerImpl.java | 11 +- .../client/java/RepositoryJavaClientImpl.java | 4 +- .../nuxeo-platform-cs-contact/.classpath | 12 +- .../nuxeo-platform-cs-contact/.project | 2 +- services/contact/client/.classpath | 230 ++++++++++++- services/contact/client/.project | 4 +- services/contact/client/pom.xml | 6 + .../services/client/ContactClient.java | 30 +- .../services/client/ContactClientUtils.java | 18 +- .../services/client/ContactProxy.java | 15 +- .../client/test/ContactServiceTest.java | 57 ++-- services/contact/jaxb/.classpath | 39 ++- services/contact/jaxb/.project | 6 +- .../.settings/org.maven.ide.eclipse.prefs | 8 +- services/contact/service/.classpath | 310 ++++++++++++++++- services/contact/service/.project | 8 +- services/contact/service/pom.xml | 5 + .../AuthorityResourceWithContacts.java | 87 ++--- .../services/contact/ContactResource.java | 68 ++-- services/jaxb/.classpath | 36 +- services/jaxb/.project | 12 +- .../.settings/org.maven.ide.eclipse.prefs | 8 +- 66 files changed, 3166 insertions(+), 667 deletions(-) create mode 100644 services/client/src/main/java/org/collectionspace/services/client/PayloadInputPart.java create mode 100644 services/client/src/main/java/org/collectionspace/services/client/PayloadOutputPart.java create mode 100644 services/client/src/main/java/org/collectionspace/services/client/PayloadPart.java create mode 100644 services/client/src/main/java/org/collectionspace/services/client/PoxPayload.java create mode 100644 services/client/src/main/java/org/collectionspace/services/client/PoxPayloadIn.java create mode 100644 services/client/src/main/java/org/collectionspace/services/client/PoxPayloadOut.java diff --git a/services/blob/3rdparty/nuxeo-platform-cs-blob/.classpath b/services/blob/3rdparty/nuxeo-platform-cs-blob/.classpath index 199bbbbdb..6fd3b8551 100644 --- a/services/blob/3rdparty/nuxeo-platform-cs-blob/.classpath +++ b/services/blob/3rdparty/nuxeo-platform-cs-blob/.classpath @@ -1,8 +1,8 @@ - - - - - + + - + + + + \ No newline at end of file diff --git a/services/blob/3rdparty/nuxeo-platform-cs-blob/.project b/services/blob/3rdparty/nuxeo-platform-cs-blob/.project index 1342197e9..6c1cf7de3 100644 --- a/services/blob/3rdparty/nuxeo-platform-cs-blob/.project +++ b/services/blob/3rdparty/nuxeo-platform-cs-blob/.project @@ -1,23 +1,17 @@ - org.collectionspace.services.blob.3rdparty.nuxeo - - - + Blob Nuxeo Document Type. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. + org.eclipse.jdt.core.javabuilder - - org.maven.ide.eclipse.maven2Builder - - org.eclipse.jdt.core.javanature org.maven.ide.eclipse.maven2Nature - + \ No newline at end of file diff --git a/services/blob/client/.classpath b/services/blob/client/.classpath index 425cd1620..f6761bae7 100644 --- a/services/blob/client/.classpath +++ b/services/blob/client/.classpath @@ -1,10 +1,311 @@ - - - - - - - + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/services/blob/client/.project b/services/blob/client/.project index ff7456be8..3923ea3a7 100644 --- a/services/blob/client/.project +++ b/services/blob/client/.project @@ -1,23 +1,27 @@ - org.collectionspace.services.blob.client - + NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. + org.collectionspace.services.3rdparty.nuxeo.quote-api + org.collectionspace.services.client + org.collectionspace.services.common + org.collectionspace.services.contact.client + org.collectionspace.services.contact.jaxb + org.collectionspace.services.hyperjaxb + org.collectionspace.services.jaxb + org.collectionspace.services.person.client + org.collectionspace.services.person.jaxb org.eclipse.jdt.core.javabuilder - - org.maven.ide.eclipse.maven2Builder - - org.eclipse.jdt.core.javanature org.maven.ide.eclipse.maven2Nature - + \ No newline at end of file diff --git a/services/blob/client/src/main/java/org/collectionspace/services/client/BlobClient.java b/services/blob/client/src/main/java/org/collectionspace/services/client/BlobClient.java index 510d30e5f..387f9af63 100644 --- a/services/blob/client/src/main/java/org/collectionspace/services/client/BlobClient.java +++ b/services/blob/client/src/main/java/org/collectionspace/services/client/BlobClient.java @@ -16,7 +16,6 @@ */ package org.collectionspace.services.client; -import javax.ws.rs.PathParam; import javax.ws.rs.core.Response; import org.collectionspace.services.common.authorityref.AuthorityRefList; @@ -26,8 +25,6 @@ import org.jboss.resteasy.client.ProxyFactory; import org.jboss.resteasy.plugins.providers.RegisterBuiltin; import org.jboss.resteasy.client.ClientResponse; import org.jboss.resteasy.client.core.executors.ApacheHttpClientExecutor; -import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; -import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; import org.jboss.resteasy.spi.ResteasyProviderFactory; /** @@ -38,20 +35,23 @@ import org.jboss.resteasy.spi.ResteasyProviderFactory; * */ public class BlobClient extends AbstractServiceClientImpl { - - /* (non-Javadoc) - * @see org.collectionspace.services.client.AbstractServiceClientImpl#getServicePathComponent() - */ + public static final String SERVICE_NAME = "blobs"; + public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME; + public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT; + public static final String SERVICE_PAYLOAD_NAME = SERVICE_NAME; + + @Override + public String getServiceName() { + return SERVICE_NAME; + } + + @Override public String getServicePathComponent() { - return "blobs"; //Laramie20100824 was blobs, but label was a mismatch. + return SERVICE_PATH_COMPONENT; } /** * */ -// private static final BlobClient instance = new BlobClient(); - /** - * - */ private BlobProxy blobProxy; /** @@ -115,7 +115,7 @@ public class BlobClient extends AbstractServiceClientImpl { * @return * @see org.collectionspace.services.client.BlobProxy#getBlob(java.lang.String) */ - public ClientResponse read(String csid) { + public ClientResponse read(String csid) { return blobProxy.read(csid); } @@ -124,8 +124,8 @@ public class BlobClient extends AbstractServiceClientImpl { * @return * */ - public ClientResponse create(MultipartOutput multipart) { - return blobProxy.create(multipart); + public ClientResponse create(PoxPayloadOut xmlPayload) { + return blobProxy.create(xmlPayload.getBytes()); } /** @@ -133,8 +133,8 @@ public class BlobClient extends AbstractServiceClientImpl { * @param blob * @return */ - public ClientResponse update(String csid, MultipartOutput multipart) { - return blobProxy.update(csid, multipart); + public ClientResponse update(String csid, PoxPayloadOut xmlPayload) { + return blobProxy.update(csid, xmlPayload.getBytes()); } diff --git a/services/blob/client/src/main/java/org/collectionspace/services/client/BlobProxy.java b/services/blob/client/src/main/java/org/collectionspace/services/client/BlobProxy.java index 18829d9a0..d6c7ff9d0 100644 --- a/services/blob/client/src/main/java/org/collectionspace/services/client/BlobProxy.java +++ b/services/blob/client/src/main/java/org/collectionspace/services/client/BlobProxy.java @@ -13,30 +13,28 @@ import javax.ws.rs.core.Response; import org.collectionspace.services.common.authorityref.AuthorityRefList; import org.collectionspace.services.jaxb.AbstractCommonList; import org.jboss.resteasy.client.ClientResponse; -import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; -import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; /** * @version $Revision: 2108 $ */ -@Path("/blobs/") -@Produces({"multipart/mixed"}) -@Consumes({"multipart/mixed"}) +@Path(BlobClient.SERVICE_PATH + "/") +@Produces({"application/xml"}) +@Consumes({"application/xml"}) public interface BlobProxy extends CollectionSpaceProxy { //(C)reate @POST - ClientResponse create(MultipartOutput multipart); + ClientResponse create(byte[] xmlPayload); //(R)ead @GET @Path("/{csid}") - ClientResponse read(@PathParam("csid") String csid); + ClientResponse read(@PathParam("csid") String csid); //(U)pdate @PUT @Path("/{csid}") - ClientResponse update(@PathParam("csid") String csid, MultipartOutput multipart); + ClientResponse update(@PathParam("csid") String csid, byte[] xmlPayload); //(D)elete @DELETE diff --git a/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobAuthRefsTest.java b/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobAuthRefsTest.java index b689d0f68..46a33466c 100644 --- a/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobAuthRefsTest.java +++ b/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobAuthRefsTest.java @@ -33,8 +33,11 @@ import javax.ws.rs.core.Response; import org.collectionspace.services.PersonJAXBSchema; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.BlobClient; +import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PersonAuthorityClient; import org.collectionspace.services.client.PersonAuthorityClientUtils; +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.common.authorityref.AuthorityRefList; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.blob.BlobsCommon; @@ -60,7 +63,6 @@ public class BlobAuthRefsTest extends BaseServiceTest { private final String CLASS_NAME = BlobAuthRefsTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); - final String SERVICE_PATH_COMPONENT = "blob"; final String PERSON_AUTHORITY_NAME = "BlobPersonAuth"; private String knownResourceId = null; private List blobIdsCreated = new ArrayList(); @@ -69,6 +71,16 @@ public class BlobAuthRefsTest extends BaseServiceTest { private String depositorRefName = null; private String blobName = null; + @Override + public String getServicePathComponent() { + return BlobClient.SERVICE_PATH_COMPONENT; + } + + @Override + protected String getServiceName() { + return BlobClient.SERVICE_NAME; + } + @Override protected CollectionSpaceClient getClientInstance() { throw new UnsupportedOperationException(); //method not supported (or needed) in this test class @@ -79,20 +91,15 @@ public class BlobAuthRefsTest extends BaseServiceTest { throw new UnsupportedOperationException(); //method not supported (or needed) in this test class } - @Override - public String getServicePathComponent() { - return SERVICE_PATH_COMPONENT; - } - - private MultipartOutput createBlobInstance(String depositorRefName) { + private PoxPayloadOut createBlobInstance(String depositorRefName) { this.depositorRefName = depositorRefName; this.blobName = "testblob-"+createIdentifier(); BlobsCommon blob = new BlobsCommon(); blob.setName(this.blobName); - MultipartOutput multipart = new MultipartOutput(); - OutputPart commonPart = multipart.addPart(blob, MediaType.APPLICATION_XML_TYPE); - commonPart.getHeaders().add("label", new BlobClient().getCommonPartName()); + PoxPayloadOut multipart = new PoxPayloadOut(BlobClient.SERVICE_PAYLOAD_NAME); + PayloadOutputPart commonPart = multipart.addPart(blob, MediaType.APPLICATION_XML_TYPE); + commonPart.setLabel(new BlobClient().getCommonPartName()); logger.debug("to be created, blob common: " + objectAsXmlString(blob, BlobsCommon.class)); return multipart; } @@ -106,7 +113,7 @@ public class BlobAuthRefsTest extends BaseServiceTest { // Create a new Loans In resource. One or more fields in this resource will be PersonAuthority // references, and will refer to Person resources by their refNames. BlobClient blobClient = new BlobClient(); - MultipartOutput multipart = createBlobInstance(depositorRefName); + PoxPayloadOut multipart = createBlobInstance(depositorRefName); ClientResponse res = blobClient.create(multipart); assertStatusCode(res, testName); if (knownResourceId == null) {// Store the ID returned from the first resource created for additional tests below. @@ -118,7 +125,7 @@ public class BlobAuthRefsTest extends BaseServiceTest { protected void createPersonRefs() { PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); // Create a temporary PersonAuthority resource, and its corresponding refName by which it can be identified. - MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName()); + PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance(PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName()); ClientResponse res = personAuthClient.create(multipart); assertStatusCode(res, "createPersonRefs (not a surefire test)"); personAuthCSID = extractId(res); @@ -141,7 +148,7 @@ public class BlobAuthRefsTest extends BaseServiceTest { personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); personInfo.put(PersonJAXBSchema.SUR_NAME, surName); personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId); - MultipartOutput multipart = PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, authRefName, personInfo, personAuthClient.getItemCommonPartName()); + PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, authRefName, personInfo, personAuthClient.getItemCommonPartName()); ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); assertStatusCode(res, "createPerson (not a surefire test)"); return extractId(res); @@ -158,9 +165,9 @@ public class BlobAuthRefsTest extends BaseServiceTest { logger.debug(testBanner(testName, CLASS_NAME)); testSetup(STATUS_OK, ServiceRequestType.READ); BlobClient blobClient = new BlobClient(); - ClientResponse res = blobClient.read(knownResourceId); + ClientResponse res = blobClient.read(knownResourceId); assertStatusCode(res, testName); - MultipartInput input = (MultipartInput) res.getEntity(); + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); BlobsCommon blob = (BlobsCommon) extractPart(input, blobClient.getCommonPartName(), BlobsCommon.class); Assert.assertNotNull(blob); logger.debug(objectAsXmlString(blob, BlobsCommon.class)); diff --git a/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobServiceTest.java b/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobServiceTest.java index 2dea5714d..b765a6e33 100644 --- a/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobServiceTest.java +++ b/services/blob/client/src/test/java/org/collectionspace/services/client/test/BlobServiceTest.java @@ -28,6 +28,10 @@ import javax.ws.rs.core.Response; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.BlobClient; +import org.collectionspace.services.client.ContactClient; +import org.collectionspace.services.client.PayloadOutputPart; +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.blob.BlobsCommon; @@ -51,9 +55,18 @@ public class BlobServiceTest extends AbstractServiceTestImpl { private final String CLASS_NAME = BlobServiceTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); - final String SERVICE_PATH_COMPONENT = "blobs"; private String knownResourceId = null; + @Override + public String getServicePathComponent() { + return BlobClient.SERVICE_PATH_COMPONENT; + } + + @Override + protected String getServiceName() { + return BlobClient.SERVICE_NAME; + } + @Override protected CollectionSpaceClient getClientInstance() { return new BlobClient(); @@ -70,7 +83,7 @@ public class BlobServiceTest extends AbstractServiceTestImpl { logger.debug(testBanner(testName, CLASS_NAME)); setupCreate(); BlobClient client = new BlobClient(); - MultipartOutput multipart = createBlobInstance(createIdentifier()); + PoxPayloadOut multipart = createBlobInstance(createIdentifier()); ClientResponse res = client.create(multipart); assertStatusCode(res, testName); if (knownResourceId == null) { @@ -95,9 +108,9 @@ public class BlobServiceTest extends AbstractServiceTestImpl { logger.debug(testBanner(testName, CLASS_NAME)); setupRead(); BlobClient client = new BlobClient(); - ClientResponse res = client.read(knownResourceId); + ClientResponse res = client.read(knownResourceId); assertStatusCode(res, testName); - MultipartInput input = (MultipartInput) res.getEntity(); + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); BlobsCommon blob = (BlobsCommon) extractPart(input, client.getCommonPartName(), BlobsCommon.class); Assert.assertNotNull(blob); } @@ -129,21 +142,21 @@ public class BlobServiceTest extends AbstractServiceTestImpl { logger.debug(testBanner(testName, CLASS_NAME)); setupUpdate(); BlobClient client = new BlobClient(); - ClientResponse res = client.read(knownResourceId); + ClientResponse res = client.read(knownResourceId); assertStatusCode(res, testName); logger.debug("got object to update with ID: " + knownResourceId); - MultipartInput input = (MultipartInput) res.getEntity(); + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); BlobsCommon blob = (BlobsCommon) extractPart(input, client.getCommonPartName(), BlobsCommon.class); Assert.assertNotNull(blob); blob.setName("updated-" + blob.getName()); logger.debug("Object to be updated:"+objectAsXmlString(blob, BlobsCommon.class)); - MultipartOutput output = new MultipartOutput(); - OutputPart commonPart = output.addPart(blob, MediaType.APPLICATION_XML_TYPE); - commonPart.getHeaders().add("label", client.getCommonPartName()); + PoxPayloadOut output = new PoxPayloadOut(BlobClient.SERVICE_PAYLOAD_NAME); + PayloadOutputPart commonPart = output.addPart(blob, MediaType.APPLICATION_XML_TYPE); + commonPart.setLabel(client.getCommonPartName()); res = client.update(knownResourceId, output); assertStatusCode(res, testName); - input = (MultipartInput) res.getEntity(); + input = new PoxPayloadIn(res.getEntity()); BlobsCommon updatedBlob = (BlobsCommon) extractPart(input, client.getCommonPartName(), BlobsCommon.class); Assert.assertNotNull(updatedBlob); } @@ -157,8 +170,8 @@ public class BlobServiceTest extends AbstractServiceTestImpl { // Note: The ID used in this 'create' call may be arbitrary. // The only relevant ID may be the one used in update(), below. BlobClient client = new BlobClient(); - MultipartOutput multipart = createBlobInstance(NON_EXISTENT_ID); - ClientResponse res = client.update(NON_EXISTENT_ID, multipart); + PoxPayloadOut multipart = createBlobInstance(NON_EXISTENT_ID); + ClientResponse res = client.update(NON_EXISTENT_ID, multipart); assertStatusCode(res, testName); } @@ -183,7 +196,7 @@ public class BlobServiceTest extends AbstractServiceTestImpl { logger.debug(testBanner(testName, CLASS_NAME)); setupReadNonExistent(); BlobClient client = new BlobClient(); - ClientResponse res = client.read(NON_EXISTENT_ID); + ClientResponse res = client.read(NON_EXISTENT_ID); assertStatusCode(res, testName); } @@ -242,19 +255,13 @@ public class BlobServiceTest extends AbstractServiceTestImpl { // --------------------------------------------------------------- // Utility methods used by tests above // --------------------------------------------------------------- - - @Override - public String getServicePathComponent() { - return SERVICE_PATH_COMPONENT; - } - - private MultipartOutput createBlobInstance(String exitNumber) { + private PoxPayloadOut createBlobInstance(String exitNumber) { String identifier = "blobNumber-" + exitNumber; BlobsCommon blob = new BlobsCommon(); blob.setName(identifier); - MultipartOutput multipart = new MultipartOutput(); - OutputPart commonPart = multipart.addPart(blob, MediaType.APPLICATION_XML_TYPE); - commonPart.getHeaders().add("label", new BlobClient().getCommonPartName()); + PoxPayloadOut multipart = new PoxPayloadOut(BlobClient.SERVICE_PAYLOAD_NAME); + PayloadOutputPart commonPart = multipart.addPart(blob, MediaType.APPLICATION_XML_TYPE); + commonPart.setLabel(new BlobClient().getCommonPartName()); if (logger.isDebugEnabled()) { logger.debug("to be created, blob common"); diff --git a/services/blob/jaxb/.classpath b/services/blob/jaxb/.classpath index 557f8a4e0..981c9add6 100644 --- a/services/blob/jaxb/.classpath +++ b/services/blob/jaxb/.classpath @@ -1,10 +1,31 @@ - - - - - - - + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/services/blob/jaxb/.project b/services/blob/jaxb/.project index 99f9fcfb7..04d0bd6db 100644 --- a/services/blob/jaxb/.project +++ b/services/blob/jaxb/.project @@ -1,23 +1,19 @@ - org.collectionspace.services.blob.jaxb - + NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. + org.collectionspace.services.jaxb org.eclipse.jdt.core.javabuilder - - org.maven.ide.eclipse.maven2Builder - - org.eclipse.jdt.core.javanature org.maven.ide.eclipse.maven2Nature - + \ No newline at end of file diff --git a/services/blob/jaxb/.settings/org.maven.ide.eclipse.prefs b/services/blob/jaxb/.settings/org.maven.ide.eclipse.prefs index a342accb7..8ff0f62ad 100644 --- a/services/blob/jaxb/.settings/org.maven.ide.eclipse.prefs +++ b/services/blob/jaxb/.settings/org.maven.ide.eclipse.prefs @@ -1,9 +1,9 @@ -#Tue Dec 21 10:25:44 PST 2010 +#Wed Jan 19 22:49:19 PST 2011 activeProfiles= eclipse.preferences.version=1 -fullBuildGoals=process-classes +fullBuildGoals=process-test-resources includeModules=false resolveWorkspaceProjects=true -resourceFilterGoals=process-classes -skipCompilerPlugin=false +resourceFilterGoals=process-resources resources\:testResources +skipCompilerPlugin=true version=1 diff --git a/services/blob/service/.classpath b/services/blob/service/.classpath index 425cd1620..0d32cead7 100644 --- a/services/blob/service/.classpath +++ b/services/blob/service/.classpath @@ -1,10 +1,313 @@ - - - - - - - + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/services/blob/service/.project b/services/blob/service/.project index e2bde3e1c..6501aa408 100644 --- a/services/blob/service/.project +++ b/services/blob/service/.project @@ -1,23 +1,28 @@ - org.collectionspace.services.blob.service - + NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. + org.collectionspace.services.3rdparty.nuxeo.quote-api + org.collectionspace.services.blob.client + org.collectionspace.services.client + org.collectionspace.services.common + org.collectionspace.services.contact.client + org.collectionspace.services.contact.jaxb + org.collectionspace.services.hyperjaxb + org.collectionspace.services.jaxb + org.collectionspace.services.person.client + org.collectionspace.services.person.jaxb org.eclipse.jdt.core.javabuilder - - org.maven.ide.eclipse.maven2Builder - - org.eclipse.jdt.core.javanature org.maven.ide.eclipse.maven2Nature - + \ No newline at end of file diff --git a/services/blob/service/pom.xml b/services/blob/service/pom.xml index 9cc520606..1cb09b79d 100644 --- a/services/blob/service/pom.xml +++ b/services/blob/service/pom.xml @@ -24,6 +24,12 @@ org.collectionspace.services.jaxb ${project.version} + + org.collectionspace.services + org.collectionspace.services.blob.client + ${project.version} + + junit diff --git a/services/blob/service/src/main/java/org/collectionspace/services/blob/BlobResource.java b/services/blob/service/src/main/java/org/collectionspace/services/blob/BlobResource.java index bb0fd3444..98b255c08 100644 --- a/services/blob/service/src/main/java/org/collectionspace/services/blob/BlobResource.java +++ b/services/blob/service/src/main/java/org/collectionspace/services/blob/BlobResource.java @@ -26,6 +26,9 @@ package org.collectionspace.services.blob; import java.util.Map; import java.util.UUID; +import org.collectionspace.services.client.BlobClient; +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.common.FileUtils; import org.collectionspace.services.common.ResourceBase; //import org.collectionspace.services.common.ClientType; @@ -72,9 +75,9 @@ import java.io.File; import java.io.InputStream; import java.util.List; -@Path("/blobs") -@Consumes("multipart/mixed") -@Produces("multipart/mixed") +@Path(BlobClient.SERVICE_PATH) +@Consumes({"multipart/mixed", "application/xml"}) +@Produces({"multipart/mixed", "application/xml"}) public class BlobResource extends ResourceBase { @Override @@ -82,7 +85,6 @@ public class BlobResource extends ResourceBase { return BlobUtil.BLOB_RESOURCE_NAME; } - @Override protected String getVersionString() { final String lastChangeRevision = "$LastChangedRevision: 2108 $"; @@ -110,7 +112,7 @@ public class BlobResource extends ResourceBase { return (CommonList) super.search(queryParams, keywords); } - private CommonList getDerivativeList(ServiceContext ctx, + private CommonList getDerivativeList(ServiceContext ctx, String csid) throws Exception { CommonList result = null; @@ -118,7 +120,7 @@ public class BlobResource extends ResourceBase { blobInput.setDerivativeListRequested(true); BlobUtil.setBlobInput(ctx, blobInput); - MultipartOutput response = this.get(csid, ctx); + PoxPayloadOut response = this.get(csid, ctx); if (logger.isDebugEnabled() == true) { logger.debug(response.toString()); } @@ -135,12 +137,12 @@ public class BlobResource extends ResourceBase { InputStream result = null; try { - ServiceContext ctx = createServiceContext(); + ServiceContext ctx = createServiceContext(); BlobInput blobInput = BlobUtil.getBlobInput(ctx); blobInput.setDerivativeTerm(derivativeTerm); blobInput.setContentRequested(true); - MultipartOutput response = this.get(csid, ctx); + PoxPayloadOut response = this.get(csid, ctx); if (logger.isDebugEnabled() == true) { logger.debug(response.toString()); } @@ -210,7 +212,7 @@ public class BlobResource extends ResourceBase { @QueryParam("blobUri") String blobUri) { Response response = null; try { - ServiceContext ctx = createServiceContext(); + ServiceContext ctx = createServiceContext(); BlobInput blobInput = BlobUtil.getBlobInput(ctx); blobInput.createBlobFile(req, blobUri); response = this.create(null, ctx); @@ -245,13 +247,13 @@ public class BlobResource extends ResourceBase { @GET @Path("{csid}/derivatives/{derivativeTerm}") - public MultipartOutput getDerivative(@PathParam("csid") String csid, + public String getDerivative(@PathParam("csid") String csid, @PathParam("derivativeTerm") String derivativeTerm) { - MultipartOutput result = null; + PoxPayloadOut result = null; ensureCSID(csid, READ); try { - ServiceContext ctx = createServiceContext(); + ServiceContext ctx = createServiceContext(); BlobInput blobInput = BlobUtil.getBlobInput(ctx); blobInput.setDerivativeTerm(derivativeTerm); result = get(csid, ctx); @@ -264,7 +266,7 @@ public class BlobResource extends ResourceBase { throw bigReThrow(e, ServiceMessages.READ_FAILED, csid); } - return result; + return result.toXML(); } @GET @@ -276,7 +278,7 @@ public class BlobResource extends ResourceBase { ensureCSID(csid, READ); try { - ServiceContext ctx = createServiceContext(); + ServiceContext ctx = createServiceContext(); result = this.getDerivativeList(ctx, csid); if (result == null) { Response response = Response.status(Response.Status.NOT_FOUND).entity( diff --git a/services/client/.classpath b/services/client/.classpath index 425cd1620..ac845bf70 100644 --- a/services/client/.classpath +++ b/services/client/.classpath @@ -1,10 +1,218 @@ - - - - - - - + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/services/client/.project b/services/client/.project index c533bc253..a89fde126 100644 --- a/services/client/.project +++ b/services/client/.project @@ -1,24 +1,19 @@ - org.collectionspace.services.client - + NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. - org.collectionspace.services.common + org.collectionspace.services.jaxb org.eclipse.jdt.core.javabuilder - - org.maven.ide.eclipse.maven2Builder - - org.maven.ide.eclipse.maven2Nature org.eclipse.jdt.core.javanature - + \ No newline at end of file diff --git a/services/client/pom.xml b/services/client/pom.xml index facb89bb2..d2535166a 100644 --- a/services/client/pom.xml +++ b/services/client/pom.xml @@ -83,6 +83,13 @@ 1.0.01 provided + + com.sun.xml.bind + jaxb-impl + 2.2.2 + jar + compile + dom4j dom4j diff --git a/services/client/src/main/java/org/collectionspace/services/client/AbstractServiceClientImpl.java b/services/client/src/main/java/org/collectionspace/services/client/AbstractServiceClientImpl.java index 48c6be2cf..53a4e8fa4 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/AbstractServiceClientImpl.java +++ b/services/client/src/main/java/org/collectionspace/services/client/AbstractServiceClientImpl.java @@ -24,6 +24,7 @@ package org.collectionspace.services.client; import java.io.InputStream; +import java.io.UnsupportedEncodingException; import java.net.URL; import java.util.Properties; @@ -74,13 +75,32 @@ public abstract class AbstractServiceClientImpl implements return logger; } + abstract public String getServicePathComponent(); + + /** + * Returns a UTF-8 encode byte array from 'string' + * + * @return UTF-8 encoded byte array + */ + protected byte[] getBytes(String string) { + byte[] result = null; + try { + result = string.getBytes("UTF8"); + } catch (UnsupportedEncodingException e) { + if (logger.isWarnEnabled() == true) { + logger.warn(e.getMessage(), e); + } + } + return result; + } + /** * Gets the common part name. * * @return the common part name */ public String getCommonPartName() { - return getCommonPartName(getServicePathComponent()); + return getCommonPartName(getServiceName()); } /** @@ -90,16 +110,16 @@ public abstract class AbstractServiceClientImpl implements * the service path component * @return the common part name */ - public String getCommonPartName(String servicePathComponent) { - return servicePathComponent + PART_LABEL_SEPARATOR + PART_COMMON_LABEL; + protected String getCommonPartName(String commonPrefix) { + return commonPrefix + PART_LABEL_SEPARATOR + PART_COMMON_LABEL; } - /** - * Gets the service path component. - * - * @return the service path component - */ - abstract public String getServicePathComponent(); +// /** +// * Gets the service path component. +// * +// * @return the service path component +// */ +// abstract public String getServicePathComponent(); /** * Instantiates a new abstract service client impl. diff --git a/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClient.java b/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClient.java index f61b18b2a..b785d1d3b 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClient.java +++ b/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClient.java @@ -53,6 +53,8 @@ public interface CollectionSpaceClient { * @return the base url */ String getBaseURL(); + + String getServiceName(); /** * Gets the http client. diff --git a/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClientUtils.java b/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClientUtils.java index c2236dfd4..4cd6764e7 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClientUtils.java +++ b/services/client/src/main/java/org/collectionspace/services/client/CollectionSpaceClientUtils.java @@ -100,6 +100,29 @@ public class CollectionSpaceClientUtils { * @return the object * @throws Exception the exception */ + static protected Object extractPart(PoxPayloadIn input, String label, Class clazz) + throws Exception { + Object result = null; + PayloadInputPart payloadInputPart = input.getPart(label); + if (payloadInputPart != null) { + result = payloadInputPart.getBody(); + } else if (logger.isWarnEnabled() == true) { + logger.warn("Payload part: " + label + + " is missing from payload: " + input.getName()); + } + return result; + } + + /** + * Extract part. + * + * @param input the input + * @param label the label + * @param clazz the clazz + * @return the object + * @throws Exception the exception + */ + @Deprecated static public Object extractPart(MultipartInput input, String label, Class clazz) throws Exception { Object obj = null; diff --git a/services/client/src/main/java/org/collectionspace/services/client/PayloadInputPart.java b/services/client/src/main/java/org/collectionspace/services/client/PayloadInputPart.java new file mode 100644 index 000000000..af3b5d721 --- /dev/null +++ b/services/client/src/main/java/org/collectionspace/services/client/PayloadInputPart.java @@ -0,0 +1,36 @@ +package org.collectionspace.services.client; + +import javax.ws.rs.core.MediaType; +import org.dom4j.Element; + +public class PayloadInputPart extends PayloadPart { +// private Element elementBody; + + public PayloadInputPart(String label, Object body) { + super(label, body); + } + + public PayloadInputPart(String label, Object body, Element elementBody) { + super(label, body, elementBody); + } + + public PayloadInputPart(String label, Element elementBody) { + super(label, elementBody); + } + + @Override + public String asXML() { + String result = null; + Object body = getBody(); + if (getElementBody() != null) { + result = getElementBody().asXML(); + } else if (body != null) { + result = PoxPayload.toElement(getBody()).asXML(); + } + return result; + } + + public MediaType getMediaType() { + return MediaType.APPLICATION_XML_TYPE; + } +} diff --git a/services/client/src/main/java/org/collectionspace/services/client/PayloadOutputPart.java b/services/client/src/main/java/org/collectionspace/services/client/PayloadOutputPart.java new file mode 100644 index 000000000..96e1f1af8 --- /dev/null +++ b/services/client/src/main/java/org/collectionspace/services/client/PayloadOutputPart.java @@ -0,0 +1,48 @@ +package org.collectionspace.services.client; + +import org.dom4j.DocumentException; +import org.dom4j.Element; + +public class PayloadOutputPart extends PayloadPart { + + // + // Constructors + // + PayloadOutputPart(String label, Object body) { + super(label, body); + } + + PayloadOutputPart(String label, Element elementBody) { + super(label, elementBody); + } + + PayloadOutputPart(String label, String xmlBody) throws DocumentException { + super(label, xmlBody); + } + + PayloadOutputPart(String label, Object body, Element elementBody) { + super(label, body, elementBody); + } + + // + // Utility Methods + // + + @Override + public String asXML() { + String result = null; + + Element elementBody = getElementBody(); + if (elementBody != null) { + result = elementBody.asXML(); + } else { + Object body = getBody(); + if (body != null) { + result = PoxPayload.toElement(body).asXML(); + } + } + + return result; + } + +} diff --git a/services/client/src/main/java/org/collectionspace/services/client/PayloadPart.java b/services/client/src/main/java/org/collectionspace/services/client/PayloadPart.java new file mode 100644 index 000000000..9cdece300 --- /dev/null +++ b/services/client/src/main/java/org/collectionspace/services/client/PayloadPart.java @@ -0,0 +1,77 @@ +package org.collectionspace.services.client; + +import org.dom4j.DocumentException; +import org.dom4j.Element; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public abstract class PayloadPart { + protected final Logger logger = LoggerFactory.getLogger(PayloadPart.class); + + private String label; + private Object body; + private Element elementBody; + + public PayloadPart(String label) { + this.label = label; + } + + public PayloadPart(String label, Object body) { + this(label); + this.body = body; + } + + /** + * Instantiates a new payload part by parsing the XML string 'xmlPayload' + * + * @param label the label + * @param xmlPayload the xml payload + * @throws DocumentException the document exception + */ + public PayloadPart(String label, String xmlPayload) throws DocumentException { + this(label); + Element element = PoxPayload.toElement(xmlPayload); + this.elementBody = element; + + } + + public PayloadPart(String label, Object body, Element elementBody) { + this(label, body); + this.elementBody = elementBody; + } + + public PayloadPart(String label, Element elementBody) { + this(label); + this.elementBody = elementBody; + } + + abstract public String asXML(); + + public Element asElement() { + Element result = elementBody; + // if we don't already have an Element, let's try to create one from a JAXB object + if (result == null) { + if (body != null) { + //toElement(body) will return null if not given an JAXB object + result = PoxPayload.toElement(body); + } + } + return result; + } + + public Object getBody() { + return body; + } + + public Element getElementBody() { + return elementBody; + } + + public void setLabel(String label) { + this.label = label; + } + + public String getLabel() { + return this.label; + } +} diff --git a/services/client/src/main/java/org/collectionspace/services/client/PoxPayload.java b/services/client/src/main/java/org/collectionspace/services/client/PoxPayload.java new file mode 100644 index 000000000..32ffddf3e --- /dev/null +++ b/services/client/src/main/java/org/collectionspace/services/client/PoxPayload.java @@ -0,0 +1,304 @@ +package org.collectionspace.services.client; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.StringReader; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; +import javax.xml.bind.Unmarshaller; +import javax.xml.transform.stream.StreamSource; + +import com.sun.xml.bind.api.impl.NameConverter; +import org.apache.commons.io.FileUtils; + +import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.DocumentHelper; +import org.dom4j.Element; +import org.dom4j.Namespace; +import org.dom4j.io.SAXReader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +// TODO: Auto-generated Javadoc +/** + * The Class PoxPayload. + * + * @param the generic type + */ +public abstract class PoxPayload { + + /** The Constant logger. */ + protected static final Logger logger = LoggerFactory.getLogger(PayloadPart.class); + + /** The xml text. */ + private String xmlPayload; + + private Document domDocument; + + /** The payload name. */ + private String payloadName; + + // The list of POX parts contained in the xmlText payload + /** The parts. */ + private List parts = new ArrayList(); + + /** + * Instantiates a new pox payload. + */ + protected PoxPayload() { + //empty + } + + final protected void setPayloadName(String name) { + this.payloadName = name; + } + + private void setDomDocument(Document dom) throws DocumentException { + this.domDocument = dom; + String label = domDocument.getRootElement().getName(); + if (label != null) { + this.payloadName = label; + } else if (logger.isWarnEnabled() == true) { + logger.warn("Incoming message payload is missing a name/label."); + logger.warn(this.xmlPayload); + } + parseParts(); + } + + /** + * Instantiates a new PoxPayload by parsing the payload into a DOM4j + * Document instance + * + * @param payloadName the payload name + */ + protected PoxPayload(String xmlPayload) throws DocumentException { + this.xmlPayload = xmlPayload; + SAXReader reader = new SAXReader(); + Document dom = reader.read(new StringReader(xmlPayload)); + setDomDocument(dom); + } + + /** + * Instantiates a new payload, saves the original xml, creates a DOM and parses it into parts + * + * @param file the file + * @throws DocumentException the document exception + * @throws IOException Signals that an I/O exception has occurred. + */ + protected PoxPayload(File file) throws DocumentException, IOException { + this.xmlPayload = FileUtils.readFileToString(file); + SAXReader reader = new SAXReader(); + Document dom = reader.read(file); + setDomDocument(dom); + } + + /** + * Creates the part -either an PayloadOutputPart or a PayloadInputPart + * + * @param label the part label + * @param jaxbObject the JAXB object + * @param element the DOM4j element + * @return the pT + */ + abstract protected PT createPart(String label, Object jaxbObject, Element element); + + /** + * Creates the part -either an PayloadOutputPart or a PayloadInputPart + * + * @param label the part label + * @param element the DOM4j element + * @return the pT + */ + abstract protected PT createPart(String label, Element element); + + /** + * Parse the DOM object into schema parts. + * + * @throws DocumentException the document exception + */ + protected void parseParts() throws DocumentException { + Iterator it = getDOMDocument().getRootElement().elementIterator(); + PT payloadPart = null; + while (it.hasNext() == true) { + Element element = (Element) it.next(); + String label = element.getName(); + Object jaxbObject = PoxPayload.toObject(element); + if (jaxbObject != null) { + payloadPart = createPart(label, jaxbObject, element); + } else { + payloadPart = createPart(label, element); + } + if (payloadPart != null) { + this.addPart(payloadPart); + } + } + } + + /** + * Gets the name of the payload. + * + * @return the name + */ + public String getName() { + return payloadName; + } + + /** + * Gets the DOM object that we created at init time. This should never be null; + * + * @return the dOM document + */ + public Document getDOMDocument() { + return this.domDocument; + } + + /** + * Gets the xml text. + * + * @return the xml text + */ + public String getXmlPayload() { + return xmlPayload; + } + + /** + * Gets the POX part with name match 'label'. + * + * @param label the label + * @return the part + */ + public PT getPart(String label) { + PT result = null; + if (parts != null) { + Iterator it = parts.iterator(); + while (it.hasNext() == true) { + PT part = it.next(); + if (part.getLabel().equalsIgnoreCase(label) == true) { + result = part; + break; + } + } + } + return result; + } + + /** + * Gets a list of the POX parts. + * + * @return the parts + */ + public List getParts() { + return parts; + } + + /** + * Adds a POX part to the list of existing parts with the label 'label'. + * + * @param label the label + * @param entity the entity + * @return the pT + */ + public PT addPart(String label, PT entity) { + parts.add(entity); + return entity; + } + + /** + * Adds a POX part -assuming the part already has a label name. + * + * @param entity the entity + * @return the pT + */ + public PT addPart(PT entity) { + parts.add(entity); + return entity; + } + + /** + * Gets the Java package name from the specified namespace. This method + * assumes the Namespace is a xjc (JAXB compiler) generate namespace from + * which we can extract the Java package name. + * + * @param namespace the namespace + * @return the Java package name + */ + private static String getPackage(Namespace namespace) { + NameConverter nc = NameConverter.standard; + String namespaceURI = namespace.getURI(); + return nc.toPackageName(namespaceURI); + } + + /** + * Attempts to marshal a DOM4j element into an instance of a JAXB object + * + * @param elementInput the element input + * @return the object + */ + public static Object toObject(Element elementInput) { + Object result = null; + try { + Namespace namespace = elementInput.getNamespace(); + String thePackage = getPackage(namespace); + JAXBContext jc = JAXBContext.newInstance(thePackage); + Unmarshaller um = jc.createUnmarshaller(); + result = um.unmarshal( + new StreamSource(new StringReader(elementInput.asXML()))); + } catch (Exception e) { + if (logger.isTraceEnabled() == true) { + logger.trace(e.getMessage()); + } + } + + return result; + } + + /** + * Attempts to unmarshal a JAXB object to a DOM4j element. + * + * @param jaxbObject the jaxb object + * @return the element + */ + public static Element toElement(Object jaxbObject) { + Element result = null; + String text = null; + ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); + try { + String thePackage = jaxbObject.getClass().getPackage().getName(); + JAXBContext jc = JAXBContext.newInstance(thePackage); + //Create marshaller + Marshaller m = jc.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, false); + //Marshal object into file. + m.marshal(jaxbObject, outputStream); + text = outputStream.toString("UTF8"); + + Document doc = DocumentHelper.parseText(text); + result = doc.getRootElement(); //FIXME: REM - call .detach() to free the element + } catch (Exception e) { + e.printStackTrace(); //FIXME: REM - Please use proper logger.isWarning() statement + } + + return result; + } + + /** + * Attempts to unmarshal a JAXB object to a DOM4j element. + * + * @param jaxbObject the jaxb object + * @return the element + */ + public static Element toElement(String xmlPayload) throws DocumentException { + Element result = null; + Document doc = DocumentHelper.parseText(xmlPayload); + result = doc.getRootElement(); //FIXME: REM - .detach(); + return result; + } + + +} diff --git a/services/client/src/main/java/org/collectionspace/services/client/PoxPayloadIn.java b/services/client/src/main/java/org/collectionspace/services/client/PoxPayloadIn.java new file mode 100644 index 000000000..585a0f38f --- /dev/null +++ b/services/client/src/main/java/org/collectionspace/services/client/PoxPayloadIn.java @@ -0,0 +1,51 @@ +package org.collectionspace.services.client; + +//import java.io.ByteArrayInputStream; //FIXME: REM - Remove these unneeded import statements +//import java.io.InputStream; +//import java.io.Reader; +//import java.io.StringReader; +//import java.util.Iterator; +//import java.util.List; + +//import javax.xml.transform.Source; +//import javax.xml.transform.stream.StreamSource; + +//import org.dom4j.Attribute; +//import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.Element; +//import org.dom4j.Namespace; +//import org.dom4j.io.SAXReader; +//import org.xml.sax.InputSource; + +public class PoxPayloadIn extends PoxPayload { + + /* + * Parse the POX 'xmlPayload' into individual parts. Each part is saved + * as a DOM4j Element and, if possible, a JAXB object instance as well. + */ + public PoxPayloadIn(String xmlPayload) throws DocumentException { + super(xmlPayload); + } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.PoxPayload#createPart(java.lang.String, java.lang.Object, org.dom4j.Element) + * + * We need this method because the generic base class has no way of calling our constructor. + */ + @Override + protected PayloadInputPart createPart(String label, Object jaxbObject, Element element) { + return new PayloadInputPart(label, jaxbObject, element); + } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.PoxPayload#createPart(java.lang.String, org.dom4j.Element) + * + * We need this method because the generic base class has no way of calling our constructor. + */ + @Override + protected PayloadInputPart createPart(String label, Element element) { + return new PayloadInputPart(label, element); + } + +} diff --git a/services/client/src/main/java/org/collectionspace/services/client/PoxPayloadOut.java b/services/client/src/main/java/org/collectionspace/services/client/PoxPayloadOut.java new file mode 100644 index 000000000..3bae323df --- /dev/null +++ b/services/client/src/main/java/org/collectionspace/services/client/PoxPayloadOut.java @@ -0,0 +1,174 @@ +package org.collectionspace.services.client; + +import javax.ws.rs.core.MediaType; + +import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.DocumentHelper; +import org.dom4j.Element; +import org.dom4j.io.SAXReader; + +import java.io.File; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.util.Iterator; + +// TODO: Auto-generated Javadoc +/** + * The Class PoxPayloadOut. + */ +public class PoxPayloadOut extends PoxPayload { + + /** + * Instantiates a new pox payload out. + * + * @param payloadName the payload name + * @throws DocumentException the document exception + */ + public PoxPayloadOut(String payloadName) { + super(); + setPayloadName(payloadName); + } + + public PoxPayloadOut(byte[] xmlPayload) throws DocumentException { + super(new String(xmlPayload)); + } + + /** + * Instantiates a new PoxPayloadOut, saves the xml, creates a DOM, and parses the parts. + * + * @param file the file + * @throws DocumentException the document exception + * @throws IOException Signals that an I/O exception has occurred. + */ + protected PoxPayloadOut(File file) throws DocumentException, IOException { + super(file); + } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.PoxPayload#createPart(java.lang.String, java.lang.Object, org.dom4j.Element) + * + * We need this method because the generic base class has no way of calling our constructor. + */ + @Override + protected PayloadOutputPart createPart(String label, Object jaxbObject, Element element) { + return new PayloadOutputPart(label, jaxbObject, element); + } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.PoxPayload#createPart(java.lang.String, org.dom4j.Element) + * + * We need this method because the generic base class has no way of calling our constructor. + */ + @Override + protected PayloadOutputPart createPart(String label, Element element) { + return new PayloadOutputPart(label, element); + } + + /** + * Creates and returns an XML string representation of ourself. + * + * @return the string + */ + public String toXML() { + String result = null; + Document document = DocumentHelper.createDocument(); + document.setXMLEncoding("UTF-8"); + document.setName(getName()); + Element root = document.addElement( "document" ); + root.addAttribute("name", getName()); + + Iterator it = getParts().iterator(); + while (it.hasNext() == true) { + PayloadOutputPart outPart = it.next(); + Element element = outPart.asElement(); + if (element != null) { + root.add(element.detach()); + } else { + //Add if (logger.isTraceEnabled() == true) logger.trace("Output part: " + outPart.getLabel() + " was empty."); + } + } + result = document.asXML(); + return result; + } + + /** + * Adds the part. + * + * @param entity the entity + * @param mediaType the media type + * @return the payload output part + */ + @Deprecated + public PayloadOutputPart addPart(Object entity, MediaType mediaType) { + PayloadOutputPart result = addPart("unlabelled", entity); + return result; + } + + @Deprecated + public PayloadOutputPart addPart(String xmlPayload, MediaType mediaType) throws DocumentException { + PayloadOutputPart result = addPart("unlabelled", xmlPayload); + return result; + } + + + /** + * Adds a DOM4j Element part. + * + * @param label the label + * @param elementBody the element body + * @return the payload output part + */ + public PayloadOutputPart addPart(String label, Element elementBody) { + PayloadOutputPart result = new PayloadOutputPart(label, elementBody); + getParts().add(result); + return result; + } + + /** + * Adds a DOM4j Element part. + * + * @param label the label + * @param elementBody the element body + * @return the payload output part + */ + public PayloadOutputPart addPart(String label, String xmlBody) throws DocumentException { + PayloadOutputPart result = new PayloadOutputPart(label, xmlBody); + getParts().add(result); + return result; + } + + + /** + * Adds a JAXB object part. + * + * @param label the label + * @param entity the entity + * @return the payload output part + */ + public PayloadOutputPart addPart(String label, Object entity) { + PayloadOutputPart result = new PayloadOutputPart(label, entity); + getParts().add(result); + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#toString() + * This method calls our "toXML()" method to return an XML representation of ourself. + */ + @Override + public String toString() { + return toXML(); + } + + public byte[] getBytes() { + byte[] result = null; + try { + result = toString().getBytes("UTF8"); + } catch (UnsupportedEncodingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); //FIXME: REM - Add proper logging statement here + } + return result; + } +} diff --git a/services/client/src/main/java/org/collectionspace/services/client/TestServiceClient.java b/services/client/src/main/java/org/collectionspace/services/client/TestServiceClient.java index faf5fdc16..a65ab0004 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/TestServiceClient.java +++ b/services/client/src/main/java/org/collectionspace/services/client/TestServiceClient.java @@ -57,5 +57,10 @@ public class TestServiceClient extends AbstractServiceClientImpl { public ClientResponse delete(String csid) { throw new UnsupportedOperationException(); + } + + @Override + public String getServiceName() { + throw new UnsupportedOperationException(); } } diff --git a/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java b/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java index 007a19005..cea08b4c7 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java +++ b/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java @@ -546,6 +546,16 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements } } +// @Override +// protected CollectionSpaceClient getClientInstance() { +// throw new UnsupportedOperationException(); //FIXME: REM - See http://issues.collectionspace.org/browse/CSPACE-3498 +// } +// +// @Override +// protected String getServiceName() { +// throw new UnsupportedOperationException(); //FIXME: REM - See http://issues.collectionspace.org/browse/CSPACE-3498 +// } + } diff --git a/services/client/src/main/java/org/collectionspace/services/client/test/BaseServiceTest.java b/services/client/src/main/java/org/collectionspace/services/client/test/BaseServiceTest.java index 80b4495b2..b32d6ee59 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/test/BaseServiceTest.java +++ b/services/client/src/main/java/org/collectionspace/services/client/test/BaseServiceTest.java @@ -46,10 +46,7 @@ import org.apache.commons.httpclient.methods.PostMethod; import org.apache.commons.httpclient.methods.PutMethod; import org.apache.commons.httpclient.methods.StringRequestEntity; import org.apache.commons.io.FileUtils; -import org.collectionspace.services.client.TestServiceClient; import org.jboss.resteasy.client.ClientResponse; -import org.jboss.resteasy.plugins.providers.multipart.InputPart; -import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testng.Assert; @@ -57,6 +54,10 @@ import org.testng.annotations.DataProvider; import org.w3c.dom.Document; import org.collectionspace.services.client.CollectionSpaceClient; +import org.collectionspace.services.client.PayloadInputPart; +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.TestServiceClient; + import org.collectionspace.services.jaxb.AbstractCommonList; /** @@ -101,6 +102,20 @@ public abstract class BaseServiceTest { "\n" + BANNER_SEPARATOR_LINE + "\n"; private static final String BANNER_SUFFIX = "\n" + BANNER_SEPARATOR_LINE; + + // A Unicode UTF-8 data fragment for use in test payloads: a random sequence, + // unlikely to be encountered in actual collections data, and capable of + // being rendered by the default fonts in many modern operating systems. + // + // This fragment consists of a run of USASCII characters, followed by + // four non-USASCII range Unicode UTF-8 characters: + // + // Δ : Greek capital letter Delta (U+0394) + // Ж : Cyrillic capital letter Zhe with breve (U+04C1) + // Ŵ : Latin capital letter W with circumflex (U+0174) + // Ω : Greek capital letter Omega (U+03A9) + private final static String UTF8_DATA_FRAGMENT = "utf-8-data-fragment:" + + '\u0394' + '\u04C1' + '\u0174' +'\u03A9'; protected static final int STATUS_BAD_REQUEST = Response.Status.BAD_REQUEST.getStatusCode(); @@ -161,6 +176,8 @@ public abstract class BaseServiceTest { * @return The URL path component of the service. */ protected abstract String getServicePathComponent(); + + protected abstract String getServiceName(); /** * Reinitializes setup values, to help expose any unintended reuse @@ -172,8 +189,7 @@ public abstract class BaseServiceTest { } /** - * Initializes setup values for a given test. Returns a banner - * identifying the test being run, using the local logger for this class. + * Initializes setup values for a given test. * * @param expectedStatusCode A status code expected to be returned in the response. * @@ -214,7 +230,7 @@ public abstract class BaseServiceTest { * @return The root URL for a service. */ protected String getServiceRootURL() { - return serviceClient.getBaseURL() + getServicePathComponent(); + return serviceClient.getBaseURL() + getServiceName(); //FIXME: REM - This should probably be calling getServicePathComponent() and not getServiceName(); } public String getServiceClientTenantID() { @@ -359,59 +375,18 @@ public abstract class BaseServiceTest { * @return the object * @throws Exception the exception */ - static protected Object extractPart(MultipartInput input, String label, Class clazz) + static protected Object extractPart(PoxPayloadIn input, String label, Class clazz) throws Exception { - Object obj = null; - String partLabel = ""; - List parts = input.getParts(); - if (parts.size() == 0) { - logger.warn("No parts found in multipart body."); - } - if (logger.isDebugEnabled()) { - logger.debug("Parts:"); - for (InputPart part : parts) { - partLabel = part.getHeaders().getFirst("label"); - logger.debug("part = " + partLabel); - } + Object result = null; + PayloadInputPart payloadInputPart = input.getPart(label); + if (payloadInputPart != null) { + result = payloadInputPart.getBody(); + } else if (logger.isWarnEnabled() == true) { + logger.warn("Payload part: " + label + + " is missing from payload: " + input.getName()); } - boolean partLabelMatched = false; - for (InputPart part : parts) { - partLabel = part.getHeaders().getFirst("label"); - if (label.equalsIgnoreCase(partLabel)) { - partLabelMatched = true; - if (logger.isDebugEnabled()) { - logger.debug("found part" + partLabel); - } - String partStr = part.getBodyAsString(); - if (partStr == null || partStr.trim().isEmpty()) { - logger.warn("Part '" + label + "' in multipart body is empty."); - } else { - if (logger.isDebugEnabled()) { - logger.debug("extracted part as str=\n" + partStr); - } - try { - obj = part.getBody(clazz, null); - if (logger.isDebugEnabled()) { - logger.debug("extracted part as obj="+objectAsXmlString(obj, clazz)); - } - } catch (Throwable t) { - logger.error("Could not get part body based on content and classname. "+ clazz.getName()+ " error: "+t); - } - } - break; + return result; } - } - if (!partLabelMatched) { - logger.warn("Could not find part '" + label + "' in multipart body."); - // In the event that getBodyAsString() or getBody(), above, do *not* - // throw an IOException, but getBody() nonetheless retrieves a null object. - // This *may* be unreachable. - } else if (obj == null) { - logger.warn("Could not extract part '" + label - + "' in multipart body as an object."); - } - return obj; - } /** * Gets the part object. @@ -421,6 +396,7 @@ public abstract class BaseServiceTest { * @return the part object * @throws JAXBException the jAXB exception */ + @Deprecated static protected Object getPartObject(String partStr, Class clazz) throws JAXBException { JAXBContext jc = JAXBContext.newInstance(clazz); @@ -509,8 +485,8 @@ public abstract class BaseServiceTest { * @throws Exception the exception */ static protected String getXmlDocumentAsString(String fileName) throws Exception { - byte[] b = FileUtils.readFileToByteArray(new File(fileName)); - return new String(b); + String result = FileUtils.readFileToString(new File(fileName), "UTF8"); + return result; } /** @@ -611,5 +587,8 @@ public abstract class BaseServiceTest { Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); } + public static String getUTF8DataFragment() { + return UTF8_DATA_FRAGMENT; + } } diff --git a/services/common/.classpath b/services/common/.classpath index c9fc5a5af..46ae1135b 100644 --- a/services/common/.classpath +++ b/services/common/.classpath @@ -1,10 +1,316 @@ - - - - - - - + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/services/common/.project b/services/common/.project index 53ae6fb19..dbbed086a 100644 --- a/services/common/.project +++ b/services/common/.project @@ -1,23 +1,26 @@ - org.collectionspace.services.common - + NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. + org.collectionspace.services.3rdparty.nuxeo.quote-api + org.collectionspace.services.authentication.jaxb + org.collectionspace.services.authentication.service + org.collectionspace.services.authorization.jaxb + org.collectionspace.services.authorization.service + org.collectionspace.services.client + org.collectionspace.services.hyperjaxb + org.collectionspace.services.jaxb org.eclipse.jdt.core.javabuilder - - org.maven.ide.eclipse.maven2Builder - - org.maven.ide.eclipse.maven2Nature org.eclipse.jdt.core.javanature - + \ No newline at end of file diff --git a/services/common/.settings/org.maven.ide.eclipse.prefs b/services/common/.settings/org.maven.ide.eclipse.prefs index 578bdf135..2a7cb62bf 100644 --- a/services/common/.settings/org.maven.ide.eclipse.prefs +++ b/services/common/.settings/org.maven.ide.eclipse.prefs @@ -1,9 +1,9 @@ -#Fri Dec 03 15:42:16 PST 2010 +#Wed Jan 19 22:49:24 PST 2011 activeProfiles= eclipse.preferences.version=1 fullBuildGoals=process-test-resources includeModules=false resolveWorkspaceProjects=true resourceFilterGoals=process-resources resources\:testResources -skipCompilerPlugin=false +skipCompilerPlugin=true version=1 diff --git a/services/common/pom.xml b/services/common/pom.xml index 118851742..f9661ec5a 100644 --- a/services/common/pom.xml +++ b/services/common/pom.xml @@ -281,11 +281,11 @@ - + commons-fileupload commons-fileupload diff --git a/services/common/src/main/java/org/collectionspace/services/common/AbstractMultiPartCollectionSpaceResourceImpl.java b/services/common/src/main/java/org/collectionspace/services/common/AbstractMultiPartCollectionSpaceResourceImpl.java index 4e5b1d4f2..a557ba757 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/AbstractMultiPartCollectionSpaceResourceImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/AbstractMultiPartCollectionSpaceResourceImpl.java @@ -26,6 +26,9 @@ */ package org.collectionspace.services.common; +import org.collectionspace.services.client.PayloadInputPart; +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.common.context.MultipartServiceContext; import org.collectionspace.services.common.context.MultipartServiceContextFactory; import org.collectionspace.services.common.context.ServiceContext; @@ -41,18 +44,18 @@ import org.slf4j.LoggerFactory; * The Class AbstractMultiPartCollectionSpaceResourceImpl. */ public abstract class AbstractMultiPartCollectionSpaceResourceImpl extends - AbstractCollectionSpaceResourceImpl { + AbstractCollectionSpaceResourceImpl { protected final Logger logger = LoggerFactory.getLogger(this.getClass()); @Override - public ServiceContextFactory getServiceContextFactory() { + public ServiceContextFactory getServiceContextFactory() { return MultipartServiceContextFactory.get(); } @Override - public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception { - return createDocumentHandler(ctx, ctx.getCommonPartLabel(),getCommonPartClass()); + public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception { + return createDocumentHandler(ctx, ctx.getCommonPartLabel(), getCommonPartClass()); } /** @@ -66,15 +69,19 @@ public abstract class AbstractMultiPartCollectionSpaceResourceImpl extends * * @throws Exception the exception */ - public DocumentHandler createDocumentHandler(ServiceContext serviceContext, + public DocumentHandler createDocumentHandler(ServiceContext serviceContext, String schemaName, Class commonClass) throws Exception { + DocumentHandler result = null; + MultipartServiceContext ctx = (MultipartServiceContext)serviceContext; Object commonPart = null; if (ctx.getInput() != null) { - commonPart = ctx.getInputPart(schemaName, commonClass); + commonPart = ctx.getInputPart(schemaName); } - return super.createDocumentHandler(ctx, commonPart); + result = super.createDocumentHandler(ctx, commonPart); + + return result; } /** @@ -88,7 +95,7 @@ public abstract class AbstractMultiPartCollectionSpaceResourceImpl extends * @throws Exception the exception */ public DocumentHandler createDocumentHandler( - ServiceContext ctx, + ServiceContext ctx, Class commonClass) throws Exception { return createDocumentHandler(ctx, ctx.getCommonPartLabel(), commonClass); } diff --git a/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java b/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java index 923a51b31..ab0f3ff65 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java +++ b/services/common/src/main/java/org/collectionspace/services/common/ResourceBase.java @@ -1,5 +1,7 @@ package org.collectionspace.services.common; +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.common.authorityref.AuthorityRefList; import org.collectionspace.services.common.context.MultipartServiceContextImpl; import org.collectionspace.services.common.context.ServiceBindingUtils; @@ -90,16 +92,17 @@ extends AbstractMultiPartCollectionSpaceResourceImpl { //======================= CREATE ==================================================== @POST - public Response create(MultipartInput input) { + public Response create(String xmlPayload) { try { - ServiceContext ctx = createServiceContext(input); + PoxPayloadIn input = new PoxPayloadIn(xmlPayload); + ServiceContext ctx = createServiceContext(input); return create(input, ctx); } catch (Exception e) { throw bigReThrow(e, ServiceMessages.CREATE_FAILED); } } - protected Response create(MultipartInput input, ServiceContext ctx) { + protected Response create(PoxPayloadIn input, ServiceContext ctx) { try { DocumentHandler handler = createDocumentHandler(ctx); UriBuilder path = UriBuilder.fromResource(this.getClass()); @@ -110,8 +113,8 @@ extends AbstractMultiPartCollectionSpaceResourceImpl { } /** Subclasses may override this overload, which gets called from @see #create(MultipartInput) */ - protected Response create(MultipartInput input, - ServiceContext ctx, + protected Response create(PoxPayloadIn input, + ServiceContext ctx, DocumentHandler handler, UriBuilder path) throws Exception { @@ -125,34 +128,37 @@ extends AbstractMultiPartCollectionSpaceResourceImpl { @PUT @Path("{csid}") - public MultipartOutput update(@PathParam("csid") String csid, MultipartInput theUpdate) { + public byte[] update(@PathParam("csid") String csid, String xmlPayload) { + PoxPayloadOut result = null; ensureCSID(csid, UPDATE); try { - ServiceContext ctx = createServiceContext(theUpdate); - return update(csid, theUpdate, ctx); //==> CALL implementation method, which subclasses may override. + PoxPayloadIn theUpdate = new PoxPayloadIn(xmlPayload); + ServiceContext ctx = createServiceContext(theUpdate); + result = update(csid, theUpdate, ctx); //==> CALL implementation method, which subclasses may override. } catch (Exception e) { throw bigReThrow(e, ServiceMessages.UPDATE_FAILED, csid); } + return result.getBytes(); } /** Subclasses may override this overload, which gets called from #udpate(String,MultipartInput) */ - protected MultipartOutput update(String csid, - MultipartInput theUpdate, - ServiceContext ctx) + protected PoxPayloadOut update(String csid, + PoxPayloadIn theUpdate, + ServiceContext ctx) throws Exception { DocumentHandler handler = createDocumentHandler(ctx); getRepositoryClient(ctx).update(ctx, csid, handler); - return (MultipartOutput) ctx.getOutput(); + return ctx.getOutput(); } /** Subclasses may override this overload, which gets called from #udpate(String,MultipartInput) */ - protected MultipartOutput update(String csid, + protected PoxPayloadOut update(String csid, MultipartInput theUpdate, - ServiceContext ctx, + ServiceContext ctx, DocumentHandler handler) throws Exception { getRepositoryClient(ctx).update(ctx, csid, handler); - return (MultipartOutput) ctx.getOutput(); + return ctx.getOutput(); } //======================= DELETE ==================================================== @@ -162,7 +168,7 @@ extends AbstractMultiPartCollectionSpaceResourceImpl { public Response delete(@PathParam("csid") String csid) { ensureCSID(csid, DELETE); try { - ServiceContext ctx = createServiceContext(); + ServiceContext ctx = createServiceContext(); return delete(csid, ctx); //==> CALL implementation method, which subclasses may override. } catch (Exception e) { throw bigReThrow(e, ServiceMessages.DELETE_FAILED, csid); @@ -171,7 +177,7 @@ extends AbstractMultiPartCollectionSpaceResourceImpl { /** subclasses may override this method, which is called from #delete(String) * which handles setup of ServiceContext, and does Exception handling. */ - protected Response delete(String csid, ServiceContext ctx) + protected Response delete(String csid, ServiceContext ctx) throws Exception { getRepositoryClient(ctx).delete(ctx, csid); return Response.status(HttpResponseCodes.SC_OK).build(); @@ -182,25 +188,27 @@ extends AbstractMultiPartCollectionSpaceResourceImpl { @GET @Path("{csid}") - public MultipartOutput get(@PathParam("csid") String csid) { + public byte[] get(@PathParam("csid") String csid) { + PoxPayloadOut result = null; ensureCSID(csid, READ); try { - ServiceContext ctx = createServiceContext(); - MultipartOutput result = get(csid, ctx);// ==> CALL implementation method, which subclasses may override. + ServiceContext ctx = createServiceContext(); + result = get(csid, ctx);// ==> CALL implementation method, which subclasses may override. if (result == null) { Response response = Response.status(Response.Status.NOT_FOUND).entity( ServiceMessages.READ_FAILED + ServiceMessages.resourceNotFoundMsg(csid)).type("text/plain").build(); throw new WebApplicationException(response); } - return result; } catch (Exception e) { throw bigReThrow(e, ServiceMessages.READ_FAILED, csid); } + + return result.getBytes(); } - protected MultipartOutput get(@PathParam("csid") String csid, - ServiceContext ctx) throws Exception { - MultipartOutput result = null; + protected PoxPayloadOut get(@PathParam("csid") String csid, + ServiceContext ctx) throws Exception { + PoxPayloadOut result = null; ensureCSID(csid, READ); DocumentHandler handler = createDocumentHandler(ctx); @@ -219,18 +227,17 @@ extends AbstractMultiPartCollectionSpaceResourceImpl { /** subclasses may override this method, which is called from #get(String) * which handles setup of ServiceContext and DocumentHandler, and Exception handling.*/ - protected MultipartOutput get(String csid, - ServiceContext ctx, + protected PoxPayloadOut get(String csid, + ServiceContext ctx, DocumentHandler handler) throws Exception { getRepositoryClient(ctx).get(ctx, csid, handler); - return (MultipartOutput) ctx.getOutput(); + return ctx.getOutput(); } //======================= GET without csid. List, search, etc. ===================================== @GET - @Produces("application/xml") public AbstractCommonList getList(@Context UriInfo ui, @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords) { MultivaluedMap queryParams = ui.getQueryParameters(); @@ -243,7 +250,7 @@ extends AbstractMultiPartCollectionSpaceResourceImpl { protected AbstractCommonList getList(MultivaluedMap queryParams) { try { - ServiceContext ctx = createServiceContext(queryParams); + ServiceContext ctx = createServiceContext(queryParams); DocumentHandler handler = createDocumentHandler(ctx); getRepositoryClient(ctx).getFiltered(ctx, handler); return (AbstractCommonList)handler.getCommonPartList(); @@ -254,7 +261,7 @@ extends AbstractMultiPartCollectionSpaceResourceImpl { protected AbstractCommonList search(MultivaluedMap queryParams, String keywords) { try { - ServiceContext ctx = createServiceContext(queryParams); + ServiceContext ctx = createServiceContext(queryParams); DocumentHandler handler = createDocumentHandler(ctx); // perform a keyword search if (keywords != null && !keywords.isEmpty()) { @@ -276,7 +283,7 @@ extends AbstractMultiPartCollectionSpaceResourceImpl { @Deprecated public AbstractCommonList getList(List csidList) { try { - ServiceContext ctx = createServiceContext(); + ServiceContext ctx = createServiceContext(); DocumentHandler handler = createDocumentHandler(ctx); getRepositoryClient(ctx).get(ctx, csidList, handler); return (AbstractCommonList)handler.getCommonPartList(); @@ -296,9 +303,9 @@ extends AbstractMultiPartCollectionSpaceResourceImpl { AuthorityRefList authRefList = null; try { MultivaluedMap queryParams = ui.getQueryParameters(); - ServiceContext ctx = createServiceContext(queryParams); + ServiceContext ctx = createServiceContext(queryParams); DocumentWrapper docWrapper = getRepositoryClient(ctx).getDoc(ctx, csid); - DocumentModelHandler handler = (DocumentModelHandler)createDocumentHandler(ctx); + DocumentModelHandler handler = (DocumentModelHandler)createDocumentHandler(ctx); List authRefFields = ((MultipartServiceContextImpl) ctx).getCommonPartPropertyValues( ServiceBindingUtils.AUTH_REF_PROP, ServiceBindingUtils.QUALIFIED_PROP_NAMES); diff --git a/services/common/src/main/java/org/collectionspace/services/common/blob/BlobUtil.java b/services/common/src/main/java/org/collectionspace/services/common/blob/BlobUtil.java index 3c04bc0d8..57c67baa0 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/blob/BlobUtil.java +++ b/services/common/src/main/java/org/collectionspace/services/common/blob/BlobUtil.java @@ -1,5 +1,7 @@ package org.collectionspace.services.common.blob; +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.common.context.ServiceContext; import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; @@ -11,7 +13,7 @@ public class BlobUtil { public static String BLOB_RESOURCE_NAME = "blobs"; private static final Logger logger = LoggerFactory.getLogger(BlobUtil.class); - public static BlobInput getBlobInput(ServiceContext ctx) { + public static BlobInput getBlobInput(ServiceContext ctx) { BlobInput result = (BlobInput)ctx.getProperty(BlobInput.class.getName()); if (result == null) { result = new BlobInput(); @@ -20,13 +22,13 @@ public class BlobUtil { return result; } - public static BlobInput resetBlobInput(ServiceContext ctx) { + public static BlobInput resetBlobInput(ServiceContext ctx) { BlobInput blobInput = new BlobInput(); setBlobInput(ctx, blobInput); return blobInput; } - public static void setBlobInput(ServiceContext ctx, + public static void setBlobInput(ServiceContext ctx, BlobInput blobInput) { ctx.setProperty(BlobInput.class.getName(), blobInput); } diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContext.java b/services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContext.java index 7063485a1..3c6fe48b3 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContext.java +++ b/services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContext.java @@ -25,23 +25,27 @@ package org.collectionspace.services.common.context; import java.io.IOException; import java.io.InputStream; + +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.PoxPayloadOut; +import org.dom4j.Element; import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; -import org.w3c.dom.Document; +import org.dom4j.Document; /** * RemoteServiceContext is used to encapsulate the service context of a * remotely invokable service */ public interface MultipartServiceContext - extends RemoteServiceContext { + extends RemoteServiceContext { /** * Get input parts as received over the wire from service consumer * @return the input */ @Override - public MultipartInput getInput(); + public PoxPayloadIn getInput(); /** * setInput is used to set request input before starting to @@ -49,21 +53,21 @@ public interface MultipartServiceContext * @param input */ @Override - public void setInput(MultipartInput input); + public void setInput(PoxPayloadIn input); /** * Get output parts to send over the wire to service consumer * @return the output */ @Override - public MultipartOutput getOutput(); + public PoxPayloadOut getOutput(); /** * Set output parts to send over the wire to service consumer * @return the output */ @Override - public void setOutput(MultipartOutput output); + public void setOutput(PoxPayloadOut output); /** * getInputPart returns the input part object for given label and clazz @@ -71,7 +75,17 @@ public interface MultipartServiceContext * @param clazz class of the object * @return part */ - public Object getInputPart(String label, Class clazz) throws IOException; + @Deprecated + public Object getInputPart(String label, Class clazz) throws IOException; + + /** + * Gets the input part. + * + * @param label the label + * @return the input part + * @throws IOException Signals that an I/O exception has occurred. + */ + public Object getInputPart(String label) throws IOException; /** * getInputPartAsString returns the input part with given label in the string form @@ -94,5 +108,5 @@ public interface MultipartServiceContext * @param document * @param contentType media type */ - public void addOutputPart(String label, Document doc, String contentType) throws Exception; + public void addOutputPart(String label, Element doc, String contentType) throws Exception; } diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContextFactory.java b/services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContextFactory.java index 535b092e5..ba8626206 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContextFactory.java +++ b/services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContextFactory.java @@ -25,6 +25,8 @@ package org.collectionspace.services.common.context; import javax.ws.rs.core.MultivaluedMap; +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.PoxPayloadOut; import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; @@ -35,7 +37,7 @@ import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; * */ public class MultipartServiceContextFactory - implements ServiceContextFactory { + implements ServiceContextFactory { /** The Constant self. */ final private static MultipartServiceContextFactory self = new MultipartServiceContextFactory(); @@ -58,7 +60,7 @@ public class MultipartServiceContextFactory * @see org.collectionspace.services.common.context.ServiceContextFactory#createServiceContext(java.lang.String) */ @Override - public ServiceContext createServiceContext(String serviceName) throws Exception { + public ServiceContext createServiceContext(String serviceName) throws Exception { MultipartServiceContext ctx = new MultipartServiceContextImpl(serviceName); return ctx; } @@ -67,8 +69,8 @@ public class MultipartServiceContextFactory * @see org.collectionspace.services.common.context.ServiceContextFactory#createServiceContext(java.lang.String, java.lang.Object) */ @Override - public ServiceContext createServiceContext(String serviceName, - MultipartInput input) throws Exception { + public ServiceContext createServiceContext(String serviceName, + PoxPayloadIn input) throws Exception { MultipartServiceContext ctx = new MultipartServiceContextImpl(serviceName, input); return ctx; } @@ -77,11 +79,11 @@ public class MultipartServiceContextFactory * @see org.collectionspace.services.common.context.ServiceContextFactory#createServiceContext(java.lang.String, java.lang.Object, javax.ws.rs.core.MultivaluedMap) */ @Override - public ServiceContext createServiceContext(String serviceName, - MultipartInput input, + public ServiceContext createServiceContext(String serviceName, + PoxPayloadIn input, MultivaluedMap queryParams) throws Exception { - ServiceContext ctx = new MultipartServiceContextImpl(serviceName, + ServiceContext ctx = new MultipartServiceContextImpl(serviceName, input, queryParams); return ctx; @@ -91,8 +93,8 @@ public class MultipartServiceContextFactory * @see org.collectionspace.services.common.context.ServiceContextFactory#createServiceContext(java.lang.String, java.lang.Object, javax.ws.rs.core.MultivaluedMap, java.lang.String, java.lang.String) */ @Override - public ServiceContext createServiceContext(String serviceName, - MultipartInput input, + public ServiceContext createServiceContext(String serviceName, + PoxPayloadIn input, MultivaluedMap queryParams, String documentType, String entityName) throws Exception { diff --git a/services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContextImpl.java b/services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContextImpl.java index d760ecbf6..cc068a283 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContextImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/common/context/MultipartServiceContextImpl.java @@ -24,22 +24,24 @@ package org.collectionspace.services.common.context; import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Constructor; -import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; -import org.collectionspace.services.common.document.DocumentUtils; +import org.collectionspace.services.client.PayloadInputPart; +import org.collectionspace.services.client.PayloadOutputPart; +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.common.security.UnauthorizedException; -import org.jboss.resteasy.plugins.providers.multipart.InputPart; -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.dom4j.DocumentException; +import org.dom4j.Element; +//import org.jboss.resteasy.plugins.providers.multipart.InputPart; +//import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; +//import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; +//import org.jboss.resteasy.plugins.providers.multipart.OutputPart; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.w3c.dom.Document; /** * MultipartServiceContextImpl takes Multipart Input/Output @@ -48,7 +50,7 @@ import org.w3c.dom.Document; * $LastChangedDate: $ */ public class MultipartServiceContextImpl - extends RemoteServiceContextImpl + extends RemoteServiceContextImpl implements MultipartServiceContext { /** The logger. */ @@ -62,9 +64,9 @@ public class MultipartServiceContextImpl * @throws UnauthorizedException the unauthorized exception */ protected MultipartServiceContextImpl(String serviceName) - throws UnauthorizedException { + throws DocumentException, UnauthorizedException { super(serviceName); - setOutput(new MultipartOutput()); + setOutput(new PoxPayloadOut(serviceName)); } /** @@ -74,10 +76,10 @@ public class MultipartServiceContextImpl * * @throws UnauthorizedException the unauthorized exception */ - protected MultipartServiceContextImpl(String serviceName, MultipartInput theInput) - throws UnauthorizedException { + protected MultipartServiceContextImpl(String serviceName, PoxPayloadIn theInput) + throws DocumentException, UnauthorizedException { super(serviceName, theInput); - setOutput(new MultipartOutput()); + setOutput(new PoxPayloadOut(serviceName)); } /** @@ -89,62 +91,49 @@ public class MultipartServiceContextImpl * @throws UnauthorizedException the unauthorized exception */ protected MultipartServiceContextImpl(String serviceName, - MultipartInput theInput, - MultivaluedMap queryParams) throws UnauthorizedException { + PoxPayloadIn theInput, + MultivaluedMap queryParams) + throws DocumentException, UnauthorizedException { super(serviceName, theInput, queryParams); - setOutput(new MultipartOutput()); + setOutput(new PoxPayloadOut(serviceName)); } - /** - * Gets the input part. - * - * @param label the label - * - * @return the input part - * - * @throws IOException Signals that an I/O exception has occurred. + /* (non-Javadoc) + * @see org.collectionspace.services.common.context.MultipartServiceContext#getInputPart(java.lang.String, java.lang.Class) */ - private InputPart getInputPart(String label) throws IOException { - if (getInput() != null) { - MultipartInput fdip = getInput(); - - for (InputPart part : fdip.getParts()) { - String partLabel = part.getHeaders().getFirst("label"); - if (label.equalsIgnoreCase(partLabel)) { - if (logger.isTraceEnabled()) { - logger.trace("getInputPart found part with label=" + partLabel - + "\npayload=" + part.getBodyAsString()); + @Override + @Deprecated + public Object getInputPart(String label, Class clazz) throws IOException { + return getInputPart(label); } - return part; - } - } - } - return null; - } - + /* (non-Javadoc) * @see org.collectionspace.services.common.context.MultipartServiceContext#getInputPart(java.lang.String, java.lang.Class) */ @Override - public Object getInputPart(String label, Class clazz) throws IOException { - Object obj = null; - InputPart part = getInputPart(label); - if (part != null) { - obj = part.getBody(clazz, null); + public Object getInputPart(String label) throws IOException { + Object result = null; + PayloadInputPart payloadInputPart = getInput().getPart(label); + if (payloadInputPart != null) { + result = payloadInputPart.getBody(); } - return obj; + return result; } - + /* (non-Javadoc) * @see org.collectionspace.services.common.context.MultipartServiceContext#getInputPartAsString(java.lang.String) */ @Override public String getInputPartAsString(String label) throws IOException { - InputPart part = getInputPart(label); + String result = null; + PayloadInputPart part = getInput().getPart(label); if (part != null) { - return part.getBodyAsString(); + Element element = part.asElement(); + if (element != null) { + result = element.asXML(); } - return null; + } + return result; } /* (non-Javadoc) @@ -152,34 +141,25 @@ public class MultipartServiceContextImpl */ @Override public InputStream getInputPartAsStream(String label) throws IOException { - InputPart part = getInputPart(label); + InputStream result = null; + String part = getInputPartAsString(label); if (part != null) { - return new ByteArrayInputStream(part.getBodyAsString().getBytes()); + result = new ByteArrayInputStream(part.getBytes()); } - return null; + return result; } /* (non-Javadoc) * @see org.collectionspace.services.common.context.MultipartServiceContext#addOutputPart(java.lang.String, org.w3c.dom.Document, java.lang.String) */ @Override - public void addOutputPart(String label, Document doc, String contentType) throws Exception { - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try { - DocumentUtils.writeDocument(doc, baos); - baos.close(); - OutputPart part = getOutput().addPart(new String(baos.toByteArray()), - MediaType.valueOf(contentType)); - part.getHeaders().add("label", label); - } finally { - if (baos != null) { - try { - baos.close(); - } catch (Exception e) { + public void addOutputPart(String label, Element element, String contentType) throws Exception { + PayloadOutputPart part = getOutput().addPart(label, element); + if (logger.isTraceEnabled() == true) { + logger.trace("Adding part:" + label + + " to " + getOutput().getName() + " document."); } } - } - } /* (non-Javadoc) * @see org.collectionspace.services.common.context.RemoteServiceContextImpl#getLocalContext(java.lang.String) diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java index c8d297891..9559c3903 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java @@ -59,6 +59,7 @@ import org.collectionspace.services.common.datetime.DateTimeFormatUtils; import org.collectionspace.services.common.service.ObjectPartContentType; import org.collectionspace.services.common.service.ObjectPartType; import org.collectionspace.services.common.service.XmlContentType; +import org.dom4j.io.DOMReader; import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; import org.jboss.resteasy.plugins.providers.multipart.InputPart; @@ -93,8 +94,9 @@ import org.w3c.dom.Text; //import org.dom4j.Document; //import org.dom4j.Element; -//import org.dom4j.*; - +//import org.dom4j.Node; +//import org.dom4j.NodeList; +//import org.dom4j.Text; /** * DocumentUtils is a collection of utilities related to document management @@ -295,9 +297,8 @@ public class DocumentUtils { result = db.parse(payload); // Write it to the log so we can see what we've created. - if (logger.isDebugEnabled() == true) { - logger.debug(xmlToString(result)); - //System.out.println(xmlToString(result)); //FIXME: REM - Need this until we figure out why messages are not showing up in logger. + if (logger.isTraceEnabled() == true) { + logger.trace(xmlToString(result)); } } finally { if (payload != null) { @@ -493,7 +494,7 @@ public class DocumentUtils { * @return Document * @throws Exception */ - public static Document buildDocument(ObjectPartType partMeta, String rootElementName, + public static org.dom4j.Element buildDocument(ObjectPartType partMeta, String rootElementName, Map objectProps) throws Exception { ObjectPartContentType partContentMeta = partMeta.getContent(); @@ -505,27 +506,42 @@ public class DocumentUtils { //FIXME: We support XML validation on the way in, so we should add it here (on the way out) as well. DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document document = builder.newDocument(); - document.setXmlStandalone(true); - //JAXB unmarshaller recognizes the following kind of namespace qualification - //only. More investigation is needed to use other prefix - // - // - // objectNumber-1252960222412 - // objectName-1252960222412 - // + document.setXmlStandalone(true); //FIXME: REM - Can we set this to false since it is not really standalone? + + /* + * JAXB unmarshaller recognizes the following kind of namespace + * qualification only. More investigation is needed to use other prefix + * + * + * + * objectNumber-1252960222412 + * objectName-1252960222412 + * + */ String ns = "ns2"; Element root = document.createElementNS(xc.getNamespaceURI(), ns + ":" + rootElementName); root.setAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance"); - root.setAttribute("xsi:schemaLocation", xc.getSchemaLocation()); + +// String getSchemaLocation = xc.getSchemaLocation(); //FIXME: REM - w3c Document to DOM4j Document mangles this attribute +// root.setAttribute("xsi:schemaLocation", xc.getSchemaLocation()); + + String getNamespaceURI = xc.getNamespaceURI(); root.setAttribute("xmlns:" + ns, xc.getNamespaceURI()); document.appendChild(root); Schema schema = getSchemaFromName(partMeta.getLabel()); buildDocument(document, root, objectProps, schema); + String w3cDocumentStr = xmlToString(document); + - return document; + DOMReader reader = new DOMReader(); + org.dom4j.Document dom4jDoc = reader.read(document); + org.dom4j.Element result = dom4jDoc.getRootElement(); + result.detach(); //return just the root element detached from the DOM document + + return result;//FIXME: REM - Add if (logger.isTraceEnabled() == true) logger.trace(document.asXML()); } /** @@ -1076,22 +1092,23 @@ public class DocumentUtils { * @return the map */ public static Map parseProperties(ObjectPartType partMeta, - Document document, ServiceContext ctx) throws Exception { + org.dom4j.Element document, ServiceContext ctx) throws Exception { Map result = null; String schemaName = partMeta.getLabel(); Schema schema = getSchemaFromName(schemaName); - - org.dom4j.io.DOMReader xmlReader = new org.dom4j.io.DOMReader(); - org.dom4j.Document dom4jDocument = xmlReader.read(document); + + // org.dom4j.io.DOMReader xmlReader = new org.dom4j.io.DOMReader(); + // org.dom4j.Document dom4jDocument = xmlReader.read(document); try { - result = loadSchema(schema, dom4jDocument.getRootElement(), ctx); + // result = loadSchema(schema, dom4jDocument.getRootElement(), ctx); + result = loadSchema(schema, document, ctx); } catch (IllegalArgumentException iae) { throw iae; } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } - + return result; } @@ -1106,7 +1123,7 @@ public class DocumentUtils { @SuppressWarnings("unchecked") static private Map loadSchema(Schema schema, org.dom4j.Element schemaElement, ServiceContext ctx) throws Exception { - String schemaName1 = schemaElement.attributeValue(ExportConstants.NAME_ATTR); + String schemaName1 = schemaElement.attributeValue(ExportConstants.NAME_ATTR);//FIXME: Do we need this local var? String schemaName = schema.getName(); Map data = new HashMap(); diff --git a/services/common/src/main/java/org/collectionspace/services/common/query/QueryContext.java b/services/common/src/main/java/org/collectionspace/services/common/query/QueryContext.java index b70a0e185..5d31c9c27 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/query/QueryContext.java +++ b/services/common/src/main/java/org/collectionspace/services/common/query/QueryContext.java @@ -1,5 +1,7 @@ package org.collectionspace.services.common.query; +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.document.DocumentException; import org.collectionspace.services.common.document.DocumentFilter; @@ -35,7 +37,7 @@ public class QueryContext { * @throws DocumentNotFoundException the document not found exception * @throws DocumentException the document exception */ - QueryContext(ServiceContext ctx) throws DocumentNotFoundException, DocumentException { + QueryContext(ServiceContext ctx) throws DocumentNotFoundException, DocumentException { docType = ctx.getDocumentType(); if (docType == null) { throw new DocumentNotFoundException( @@ -57,7 +59,7 @@ public class QueryContext { * @throws DocumentNotFoundException the document not found exception * @throws DocumentException the document exception */ - public QueryContext(ServiceContext ctx, + public QueryContext(ServiceContext ctx, String theWhereClause) throws DocumentNotFoundException, DocumentException { this(ctx); whereClause = theWhereClause; @@ -71,7 +73,7 @@ public class QueryContext { * @throws DocumentNotFoundException the document not found exception * @throws DocumentException the document exception */ - public QueryContext(ServiceContext ctx, + public QueryContext(ServiceContext ctx, DocumentHandler handler) throws DocumentNotFoundException, DocumentException { this(ctx); if (handler == null) { diff --git a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java index b639f0ff0..cf7eb0789 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java +++ b/services/common/src/main/java/org/collectionspace/services/common/vocabulary/AuthorityResource.java @@ -42,6 +42,8 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriInfo; +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema; import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema; import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityItemDocumentModelHandler; @@ -63,21 +65,18 @@ import org.collectionspace.services.common.security.UnauthorizedException; import org.collectionspace.services.common.query.IQueryManager; import org.collectionspace.services.common.query.QueryManager; import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; -import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; -import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; import org.jboss.resteasy.util.HttpResponseCodes; import org.nuxeo.ecm.core.api.DocumentModel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** - * The Class VocabularyResource. + * The Class AuthorityResource. */ -@Path("/vocabularies") -@Consumes("multipart/mixed") -@Produces("multipart/mixed") +@Consumes("application/xml") +@Produces("application/xml") public abstract class AuthorityResource extends -AbstractMultiPartCollectionSpaceResourceImpl { + AbstractMultiPartCollectionSpaceResourceImpl { protected Class authCommonClass; protected Class resourceClass; @@ -179,7 +178,7 @@ AbstractMultiPartCollectionSpaceResourceImpl { * @throws Exception the exception */ public DocumentHandler createItemDocumentHandler( - ServiceContext ctx, + ServiceContext ctx, String inAuthority) throws Exception { AuthItemHandler docHandler; @@ -200,9 +199,10 @@ AbstractMultiPartCollectionSpaceResourceImpl { * @return the response */ @POST - public Response createAuthority(MultipartInput input) { + public Response createAuthority(String xmlPayload) { try { - ServiceContext ctx = createServiceContext(input); + PoxPayloadIn input = new PoxPayloadIn(xmlPayload); + ServiceContext ctx = createServiceContext(input); DocumentHandler handler = createDocumentHandler(ctx); String csid = getRepositoryClient(ctx).create(ctx, handler); UriBuilder path = UriBuilder.fromResource(resourceClass); @@ -252,13 +252,13 @@ AbstractMultiPartCollectionSpaceResourceImpl { */ @GET @Path("{csid}") - public MultipartOutput getAuthority(@PathParam("csid") String specifier) { - MultipartOutput result = null; + public String getAuthority(@PathParam("csid") String specifier) { + PoxPayloadOut result = null; try { Specifier spec = getSpecifier(specifier, "getAuthority", "GET"); - ServiceContext ctx = createServiceContext(); + ServiceContext ctx = createServiceContext(); DocumentHandler handler = createDocumentHandler(ctx); - if(spec.form==SpecifierForm.CSID) { + if(spec.form == SpecifierForm.CSID) { if (logger.isDebugEnabled()) { logger.debug("getAuthority with csid=" + spec.value); } @@ -269,7 +269,7 @@ AbstractMultiPartCollectionSpaceResourceImpl { handler.setDocumentFilter(myFilter); getRepositoryClient(ctx).get(ctx, handler); } - result = (MultipartOutput) ctx.getOutput(); + result = ctx.getOutput(); } catch (UnauthorizedException ue) { Response response = Response.status( Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); @@ -298,7 +298,7 @@ AbstractMultiPartCollectionSpaceResourceImpl { throw new WebApplicationException(response); } - return result; + return result.toXML(); } /** @@ -313,7 +313,7 @@ AbstractMultiPartCollectionSpaceResourceImpl { public AuthCommonList getAuthorityList(@Context UriInfo ui) { try { MultivaluedMap queryParams = ui.getQueryParameters(); - ServiceContext ctx = createServiceContext(queryParams); + ServiceContext ctx = createServiceContext(queryParams); DocumentHandler handler = createDocumentHandler(ctx); DocumentFilter myFilter = handler.getDocumentFilter(); String nameQ = queryParams.getFirst("refName"); @@ -346,13 +346,14 @@ AbstractMultiPartCollectionSpaceResourceImpl { */ @PUT @Path("{csid}") - public MultipartOutput updateAuthority( + public String updateAuthority( @PathParam("csid") String specifier, - MultipartInput theUpdate) { - MultipartOutput result = null; + String xmlPayload) { + PoxPayloadOut result = null; try { + PoxPayloadIn theUpdate = new PoxPayloadIn(xmlPayload); Specifier spec = getSpecifier(specifier, "updateAuthority", "UPDATE"); - ServiceContext ctx = createServiceContext(theUpdate); + ServiceContext ctx = createServiceContext(theUpdate); DocumentHandler handler = createDocumentHandler(ctx); String csid; if(spec.form==SpecifierForm.CSID) { @@ -362,7 +363,7 @@ AbstractMultiPartCollectionSpaceResourceImpl { csid = getRepositoryClient(ctx).findDocCSID(ctx, whereClause); } getRepositoryClient(ctx).update(ctx, csid, handler); - result = (MultipartOutput) ctx.getOutput(); + result = ctx.getOutput(); } catch (UnauthorizedException ue) { Response response = Response.status( Response.Status.UNAUTHORIZED).entity("Update failed reason " + ue.getErrorReason()).type("text/plain").build(); @@ -380,7 +381,7 @@ AbstractMultiPartCollectionSpaceResourceImpl { Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build(); throw new WebApplicationException(response); } - return result; + return result.toXML(); } /** @@ -405,7 +406,7 @@ AbstractMultiPartCollectionSpaceResourceImpl { throw new WebApplicationException(response); } try { - ServiceContext ctx = createServiceContext(); + ServiceContext ctx = createServiceContext(); getRepositoryClient(ctx).delete(ctx, csid); return Response.status(HttpResponseCodes.SC_OK).build(); } catch (UnauthorizedException ue) { @@ -436,9 +437,10 @@ AbstractMultiPartCollectionSpaceResourceImpl { *************************************************************************/ @POST @Path("{csid}/items") - public Response createAuthorityItem(@PathParam("csid") String specifier, MultipartInput input) { + public Response createAuthorityItem(@PathParam("csid") String specifier, String xmlPayload) { try { - ServiceContext ctx = null; + PoxPayloadIn input = new PoxPayloadIn(xmlPayload); + ServiceContext ctx = null; Specifier spec = getSpecifier(specifier, "createAuthorityItem", "CREATE_ITEM"); String parentcsid; if(spec.form==SpecifierForm.CSID) { @@ -483,15 +485,15 @@ AbstractMultiPartCollectionSpaceResourceImpl { */ @GET @Path("{csid}/items/{itemcsid}") - public MultipartOutput getAuthorityItem( + public String getAuthorityItem( @PathParam("csid") String parentspecifier, @PathParam("itemcsid") String itemspecifier) { - MultipartOutput result = null; + PoxPayloadOut result = null; try { Specifier parentSpec = getSpecifier(parentspecifier, "getAuthorityItem(parent)", "GET_ITEM"); Specifier itemSpec = getSpecifier(itemspecifier, "getAuthorityItem(item)", "GET_ITEM"); // Note that we have to create the service context for the Items, not the main service - ServiceContext ctx = null; + ServiceContext ctx = null; String parentcsid; if(parentSpec.form==SpecifierForm.CSID) { parentcsid = parentSpec.value; @@ -512,7 +514,7 @@ AbstractMultiPartCollectionSpaceResourceImpl { getRepositoryClient(ctx).get(ctx, handler); } // TODO should we assert that the item is in the passed vocab? - result = (MultipartOutput) ctx.getOutput(); + result = ctx.getOutput(); } catch (UnauthorizedException ue) { Response response = Response.status( Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); @@ -539,7 +541,7 @@ AbstractMultiPartCollectionSpaceResourceImpl { "text/plain").build(); throw new WebApplicationException(response); } - return result; + return result.toXML(); } @@ -566,7 +568,7 @@ AbstractMultiPartCollectionSpaceResourceImpl { Specifier spec = getSpecifier(specifier, "getAuthorityItemList", "LIST"); MultivaluedMap queryParams = ui.getQueryParameters(); // Note that docType defaults to the ServiceName, so we're fine with that. - ServiceContext ctx = null; + ServiceContext ctx = null; String parentcsid; if(spec.form==SpecifierForm.CSID) { parentcsid = spec.value; @@ -640,7 +642,7 @@ AbstractMultiPartCollectionSpaceResourceImpl { Specifier itemSpec = getSpecifier(itemspecifier, "getReferencingObjects(item)", "GET_ITEM_REF_OBJS"); // Note that we have to create the service context for the Items, not the main service - ServiceContext ctx = null; + ServiceContext ctx = null; String parentcsid; if(parentSpec.form==SpecifierForm.CSID) { parentcsid = parentSpec.value; @@ -728,7 +730,7 @@ AbstractMultiPartCollectionSpaceResourceImpl { Specifier itemSpec = getSpecifier(itemspecifier, "getAuthorityItemAuthRefs(item)", "GET_ITEM_AUTH_REFS"); // Note that we have to create the service context for the Items, not the main service MultivaluedMap queryParams = ui.getQueryParameters(); - ServiceContext ctx = null; + ServiceContext ctx = null; String parentcsid; if(parentSpec.form==SpecifierForm.CSID) { parentcsid = parentSpec.value; @@ -769,8 +771,6 @@ AbstractMultiPartCollectionSpaceResourceImpl { return authRefList; } - - /** * Update authorityItem. * @@ -782,18 +782,19 @@ AbstractMultiPartCollectionSpaceResourceImpl { */ @PUT @Path("{csid}/items/{itemcsid}") - public MultipartOutput updateAuthorityItem( + public String updateAuthorityItem( @PathParam("csid") String parentspecifier, @PathParam("itemcsid") String itemspecifier, - MultipartInput theUpdate) { - MultipartOutput result = null; + String xmlPayload) { + PoxPayloadOut result = null; try { + PoxPayloadIn theUpdate = new PoxPayloadIn(xmlPayload); Specifier parentSpec = getSpecifier(parentspecifier, "updateAuthorityItem(parent)", "UPDATE_ITEM"); Specifier itemSpec = getSpecifier(itemspecifier, "updateAuthorityItem(item)", "UPDATE_ITEM"); // Note that we have to create the service context for the Items, not the main service - ServiceContext ctx = null; + ServiceContext ctx = null; String parentcsid; if(parentSpec.form==SpecifierForm.CSID) { parentcsid = parentSpec.value; @@ -814,7 +815,7 @@ AbstractMultiPartCollectionSpaceResourceImpl { // Note that we have to create the service context for the Items, not the main service DocumentHandler handler = createItemDocumentHandler(ctx, parentcsid); getRepositoryClient(ctx).update(ctx, itemcsid, handler); - result = (MultipartOutput) ctx.getOutput(); + result = ctx.getOutput(); } catch (BadRequestException bre) { Response response = Response.status( Response.Status.BAD_REQUEST).entity("Create failed reason " + bre.getErrorReason()).type("text/plain").build(); @@ -836,7 +837,7 @@ AbstractMultiPartCollectionSpaceResourceImpl { Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build(); throw new WebApplicationException(response); } - return result; + return result.toXML(); } /** @@ -871,7 +872,7 @@ AbstractMultiPartCollectionSpaceResourceImpl { } try { // Note that we have to create the service context for the Items, not the main service - ServiceContext ctx = createServiceContext(getItemServiceName()); + ServiceContext ctx = createServiceContext(getItemServiceName()); getRepositoryClient(ctx).delete(ctx, itemcsid); return Response.status(HttpResponseCodes.SC_OK).build(); } catch (UnauthorizedException ue) { diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java index 829f7f9c0..d13c122a2 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java @@ -36,6 +36,9 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import org.collectionspace.services.jaxb.AbstractCommonList; +import org.collectionspace.services.client.PayloadInputPart; +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.common.authorityref.AuthorityRefList; import org.collectionspace.services.common.context.MultipartServiceContext; import org.collectionspace.services.common.context.ServiceContext; @@ -46,6 +49,7 @@ import org.collectionspace.services.common.document.DocumentFilter; import org.collectionspace.services.common.document.DocumentHandler.Action; import org.collectionspace.services.common.service.ObjectPartType; import org.collectionspace.services.common.vocabulary.RefNameUtils; +import org.dom4j.Element; import org.jboss.resteasy.plugins.providers.multipart.InputPart; import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; @@ -59,7 +63,7 @@ import org.nuxeo.ecm.core.schema.types.Schema; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.w3c.dom.Document; +import org.dom4j.Document; /** * RemoteDocumentModelHandler @@ -79,7 +83,7 @@ public abstract class RemoteDocumentModelHandlerImpl * @see org.collectionspace.services.common.document.AbstractDocumentHandlerImpl#setServiceContext(org.collectionspace.services.common.context.ServiceContext) */ @Override - public void setServiceContext(ServiceContext ctx) { //FIXME: Apply proper generics to ServiceContext + public void setServiceContext(ServiceContext ctx) { //FIXME: Apply proper generics to ServiceContext if (ctx instanceof MultipartServiceContext) { super.setServiceContext(ctx); } else { @@ -97,11 +101,11 @@ public abstract class RemoteDocumentModelHandlerImpl //return at least those document part(s) that were received Map partsMetaMap = getServiceContext().getPartsMetadata(); MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext(); - MultipartInput input = ctx.getInput(); + PoxPayloadIn input = ctx.getInput(); if (input != null) { - List inputParts = ctx.getInput().getParts(); - for (InputPart part : inputParts) { - String partLabel = part.getHeaders().getFirst("label"); + List inputParts = ctx.getInput().getParts(); + for (PayloadInputPart part : inputParts) { + String partLabel = part.getLabel(); ObjectPartType partMeta = partsMetaMap.get(partLabel); // extractPart(docModel, partLabel, partMeta); Map unQObjectProperties = extractPart(docModel, partLabel, partMeta); @@ -125,10 +129,10 @@ public abstract class RemoteDocumentModelHandlerImpl */ private void addOutputPart(Map unQObjectProperties, String schema, ObjectPartType partMeta) throws Exception { - Document doc = DocumentUtils.buildDocument(partMeta, schema, + Element doc = DocumentUtils.buildDocument(partMeta, schema, unQObjectProperties); if (logger.isDebugEnabled() == true) { - logger.debug(DocumentUtils.xmlToString(doc)); + logger.debug(doc.asXML()); } MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext(); ctx.addOutputPart(schema, doc, partMeta.getContent().getContentType()); @@ -191,7 +195,7 @@ public abstract class RemoteDocumentModelHandlerImpl //not an ideal way of populating objects. DocumentModel docModel = wrapDoc.getWrappedObject(); MultipartServiceContext ctx = (MultipartServiceContext) getServiceContext(); - MultipartInput input = ctx.getInput(); + PoxPayloadIn input = ctx.getInput(); if (input.getParts().isEmpty()) { String msg = "No payload found!"; logger.error(msg + "Ctx=" + getServiceContext().toString()); @@ -201,10 +205,10 @@ public abstract class RemoteDocumentModelHandlerImpl Map partsMetaMap = getServiceContext().getPartsMetadata(); //iterate over parts received and fill those parts - List inputParts = input.getParts(); - for (InputPart part : inputParts) { + List inputParts = input.getParts(); + for (PayloadInputPart part : inputParts) { - String partLabel = part.getHeaders().getFirst("label"); + String partLabel = part.getLabel(); if (partLabel == null) { String msg = "Part label is missing or empty!"; logger.error(msg + "Ctx=" + getServiceContext().toString()); @@ -228,24 +232,21 @@ public abstract class RemoteDocumentModelHandlerImpl * @param partMeta metadata for the object to fill * @throws Exception */ - protected void fillPart(InputPart part, DocumentModel docModel, - ObjectPartType partMeta, Action action, ServiceContext ctx) + protected void fillPart(PayloadInputPart part, DocumentModel docModel, + ObjectPartType partMeta, Action action, ServiceContext ctx) throws Exception { - InputStream payload = part.getBody(InputStream.class, null); - //check if this is an xml part if (part.getMediaType().equals(MediaType.APPLICATION_XML_TYPE)) { - if (payload != null) { - Document document = DocumentUtils.parseDocument(payload, partMeta, - false /*don't validate*/); - Map objectProps = DocumentUtils.parseProperties(partMeta, document, ctx); +// Document document = DocumentUtils.parseDocument(payload, partMeta, +// false /*don't validate*/); + Element element = part.getElementBody(); + Map objectProps = DocumentUtils.parseProperties(partMeta, element, ctx); if (action == Action.UPDATE) { this.filterReadOnlyPropertiesForPart(objectProps, partMeta); } docModel.setProperties(partMeta.getLabel(), objectProps); } } - } /** * Filters out read only properties, so they cannot be set on update. @@ -283,11 +284,11 @@ public abstract class RemoteDocumentModelHandlerImpl throws Exception { Map result = null; - MediaType mt = MediaType.valueOf(partMeta.getContent().getContentType()); + MediaType mt = MediaType.valueOf(partMeta.getContent().getContentType()); //FIXME: REM - This is no longer needed. Everything is POX if (mt.equals(MediaType.APPLICATION_XML_TYPE)) { Map objectProps = docModel.getProperties(schema); //unqualify properties before sending the doc over the wire (to save bandwidh) - //FIXME: is there a better way to avoid duplication of a collection? + //FIXME: is there a better way to avoid duplication of a Map/Collection? Map unQObjectProperties = (addToMap != null) ? addToMap : (new HashMap()); Set> qualifiedEntries = objectProps.entrySet(); diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteSubItemDocumentModelHandlerImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteSubItemDocumentModelHandlerImpl.java index baabb0adb..37856ad86 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteSubItemDocumentModelHandlerImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteSubItemDocumentModelHandlerImpl.java @@ -24,9 +24,13 @@ package org.collectionspace.services.nuxeo.client.java; import java.io.InputStream; +import java.io.ByteArrayInputStream; import java.util.HashMap; import java.util.Map; +import org.collectionspace.services.client.PayloadInputPart; +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.document.DocumentUtils; import org.collectionspace.services.common.service.ObjectPartType; @@ -66,10 +70,11 @@ public abstract class RemoteSubItemDocumentModelHandlerImpl extends * @throws Exception */ @Override - protected void fillPart(InputPart part, DocumentModel docModel, - ObjectPartType partMeta, Action action, ServiceContext ctx) + protected void fillPart(PayloadInputPart part, DocumentModel docModel, + ObjectPartType partMeta, Action action, ServiceContext ctx) throws Exception { - InputStream payload = part.getBody(InputStream.class, null); + ByteArrayInputStream bas = new ByteArrayInputStream(part.getElementBody().asXML().getBytes()); + InputStream payload = bas;//part.getBody(/*InputStream.class, null*/); //check if this is an xml part // TODO - we could configure the parts that have subitem content, diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java index cc6ba105b..5fd937907 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RepositoryJavaClientImpl.java @@ -24,6 +24,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils; import org.collectionspace.services.common.query.IQueryManager; @@ -91,7 +93,7 @@ public class RepositoryJavaClientImpl implements RepositoryClient { * @param documentModel the document model * @throws ClientException the client exception */ - private void setCollectionSpaceCoreValues(ServiceContext ctx, + private void setCollectionSpaceCoreValues(ServiceContext ctx, DocumentModel documentModel, Action action) throws ClientException { // diff --git a/services/contact/3rdparty/nuxeo-platform-cs-contact/.classpath b/services/contact/3rdparty/nuxeo-platform-cs-contact/.classpath index 199bbbbdb..6fd3b8551 100644 --- a/services/contact/3rdparty/nuxeo-platform-cs-contact/.classpath +++ b/services/contact/3rdparty/nuxeo-platform-cs-contact/.classpath @@ -1,8 +1,8 @@ - - - - - + + - + + + + \ No newline at end of file diff --git a/services/contact/3rdparty/nuxeo-platform-cs-contact/.project b/services/contact/3rdparty/nuxeo-platform-cs-contact/.project index a0168ccf7..d3a9126e8 100644 --- a/services/contact/3rdparty/nuxeo-platform-cs-contact/.project +++ b/services/contact/3rdparty/nuxeo-platform-cs-contact/.project @@ -1,6 +1,6 @@ org.collectionspace.services.contact.3rdparty.nuxeo - Contact Nuxeo Document Type + Contact Nuxeo Document Type. NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. diff --git a/services/contact/client/.classpath b/services/contact/client/.classpath index 425cd1620..77bfde7e1 100644 --- a/services/contact/client/.classpath +++ b/services/contact/client/.classpath @@ -1,10 +1,224 @@ - - - - - - - + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/services/contact/client/.project b/services/contact/client/.project index b5aa0b196..2144e4370 100644 --- a/services/contact/client/.project +++ b/services/contact/client/.project @@ -1,10 +1,10 @@ org.collectionspace.services.contact.client - + NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. - org.collectionspace.services.common org.collectionspace.services.client org.collectionspace.services.contact.jaxb + org.collectionspace.services.jaxb diff --git a/services/contact/client/pom.xml b/services/contact/client/pom.xml index d780e2a68..df284332e 100644 --- a/services/contact/client/pom.xml +++ b/services/contact/client/pom.xml @@ -35,6 +35,12 @@ ${project.version} + + dom4j + dom4j + 1.6.1 + provided + org.testng testng 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 index 284d2065b..ff80b7b92 100644 --- 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 @@ -24,8 +24,6 @@ import org.jboss.resteasy.client.ProxyFactory; import org.jboss.resteasy.plugins.providers.RegisterBuiltin; import org.jboss.resteasy.client.ClientResponse; import org.jboss.resteasy.client.core.executors.ApacheHttpClientExecutor; -import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; -import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; import org.jboss.resteasy.spi.ResteasyProviderFactory; /** @@ -36,12 +34,20 @@ import org.jboss.resteasy.spi.ResteasyProviderFactory; */ public class ContactClient extends AbstractServiceClientImpl { - - /* (non-Javadoc) - * @see org.collectionspace.services.client.BaseServiceClient#getServicePathComponent() - */ + public static final String SERVICE_NAME = "contacts"; + public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME; + public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT; + public static final String SERVICE_PATH_PROXY = SERVICE_PATH + "/"; + public static final String SERVICE_PAYLOAD_NAME = SERVICE_NAME; + + @Override + public String getServiceName() { + return SERVICE_NAME; + } + + @Override public String getServicePathComponent() { - return "contacts"; + return SERVICE_PATH_COMPONENT; } /** @@ -106,7 +112,7 @@ public class ContactClient extends AbstractServiceClientImpl { * @see org.collectionspace.services.client.Contact#getContact(java.lang.String) */ - public ClientResponse read(String csid) { + public ClientResponse read(String csid) { return contactProxy.read(csid); } @@ -115,8 +121,8 @@ public class ContactClient extends AbstractServiceClientImpl { * @return * @see org.collectionspace.services.client.Contact#createContact(org.collectionspace.services.Contact) */ - public ClientResponse create(MultipartOutput multipart) { - return contactProxy.create(multipart); + public ClientResponse create(PoxPayloadOut xmlPayload) { + return contactProxy.create(xmlPayload.getBytes()); } /** @@ -125,8 +131,8 @@ public class ContactClient extends AbstractServiceClientImpl { * @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); + public ClientResponse update(String csid, PoxPayloadOut xmlPayload) { + return contactProxy.update(csid, xmlPayload.getBytes()); } diff --git a/services/contact/client/src/main/java/org/collectionspace/services/client/ContactClientUtils.java b/services/contact/client/src/main/java/org/collectionspace/services/client/ContactClientUtils.java index 01a6755b1..39d173de4 100644 --- a/services/contact/client/src/main/java/org/collectionspace/services/client/ContactClientUtils.java +++ b/services/contact/client/src/main/java/org/collectionspace/services/client/ContactClientUtils.java @@ -4,8 +4,7 @@ import javax.ws.rs.core.MediaType; import org.collectionspace.services.client.ContactClient; import org.collectionspace.services.contact.ContactsCommon; -import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; -import org.jboss.resteasy.plugins.providers.multipart.OutputPart; +//import org.jboss.resteasy.plugins.providers.multipart.OutputPart; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -15,7 +14,7 @@ public class ContactClientUtils { private static final Logger logger = LoggerFactory.getLogger(ContactClientUtils.class); - public static MultipartOutput createContactInstance(String identifier, String headerLabel) { + public static PoxPayloadOut createContactInstance(String identifier, String headerLabel) { final String inAuthority = ""; final String inItem = ""; return createContactInstance( @@ -27,7 +26,7 @@ public class ContactClientUtils { headerLabel); } - public static MultipartOutput createContactInstance( + public static PoxPayloadOut createContactInstance( String inAuthority, String inItem, String identifier, String headerLabel) { return createContactInstance( inAuthority, @@ -38,7 +37,7 @@ public class ContactClientUtils { headerLabel); } - public static MultipartOutput createContactInstance( + public static PoxPayloadOut createContactInstance( String inAuthority, String inItem, String addressType, String addressPlace, String email, String headerLabel) { ContactsCommon contact = new ContactsCommon(); @@ -47,11 +46,12 @@ public class ContactClientUtils { contact.setAddressType(addressType); contact.setAddressPlace(addressPlace); contact.setEmail(email); - MultipartOutput multipart = new MultipartOutput(); - OutputPart commonPart = + PoxPayloadOut multipart = new PoxPayloadOut(ContactClient.SERVICE_PAYLOAD_NAME); + @SuppressWarnings("deprecation") + PayloadOutputPart commonPart = multipart.addPart(contact, MediaType.APPLICATION_XML_TYPE); - ContactClient client = new ContactClient(); - commonPart.getHeaders().add("label", headerLabel); +// ContactClient client = new ContactClient(); + commonPart.setLabel(headerLabel); if(logger.isDebugEnabled()){ logger.debug("to be created, contact common"); 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 index 35ff0fdbd..d62a4ee7a 100644 --- 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 @@ -12,34 +12,31 @@ 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"}) +@Path(ContactClient.SERVICE_PATH_PROXY) +@Produces({"application/xml"}) +@Consumes({"application/xml"}) public interface ContactProxy extends CollectionSpaceProxy { @GET - @Produces({"application/xml"}) ClientResponse readList(); //(C)reate @POST - ClientResponse create(MultipartOutput multipart); + ClientResponse create(byte[] xmlPayload); //(R)ead @GET @Path("/{csid}") - ClientResponse read(@PathParam("csid") String csid); + ClientResponse read(@PathParam("csid") String csid); //(U)pdate @PUT @Path("/{csid}") - ClientResponse update(@PathParam("csid") String csid, MultipartOutput multipart); + ClientResponse update(@PathParam("csid") String csid, byte[] xmlPayload); //(D)elete @DELETE 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 index c5475391b..b70255bc5 100644 --- 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 @@ -22,7 +22,6 @@ */ package org.collectionspace.services.client.test; -import java.util.ArrayList; import java.util.List; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -30,15 +29,16 @@ import javax.ws.rs.core.Response; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.ContactClient; import org.collectionspace.services.client.ContactClientUtils; +import org.collectionspace.services.client.PayloadOutputPart; +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.contact.ContactsCommon; import org.collectionspace.services.contact.ContactsCommonList; import org.collectionspace.services.jaxb.AbstractCommonList; import org.jboss.resteasy.client.ClientResponse; +//import org.jboss.resteasy.plugins.providers.multipart.OutputPart; -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.AfterClass; import org.testng.annotations.Test; @@ -54,14 +54,24 @@ import org.slf4j.LoggerFactory; * $LastChangedDate: 2009-11-06 12:20:28 -0800 (Fri, 06 Nov 2009) $ */ public class ContactServiceTest extends AbstractServiceTestImpl { - private final String CLASS_NAME = ContactServiceTest.class.getName(); - private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); + private final Logger logger = LoggerFactory.getLogger(ContactServiceTest.class); // Instance variables specific to this test. - final String SERVICE_PATH_COMPONENT = "contacts"; +// final String SERVICE_PATH_COMPONENT = "contacts"; + private String knownResourceId = null; + @Override + public String getServicePathComponent() { + return ContactClient.SERVICE_PATH_COMPONENT; + } + + @Override + protected String getServiceName() { + return ContactClient.SERVICE_NAME; + } + /* (non-Javadoc) * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() */ @@ -98,7 +108,7 @@ public class ContactServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. ContactClient client = new ContactClient(); String identifier = createIdentifier(); - MultipartOutput multipart = + PoxPayloadOut multipart = ContactClientUtils.createContactInstance(identifier, client.getCommonPartName()); ClientResponse res = client.create(multipart); @@ -264,7 +274,7 @@ public class ContactServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. ContactClient client = new ContactClient(); - ClientResponse res = client.read(knownResourceId); + ClientResponse res = client.read(knownResourceId); int statusCode = res.getStatus(); // Check the status code of the response: does it match @@ -276,7 +286,7 @@ public class ContactServiceTest extends AbstractServiceTestImpl { invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - MultipartInput input = (MultipartInput) res.getEntity(); + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); ContactsCommon contact = (ContactsCommon) extractPart(input, client.getCommonPartName(), ContactsCommon.class); Assert.assertNotNull(contact); @@ -296,7 +306,7 @@ public class ContactServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. ContactClient client = new ContactClient(); - ClientResponse res = client.read(NON_EXISTENT_ID); + ClientResponse res = client.read(NON_EXISTENT_ID); int statusCode = res.getStatus(); // Check the status code of the response: does it match @@ -377,8 +387,7 @@ public class ContactServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. ContactClient client = new ContactClient(); - ClientResponse res = - client.read(knownResourceId); + ClientResponse res = client.read(knownResourceId); if(logger.isDebugEnabled()){ logger.debug(testName + ": read status = " + res.getStatus()); } @@ -387,7 +396,7 @@ public class ContactServiceTest extends AbstractServiceTestImpl { if(logger.isDebugEnabled()){ logger.debug("got object to update with ID: " + knownResourceId); } - MultipartInput input = (MultipartInput) res.getEntity(); + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); ContactsCommon contact = (ContactsCommon) extractPart(input, client.getCommonPartName(), ContactsCommon.class); Assert.assertNotNull(contact); @@ -401,9 +410,9 @@ public class ContactServiceTest extends AbstractServiceTestImpl { 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()); + PoxPayloadOut output = new PoxPayloadOut(ContactClient.SERVICE_PAYLOAD_NAME); + PayloadOutputPart commonPart = output.addPart(contact, MediaType.APPLICATION_XML_TYPE); + commonPart.setLabel(client.getCommonPartName()); res = client.update(knownResourceId, output); int statusCode = res.getStatus(); @@ -416,7 +425,7 @@ public class ContactServiceTest extends AbstractServiceTestImpl { Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - input = (MultipartInput) res.getEntity(); + input = new PoxPayloadIn(res.getEntity()); ContactsCommon updatedContact = (ContactsCommon) extractPart(input, client.getCommonPartName(), ContactsCommon.class); @@ -553,9 +562,9 @@ public class ContactServiceTest extends AbstractServiceTestImpl { // Note: The ID used in this 'create' call may be arbitrary. // The only relevant ID may be the one used in update(), below. ContactClient client = new ContactClient(); - MultipartOutput multipart = + PoxPayloadOut multipart = ContactClientUtils.createContactInstance(NON_EXISTENT_ID, client.getCommonPartName()); - ClientResponse res = + ClientResponse res = client.update(NON_EXISTENT_ID, multipart); int statusCode = res.getStatus(); @@ -653,12 +662,4 @@ public class ContactServiceTest extends AbstractServiceTestImpl { Assert.assertEquals(statusCode, EXPECTED_STATUS); } - - // --------------------------------------------------------------- - // Utility methods used by tests above - // --------------------------------------------------------------- - @Override - public String getServicePathComponent() { - return SERVICE_PATH_COMPONENT; - } } diff --git a/services/contact/jaxb/.classpath b/services/contact/jaxb/.classpath index 1707f3e6f..0d593e17f 100644 --- a/services/contact/jaxb/.classpath +++ b/services/contact/jaxb/.classpath @@ -1,11 +1,32 @@ - - - - - - - - + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/services/contact/jaxb/.project b/services/contact/jaxb/.project index ca0775f80..444821230 100644 --- a/services/contact/jaxb/.project +++ b/services/contact/jaxb/.project @@ -1,7 +1,9 @@ org.collectionspace.services.contact.jaxb - - + NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. + + org.collectionspace.services.jaxb + org.eclipse.jdt.core.javabuilder diff --git a/services/contact/jaxb/.settings/org.maven.ide.eclipse.prefs b/services/contact/jaxb/.settings/org.maven.ide.eclipse.prefs index e51e8e711..dd2ea026f 100644 --- a/services/contact/jaxb/.settings/org.maven.ide.eclipse.prefs +++ b/services/contact/jaxb/.settings/org.maven.ide.eclipse.prefs @@ -1,9 +1,9 @@ -#Tue Dec 21 09:59:48 PST 2010 +#Wed Jan 19 22:49:48 PST 2011 activeProfiles= eclipse.preferences.version=1 -fullBuildGoals=process-classes +fullBuildGoals=process-test-resources includeModules=false resolveWorkspaceProjects=true -resourceFilterGoals=process-classes -skipCompilerPlugin=false +resourceFilterGoals=process-resources resources\:testResources +skipCompilerPlugin=true version=1 diff --git a/services/contact/service/.classpath b/services/contact/service/.classpath index 3a317acf0..bb2110fea 100644 --- a/services/contact/service/.classpath +++ b/services/contact/service/.classpath @@ -1,10 +1,306 @@ - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/services/contact/service/.project b/services/contact/service/.project index 97e7939d0..ae6b995bf 100644 --- a/services/contact/service/.project +++ b/services/contact/service/.project @@ -1,9 +1,13 @@ org.collectionspace.services.contact.service - + NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. - org.collectionspace.services.contact.jaxb + org.collectionspace.services.3rdparty.nuxeo.quote-api + org.collectionspace.services.client org.collectionspace.services.common + org.collectionspace.services.contact.client + org.collectionspace.services.contact.jaxb + org.collectionspace.services.hyperjaxb org.collectionspace.services.jaxb diff --git a/services/contact/service/pom.xml b/services/contact/service/pom.xml index 102b21148..6f53aa677 100644 --- a/services/contact/service/pom.xml +++ b/services/contact/service/pom.xml @@ -23,6 +23,11 @@ org.collectionspace.services.contact.jaxb ${project.version} + + org.collectionspace.services + org.collectionspace.services.contact.client + ${project.version} + org.testng diff --git a/services/contact/service/src/main/java/org/collectionspace/services/contact/AuthorityResourceWithContacts.java b/services/contact/service/src/main/java/org/collectionspace/services/contact/AuthorityResourceWithContacts.java index 19971c8ee..b2fe3d3d6 100644 --- a/services/contact/service/src/main/java/org/collectionspace/services/contact/AuthorityResourceWithContacts.java +++ b/services/contact/service/src/main/java/org/collectionspace/services/contact/AuthorityResourceWithContacts.java @@ -23,7 +23,7 @@ */ package org.collectionspace.services.contact; -import java.util.List; +//import java.util.List; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; @@ -33,7 +33,7 @@ import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; +//import javax.ws.rs.QueryParam; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Context; import javax.ws.rs.core.MultivaluedMap; @@ -41,54 +41,53 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriInfo; +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.common.vocabulary.AuthorityResource; -import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema; -import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema; -import org.collectionspace.services.common.vocabulary.AuthorityResource.Specifier; -import org.collectionspace.services.common.vocabulary.AuthorityResource.SpecifierForm; -import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityItemDocumentModelHandler; -import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl; -import org.collectionspace.services.common.ClientType; -import org.collectionspace.services.common.ServiceMain; -import org.collectionspace.services.common.authorityref.AuthorityRefDocList; -import org.collectionspace.services.common.authorityref.AuthorityRefList; -import org.collectionspace.services.common.context.MultipartServiceContextImpl; -import org.collectionspace.services.common.context.ServiceBindingUtils; +//import org.collectionspace.services.common.vocabulary.AuthorityJAXBSchema; +//import org.collectionspace.services.common.vocabulary.AuthorityItemJAXBSchema; +//import org.collectionspace.services.common.vocabulary.AuthorityResource.Specifier; +//import org.collectionspace.services.common.vocabulary.AuthorityResource.SpecifierForm; +//import org.collectionspace.services.common.vocabulary.nuxeo.AuthorityItemDocumentModelHandler; +//import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl; +//import org.collectionspace.services.common.ClientType; +//import org.collectionspace.services.common.ServiceMain; +//import org.collectionspace.services.common.authorityref.AuthorityRefDocList; +//import org.collectionspace.services.common.authorityref.AuthorityRefList; +//import org.collectionspace.services.common.context.MultipartServiceContextImpl; +//import org.collectionspace.services.common.context.ServiceBindingUtils; import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.common.document.BadRequestException; import org.collectionspace.services.common.document.DocumentFilter; import org.collectionspace.services.common.document.DocumentHandler; import org.collectionspace.services.common.document.DocumentNotFoundException; -import org.collectionspace.services.common.document.DocumentWrapper; +//import org.collectionspace.services.common.document.DocumentWrapper; import org.collectionspace.services.contact.ContactResource; import org.collectionspace.services.contact.ContactsCommon; import org.collectionspace.services.contact.ContactsCommonList; import org.collectionspace.services.contact.ContactJAXBSchema; import org.collectionspace.services.contact.nuxeo.ContactDocumentModelHandler; -import org.collectionspace.services.common.repository.RepositoryClient; +//import org.collectionspace.services.common.repository.RepositoryClient; import org.collectionspace.services.common.security.UnauthorizedException; import org.collectionspace.services.common.query.IQueryManager; -import org.collectionspace.services.common.query.QueryManager; -import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; -import org.jboss.remoting.samples.chat.exceptions.InvalidArgumentException; -import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; -import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; +//import org.collectionspace.services.common.query.QueryManager; +//import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; +//import org.jboss.remoting.samples.chat.exceptions.InvalidArgumentException; import org.jboss.resteasy.util.HttpResponseCodes; -import org.nuxeo.ecm.core.api.DocumentModel; +//import org.nuxeo.ecm.core.api.DocumentModel; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * The Class AuthorityResourceWithContacts. */ -@Path("/vocabularies") -@Consumes("multipart/mixed") -@Produces("multipart/mixed") -public abstract class AuthorityResourceWithContacts extends +@Consumes("application/xml") +@Produces("application/xml") +public abstract class AuthorityResourceWithContacts extends //FIXME: REM - Why is this resource in this package instead of somewhere in 'common'? AuthorityResource { /** The contact resource. */ - private ContactResource contactResource = new ContactResource(); + private ContactResource contactResource = new ContactResource(); // Warning: ContactResource is a singleton. final Logger logger = LoggerFactory.getLogger(AuthorityResourceWithContacts.class); @@ -125,7 +124,7 @@ public abstract class AuthorityResourceWithContacts ctx, String inAuthority, + ServiceContext ctx, String inAuthority, String inItem) throws Exception { ContactDocumentModelHandler docHandler = (ContactDocumentModelHandler)createDocumentHandler( @@ -150,14 +149,15 @@ public abstract class AuthorityResourceWithContacts ctx = null; + ServiceContext ctx = null; String parentcsid; if(parentSpec.form==SpecifierForm.CSID) { parentcsid = parentSpec.value; @@ -237,7 +237,7 @@ public abstract class AuthorityResourceWithContacts ctx = null; + ServiceContext ctx = null; String parentcsid; if(parentSpec.form==SpecifierForm.CSID) { parentcsid = parentSpec.value; @@ -303,18 +303,18 @@ public abstract class AuthorityResourceWithContacts ctx = null; + ServiceContext ctx = null; String parentcsid; if(parentSpec.form==SpecifierForm.CSID) { parentcsid = parentSpec.value; @@ -337,7 +337,7 @@ public abstract class AuthorityResourceWithContacts ctx = null; + ServiceContext ctx = null; String parentcsid; if(parentSpec.form==SpecifierForm.CSID) { parentcsid = parentSpec.value; @@ -418,7 +419,7 @@ public abstract class AuthorityResourceWithContacts ctx = null; + ServiceContext ctx = null; String parentcsid; if(parentSpec.form==SpecifierForm.CSID) { parentcsid = parentSpec.value; 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 index 438e59e00..774b19ba0 100644 --- 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 @@ -38,6 +38,9 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriInfo; +import org.collectionspace.services.client.ContactClient; +import org.collectionspace.services.client.PoxPayloadIn; +import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.common.AbstractMultiPartCollectionSpaceResourceImpl; import org.collectionspace.services.common.ClientType; import org.collectionspace.services.common.ServiceMain; @@ -45,9 +48,6 @@ 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; @@ -55,17 +55,16 @@ import org.slf4j.LoggerFactory; /** * The Class ContactResource. */ -@Path("/contacts") -@Consumes("multipart/mixed") -@Produces("multipart/mixed") +@Path(ContactClient.SERVICE_PATH) +@Consumes("application/xml") +@Produces("application/xml") public class ContactResource extends AbstractMultiPartCollectionSpaceResourceImpl { - - /** The Constant serviceName. */ - private final static String serviceName = "contacts"; - - /** The logger. */ + // + // The logger init + // final Logger logger = LoggerFactory.getLogger(ContactResource.class); + //FIXME retrieve client type from configuration /** The Constant CLIENT_TYPE. */ final static ClientType CLIENT_TYPE = ServiceMain.getInstance().getClientType(); @@ -92,7 +91,7 @@ public class ContactResource extends */ @Override public String getServiceName() { - return serviceName; + return ContactClient.SERVICE_NAME; } /* (non-Javadoc) @@ -103,7 +102,7 @@ public class ContactResource extends return ContactsCommon.class; } -// @Override +// @Override //FIXME: REM - Remove this dead code please // public DocumentHandler createDocumentHandler(ServiceContext ctx) throws Exception { // DocumentHandler docHandler = ctx.getDocumentHandler(); // if (ctx.getInput() != null) { @@ -117,15 +116,15 @@ public class ContactResource extends /** * Creates the contact. - * - * @param input the input - * + * + * @param xmlPayload the xml payload * @return the response */ -@POST - public Response createContact(MultipartInput input) { + @POST + public Response createContact(String xmlPayload) { try { - ServiceContext ctx = createServiceContext(input); + PoxPayloadIn input = new PoxPayloadIn(xmlPayload); + ServiceContext ctx = createServiceContext(input); DocumentHandler handler = createDocumentHandler(ctx); String csid = getRepositoryClient(ctx).create(ctx, handler); //contactObject.setCsid(csid); @@ -152,24 +151,24 @@ public class ContactResource extends */ @GET @Path("{csid}") - public MultipartOutput getContact( + public String getContact( @PathParam("csid") String csid) { if (logger.isDebugEnabled()) { logger.debug("getContact with csid=" + csid); } - if (csid == null || "".equals(csid)) { + if (csid == null || "".equals(csid)) { //FIXME: REM - This is a silly check? We can't reach this resource if CSID is blank in the URL 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; + PoxPayloadOut result = null; try { - ServiceContext ctx = createServiceContext(); + ServiceContext ctx = createServiceContext(); DocumentHandler handler = createDocumentHandler(ctx); getRepositoryClient(ctx).get(ctx, csid, handler); - result = (MultipartOutput) ctx.getOutput(); + result = ctx.getOutput(); } catch (DocumentNotFoundException dnfe) { if (logger.isDebugEnabled()) { logger.debug("getContact", dnfe); @@ -192,7 +191,7 @@ public class ContactResource extends "text/plain").build(); throw new WebApplicationException(response); } - return result; + return result.toXML(); } /** @@ -208,7 +207,7 @@ public class ContactResource extends MultivaluedMap queryParams = ui.getQueryParameters(); ContactsCommonList contactObjectList = new ContactsCommonList(); try { - ServiceContext ctx = createServiceContext(queryParams); + ServiceContext ctx = createServiceContext(queryParams); DocumentHandler handler = createDocumentHandler(ctx); getRepositoryClient(ctx).getFiltered(ctx, handler); contactObjectList = (ContactsCommonList) handler.getCommonPartList(); @@ -233,25 +232,26 @@ public class ContactResource extends */ @PUT @Path("{csid}") - public MultipartOutput updateContact( + public String updateContact( @PathParam("csid") String csid, - MultipartInput theUpdate) { + String xmlPayload) { if (logger.isDebugEnabled()) { logger.debug("updateContact with csid=" + csid); } - if (csid == null || "".equals(csid)) { + if (csid == null || "".equals(csid)) {//FIXME: REM - This is a silly check? We can't reach this resource if CSID is blank in the URL. 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; + PoxPayloadOut result = null; try { - ServiceContext ctx = createServiceContext(theUpdate); + PoxPayloadIn theUpdate = new PoxPayloadIn(xmlPayload); + ServiceContext ctx = createServiceContext(theUpdate); DocumentHandler handler = createDocumentHandler(ctx); getRepositoryClient(ctx).update(ctx, csid, handler); - result = (MultipartOutput) ctx.getOutput(); + result = ctx.getOutput(); } catch (DocumentNotFoundException dnfe) { if (logger.isDebugEnabled()) { logger.debug("Caught exception in updateContact", dnfe); @@ -265,7 +265,7 @@ public class ContactResource extends Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build(); throw new WebApplicationException(response); } - return result; + return result.toXML(); } /** @@ -290,7 +290,7 @@ public class ContactResource extends throw new WebApplicationException(response); } try { - ServiceContext ctx = createServiceContext(); + ServiceContext ctx = createServiceContext(); getRepositoryClient(ctx).delete(ctx, csid); return Response.status(HttpResponseCodes.SC_OK).build(); } catch (DocumentNotFoundException dnfe) { diff --git a/services/jaxb/.classpath b/services/jaxb/.classpath index 557f8a4e0..2ffc80546 100644 --- a/services/jaxb/.classpath +++ b/services/jaxb/.classpath @@ -1,10 +1,30 @@ - - - - - - - + + + + - + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/services/jaxb/.project b/services/jaxb/.project index a0fdd4162..fabf3e79f 100644 --- a/services/jaxb/.project +++ b/services/jaxb/.project @@ -1,23 +1,17 @@ - org.collectionspace.services.jaxb - - - + NO_M2ECLIPSE_SUPPORT: Project files created with the maven-eclipse-plugin are not supported in M2Eclipse. + org.eclipse.jdt.core.javabuilder - - org.maven.ide.eclipse.maven2Builder - - org.maven.ide.eclipse.maven2Nature org.eclipse.jdt.core.javanature - + \ No newline at end of file diff --git a/services/jaxb/.settings/org.maven.ide.eclipse.prefs b/services/jaxb/.settings/org.maven.ide.eclipse.prefs index 179c3750a..97c7be065 100644 --- a/services/jaxb/.settings/org.maven.ide.eclipse.prefs +++ b/services/jaxb/.settings/org.maven.ide.eclipse.prefs @@ -1,9 +1,9 @@ -#Tue Dec 21 10:13:02 PST 2010 +#Wed Jan 19 22:49:22 PST 2011 activeProfiles= eclipse.preferences.version=1 -fullBuildGoals=process-classes +fullBuildGoals=process-test-resources includeModules=false resolveWorkspaceProjects=true -resourceFilterGoals=process-classes -skipCompilerPlugin=false +resourceFilterGoals=process-resources resources\:testResources +skipCompilerPlugin=true version=1 -- 2.47.3