From 9930b68477f631df7697539e8d7ab65a5ca2e021 Mon Sep 17 00:00:00 2001 From: Richard Millet Date: Wed, 16 Feb 2011 00:19:06 +0000 Subject: [PATCH] CSPACE-3574: Merging Plain Old XML payload work into trunk. --- .../nuxeo-platform-cs-loanin/.classpath | 12 +- .../nuxeo-platform-cs-loanin/.project | 12 +- services/loanin/client/.classpath | 318 +++++++++++++++++- services/loanin/client/.project | 19 +- .../services/client/LoaninClient.java | 43 ++- .../services/client/LoaninProxy.java | 14 +- .../client/test/LoaninAuthRefsTest.java | 68 ++-- .../client/test/LoaninServiceTest.java | 149 +++++--- services/loanin/jaxb/.classpath | 37 +- services/loanin/jaxb/.project | 10 +- .../.settings/org.maven.ide.eclipse.prefs | 8 +- services/loanin/service/.classpath | 314 ++++++++++++++++- services/loanin/service/.project | 15 +- .../services/loanin/LoaninResource.java | 61 ++-- 14 files changed, 871 insertions(+), 209 deletions(-) diff --git a/services/loanin/3rdparty/nuxeo-platform-cs-loanin/.classpath b/services/loanin/3rdparty/nuxeo-platform-cs-loanin/.classpath index 199bbbbdb..6fd3b8551 100644 --- a/services/loanin/3rdparty/nuxeo-platform-cs-loanin/.classpath +++ b/services/loanin/3rdparty/nuxeo-platform-cs-loanin/.classpath @@ -1,8 +1,8 @@ - - - - - + + - + + + + \ No newline at end of file diff --git a/services/loanin/3rdparty/nuxeo-platform-cs-loanin/.project b/services/loanin/3rdparty/nuxeo-platform-cs-loanin/.project index 3f2868873..44081dd0d 100644 --- a/services/loanin/3rdparty/nuxeo-platform-cs-loanin/.project +++ b/services/loanin/3rdparty/nuxeo-platform-cs-loanin/.project @@ -1,23 +1,17 @@ - org.collectionspace.services.loanin.3rdparty.nuxeo - - - + Loanin 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/loanin/client/.classpath b/services/loanin/client/.classpath index 425cd1620..b0fa05352 100644 --- a/services/loanin/client/.classpath +++ b/services/loanin/client/.classpath @@ -1,10 +1,312 @@ - - - - - - - + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/services/loanin/client/.project b/services/loanin/client/.project index 43d3f6975..41d201cbb 100644 --- a/services/loanin/client/.project +++ b/services/loanin/client/.project @@ -1,23 +1,28 @@ - org.collectionspace.services.loanin.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.loanin.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/loanin/client/src/main/java/org/collectionspace/services/client/LoaninClient.java b/services/loanin/client/src/main/java/org/collectionspace/services/client/LoaninClient.java index 428d9a14f..ef2f339ce 100644 --- a/services/loanin/client/src/main/java/org/collectionspace/services/client/LoaninClient.java +++ b/services/loanin/client/src/main/java/org/collectionspace/services/client/LoaninClient.java @@ -27,8 +27,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; /** @@ -40,20 +38,10 @@ import org.jboss.resteasy.spi.ResteasyProviderFactory; */ public class LoaninClient extends AbstractServiceClientImpl { - /* (non-Javadoc) - * @see org.collectionspace.services.client.AbstractServiceClientImpl#getServicePathComponent() - */ - public String getServicePathComponent() { - return "loansin"; - } - /** - * - */ -// private static final LoaninClient instance = new LoaninClient(); - /** - * - */ private LoaninProxy loaninProxy; + public static final String SERVICE_NAME = "loansin"; + public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME; + /** * @@ -65,7 +53,19 @@ public class LoaninClient extends AbstractServiceClientImpl { RegisterBuiltin.register(factory); setProxy(); } - + + /* (non-Javadoc) + * @see org.collectionspace.services.client.AbstractServiceClientImpl#getServicePathComponent() + */ + @Override + public String getServicePathComponent() { + return SERVICE_PATH_COMPONENT; + } + + public String getServiceName() { + return SERVICE_NAME; + } + @Override public CollectionSpaceProxy getProxy() { return this.loaninProxy; @@ -116,7 +116,7 @@ public class LoaninClient extends AbstractServiceClientImpl { * @return * @see org.collectionspace.services.client.LoaninProxy#getLoanin(java.lang.String) */ - public ClientResponse read(String csid) { + public ClientResponse read(String csid) { return loaninProxy.read(csid); } @@ -125,8 +125,8 @@ public class LoaninClient extends AbstractServiceClientImpl { * @return * @see org.collectionspace.services.client.LoaninProxy#createLoanin(org.collectionspace.hello.Loanin) */ - public ClientResponse create(MultipartOutput multipart) { - return loaninProxy.create(multipart); + public ClientResponse create(PoxPayloadOut xmlPayload) { + return loaninProxy.create(xmlPayload.getBytes()); } /** @@ -135,9 +135,8 @@ public class LoaninClient extends AbstractServiceClientImpl { * @return * @see org.collectionspace.services.client.LoaninProxy#updateLoanin(java.lang.Long, org.collectionspace.hello.Loanin) */ - public ClientResponse update(String csid, MultipartOutput multipart) { - return loaninProxy.update(csid, multipart); - + public ClientResponse update(String csid, PoxPayloadOut xmlPayload) { + return loaninProxy.update(csid, xmlPayload.getBytes()); } /** diff --git a/services/loanin/client/src/main/java/org/collectionspace/services/client/LoaninProxy.java b/services/loanin/client/src/main/java/org/collectionspace/services/client/LoaninProxy.java index d3dd1f885..1666703bc 100644 --- a/services/loanin/client/src/main/java/org/collectionspace/services/client/LoaninProxy.java +++ b/services/loanin/client/src/main/java/org/collectionspace/services/client/LoaninProxy.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$ */ @Path("/loansin/") -@Produces({"multipart/mixed"}) -@Consumes({"multipart/mixed"}) +@Produces({"application/xml;charset=UTF-8"}) +@Consumes({"application/xml"}) public interface LoaninProxy 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 @@ -45,12 +43,10 @@ public interface LoaninProxy extends CollectionSpaceProxy { // List @GET - @Produces({"application/xml"}) ClientResponse readList(); // List Authority References @GET - @Produces({"application/xml"}) @Path("/{csid}/authorityrefs/") ClientResponse getAuthorityRefs(@PathParam("csid") String csid); diff --git a/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninAuthRefsTest.java b/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninAuthRefsTest.java index fb2a82bdc..cd761fc1b 100644 --- a/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninAuthRefsTest.java +++ b/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninAuthRefsTest.java @@ -35,19 +35,18 @@ import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.LoaninClient; import org.collectionspace.services.client.PersonAuthorityClient; import org.collectionspace.services.client.PersonAuthorityClientUtils; +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.authorityref.AuthorityRefList; -//import org.collectionspace.services.common.authorityref.AuthorityRefList.AuthorityRefItem; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.loanin.LenderGroup; import org.collectionspace.services.loanin.LenderGroupList; import org.collectionspace.services.loanin.LoansinCommon; -//import org.collectionspace.services.loanin.LoansinCommonList; 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; @@ -68,6 +67,7 @@ public class LoaninAuthRefsTest extends BaseServiceTest { private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); // Instance variables specific to this test. + final String SERVICE_NAME = "loansin"; final String SERVICE_PATH_COMPONENT = "loansin"; final String PERSON_AUTHORITY_NAME = "TestPersonAuth"; private String knownResourceId = null; @@ -123,7 +123,7 @@ public class LoaninAuthRefsTest extends BaseServiceTest { // One or more fields in this resource will be PersonAuthority // references, and will refer to Person resources by their refNames. LoaninClient loaninClient = new LoaninClient(); - MultipartOutput multipart = createLoaninInstance( + PoxPayloadOut multipart = createLoaninInstance( "loanInNumber-" + identifier, "returnDate-" + identifier, lenderRefName, @@ -169,7 +169,7 @@ public class LoaninAuthRefsTest 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(); @@ -215,7 +215,7 @@ public class LoaninAuthRefsTest extends BaseServiceTest { personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); personInfo.put(PersonJAXBSchema.SUR_NAME, surName); personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId); - MultipartOutput multipart = + PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonInstance(personAuthCSID, authRefName, personInfo, personAuthClient.getItemCommonPartName()); ClientResponse res = personAuthClient.createItem(personAuthCSID, multipart); @@ -240,7 +240,7 @@ public class LoaninAuthRefsTest extends BaseServiceTest { // Submit the request to the service and store the response. LoaninClient loaninClient = new LoaninClient(); - ClientResponse res = loaninClient.read(knownResourceId); + ClientResponse res = loaninClient.read(knownResourceId); int statusCode = res.getStatus(); // Check the status code of the response: does it match @@ -252,19 +252,21 @@ public class LoaninAuthRefsTest extends BaseServiceTest { invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - MultipartInput input = (MultipartInput) res.getEntity(); - LoansinCommon loanin = (LoansinCommon) extractPart(input, + // Extract the common part from the response. + PoxPayloadIn input = new PoxPayloadIn(res.getEntity()); + LoansinCommon loaninCommon = (LoansinCommon) extractPart(input, loaninClient.getCommonPartName(), LoansinCommon.class); - Assert.assertNotNull(loanin); + Assert.assertNotNull(loaninCommon); if(logger.isDebugEnabled()){ - logger.debug(objectAsXmlString(loanin, LoansinCommon.class)); + logger.debug(objectAsXmlString(loaninCommon, LoansinCommon.class)); } + // Check a couple of fields -// Assert.assertEquals(loanin.getLender(), lenderRefName); -// Assert.assertEquals(loanin.getLendersAuthorizer(), lendersAuthorizerRefName); -// Assert.assertEquals(loanin.getLendersContact(), lendersContactRefName); - Assert.assertEquals(loanin.getLoanInContact(), loanInContactRefName); - Assert.assertEquals(loanin.getBorrowersAuthorizer(), borrowersAuthorizerRefName); + // Assert.assertEquals(loaninCommon.getLender(), lenderRefName); + // Assert.assertEquals(loaninCommon.getLendersAuthorizer(), lendersAuthorizerRefName); + // Assert.assertEquals(loaninCommon.getLendersContact(), lendersContactRefName); + Assert.assertEquals(loaninCommon.getLoanInContact(), loanInContactRefName); + Assert.assertEquals(loaninCommon.getBorrowersAuthorizer(), borrowersAuthorizerRefName); // Get the auth refs and check them ClientResponse res2 = @@ -362,38 +364,44 @@ public class LoaninAuthRefsTest extends BaseServiceTest { // --------------------------------------------------------------- // Utility methods used by tests above // --------------------------------------------------------------- + public String getServiceName() { + return SERVICE_NAME; + } + @Override public String getServicePathComponent() { return SERVICE_PATH_COMPONENT; } - private MultipartOutput createLoaninInstance(String loaninNumber, + + private PoxPayloadOut createLoaninInstance(String loaninNumber, String returnDate, String lender, String lendersAuthorizer, String lendersContact, String loaninContact, String borrowersAuthorizer) { - LoansinCommon loanin = new LoansinCommon(); - loanin.setLoanInNumber(loaninNumber); - loanin.setLoanInNumber(returnDate); + LoansinCommon loaninCommon = new LoansinCommon(); + loaninCommon.setLoanInNumber(loaninNumber); + loaninCommon.setLoanInNumber(returnDate); LenderGroupList lenderGroupList = new LenderGroupList(); LenderGroup lenderGroup = new LenderGroup(); lenderGroup.setLender(lender); lenderGroup.setLendersAuthorizer(lendersAuthorizer); lenderGroup.setLendersContact(lendersContact); lenderGroupList.getLenderGroup().add(lenderGroup); - loanin.setLenderGroupList(lenderGroupList); - loanin.setLoanInContact(loaninContact); - loanin.setBorrowersAuthorizer(borrowersAuthorizer); - MultipartOutput multipart = new MultipartOutput(); - OutputPart commonPart = - multipart.addPart(loanin, MediaType.APPLICATION_XML_TYPE); - commonPart.getHeaders().add("label", new LoaninClient().getCommonPartName()); + loaninCommon.setLenderGroupList(lenderGroupList); + loaninCommon.setLoanInContact(loaninContact); + loaninCommon.setBorrowersAuthorizer(borrowersAuthorizer); + + PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent()); + PayloadOutputPart commonPart = + multipart.addPart(loaninCommon, MediaType.APPLICATION_XML_TYPE); + commonPart.setLabel(new LoaninClient().getCommonPartName()); if(logger.isDebugEnabled()){ logger.debug("to be created, loanin common"); - logger.debug(objectAsXmlString(loanin, LoansinCommon.class)); + logger.debug(objectAsXmlString(loaninCommon, LoansinCommon.class)); } return multipart; diff --git a/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninServiceTest.java b/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninServiceTest.java index 924617929..0bf6b010a 100644 --- a/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninServiceTest.java +++ b/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninServiceTest.java @@ -29,6 +29,10 @@ import javax.ws.rs.core.Response; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.LoaninClient; +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.loanin.LenderGroup; import org.collectionspace.services.loanin.LenderGroupList; @@ -36,9 +40,6 @@ import org.collectionspace.services.loanin.LoansinCommon; //import org.collectionspace.services.loanin.LoansinCommonList; 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; @@ -61,6 +62,7 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { // Instance variables specific to this test. /** The service path component. */ + final String SERVICE_NAME = "loansin"; final String SERVICE_PATH_COMPONENT = "loansin"; /** The known resource id. */ @@ -108,7 +110,7 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. LoaninClient client = new LoaninClient(); String identifier = createIdentifier(); - MultipartOutput multipart = createLoaninInstance(identifier); + PoxPayloadOut multipart = createLoaninInstance(identifier); String newID = null; ClientResponse res = client.create(multipart); try { @@ -293,9 +295,9 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { setupRead(); // Submit the request to the service and store the response. - MultipartInput input = null; LoaninClient client = new LoaninClient(); - ClientResponse res = client.read(knownResourceId); + ClientResponse res = client.read(knownResourceId); + PoxPayloadIn input = null; try { int statusCode = res.getStatus(); @@ -307,17 +309,21 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - input = res.getEntity(); + input = new PoxPayloadIn(res.getEntity()); } finally { res.releaseConnection(); } - - LoansinCommon loanin = (LoansinCommon) extractPart(input, - client.getCommonPartName(), LoansinCommon.class); - Assert.assertNotNull(loanin); - LenderGroupList lenderGroupList = loanin.getLenderGroupList(); + // Get the common part of the response and verify that it is not null. + PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName()); + LoansinCommon loaninCommon = null; + if (payloadInputPart != null) { + loaninCommon = (LoansinCommon) payloadInputPart.getBody(); + } + Assert.assertNotNull(loaninCommon); + + // Check selected fields. + LenderGroupList lenderGroupList = loaninCommon.getLenderGroupList(); Assert.assertNotNull(lenderGroupList); List lenderGroups = lenderGroupList.getLenderGroup(); Assert.assertNotNull(lenderGroups); @@ -325,6 +331,15 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { String lender = lenderGroups.get(0).getLender(); Assert.assertEquals(lender, LENDER_REF_NAME); + if(logger.isDebugEnabled()){ + logger.debug("UTF-8 data sent=" + getUTF8DataFragment() + "\n" + + "UTF-8 data received=" + loaninCommon.getLoanInNote()); + } + + Assert.assertEquals(loaninCommon.getLoanInNote(), getUTF8DataFragment(), + "UTF-8 data retrieved '" + loaninCommon.getLoanInNote() + + "' does not match expected data '" + getUTF8DataFragment()); + } // Failure outcomes @@ -344,7 +359,7 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. LoaninClient client = new LoaninClient(); - ClientResponse res = client.read(NON_EXISTENT_ID); + ClientResponse res = client.read(NON_EXISTENT_ID); try { int statusCode = res.getStatus(); @@ -435,10 +450,9 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { setupUpdate(); // Retrieve the contents of a resource to update. - MultipartInput input = null; LoaninClient client = new LoaninClient(); - ClientResponse res = - client.read(knownResourceId); + ClientResponse res = client.read(knownResourceId); + PoxPayloadIn input = null; try { if(logger.isDebugEnabled()){ logger.debug(testName + ": read status = " + res.getStatus()); @@ -448,27 +462,33 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { if(logger.isDebugEnabled()){ logger.debug("got object to update with ID: " + knownResourceId); } - input = res.getEntity(); + input = new PoxPayloadIn(res.getEntity()); } finally { res.releaseConnection(); } - - LoansinCommon loanin = (LoansinCommon) extractPart(input, - client.getCommonPartName(), LoansinCommon.class); - Assert.assertNotNull(loanin); + + // Extract the common part from the response. + PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName()); + LoansinCommon loaninCommon = null; + if (payloadInputPart != null) { + loaninCommon = (LoansinCommon) payloadInputPart.getBody(); + } + Assert.assertNotNull(loaninCommon); // Update the content of this resource. - loanin.setLoanInNumber("updated-" + loanin.getLoanInNumber()); - loanin.setLoanReturnDate("updated-" + loanin.getLoanReturnDate()); + loaninCommon.setLoanInNumber("updated-" + loaninCommon.getLoanInNumber()); + loaninCommon.setLoanReturnDate("updated-" + loaninCommon.getLoanReturnDate()); + loaninCommon.setLoanInNote("updated-" + loaninCommon.getLoanInNote()); if(logger.isDebugEnabled()){ logger.debug("to be updated object"); - logger.debug(objectAsXmlString(loanin, LoansinCommon.class)); + logger.debug(objectAsXmlString(loaninCommon, LoansinCommon.class)); } - // Submit the request to the service and store the response. - MultipartOutput output = new MultipartOutput(); - OutputPart commonPart = output.addPart(loanin, MediaType.APPLICATION_XML_TYPE); - commonPart.getHeaders().add("label", client.getCommonPartName()); + // Submit the updated common part in an update request to the service + // and store the response. + PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent()); + PayloadOutputPart commonPart = output.addPart(loaninCommon, MediaType.APPLICATION_XML_TYPE); + commonPart.setLabel(client.getCommonPartName()); res = client.update(knownResourceId, output); try { int statusCode = res.getStatus(); @@ -479,20 +499,33 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - - - input = (MultipartInput) res.getEntity(); + input = new PoxPayloadIn(res.getEntity()); } finally { res.releaseConnection(); } - - LoansinCommon updatedLoanin = - (LoansinCommon) extractPart(input, - client.getCommonPartName(), LoansinCommon.class); - Assert.assertNotNull(updatedLoanin); - Assert.assertEquals(updatedLoanin.getLoanReturnDate(), - loanin.getLoanReturnDate(), + // Extract the updated common part from the response. + payloadInputPart = input.getPart(client.getCommonPartName()); + LoansinCommon updatedLoaninCommon = null; + if (payloadInputPart != null) { + updatedLoaninCommon = (LoansinCommon) payloadInputPart.getBody(); + } + Assert.assertNotNull(updatedLoaninCommon); + + // Check selected fields in the updated common part. + Assert.assertEquals(updatedLoaninCommon.getLoanReturnDate(), + loaninCommon.getLoanReturnDate(), + "Data in updated object did not match submitted data."); + + if(logger.isDebugEnabled()){ + logger.debug("UTF-8 data sent=" + loaninCommon.getLoanInNote() + "\n" + + "UTF-8 data received=" + updatedLoaninCommon.getLoanInNote()); + } + Assert.assertTrue(updatedLoaninCommon.getLoanInNote().contains(getUTF8DataFragment()), + "UTF-8 data retrieved '" + updatedLoaninCommon.getLoanInNote() + + "' does not contain expected data '" + getUTF8DataFragment()); + Assert.assertEquals(updatedLoaninCommon.getLoanInNote(), + loaninCommon.getLoanInNote(), "Data in updated object did not match submitted data."); } @@ -630,9 +663,8 @@ public class LoaninServiceTest 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. LoaninClient client = new LoaninClient(); - MultipartOutput multipart = createLoaninInstance(NON_EXISTENT_ID); - ClientResponse res = - client.update(NON_EXISTENT_ID, multipart); + PoxPayloadOut multipart = createLoaninInstance(NON_EXISTENT_ID); + ClientResponse res = client.update(NON_EXISTENT_ID, multipart); try { int statusCode = res.getStatus(); @@ -751,6 +783,12 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { // --------------------------------------------------------------- // Utility methods used by tests above // --------------------------------------------------------------- + + @Override + public String getServiceName() { + return SERVICE_NAME; + } + /* (non-Javadoc) * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent() */ @@ -765,7 +803,7 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { * @param identifier the identifier * @return the multipart output */ - private MultipartOutput createLoaninInstance(String identifier) { + private PoxPayloadOut createLoaninInstance(String identifier) { return createLoaninInstance( "loaninNumber-" + identifier, "returnDate-" + identifier); @@ -778,25 +816,28 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { * @param returnDate the return date * @return the multipart output */ - private MultipartOutput createLoaninInstance(String loaninNumber, + private PoxPayloadOut createLoaninInstance(String loaninNumber, String returnDate) { - LoansinCommon loanin = new LoansinCommon(); - loanin.setLoanInNumber(loaninNumber); - loanin.setLoanReturnDate(returnDate); + + LoansinCommon loaninCommon = new LoansinCommon(); + loaninCommon.setLoanInNumber(loaninNumber); + loaninCommon.setLoanReturnDate(returnDate); LenderGroupList lenderGroupList = new LenderGroupList(); LenderGroup lenderGroup = new LenderGroup(); lenderGroup.setLender(LENDER_REF_NAME); lenderGroupList.getLenderGroup().add(lenderGroup); - loanin.setLenderGroupList(lenderGroupList); - loanin.setLoanPurpose("For Surfboards of the 1960s exhibition."); - MultipartOutput multipart = new MultipartOutput(); - OutputPart commonPart = - multipart.addPart(loanin, MediaType.APPLICATION_XML_TYPE); - commonPart.getHeaders().add("label", new LoaninClient().getCommonPartName()); + loaninCommon.setLenderGroupList(lenderGroupList); + loaninCommon.setLoanPurpose("For Surfboards of the 1960s exhibition."); + loaninCommon.setLoanInNote(getUTF8DataFragment()); + + PoxPayloadOut multipart = new PoxPayloadOut(this.getServicePathComponent()); + PayloadOutputPart commonPart = + multipart.addPart(loaninCommon, MediaType.APPLICATION_XML_TYPE); + commonPart.setLabel(new LoaninClient().getCommonPartName()); if(logger.isDebugEnabled()){ logger.debug("to be created, loanin common"); - logger.debug(objectAsXmlString(loanin, LoansinCommon.class)); + logger.debug(objectAsXmlString(loaninCommon, LoansinCommon.class)); } return multipart; diff --git a/services/loanin/jaxb/.classpath b/services/loanin/jaxb/.classpath index 557f8a4e0..981c9add6 100644 --- a/services/loanin/jaxb/.classpath +++ b/services/loanin/jaxb/.classpath @@ -1,10 +1,31 @@ - - - - - - - + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/services/loanin/jaxb/.project b/services/loanin/jaxb/.project index c84000cb7..c0de55cb6 100644 --- a/services/loanin/jaxb/.project +++ b/services/loanin/jaxb/.project @@ -1,23 +1,19 @@ - org.collectionspace.services.loanin.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/loanin/jaxb/.settings/org.maven.ide.eclipse.prefs b/services/loanin/jaxb/.settings/org.maven.ide.eclipse.prefs index 537dcc954..a9fa9d627 100644 --- a/services/loanin/jaxb/.settings/org.maven.ide.eclipse.prefs +++ b/services/loanin/jaxb/.settings/org.maven.ide.eclipse.prefs @@ -1,9 +1,9 @@ -#Tue Dec 21 09:56:51 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/loanin/service/.classpath b/services/loanin/service/.classpath index 425cd1620..2a71f1ccb 100644 --- a/services/loanin/service/.classpath +++ b/services/loanin/service/.classpath @@ -1,10 +1,308 @@ - - - - - - - + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/services/loanin/service/.project b/services/loanin/service/.project index b98ef5a43..b15c93b70 100644 --- a/services/loanin/service/.project +++ b/services/loanin/service/.project @@ -1,26 +1,25 @@ - org.collectionspace.services.loanin.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.loanin.jaxb + org.collectionspace.services.hyperjaxb org.collectionspace.services.jaxb + org.collectionspace.services.loanin.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/loanin/service/src/main/java/org/collectionspace/services/loanin/LoaninResource.java b/services/loanin/service/src/main/java/org/collectionspace/services/loanin/LoaninResource.java index 590539012..29468a7d2 100644 --- a/services/loanin/service/src/main/java/org/collectionspace/services/loanin/LoaninResource.java +++ b/services/loanin/service/src/main/java/org/collectionspace/services/loanin/LoaninResource.java @@ -42,6 +42,8 @@ import javax.ws.rs.core.UriBuilder; import javax.ws.rs.core.UriInfo; import javax.xml.parsers.ParserConfigurationException; +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; @@ -63,8 +65,6 @@ import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.nuxeo.client.java.CommonList; 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; @@ -74,13 +74,13 @@ import org.slf4j.LoggerFactory; * The Class LoaninResource. */ @Path("/loansin") -@Consumes("multipart/mixed") -@Produces("multipart/mixed") +@Consumes("application/xml") +@Produces("application/xml") public class LoaninResource extends AbstractMultiPartCollectionSpaceResourceImpl { - /** The Constant serviceName. */ - private final static String serviceName = "loansin"; + /** The Constant SERVICE_NAME. */ + private final static String SERVICE_NAME = "loansin"; /** The logger. */ final Logger logger = LoggerFactory.getLogger(LoaninResource.class); @@ -110,7 +110,7 @@ public class LoaninResource extends */ @Override public String getServiceName() { - return serviceName; + return SERVICE_NAME; } /* (non-Javadoc) @@ -144,9 +144,10 @@ public class LoaninResource extends * @return the response */ @POST - public Response createLoanin(MultipartInput input) { + public Response createLoanin(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); //loaninObject.setCsid(csid); @@ -177,7 +178,7 @@ public class LoaninResource extends */ @GET @Path("{csid}") - public MultipartOutput getLoanin( + public byte[] getLoanin( @PathParam("csid") String csid) { if (logger.isDebugEnabled()) { logger.debug("getLoanin with csid=" + csid); @@ -189,12 +190,12 @@ public class LoaninResource 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(); @@ -221,7 +222,7 @@ public class LoaninResource extends "text/plain").build(); throw new WebApplicationException(response); } - return result; + return result.getBytes(); } /** @@ -233,7 +234,7 @@ public class LoaninResource extends * @return the loanin list */ @GET - @Produces("application/xml") + @Produces({"application/xml"}) public AbstractCommonList getLoaninList(@Context UriInfo ui, @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords) { AbstractCommonList result = null; @@ -255,7 +256,7 @@ public class LoaninResource extends private CommonList getLoaninList(MultivaluedMap queryParams) { CommonList loaninObjectList; try { - ServiceContext ctx = createServiceContext(queryParams); + ServiceContext ctx = createServiceContext(queryParams); DocumentHandler handler = createDocumentHandler(ctx); getRepositoryClient(ctx).getFiltered(ctx, handler); loaninObjectList = (CommonList) handler.getCommonPartList(); @@ -284,18 +285,17 @@ public class LoaninResource extends */ @GET @Path("{csid}/authorityrefs") - @Produces("application/xml") public AuthorityRefList getAuthorityRefs( @PathParam("csid") String csid, @Context UriInfo ui) { 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); @@ -322,12 +322,14 @@ public class LoaninResource extends * * @return the loanin list */ + @Produces({"application/xml"}) @Deprecated public CommonList getLoaninList(List csidList) { CommonList loaninObjectList; try { + ServiceContext ctx = createServiceContext(); loaninObjectList = new CommonList(); - ServiceContext ctx = createServiceContext(); +// ServiceContext ctx = createServiceContext(); DocumentHandler handler = createDocumentHandler(ctx); getRepositoryClient(ctx).get(ctx, csidList, handler); loaninObjectList = (CommonList) handler.getCommonPartList(); @@ -356,9 +358,9 @@ public class LoaninResource extends */ @PUT @Path("{csid}") - public MultipartOutput updateLoanin( + public byte[] updateLoanin( @PathParam("csid") String csid, - MultipartInput theUpdate) { + String xmlText) { if (logger.isDebugEnabled()) { logger.debug("updateLoanin with csid=" + csid); } @@ -369,12 +371,13 @@ public class LoaninResource 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(); @@ -392,7 +395,7 @@ public class LoaninResource extends Response.Status.INTERNAL_SERVER_ERROR).entity("Update failed").type("text/plain").build(); throw new WebApplicationException(response); } - return result; + return result.getBytes(); } /** @@ -417,7 +420,7 @@ public class LoaninResource 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) { @@ -451,7 +454,7 @@ public class LoaninResource extends String keywords) { CommonList loansinObjectList; try { - ServiceContext ctx = createServiceContext(queryParams); + ServiceContext ctx = createServiceContext(queryParams); DocumentHandler handler = createDocumentHandler(ctx); // perform a keyword search -- 2.47.3