From 0e98093fcb074fe41ec87f260c22c782e18055de Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Wed, 16 Feb 2011 00:15:22 +0000 Subject: [PATCH] CSPACE-3574: Merging Plain Old XML payload work into trunk. --- .../nuxeo-platform-cs-loanout/.classpath | 12 +- .../nuxeo-platform-cs-loanout/.project | 12 +- services/loanout/client/.classpath | 318 +++++++++++++++++- services/loanout/client/.project | 19 +- .../services/client/LoanoutClient.java | 61 ++-- .../services/client/LoanoutProxy.java | 12 +- .../client/test/LoanoutAuthRefsTest.java | 65 ++-- .../client/test/LoanoutServiceTest.java | 176 ++++++---- services/loanout/jaxb/.classpath | 37 +- services/loanout/jaxb/.project | 10 +- .../.settings/org.maven.ide.eclipse.prefs | 8 +- services/loanout/service/.classpath | 314 ++++++++++++++++- services/loanout/service/.project | 16 +- .../services/loanout/LoanoutResource.java | 50 +-- 14 files changed, 884 insertions(+), 226 deletions(-) diff --git a/services/loanout/3rdparty/nuxeo-platform-cs-loanout/.classpath b/services/loanout/3rdparty/nuxeo-platform-cs-loanout/.classpath index 199bbbbdb..6fd3b8551 100644 --- a/services/loanout/3rdparty/nuxeo-platform-cs-loanout/.classpath +++ b/services/loanout/3rdparty/nuxeo-platform-cs-loanout/.classpath @@ -1,8 +1,8 @@ - - - - - + + - + + + + \ No newline at end of file diff --git a/services/loanout/3rdparty/nuxeo-platform-cs-loanout/.project b/services/loanout/3rdparty/nuxeo-platform-cs-loanout/.project index e2be94571..9cc1542ac 100644 --- a/services/loanout/3rdparty/nuxeo-platform-cs-loanout/.project +++ b/services/loanout/3rdparty/nuxeo-platform-cs-loanout/.project @@ -1,23 +1,17 @@ - org.collectionspace.services.loanout.3rdparty.nuxeo - - - + Loanout 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/loanout/client/.classpath b/services/loanout/client/.classpath index 425cd1620..2d6eed2b5 100644 --- a/services/loanout/client/.classpath +++ b/services/loanout/client/.classpath @@ -1,10 +1,312 @@ - - - - - - - + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/services/loanout/client/.project b/services/loanout/client/.project index 202ad68f4..7c18670a6 100644 --- a/services/loanout/client/.project +++ b/services/loanout/client/.project @@ -1,23 +1,28 @@ - org.collectionspace.services.loanout.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.loanout.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/loanout/client/src/main/java/org/collectionspace/services/client/LoanoutClient.java b/services/loanout/client/src/main/java/org/collectionspace/services/client/LoanoutClient.java index 39051aa62..071e4c874 100644 --- a/services/loanout/client/src/main/java/org/collectionspace/services/client/LoanoutClient.java +++ b/services/loanout/client/src/main/java/org/collectionspace/services/client/LoanoutClient.java @@ -16,19 +16,15 @@ */ package org.collectionspace.services.client; -import javax.ws.rs.PathParam; import javax.ws.rs.core.Response; import org.collectionspace.services.common.authorityref.AuthorityRefList; -//import org.collectionspace.services.common.context.ServiceContext; import org.collectionspace.services.loanout.LoansoutCommonList; 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,25 +32,21 @@ import org.jboss.resteasy.spi.ResteasyProviderFactory; * * $LastChangedRevision$ * $LastChangedDate$ - * */ public class LoanoutClient extends AbstractServiceClientImpl { + public static final String SERVICE_NAME = "loansout"; + 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; - /* (non-Javadoc) - * @see org.collectionspace.services.client.AbstractServiceClientImpl#getServicePathComponent() - */ - public String getServicePathComponent() { - return "loansout"; - } - /** - * - */ -// private static final LoanoutClient instance = new LoanoutClient(); - /** - * - */ private LoanoutProxy loanoutProxy; + @Override + public String getServiceName() { + return SERVICE_NAME; + } + /** * * Default constructor for LoanoutClient class. @@ -65,6 +57,14 @@ public class LoanoutClient extends AbstractServiceClientImpl { RegisterBuiltin.register(factory); setProxy(); } + + /* (non-Javadoc) + * @see org.collectionspace.services.client.AbstractServiceClientImpl#getServicePathComponent() + */ + @Override + public String getServicePathComponent() { + return SERVICE_PATH_COMPONENT; + } @Override public CollectionSpaceProxy getProxy() { @@ -74,6 +74,7 @@ public class LoanoutClient extends AbstractServiceClientImpl { /** * allow to reset proxy as per security needs */ + @Override public void setProxy() { if (useAuth()) { loanoutProxy = ProxyFactory.create(LoanoutProxy.class, @@ -84,15 +85,6 @@ public class LoanoutClient extends AbstractServiceClientImpl { } } - /** - * FIXME Comment this - * - * @return - */ -// public static LoanoutClient getInstance() { -// return instance; -// } - /** * @return * @see org.collectionspace.services.client.LoanoutProxy#getLoanout() @@ -116,27 +108,27 @@ public class LoanoutClient extends AbstractServiceClientImpl { * @return * @see org.collectionspace.services.client.LoanoutProxy#getLoanout(java.lang.String) */ - public ClientResponse read(String csid) { + public ClientResponse read(String csid) { return loanoutProxy.read(csid); } /** - * @param loanout + * @param multipart * @return * @see org.collectionspace.services.client.LoanoutProxy#createLoanout(org.collectionspace.hello.Loanout) */ - public ClientResponse create(MultipartOutput multipart) { - return loanoutProxy.create(multipart); + public ClientResponse create(PoxPayloadOut xmlPayload) { + return loanoutProxy.create(xmlPayload.getBytes()); } /** * @param csid - * @param loanout + * @param multipart * @return * @see org.collectionspace.services.client.LoanoutProxy#updateLoanout(java.lang.Long, org.collectionspace.hello.Loanout) */ - public ClientResponse update(String csid, MultipartOutput multipart) { - return loanoutProxy.update(csid, multipart); + public ClientResponse update(String csid, PoxPayloadOut xmlPayload) { + return loanoutProxy.update(csid, xmlPayload.getBytes()); } @@ -145,6 +137,7 @@ public class LoanoutClient extends AbstractServiceClientImpl { * @return * @see org.collectionspace.services.client.LoanoutProxy#deleteLoanout(java.lang.Long) */ + @Override public ClientResponse delete(String csid) { return loanoutProxy.delete(csid); } diff --git a/services/loanout/client/src/main/java/org/collectionspace/services/client/LoanoutProxy.java b/services/loanout/client/src/main/java/org/collectionspace/services/client/LoanoutProxy.java index 149564eb2..b3e18945a 100644 --- a/services/loanout/client/src/main/java/org/collectionspace/services/client/LoanoutProxy.java +++ b/services/loanout/client/src/main/java/org/collectionspace/services/client/LoanoutProxy.java @@ -13,30 +13,28 @@ import javax.ws.rs.core.Response; import org.collectionspace.services.common.authorityref.AuthorityRefList; import org.collectionspace.services.loanout.LoansoutCommonList; 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("/loansout/") -@Produces({"multipart/mixed"}) -@Consumes({"multipart/mixed"}) +@Produces({"application/xml"}) +@Consumes({"application/xml"}) public interface LoanoutProxy extends CollectionSpaceProxy { //(C)reate @POST - ClientResponse create(MultipartOutput multipart); + ClientResponse create(byte[] payload); //(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[] payload); //(D)elete @DELETE diff --git a/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutAuthRefsTest.java b/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutAuthRefsTest.java index ed87a83ed..dd96fe9cc 100644 --- a/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutAuthRefsTest.java +++ b/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutAuthRefsTest.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.LoanoutClient; +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.common.authorityref.AuthorityRefList.AuthorityRefItem; import org.collectionspace.services.jaxb.AbstractCommonList; @@ -43,9 +46,6 @@ import org.collectionspace.services.loanout.LoansoutCommon; import org.jboss.resteasy.client.ClientResponse; -import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; -import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; -import org.jboss.resteasy.plugins.providers.multipart.OutputPart; import org.testng.Assert; import org.testng.annotations.AfterClass; import org.testng.annotations.Test; @@ -66,6 +66,7 @@ public class LoanoutAuthRefsTest extends BaseServiceTest { private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); // Instance variables specific to this test. + final String SERVICE_NAME = "loansout"; final String SERVICE_PATH_COMPONENT = "loansout"; final String PERSON_AUTHORITY_NAME = "TestPersonAuth"; private String knownResourceId = null; @@ -122,7 +123,7 @@ public class LoanoutAuthRefsTest extends BaseServiceTest { // One or more fields in this resource will be PersonAuthority // references, and will refer to Person resources by their refNames. LoanoutClient loanoutClient = new LoanoutClient(); - MultipartOutput multipart = createLoanoutInstance( + PoxPayloadOut multipart = createLoanoutInstance( "loanOutNumber-" + identifier, "returnDate-" + identifier, borrowerRefName, @@ -164,7 +165,7 @@ public class LoanoutAuthRefsTest extends BaseServiceTest { PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); // Create a temporary PersonAuthority resource, and its corresponding // refName by which it can be identified. - MultipartOutput multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance( + PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance( PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName()); ClientResponse res = personAuthClient.create(multipart); int statusCode = res.getStatus(); @@ -205,8 +206,8 @@ public class LoanoutAuthRefsTest 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, + PoxPayloadOut multipart = + PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, authRefName, personInfo, personAuthClient.getItemCommonPartName()); ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); int statusCode = res.getStatus(); @@ -230,7 +231,7 @@ public class LoanoutAuthRefsTest extends BaseServiceTest { // Submit the request to the service and store the response. LoanoutClient loanoutClient = new LoanoutClient(); - ClientResponse res = loanoutClient.read(knownResourceId); + ClientResponse res = loanoutClient.read(knownResourceId); int statusCode = res.getStatus(); // Check the status code of the response: does it match @@ -242,18 +243,19 @@ public class LoanoutAuthRefsTest extends BaseServiceTest { invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - MultipartInput input = (MultipartInput) res.getEntity(); - LoansoutCommon loanout = (LoansoutCommon) extractPart(input, + // Extract the common part from the response. + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + LoansoutCommon loanoutCommon = (LoansoutCommon) extractPart(input, loanoutClient.getCommonPartName(), LoansoutCommon.class); - Assert.assertNotNull(loanout); + Assert.assertNotNull(loanoutCommon); if(logger.isDebugEnabled()){ - logger.debug(objectAsXmlString(loanout, LoansoutCommon.class)); + logger.debug(objectAsXmlString(loanoutCommon, LoansoutCommon.class)); } // Check a couple of fields - Assert.assertEquals(loanout.getBorrower(), borrowerRefName); - Assert.assertEquals(loanout.getBorrowersContact(), borrowersContactRefName); - Assert.assertEquals(loanout.getLendersAuthorizer(), lendersAuthorizerRefName); - Assert.assertEquals(loanout.getLendersContact(), lendersContactRefName); + Assert.assertEquals(loanoutCommon.getBorrower(), borrowerRefName); + Assert.assertEquals(loanoutCommon.getBorrowersContact(), borrowersContactRefName); + Assert.assertEquals(loanoutCommon.getLendersAuthorizer(), lendersAuthorizerRefName); + Assert.assertEquals(loanoutCommon.getLendersContact(), lendersContactRefName); // Get the auth refs and check them ClientResponse res2 = @@ -343,32 +345,37 @@ public class LoanoutAuthRefsTest extends BaseServiceTest { // --------------------------------------------------------------- // Utility methods used by tests above // --------------------------------------------------------------- + public String getServiceName() { + return SERVICE_NAME; + } + @Override public String getServicePathComponent() { return SERVICE_PATH_COMPONENT; } - private MultipartOutput createLoanoutInstance(String loanoutNumber, + private PoxPayloadOut createLoanoutInstance(String loanoutNumber, String returnDate, String borrower, String borrowersContact, String lendersAuthorizer, String lendersContact) { - LoansoutCommon loanout = new LoansoutCommon(); - loanout.setLoanOutNumber(loanoutNumber); - loanout.setLoanReturnDate(returnDate); - loanout.setBorrower(borrower); - loanout.setBorrowersContact(borrowersContact); - loanout.setLendersAuthorizer(lendersAuthorizer); - loanout.setLendersContact(lendersContact); - MultipartOutput multipart = new MultipartOutput(); - OutputPart commonPart = - multipart.addPart(loanout, MediaType.APPLICATION_XML_TYPE); - commonPart.getHeaders().add("label", new LoanoutClient().getCommonPartName()); + LoansoutCommon loanoutCommon = new LoansoutCommon(); + loanoutCommon.setLoanOutNumber(loanoutNumber); + loanoutCommon.setLoanReturnDate(returnDate); + loanoutCommon.setBorrower(borrower); + loanoutCommon.setBorrowersContact(borrowersContact); + loanoutCommon.setLendersAuthorizer(lendersAuthorizer); + loanoutCommon.setLendersContact(lendersContact); + + PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent()); + PayloadOutputPart commonPart = + multipart.addPart(loanoutCommon, MediaType.APPLICATION_XML_TYPE); + commonPart.setLabel(new LoanoutClient().getCommonPartName()); if(logger.isDebugEnabled()){ logger.debug("to be created, loanout common"); - logger.debug(objectAsXmlString(loanout, LoansoutCommon.class)); + logger.debug(objectAsXmlString(loanoutCommon, LoansoutCommon.class)); } return multipart; diff --git a/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutServiceTest.java b/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutServiceTest.java index e1a9d9008..c8180de24 100644 --- a/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutServiceTest.java +++ b/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutServiceTest.java @@ -28,6 +28,10 @@ import javax.ws.rs.core.Response; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.LoanoutClient; +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.jaxb.AbstractCommonList; import org.collectionspace.services.loanout.LoanedObjectStatusGroup; import org.collectionspace.services.loanout.LoanedObjectStatusGroupList; @@ -36,9 +40,6 @@ import org.collectionspace.services.loanout.LoansoutCommonList; import org.jboss.resteasy.client.ClientResponse; -import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; -import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; -import org.jboss.resteasy.plugins.providers.multipart.OutputPart; import org.testng.Assert; import org.testng.annotations.Test; @@ -57,10 +58,6 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { /** The logger. */ private final String CLASS_NAME = LoanoutServiceTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); - - // Instance variables specific to this test. - /** The service path component. */ - final String SERVICE_PATH_COMPONENT = "loansout"; /** The known resource id. */ private String knownResourceId = null; @@ -104,7 +101,7 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. LoanoutClient client = new LoanoutClient(); String identifier = createIdentifier(); - MultipartOutput multipart = createLoanoutInstance(identifier); + PoxPayloadOut multipart = createLoanoutInstance(identifier); ClientResponse res = client.create(multipart); int statusCode = res.getStatus(); @@ -284,7 +281,7 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. LoanoutClient client = new LoanoutClient(); - ClientResponse res = client.read(knownResourceId); + ClientResponse res = client.read(knownResourceId); int statusCode = res.getStatus(); // Check the status code of the response: does it match @@ -296,12 +293,19 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - MultipartInput input = (MultipartInput) res.getEntity(); - LoansoutCommon loanout = (LoansoutCommon) extractPart(input, - client.getCommonPartName(), LoansoutCommon.class); - Assert.assertNotNull(loanout); - Assert.assertNotNull(loanout.getLoanOutNumber()); - LoanedObjectStatusGroupList statusGroupList = loanout.getLoanedObjectStatusGroupList(); + // Get the common part of the response and verify that it is not null. + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName()); + LoansoutCommon loanoutCommon = null; + if (payloadInputPart != null) { + loanoutCommon = (LoansoutCommon) payloadInputPart.getBody(); + } + Assert.assertNotNull(loanoutCommon); + + // Check selected fields in the common part. + Assert.assertNotNull(loanoutCommon.getLoanOutNumber()); + + LoanedObjectStatusGroupList statusGroupList = loanoutCommon.getLoanedObjectStatusGroupList(); Assert.assertNotNull(statusGroupList); List statusGroups = statusGroupList.getLoanedObjectStatusGroup(); Assert.assertNotNull(statusGroups); @@ -309,6 +313,15 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { LoanedObjectStatusGroup statusGroup = statusGroups.get(0); Assert.assertNotNull(statusGroup); Assert.assertNotNull(statusGroup.getLoanedObjectStatus()); + + // Check the values of fields containing Unicode UTF-8 (non-Latin-1) characters. + if(logger.isDebugEnabled()){ + logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n" + + "UTF-8 data received=" + loanoutCommon.getLoanOutNote()); + } + Assert.assertEquals(loanoutCommon.getLoanOutNote(), getUTF8DataFragment(), + "UTF-8 data retrieved '" + loanoutCommon.getLoanOutNote() + + "' does not match expected data '" + getUTF8DataFragment()); } // Failure outcomes @@ -328,7 +341,7 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. LoanoutClient client = new LoanoutClient(); - 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 @@ -415,8 +428,7 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { // Retrieve the contents of a resource to update. LoanoutClient client = new LoanoutClient(); - ClientResponse res = - client.read(knownResourceId); + ClientResponse res = client.read(knownResourceId); if(logger.isDebugEnabled()){ logger.debug(testName + ": read status = " + res.getStatus()); } @@ -425,19 +437,20 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { if(logger.isDebugEnabled()){ logger.debug("got object to update with ID: " + knownResourceId); } - MultipartInput input = (MultipartInput) res.getEntity(); - LoansoutCommon loanout = (LoansoutCommon) extractPart(input, - client.getCommonPartName(), LoansoutCommon.class); - Assert.assertNotNull(loanout); - // Update the content of this resource. - loanout.setLoanOutNumber("updated-" + loanout.getLoanOutNumber()); - loanout.setLoanReturnDate("updated-" + loanout.getLoanReturnDate()); - if(logger.isDebugEnabled()){ - logger.debug("to be updated object"); - logger.debug(objectAsXmlString(loanout, LoansoutCommon.class)); + // Extract the common part from the response. + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName()); + LoansoutCommon loanoutCommon = null; + if (payloadInputPart != null) { + loanoutCommon = (LoansoutCommon) payloadInputPart.getBody(); } - LoanedObjectStatusGroupList statusGroupList = loanout.getLoanedObjectStatusGroupList(); + Assert.assertNotNull(loanoutCommon); + + // Update the content of this resource. + loanoutCommon.setLoanOutNumber("updated-" + loanoutCommon.getLoanOutNumber()); + loanoutCommon.setLoanReturnDate("updated-" + loanoutCommon.getLoanReturnDate()); + LoanedObjectStatusGroupList statusGroupList = loanoutCommon.getLoanedObjectStatusGroupList(); Assert.assertNotNull(statusGroupList); List statusGroups = statusGroupList.getLoanedObjectStatusGroup(); Assert.assertNotNull(statusGroups); @@ -448,15 +461,19 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { Assert.assertNotNull(loanedObjectStatus); String updatedLoanedObjectStatus = "updated-" + loanedObjectStatus; statusGroups.get(0).setLoanedObjectStatus(updatedLoanedObjectStatus); - loanout.setLoanedObjectStatusGroupList(statusGroupList); - - // Submit the request to the service and store the response. - MultipartOutput output = new MultipartOutput(); - OutputPart commonPart = output.addPart(loanout, MediaType.APPLICATION_XML_TYPE); - commonPart.getHeaders().add("label", client.getCommonPartName()); + loanoutCommon.setLoanedObjectStatusGroupList(statusGroupList); + if(logger.isDebugEnabled()){ + logger.debug("to be updated object"); + logger.debug(objectAsXmlString(loanoutCommon, LoansoutCommon.class)); + } + // Submit the updated resource in an update request to the service and store the response. + PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent()); + PayloadOutputPart commonPart = output.addPart(loanoutCommon, MediaType.APPLICATION_XML_TYPE); + commonPart.setLabel(client.getCommonPartName()); res = client.update(knownResourceId, output); int statusCode = res.getStatus(); + // Check the status code of the response: does it match the expected response(s)? if(logger.isDebugEnabled()){ logger.debug(testName + ": status = " + statusCode); @@ -465,27 +482,42 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); + // Extract the updated common part from the response. + input = new PoxPayloadIn(res.getEntity()); + payloadInputPart = input.getPart(client.getCommonPartName()); + LoansoutCommon updatedLoanoutCommon = null; + if (payloadInputPart != null) { + updatedLoanoutCommon = (LoansoutCommon) payloadInputPart.getBody(); + } + Assert.assertNotNull(updatedLoanoutCommon); - input = (MultipartInput) res.getEntity(); - LoansoutCommon updatedLoanout = - (LoansoutCommon) extractPart(input, - client.getCommonPartName(), LoansoutCommon.class); - Assert.assertNotNull(updatedLoanout); - - Assert.assertEquals(updatedLoanout.getLoanReturnDate(), - loanout.getLoanReturnDate(), + // Check selected fields in the updated resource. + Assert.assertEquals(updatedLoanoutCommon.getLoanReturnDate(), + loanoutCommon.getLoanReturnDate(), "Data in updated object did not match submitted data."); - statusGroupList = updatedLoanout.getLoanedObjectStatusGroupList(); - Assert.assertNotNull(statusGroupList); - statusGroups = statusGroupList.getLoanedObjectStatusGroup(); - Assert.assertNotNull(statusGroups); - Assert.assertTrue(statusGroups.size() > 0); - Assert.assertNotNull(statusGroups.get(0)); + LoanedObjectStatusGroupList updatedStatusGroupList = + updatedLoanoutCommon.getLoanedObjectStatusGroupList(); + Assert.assertNotNull(updatedStatusGroupList); + List updatedStatusGroups = + updatedStatusGroupList.getLoanedObjectStatusGroup(); + Assert.assertNotNull(updatedStatusGroups); + Assert.assertTrue(updatedStatusGroups.size() > 0); + Assert.assertNotNull(updatedStatusGroups.get(0)); Assert.assertEquals(updatedLoanedObjectStatus, - statusGroups.get(0).getLoanedObjectStatus(), + updatedStatusGroups.get(0).getLoanedObjectStatus(), "Data in updated object did not match submitted data."); + if(logger.isDebugEnabled()){ + logger.debug("UTF-8 data sent=" + loanoutCommon.getLoanOutNote() + "\n" + + "UTF-8 data received=" + updatedLoanoutCommon.getLoanOutNote()); + } + Assert.assertTrue(updatedLoanoutCommon.getLoanOutNote().contains(getUTF8DataFragment()), + "UTF-8 data retrieved '" + updatedLoanoutCommon.getLoanOutNote() + + "' does not contain expected data '" + getUTF8DataFragment()); + Assert.assertEquals(updatedLoanoutCommon.getLoanOutNote(), + loanoutCommon.getLoanOutNote(), + "Data in updated object did not match submitted data."); } // Failure outcomes @@ -622,9 +654,8 @@ public class LoanoutServiceTest 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. LoanoutClient client = new LoanoutClient(); - MultipartOutput multipart = createLoanoutInstance(NON_EXISTENT_ID); - ClientResponse res = - client.update(NON_EXISTENT_ID, multipart); + PoxPayloadOut multipart = createLoanoutInstance(NON_EXISTENT_ID); + ClientResponse res = client.update(NON_EXISTENT_ID, multipart); int statusCode = res.getStatus(); // Check the status code of the response: does it match @@ -736,7 +767,7 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { */ @Override public String getServicePathComponent() { - return SERVICE_PATH_COMPONENT; + return LoanoutClient.SERVICE_PATH_COMPONENT; } /** @@ -745,7 +776,7 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { * @param identifier the identifier * @return the multipart output */ - private MultipartOutput createLoanoutInstance(String identifier) { + private PoxPayloadOut createLoanoutInstance(String identifier) { return createLoanoutInstance( "loanoutNumber-" + identifier, "returnDate-" + identifier); @@ -758,33 +789,42 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { * @param returnDate the return date * @return the multipart output */ - private MultipartOutput createLoanoutInstance(String loanOutNumber, + private PoxPayloadOut createLoanoutInstance(String loanOutNumber, String returnDate) { - LoansoutCommon loanout = new LoansoutCommon(); - loanout.setLoanOutNumber(loanOutNumber); - loanout.setLoanReturnDate(returnDate); - loanout.setBorrower( + LoansoutCommon loanoutCommon = new LoansoutCommon(); + loanoutCommon.setLoanOutNumber(loanOutNumber); + loanoutCommon.setLoanReturnDate(returnDate); + loanoutCommon.setBorrower( "urn:cspace:org.collectionspace.demo:orgauthority:name(TestOrgAuth):organization:name(Northern Climes Museum)'Northern Climes Museum'"); - loanout.setBorrowersContact( + loanoutCommon.setBorrowersContact( "urn:cspace:org.collectionspace.demo:personauthority:name(TestPersonAuth):person:name(Chris Contact)'Chris Contact'"); - loanout.setLoanPurpose("Allow people in cold climes to share the magic of Surfboards of the 1960s."); + loanoutCommon.setLoanPurpose("Allow people in cold climes to share the magic of Surfboards of the 1960s."); LoanedObjectStatusGroupList statusGroupList = new LoanedObjectStatusGroupList(); List statusGroups = statusGroupList.getLoanedObjectStatusGroup(); LoanedObjectStatusGroup statusGroup = new LoanedObjectStatusGroup(); statusGroup.setLoanedObjectStatus("returned"); statusGroup.setLoanedObjectStatusNote("Left under the front mat."); statusGroups.add(statusGroup); - loanout.setLoanedObjectStatusGroupList(statusGroupList); - MultipartOutput multipart = new MultipartOutput(); - OutputPart commonPart = - multipart.addPart(loanout, MediaType.APPLICATION_XML_TYPE); - commonPart.getHeaders().add("label", new LoanoutClient().getCommonPartName()); + loanoutCommon.setLoanedObjectStatusGroupList(statusGroupList); + + loanoutCommon.setLoanOutNote(getUTF8DataFragment()); + + PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent()); + PayloadOutputPart commonPart = + multipart.addPart(loanoutCommon, MediaType.APPLICATION_XML_TYPE); + commonPart.setLabel(new LoanoutClient().getCommonPartName()); if(logger.isDebugEnabled()){ logger.debug("to be created, loanout common"); - logger.debug(objectAsXmlString(loanout, LoansoutCommon.class)); + logger.debug(objectAsXmlString(loanoutCommon, LoansoutCommon.class)); + // logger.debug(multipart.toXML()); } return multipart; } + + @Override + protected String getServiceName() { + return LoanoutClient.SERVICE_NAME; + } } diff --git a/services/loanout/jaxb/.classpath b/services/loanout/jaxb/.classpath index 557f8a4e0..981c9add6 100644 --- a/services/loanout/jaxb/.classpath +++ b/services/loanout/jaxb/.classpath @@ -1,10 +1,31 @@ - - - - - - - + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/services/loanout/jaxb/.project b/services/loanout/jaxb/.project index e2ddd5b9c..b1481b300 100644 --- a/services/loanout/jaxb/.project +++ b/services/loanout/jaxb/.project @@ -1,23 +1,19 @@ - org.collectionspace.services.loanout.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/loanout/jaxb/.settings/org.maven.ide.eclipse.prefs b/services/loanout/jaxb/.settings/org.maven.ide.eclipse.prefs index 279d69a17..a9fa9d627 100644 --- a/services/loanout/jaxb/.settings/org.maven.ide.eclipse.prefs +++ b/services/loanout/jaxb/.settings/org.maven.ide.eclipse.prefs @@ -1,9 +1,9 @@ -#Tue Dec 21 10:07:03 PST 2010 +#Wed Jan 19 22:49:43 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/loanout/service/.classpath b/services/loanout/service/.classpath index 425cd1620..1face034f 100644 --- a/services/loanout/service/.classpath +++ b/services/loanout/service/.classpath @@ -1,10 +1,308 @@ - - - - - - - + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/services/loanout/service/.project b/services/loanout/service/.project index 8a2c1de6c..a74be6f13 100644 --- a/services/loanout/service/.project +++ b/services/loanout/service/.project @@ -1,23 +1,25 @@ - org.collectionspace.services.loanout.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.client + org.collectionspace.services.collectionobject.jaxb + org.collectionspace.services.common + org.collectionspace.services.hyperjaxb + org.collectionspace.services.jaxb + org.collectionspace.services.loanout.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/loanout/service/src/main/java/org/collectionspace/services/loanout/LoanoutResource.java b/services/loanout/service/src/main/java/org/collectionspace/services/loanout/LoanoutResource.java index d7cdcd7b6..5df1fad80 100644 --- a/services/loanout/service/src/main/java/org/collectionspace/services/loanout/LoanoutResource.java +++ b/services/loanout/service/src/main/java/org/collectionspace/services/loanout/LoanoutResource.java @@ -41,6 +41,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.AbstractMultiPartCollectionSpaceResourceImpl; import org.collectionspace.services.common.ClientType; import org.collectionspace.services.common.ServiceMain; @@ -57,8 +59,6 @@ import org.collectionspace.services.common.query.QueryManager; import org.collectionspace.services.common.security.UnauthorizedException; import org.collectionspace.services.nuxeo.client.java.DocumentModelHandler; 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; @@ -68,8 +68,8 @@ import org.slf4j.LoggerFactory; * The Class LoanoutResource. */ @Path("/loansout") -@Consumes("multipart/mixed") -@Produces("multipart/mixed") +@Consumes("application/xml") +@Produces("application/xml") public class LoanoutResource extends AbstractMultiPartCollectionSpaceResourceImpl { @@ -138,9 +138,10 @@ public class LoanoutResource extends * @return the response */ @POST - public Response createLoanout(MultipartInput input) { + public Response createLoanout(String xmlText) { try { - ServiceContext ctx = createServiceContext(input); + PoxPayloadIn input = new PoxPayloadIn(xmlText); + ServiceContext ctx = createServiceContext(input); DocumentHandler handler = createDocumentHandler(ctx); String csid = getRepositoryClient(ctx).create(ctx, handler); //loanoutObject.setCsid(csid); @@ -171,7 +172,7 @@ public class LoanoutResource extends */ @GET @Path("{csid}") - public MultipartOutput getLoanout( + public byte[] getLoanout( @PathParam("csid") String csid) { if (logger.isDebugEnabled()) { logger.debug("getLoanout with csid=" + csid); @@ -183,12 +184,12 @@ public class LoanoutResource extends "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 (UnauthorizedException ue) { Response response = Response.status( Response.Status.UNAUTHORIZED).entity("Get failed reason " + ue.getErrorReason()).type("text/plain").build(); @@ -215,7 +216,7 @@ public class LoanoutResource extends "text/plain").build(); throw new WebApplicationException(response); } - return result; + return result.getBytes(); } /** @@ -249,7 +250,7 @@ public class LoanoutResource extends private LoansoutCommonList getLoanoutList(MultivaluedMap queryParams) { LoansoutCommonList loanoutObjectList; try { - ServiceContext ctx = createServiceContext(queryParams); + ServiceContext ctx = createServiceContext(queryParams); DocumentHandler handler = createDocumentHandler(ctx); getRepositoryClient(ctx).getFiltered(ctx, handler); loanoutObjectList = (LoansoutCommonList) handler.getCommonPartList(); @@ -285,11 +286,11 @@ public class LoanoutResource extends 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); @@ -320,7 +321,7 @@ public class LoanoutResource extends public LoansoutCommonList getLoanoutList(List csidList) { LoansoutCommonList loanoutObjectList = new LoansoutCommonList(); try { - ServiceContext ctx = createServiceContext(); + ServiceContext ctx = createServiceContext(); DocumentHandler handler = createDocumentHandler(ctx); getRepositoryClient(ctx).get(ctx, csidList, handler); loanoutObjectList = (LoansoutCommonList) handler.getCommonPartList(); @@ -349,9 +350,9 @@ public class LoanoutResource extends */ @PUT @Path("{csid}") - public MultipartOutput updateLoanout( + public byte[] updateLoanout( @PathParam("csid") String csid, - MultipartInput theUpdate) { + String xmlText) { if (logger.isDebugEnabled()) { logger.debug("updateLoanout with csid=" + csid); } @@ -362,12 +363,13 @@ public class LoanoutResource extends "text/plain").build(); throw new WebApplicationException(response); } - MultipartOutput result = null; + PoxPayloadOut result = null; try { - ServiceContext ctx = createServiceContext(theUpdate); + PoxPayloadIn update = new PoxPayloadIn(xmlText); + ServiceContext ctx = createServiceContext(update); DocumentHandler handler = createDocumentHandler(ctx); 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(); @@ -385,7 +387,7 @@ public class LoanoutResource extends Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build(); throw new WebApplicationException(response); } - return result; + return result.getBytes(); } /** @@ -410,7 +412,7 @@ public class LoanoutResource 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 (UnauthorizedException ue) { @@ -443,7 +445,7 @@ public class LoanoutResource extends String keywords) { LoansoutCommonList loansoutObjectList; try { - ServiceContext ctx = createServiceContext(queryParams); + ServiceContext ctx = createServiceContext(queryParams); DocumentHandler handler = createDocumentHandler(ctx); // perform a keyword search -- 2.47.3