From 1b417e2d9b088765f439bd21bf35c31e296f2a6b Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Sat, 23 Jul 2011 00:10:15 +0000 Subject: [PATCH] CSPACE-4172,CSPACE-3332: Updated the CollectionObject service to return the CommonList format for list results. --- .../test/PerformanceTest.java | 657 +++++++++--------- .../client/CollectionObjectClient.java | 76 +- .../client/CollectionObjectProxy.java | 38 +- .../test/CollectionObjectSearchTest.java | 181 +++-- .../test/CollectionObjectServiceTest.java | 32 +- .../resources/collectionobjects_common.xsd | 39 -- .../CollectionObjectResource.java | 5 +- .../CollectionObjectDocumentModelHandler.java | 169 +---- .../tenants/tenant-bindings-proto.xml | 25 + 9 files changed, 496 insertions(+), 726 deletions(-) diff --git a/services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/PerformanceTest.java b/services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/PerformanceTest.java index 100ba5263..4054a0cab 100644 --- a/services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/PerformanceTest.java +++ b/services/PerformanceTests/src/test/java/org/collectionspace/services/PerformanceTests/test/PerformanceTest.java @@ -36,18 +36,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.jboss.resteasy.client.ClientResponse; -import org.jboss.resteasy.plugins.providers.multipart.MultipartOutput; -import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; -import org.jboss.resteasy.plugins.providers.multipart.OutputPart; import org.jboss.resteasy.util.HttpResponseCodes; -import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.client.CollectionObjectClient; import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.collectionobject.CollectionobjectsCommon; -import org.collectionspace.services.collectionobject.CollectionobjectsCommonList; -import org.collectionspace.services.collectionobject.CollectionobjectsCommonList.CollectionObjectListItem; +import org.collectionspace.services.common.AbstractCommonListUtils; +import org.collectionspace.services.jaxb.AbstractCommonList; /** * A ServiceTest. @@ -56,330 +52,329 @@ import org.collectionspace.services.collectionobject.CollectionobjectsCommonList */ public class PerformanceTest extends CollectionSpacePerformanceTest { - /** The Constant MAX_KEYWORDS. */ - private static final int MAX_KEYWORDS = 10; - - /** The Constant MAX_SEARCHES. */ - private static final int MAX_SEARCHES = 10; - - /** The logger. */ - final Logger logger = LoggerFactory - .getLogger(PerformanceTest.class); - // - // Get clients for the CollectionSpace services - // - /** The MA x_ records. */ - private static int MAX_RECORDS = 100; - - /** - * Performance test. - */ - @Test - public void performanceTest() { - roundTripOverhead(10); - deleteCollectionObjects(); - String[] coList = this.createCollectionObjects(MAX_RECORDS); - this.searchCollectionObjects(MAX_RECORDS); - this.readCollectionObjects(coList); - //this.deleteCollectionObjects(coList); - roundTripOverhead(10); - } - - /** - * Round trip overhead. - * - * @param numOfCalls the num of calls - * @return the long - */ - private long roundTripOverhead(int numOfCalls) { - long result = 0; - CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); - - long totalTime = 0; - ClientResponse response; - for (int i = 0; i < numOfCalls; i++) { - Date startTime = new Date(); - response = collectionObjectClient.roundtrip(0); - try { - Assert.assertEquals(response.getStatus(), HttpResponseCodes.SC_OK); - } finally { - response.releaseConnection(); - } - Date stopTime = new Date(); - totalTime = totalTime + (stopTime.getTime() - startTime.getTime()); - System.out.println("Overhead roundtrip time is: " + (stopTime.getTime() - startTime.getTime())); - } - - System.out.println("------------------------------------------------------------------------------"); - System.out.println("Client to server roundtrip overhead: " + (float)(totalTime / numOfCalls) / 1000); - System.out.println("------------------------------------------------------------------------------"); - System.out.println(""); - - return result; - } - - /** - * Search collection objects. - * - * @param numberOfObjects the number of objects - */ - private void searchCollectionObjects(int numberOfObjects) { - CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); - Random randomGenerator = new Random(System.currentTimeMillis()); - ClientResponse searchResults; - - long totalTime = 0; - long totalSearchResults = 0; - String keywords = ""; - String times = ""; - for (int numOfKeywords = 0; numOfKeywords < MAX_KEYWORDS; - numOfKeywords++, totalTime = 0, totalSearchResults = 0, times = "") { - keywords = keywords + " " + OBJECT_TITLE + randomGenerator.nextInt(numberOfObjects); - for (int i = 0; i < MAX_SEARCHES; i++) { - //sandwich the call with timestamps - Date startTime = new Date(); - searchResults = collectionObjectClient.keywordSearch(keywords); - Date stopTime = new Date(); - - //extract the result list and release the ClientResponse - CollectionobjectsCommonList coListItem = null; - try { - coListItem = searchResults.getEntity(); - } finally { - searchResults.releaseConnection(); - } - - long time = stopTime.getTime() - startTime.getTime(); - times = times + " " + ((float)time / 1000); - totalTime = totalTime + time; - totalSearchResults = totalSearchResults + - coListItem.getCollectionObjectListItem().size(); - } - if (logger.isDebugEnabled()) { - System.out.println("------------------------------------------------------------------------------"); - System.out.println("Searched Objects: " + numberOfObjects); - System.out.println("Number of keywords: " + numOfKeywords); - System.out.println("List of keywords: " + keywords); - System.out.println("Number of results: " + totalSearchResults / MAX_SEARCHES); - System.out.println("Result times: " + times); - System.out.println("Average Retreive time: " + (totalTime / MAX_SEARCHES) / 1000.0 + " seconds."); - System.out.println("------------------------------------------------------------------------------"); - } - } - return; - } - - /** - * Creates the collection object. - * - * @param collectionObjectClient the collection object client - * @param identifier the identifier - * @return the string - */ - private String createCollectionObject(CollectionObjectClient collectionObjectClient, - PoxPayloadOut multipart) { - String result = null; - // Make the create call and check the response - ClientResponse response = collectionObjectClient.create(multipart); - try { - int responseStatus = response.getStatus(); - if (logger.isDebugEnabled() == true) { - if (responseStatus != Response.Status.CREATED.getStatusCode()) - logger.debug("Status of call to create CollectionObject was: " + - responseStatus); - } - - Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); - result = extractId(response); - } finally { - response.releaseConnection(); - } - - return result; - } - - /** - * Creates the collection objects. - * - * @param numberOfObjects the number of objects - * @return the string[] - */ - public String[] createCollectionObjects(int numberOfObjects) { - Random randomGenerator = new Random(System.currentTimeMillis()); - CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); - String[] coList = new String[numberOfObjects]; - - // - // First create a CollectionObject - // - CollectionobjectsCommon co = new CollectionobjectsCommon(); - fillCollectionObject(co, Long.toString(System.currentTimeMillis())); - - // Next, create a part object - PoxPayloadOut multipart = new PoxPayloadOut(CollectionObjectClient.SERVICE_PAYLOAD_NAME); - PayloadOutputPart commonPart = multipart.addPart(co, MediaType.APPLICATION_XML_TYPE); - commonPart.setLabel(collectionObjectClient.getCommonPartName()); - - int createdObjects = 0; - try { - Date startTime = new Date(); - for (int i = 0; i < numberOfObjects; i++, createdObjects++) { - coList[i] = createCollectionObject(collectionObjectClient, multipart); - if (logger.isDebugEnabled() == true) { - // - // Print out a status every 10 operations - if (i % 10 == 0) - logger.debug("Created CollectionObject #: " + i); - } - } - Date stopTime = new Date(); - if (logger.isDebugEnabled()) { - System.out.println("Created " + numberOfObjects + " CollectionObjects" + - " in " + (stopTime.getTime() - startTime.getTime())/1000.0 + " seconds."); - } - } catch (AssertionError e) { - System.out.println("FAILURE: Created " + createdObjects + " of " + numberOfObjects + - " before failing."); - Assert.assertTrue(false); - } - - return coList; - } - // - // - // - - /** - * Delete collection object. - * - * @param collectionObjectClient the collection object client - * @param resourceId the resource id - */ - private void readCollectionObject(CollectionObjectClient collectionObjectClient, - String resourceId) { - ClientResponse res = collectionObjectClient.read(resourceId); - res.releaseConnection(); - } - - /** - * Delete collection objects. - * - * @param arrayOfObjects the array of objects - */ - public void readCollectionObjects(String[] arrayOfObjects) { - CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); - - Date startTime = new Date(); - for (int i = 0; i < arrayOfObjects.length; i++) { - readCollectionObject(collectionObjectClient, arrayOfObjects[i]); - } - Date stopTime = new Date(); - - if (logger.isDebugEnabled()) { - System.out.println("Read " + arrayOfObjects.length + " CollectionObjects" + - " in " + (stopTime.getTime() - startTime.getTime())/1000.0 + " seconds."); - } - } - - /** - * Delete collection objects. - * FIXME: Deletes a page at a time until there are no more CollectionObjects. - */ - public void readCollectionObjects() { - CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); - ClientResponse response; - - List coListItems = null; - do { - response = collectionObjectClient.readList(new Long(MAX_RECORDS), - new Long(0)); - try { - CollectionobjectsCommonList commonListElement = - (CollectionobjectsCommonList)response.getEntity(CollectionobjectsCommonList.class); - coListItems = commonListElement.getCollectionObjectListItem(); - } finally { - response.releaseConnection(); - } - - Date startTime = new Date(); - for (CollectionObjectListItem i:coListItems) { - readCollectionObject(collectionObjectClient, i.getCsid()); - } - Date stopTime = new Date(); - - if (logger.isDebugEnabled()) { - System.out.println("Read " + coListItems.size() + " CollectionObjects" + - " in " + (stopTime.getTime() - startTime.getTime())/1000.0 + " seconds."); - } - } while (coListItems.size() > 0); - } - - // - // - // - /** - * Delete collection object. - * - * @param collectionObjectClient the collection object client - * @param resourceId the resource id - */ - private void deleteCollectionObject(CollectionObjectClient collectionObjectClient, - String resourceId) { - ClientResponse res = collectionObjectClient.delete(resourceId); - res.releaseConnection(); - } - - /** - * Delete collection objects. - * - * @param arrayOfObjects the array of objects - */ - private void deleteCollectionObjects(String[] arrayOfObjects) { - CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); - - Date startTime = new Date(); - for (int i = 0; i < arrayOfObjects.length; i++) { - deleteCollectionObject(collectionObjectClient, arrayOfObjects[i]); - } - Date stopTime = new Date(); - - if (logger.isDebugEnabled()) { - System.out.println("Deleted " + arrayOfObjects.length + " CollectionObjects" + - " in " + (stopTime.getTime() - startTime.getTime())/1000.0 + " seconds."); - } - } - - /** - * Delete collection objects. - * FIXME: Deletes a page at a time until there are no more CollectionObjects. - */ - private void deleteCollectionObjects() { - CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); - ClientResponse response; - - List coListItems = null; - do { - response = collectionObjectClient.readList(new Long(MAX_RECORDS), - new Long(0)); - try { - CollectionobjectsCommonList commonListElement = - (CollectionobjectsCommonList)response.getEntity(CollectionobjectsCommonList.class); - coListItems = commonListElement.getCollectionObjectListItem(); - } finally { - response.releaseConnection(); - } - - Date startTime = new Date(); - for (CollectionObjectListItem i:coListItems) { - deleteCollectionObject(collectionObjectClient, i.getCsid()); - } - Date stopTime = new Date(); - - if (logger.isDebugEnabled()) { - System.out.println("Deleted " + coListItems.size() + " CollectionObjects" + - " in " + (stopTime.getTime() - startTime.getTime())/1000.0 + " seconds."); - } - } while (coListItems.size() > 0); - } + /** The Constant MAX_KEYWORDS. */ + private static final int MAX_KEYWORDS = 10; + /** The Constant MAX_SEARCHES. */ + private static final int MAX_SEARCHES = 10; + /** The logger. */ + final Logger logger = LoggerFactory.getLogger(PerformanceTest.class); + // + // Get clients for the CollectionSpace services + // + /** The MA x_ records. */ + private static int MAX_RECORDS = 100; + + /** + * Performance test. + */ + @Test + public void performanceTest() { + roundTripOverhead(10); + deleteCollectionObjects(); + String[] coList = this.createCollectionObjects(MAX_RECORDS); + this.searchCollectionObjects(MAX_RECORDS); + this.readCollectionObjects(coList); + //this.deleteCollectionObjects(coList); + roundTripOverhead(10); + } + + /** + * Round trip overhead. + * + * @param numOfCalls the num of calls + * @return the long + */ + private long roundTripOverhead(int numOfCalls) { + long result = 0; + CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); + + long totalTime = 0; + ClientResponse response; + for (int i = 0; i < numOfCalls; i++) { + Date startTime = new Date(); + response = collectionObjectClient.roundtrip(0); + try { + Assert.assertEquals(response.getStatus(), HttpResponseCodes.SC_OK); + } finally { + response.releaseConnection(); + } + Date stopTime = new Date(); + totalTime = totalTime + (stopTime.getTime() - startTime.getTime()); + System.out.println("Overhead roundtrip time is: " + (stopTime.getTime() - startTime.getTime())); + } + + System.out.println("------------------------------------------------------------------------------"); + System.out.println("Client to server roundtrip overhead: " + (float) (totalTime / numOfCalls) / 1000); + System.out.println("------------------------------------------------------------------------------"); + System.out.println(""); + + return result; + } + + /** + * Search collection objects. + * + * @param numberOfObjects the number of objects + */ + private void searchCollectionObjects(int numberOfObjects) { + CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); + Random randomGenerator = new Random(System.currentTimeMillis()); + ClientResponse searchResults; + + long totalTime = 0; + long totalSearchResults = 0; + String keywords = ""; + String times = ""; + final boolean NOT_INCLUDING_DELETED_RESOURCES = false; + for (int numOfKeywords = 0; numOfKeywords < MAX_KEYWORDS; + numOfKeywords++, totalTime = 0, totalSearchResults = 0, times = "") { + keywords = keywords + " " + OBJECT_TITLE + randomGenerator.nextInt(numberOfObjects); + for (int i = 0; i < MAX_SEARCHES; i++) { + //sandwich the call with timestamps + Date startTime = new Date(); + searchResults = collectionObjectClient.keywordSearchIncludeDeleted(keywords, NOT_INCLUDING_DELETED_RESOURCES); + Date stopTime = new Date(); + + //extract the result list and release the ClientResponse + AbstractCommonList coListItem = null; + try { + coListItem = searchResults.getEntity(); + } finally { + searchResults.releaseConnection(); + } + + long time = stopTime.getTime() - startTime.getTime(); + times = times + " " + ((float) time / 1000); + totalTime = totalTime + time; + totalSearchResults = totalSearchResults + + coListItem.getListItem().size(); + } + if (logger.isDebugEnabled()) { + System.out.println("------------------------------------------------------------------------------"); + System.out.println("Searched Objects: " + numberOfObjects); + System.out.println("Number of keywords: " + numOfKeywords); + System.out.println("List of keywords: " + keywords); + System.out.println("Number of results: " + totalSearchResults / MAX_SEARCHES); + System.out.println("Result times: " + times); + System.out.println("Average Retreive time: " + (totalTime / MAX_SEARCHES) / 1000.0 + " seconds."); + System.out.println("------------------------------------------------------------------------------"); + } + } + return; + } + + /** + * Creates the collection object. + * + * @param collectionObjectClient the collection object client + * @param identifier the identifier + * @return the string + */ + private String createCollectionObject(CollectionObjectClient collectionObjectClient, + PoxPayloadOut multipart) { + String result = null; + // Make the create call and check the response + ClientResponse response = collectionObjectClient.create(multipart); + try { + int responseStatus = response.getStatus(); + if (logger.isDebugEnabled() == true) { + if (responseStatus != Response.Status.CREATED.getStatusCode()) { + logger.debug("Status of call to create CollectionObject was: " + + responseStatus); + } + } + + Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode()); + result = extractId(response); + } finally { + response.releaseConnection(); + } + + return result; + } + + /** + * Creates the collection objects. + * + * @param numberOfObjects the number of objects + * @return the string[] + */ + public String[] createCollectionObjects(int numberOfObjects) { + Random randomGenerator = new Random(System.currentTimeMillis()); + CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); + String[] coList = new String[numberOfObjects]; + + // + // First create a CollectionObject + // + CollectionobjectsCommon co = new CollectionobjectsCommon(); + fillCollectionObject(co, Long.toString(System.currentTimeMillis())); + + // Next, create a part object + PoxPayloadOut multipart = new PoxPayloadOut(CollectionObjectClient.SERVICE_PAYLOAD_NAME); + PayloadOutputPart commonPart = multipart.addPart(co, MediaType.APPLICATION_XML_TYPE); + commonPart.setLabel(collectionObjectClient.getCommonPartName()); + + int createdObjects = 0; + try { + Date startTime = new Date(); + for (int i = 0; i < numberOfObjects; i++, createdObjects++) { + coList[i] = createCollectionObject(collectionObjectClient, multipart); + if (logger.isDebugEnabled() == true) { + // + // Print out a status every 10 operations + if (i % 10 == 0) { + logger.debug("Created CollectionObject #: " + i); + } + } + } + Date stopTime = new Date(); + if (logger.isDebugEnabled()) { + System.out.println("Created " + numberOfObjects + " CollectionObjects" + + " in " + (stopTime.getTime() - startTime.getTime()) / 1000.0 + " seconds."); + } + } catch (AssertionError e) { + System.out.println("FAILURE: Created " + createdObjects + " of " + numberOfObjects + + " before failing."); + Assert.assertTrue(false); + } + + return coList; + } + // + // + // + + /** + * Delete collection object. + * + * @param collectionObjectClient the collection object client + * @param resourceId the resource id + */ + private void readCollectionObject(CollectionObjectClient collectionObjectClient, + String resourceId) { + ClientResponse res = collectionObjectClient.read(resourceId); + res.releaseConnection(); + } + + /** + * Delete collection objects. + * + * @param arrayOfObjects the array of objects + */ + public void readCollectionObjects(String[] arrayOfObjects) { + CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); + + Date startTime = new Date(); + for (int i = 0; i < arrayOfObjects.length; i++) { + readCollectionObject(collectionObjectClient, arrayOfObjects[i]); + } + Date stopTime = new Date(); + + if (logger.isDebugEnabled()) { + System.out.println("Read " + arrayOfObjects.length + " CollectionObjects" + + " in " + (stopTime.getTime() - startTime.getTime()) / 1000.0 + " seconds."); + } + } + + /** + * Delete collection objects. + * FIXME: Deletes a page at a time until there are no more CollectionObjects. + */ + public void readCollectionObjects() { + CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); + ClientResponse response; + + List coListItems = null; + do { + response = collectionObjectClient.readList(new Long(MAX_RECORDS), + new Long(0)); + try { + AbstractCommonList commonListElement = + (AbstractCommonList) response.getEntity(AbstractCommonList.class); + coListItems = commonListElement.getListItem(); + } finally { + response.releaseConnection(); + } + + Date startTime = new Date(); + for (AbstractCommonList.ListItem i : coListItems) { + readCollectionObject(collectionObjectClient, AbstractCommonListUtils.ListItemGetElementValue(i, "csid")); + } + Date stopTime = new Date(); + + if (logger.isDebugEnabled()) { + System.out.println("Read " + coListItems.size() + " CollectionObjects" + + " in " + (stopTime.getTime() - startTime.getTime()) / 1000.0 + " seconds."); + } + } while (coListItems.size() > 0); + } + + // + // + // + /** + * Delete collection object. + * + * @param collectionObjectClient the collection object client + * @param resourceId the resource id + */ + private void deleteCollectionObject(CollectionObjectClient collectionObjectClient, + String resourceId) { + ClientResponse res = collectionObjectClient.delete(resourceId); + res.releaseConnection(); + } + + /** + * Delete collection objects. + * + * @param arrayOfObjects the array of objects + */ + private void deleteCollectionObjects(String[] arrayOfObjects) { + CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); + + Date startTime = new Date(); + for (int i = 0; i < arrayOfObjects.length; i++) { + deleteCollectionObject(collectionObjectClient, arrayOfObjects[i]); + } + Date stopTime = new Date(); + + if (logger.isDebugEnabled()) { + System.out.println("Deleted " + arrayOfObjects.length + " CollectionObjects" + + " in " + (stopTime.getTime() - startTime.getTime()) / 1000.0 + " seconds."); + } + } + + /** + * Delete collection objects. + * FIXME: Deletes a page at a time until there are no more CollectionObjects. + */ + private void deleteCollectionObjects() { + CollectionObjectClient collectionObjectClient = new CollectionObjectClient(); + ClientResponse response; + + List coListItems = null; + do { + response = collectionObjectClient.readList(new Long(MAX_RECORDS), + new Long(0)); + try { + AbstractCommonList commonListElement = + (AbstractCommonList) response.getEntity(AbstractCommonList.class); + coListItems = commonListElement.getListItem(); + } finally { + response.releaseConnection(); + } + + Date startTime = new Date(); + for (AbstractCommonList.ListItem i : coListItems) { + deleteCollectionObject(collectionObjectClient, AbstractCommonListUtils.ListItemGetElementValue(i, "csid")); + } + Date stopTime = new Date(); + if (logger.isDebugEnabled()) { + System.out.println("Deleted " + coListItems.size() + " CollectionObjects" + + " in " + (stopTime.getTime() - startTime.getTime()) / 1000.0 + " seconds."); + } + } while (coListItems.size() > 0); + } } diff --git a/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectClient.java b/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectClient.java index 0f3ffdc26..7732c62b9 100644 --- a/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectClient.java +++ b/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectClient.java @@ -28,51 +28,40 @@ package org.collectionspace.services.client; import org.jboss.resteasy.client.ClientResponse; import javax.ws.rs.core.Response; -import org.collectionspace.services.collectionobject.CollectionobjectsCommonList; + +// FIXME: http://issues.collectionspace.org/browse/CSPACE-1684 /** - * The Class CollectionObjectClient. - * FIXME: http://issues.collectionspace.org/browse/CSPACE-1684 + * CollectionObjectClient.java + * + * $LastChangedRevision: $ + * $LastChangedDate: $ */ -public class CollectionObjectClient extends AbstractPoxServiceClientImpl { - public static final String SERVICE_NAME = "collectionobjects"; - 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; - public static final String SERVICE_COMMON_PART_NAME = SERVICE_NAME + PART_LABEL_SEPARATOR + PART_COMMON_LABEL; - - @Override - public String getServiceName() { - return SERVICE_NAME; - } - - @Override - public String getServicePathComponent() { - return SERVICE_PATH_COMPONENT; - } +public class CollectionObjectClient extends AbstractCommonListPoxServiceClientImpl { - @Override - public Class getProxyClass() { - return CollectionObjectProxy.class; - } + public static final String SERVICE_NAME = "collectionobjects"; + 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; + public static final String SERVICE_COMMON_PART_NAME = SERVICE_NAME + PART_LABEL_SEPARATOR + PART_COMMON_LABEL; - /* - * Proxied service calls - */ - - /** - * Read list. - * - * @see org.collectionspace.services.client.CollectionObjectProxy#readList() - * @return the client response< collectionobjects common list> - */ - public ClientResponse readList() { - CollectionObjectProxy proxy = (CollectionObjectProxy)getProxy(); - return proxy.readList(); + @Override + public String getServiceName() { + return SERVICE_NAME; + } + + @Override + public String getServicePathComponent() { + return SERVICE_PATH_COMPONENT; + } + @Override + public Class getProxyClass() { + return CollectionObjectProxy.class; } + /** * Roundtrip. * @@ -83,12 +72,12 @@ public class CollectionObjectClient extends AbstractPoxServiceClientImpl */ public ClientResponse roundtrip(int ms) { - getLogger().debug(">>>>Roundtrip start."); - ClientResponse result = getProxy().roundtrip(ms); - getLogger().debug("<<<>>>Roundtrip start."); + ClientResponse result = getProxy().roundtrip(ms); + getLogger().debug("<<< */ + /* public ClientResponse keywordSearch(String keywords) { return getProxy().keywordSearch(keywords); } + * + */ } diff --git a/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectProxy.java b/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectProxy.java index 517017ed1..76bb3bf4b 100644 --- a/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectProxy.java +++ b/services/collectionobject/client/src/main/java/org/collectionspace/services/client/CollectionObjectProxy.java @@ -26,26 +26,26 @@ */ package org.collectionspace.services.client; -import org.jboss.resteasy.client.ClientResponse; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; -import javax.ws.rs.QueryParam; import javax.ws.rs.Produces; import javax.ws.rs.core.Response; +import org.jboss.resteasy.client.ClientResponse; -import org.collectionspace.services.client.workflow.WorkflowClient; -import org.collectionspace.services.collectionobject.CollectionobjectsCommonList; +// FIXME: http://issues.collectionspace.org/browse/CSPACE-1684 /** - * @version $Revision:$ - * FIXME: http://issues.collectionspace.org/browse/CSPACE-1684 + * CollectionObjectProxy.java + * + * $LastChangedRevision: $ + * $LastChangedDate: $ */ @Path(CollectionObjectClient.SERVICE_PATH_PROXY) @Produces({"application/xml"}) @Consumes({"application/xml"}) -public interface CollectionObjectProxy extends CollectionSpacePoxProxy { +public interface CollectionObjectProxy extends CollectionSpaceCommonListPoxProxy { /** * Roundtrip. @@ -57,21 +57,6 @@ public interface CollectionObjectProxy extends CollectionSpacePoxProxy roundtrip(@PathParam("ms") int ms); - - /** - * Read list. - * - * @return the client response - */ - @GET - @Produces({"application/xml"}) - ClientResponse readList(); - - @Override - @GET - @Produces({"application/xml"}) - ClientResponse readIncludeDeleted( - @QueryParam(WorkflowClient.WORKFLOW_QUERY_NONDELETED) String includeDeleted); /** * Keyword search. @@ -79,16 +64,13 @@ public interface CollectionObjectProxy extends CollectionSpacePoxProxy keywordSearch( @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords); + * + */ - @Override - @GET - @Produces({"application/xml"}) - ClientResponse keywordSearchIncludeDeleted( - @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords, - @QueryParam(WorkflowClient.WORKFLOW_QUERY_NONDELETED) String includeDeleted); } diff --git a/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectSearchTest.java b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectSearchTest.java index 6ef7bdc2d..5fbd377bc 100644 --- a/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectSearchTest.java +++ b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectSearchTest.java @@ -31,9 +31,8 @@ import org.collectionspace.services.client.CollectionObjectClient; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadOut; -import org.collectionspace.services.collectionobject.BriefDescriptionList; import org.collectionspace.services.collectionobject.CollectionobjectsCommon; -import org.collectionspace.services.collectionobject.CollectionobjectsCommonList; +import org.collectionspace.services.common.AbstractCommonListUtils; import org.collectionspace.services.jaxb.AbstractCommonList; import org.jboss.resteasy.client.ClientResponse; import org.slf4j.Logger; @@ -53,23 +52,21 @@ import org.testng.annotations.Test; */ public class CollectionObjectSearchTest extends BaseServiceTest { - @Override - protected String getServiceName() { - throw new UnsupportedOperationException(); //FIXME: REM - See http://issues.collectionspace.org/browse/CSPACE-3498 - } - - @Override - protected String getServicePathComponent() { - // TODO Auto-generated method stub - throw new UnsupportedOperationException(); //FIXME: REM - See http://issues.collectionspace.org/browse/CSPACE-3498 - } - - /** The logger. */ + /** The logger. */ private final String CLASS_NAME = CollectionObjectSearchTest.class.getName(); private final Logger logger = LoggerFactory.getLogger(CLASS_NAME); - final static String IDENTIFIER = getSystemTimeIdentifier(); - + final static String KEYWORD_SEPARATOR = " "; + final long numNoiseWordResources = 10; + final double pctNonNoiseWordResources = 0.5; + // Use this to keep track of resources to delete + private List allResourceIdsCreated = new ArrayList(); + + // Constants for data used in search testing + + // Test keywords unlikely to be encountered in actual collections data, + // consisting of the names of mythical creatures in a 1970s role-playing + // game, which result in very few 'hits' in Google searches. final static String KEYWORD = "Tsolyani" + IDENTIFIER; final static List TWO_KEYWORDS = Arrays.asList(new String[]{"Cheggarra" + IDENTIFIER, "Ahoggya" + IDENTIFIER}); @@ -84,19 +81,22 @@ public class CollectionObjectSearchTest extends BaseServiceTest { // Ж : Cyrillic capital letter Zhe with breve (U+04C1) // Ŵ : Latin capital letter W with circumflex (U+0174) // Ω : Greek capital letter Omega (U+03A9) - - final String UTF8_KEYWORD = "to" + '\u0394' + '\u04C1' + '\u0174' +'\u03A9'; + final String UTF8_KEYWORD = "to" + '\u0394' + '\u04C1' + '\u0174' + '\u03A9'; // Non-existent term unlikely to be encountered in actual collections // data, consisting of two back-to-back sets of the first letters of // each of the words in a short pangram for the English alphabet. - final static String NON_EXISTENT_KEYWORD = "jlmbsoqjlmbsoq"; - - final static String KEYWORD_SEPARATOR = " "; - final long numNoiseWordResources = 10; - final double pctNonNoiseWordResources = 0.5; + final static String NON_EXISTENT_KEYWORD = "jlmbsoqjlmbsoq"; + + @Override + protected String getServiceName() { + throw new UnsupportedOperationException(); //FIXME: REM - See http://issues.collectionspace.org/browse/CSPACE-3498 + } - /* Use this to keep track of resources to delete */ - private List allResourceIdsCreated = new ArrayList(); + @Override + protected String getServicePathComponent() { + // TODO Auto-generated method stub + throw new UnsupportedOperationException(); //FIXME: REM - See http://issues.collectionspace.org/browse/CSPACE-3498 + } // /* (non-Javadoc) // * @see org.collectionspace.services.client.test.BaseServiceTest#getServicePathComponent() @@ -111,7 +111,7 @@ public class CollectionObjectSearchTest extends BaseServiceTest { */ @Override protected CollectionSpaceClient getClientInstance() { - return new CollectionObjectClient(); + return new CollectionObjectClient(); } /* (non-Javadoc) @@ -119,7 +119,7 @@ public class CollectionObjectSearchTest extends BaseServiceTest { */ @Override protected AbstractCommonList getAbstractCommonList(ClientResponse response) { - return response.getEntity(CollectionobjectsCommonList.class); + return response.getEntity(AbstractCommonList.class); } /** @@ -131,24 +131,21 @@ public class CollectionObjectSearchTest extends BaseServiceTest { * number of records containing a particular keyword represent * too high a proportion of the total number of records. */ - @BeforeClass(alwaysRun=true) + @BeforeClass(alwaysRun = true) public void setup() { if (logger.isDebugEnabled()) { - logger.debug("Creating " + numNoiseWordResources + - " 'noise word' resources ..."); + logger.debug("Creating " + numNoiseWordResources + + " 'noise word' resources ..."); } createCollectionObjects(numNoiseWordResources, NOISE_WORD); } - // --------------------------------------------------------------- // Search tests // --------------------------------------------------------------- - // Success outcomes - - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"oneKeyword"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"oneKeyword"}) public void searchWithOneKeyword(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -160,16 +157,16 @@ public class CollectionObjectSearchTest extends BaseServiceTest { long numKeywordRetrievableResources = (long) (numNoiseWordResources * pctNonNoiseWordResources); if (logger.isDebugEnabled()) { - logger.debug("Creating " + numKeywordRetrievableResources + - " keyword-retrievable resources ..."); + logger.debug("Creating " + numKeywordRetrievableResources + + " keyword-retrievable resources ..."); } createCollectionObjects(numKeywordRetrievableResources, KEYWORD); - + // Set the expected status code and group of valid status codes testSetup(STATUS_OK, ServiceRequestType.SEARCH); // Send the search request and receive a response - ClientResponse res = doSearch(KEYWORD); + ClientResponse res = doSearch(KEYWORD); int statusCode = res.getStatus(); // Check the status code of the response: does it match @@ -184,11 +181,11 @@ public class CollectionObjectSearchTest extends BaseServiceTest { // Verify that the number of resources matched by the search // is identical to the expected result long NUM_MATCHES_EXPECTED = numKeywordRetrievableResources; - long numMatched = getNumMatched(res, NUM_MATCHES_EXPECTED); + long numMatched = getNumMatched(res, NUM_MATCHES_EXPECTED, testName); Assert.assertEquals(numMatched, NUM_MATCHES_EXPECTED); } - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void searchWithTwoKeywordsInSameField(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -200,8 +197,8 @@ public class CollectionObjectSearchTest extends BaseServiceTest { long numKeywordRetrievableResources = (long) (numNoiseWordResources * pctNonNoiseWordResources); if (logger.isDebugEnabled()) { - logger.debug("Creating " + numKeywordRetrievableResources + - " keyword-retrievable resources ..."); + logger.debug("Creating " + numKeywordRetrievableResources + + " keyword-retrievable resources ..."); } boolean keywordsInSameField = true; createCollectionObjects(numKeywordRetrievableResources, TWO_KEYWORDS, keywordsInSameField); @@ -212,7 +209,7 @@ public class CollectionObjectSearchTest extends BaseServiceTest { // Search using both terms // Send the search request and receive a response - ClientResponse res = doSearch(TWO_KEYWORDS); + ClientResponse res = doSearch(TWO_KEYWORDS); int statusCode = res.getStatus(); // Check the status code of the response: does it match @@ -227,7 +224,7 @@ public class CollectionObjectSearchTest extends BaseServiceTest { // Verify that the number of resources matched by the search // is identical to the expected result long NUM_MATCHES_EXPECTED = numKeywordRetrievableResources; - long numMatched = getNumMatched(res, NUM_MATCHES_EXPECTED); + long numMatched = getNumMatched(res, NUM_MATCHES_EXPECTED, testName); Assert.assertEquals(numMatched, NUM_MATCHES_EXPECTED); // Search using a single term @@ -248,12 +245,12 @@ public class CollectionObjectSearchTest extends BaseServiceTest { // Verify that the number of resources matched by the search // is identical to the expected result NUM_MATCHES_EXPECTED = numKeywordRetrievableResources; - numMatched = getNumMatched(res, NUM_MATCHES_EXPECTED); + numMatched = getNumMatched(res, NUM_MATCHES_EXPECTED, testName); Assert.assertEquals(numMatched, NUM_MATCHES_EXPECTED); } - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void searchWithTwoKeywordsAcrossTwoFields(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -264,8 +261,8 @@ public class CollectionObjectSearchTest extends BaseServiceTest { // two specified keywords. long numKeywordRetrievableResources = 5; if (logger.isDebugEnabled()) { - logger.debug("Creating " + numKeywordRetrievableResources + - " keyword-retrievable resources ..."); + logger.debug("Creating " + numKeywordRetrievableResources + + " keyword-retrievable resources ..."); } boolean keywordsInSameField = false; createCollectionObjects(numKeywordRetrievableResources, TWO_MORE_KEYWORDS, keywordsInSameField); @@ -276,7 +273,7 @@ public class CollectionObjectSearchTest extends BaseServiceTest { // Search using both terms // Send the search request and receive a response - ClientResponse res = doSearch(TWO_MORE_KEYWORDS); + ClientResponse res = doSearch(TWO_MORE_KEYWORDS); int statusCode = res.getStatus(); // Check the status code of the response: does it match @@ -291,7 +288,7 @@ public class CollectionObjectSearchTest extends BaseServiceTest { // Verify that the number of resources matched by the search // is identical to the expected result long NUM_MATCHES_EXPECTED = numKeywordRetrievableResources; - long numMatched = getNumMatched(res, NUM_MATCHES_EXPECTED); + long numMatched = getNumMatched(res, NUM_MATCHES_EXPECTED, testName); Assert.assertEquals(numMatched, NUM_MATCHES_EXPECTED); // Search using a single term @@ -312,7 +309,7 @@ public class CollectionObjectSearchTest extends BaseServiceTest { // Verify that the number of resources matched by the search // is identical to the expected result NUM_MATCHES_EXPECTED = numKeywordRetrievableResources; - numMatched = getNumMatched(res, NUM_MATCHES_EXPECTED); + numMatched = getNumMatched(res, NUM_MATCHES_EXPECTED, testName); Assert.assertEquals(numMatched, NUM_MATCHES_EXPECTED); } @@ -326,10 +323,8 @@ public class CollectionObjectSearchTest extends BaseServiceTest { // descriptions.add(TWO_KEYWORDS.get(1)); // } // } - - - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class, - groups = {"utf8"}) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class, + groups = {"utf8"}) public void searchWithUTF8Keyword(String testName) { if (logger.isDebugEnabled()) { @@ -340,8 +335,8 @@ public class CollectionObjectSearchTest extends BaseServiceTest { // two specified keywords. long numKeywordRetrievableResources = 2; if (logger.isDebugEnabled()) { - logger.debug("Creating " + numKeywordRetrievableResources + - " keyword-retrievable resources ..."); + logger.debug("Creating " + numKeywordRetrievableResources + + " keyword-retrievable resources ..."); } createCollectionObjects(numKeywordRetrievableResources, UTF8_KEYWORD); @@ -349,7 +344,7 @@ public class CollectionObjectSearchTest extends BaseServiceTest { testSetup(STATUS_OK, ServiceRequestType.SEARCH); // Send the search request and receive a response - ClientResponse res = doSearch(UTF8_KEYWORD); + ClientResponse res = doSearch(UTF8_KEYWORD); int statusCode = res.getStatus(); // Check the status code of the response: does it match @@ -364,14 +359,13 @@ public class CollectionObjectSearchTest extends BaseServiceTest { // Verify that the number of resources matched by the search // is identical to the expected result long NUM_MATCHES_EXPECTED = numKeywordRetrievableResources; - long numMatched = getNumMatched(res, NUM_MATCHES_EXPECTED); + long numMatched = getNumMatched(res, NUM_MATCHES_EXPECTED, testName); Assert.assertEquals(numMatched, NUM_MATCHES_EXPECTED); } - - // Failure outcomes + // Failure outcomes // FIXME: Rename to searchWithNonExistentKeyword - @Test(dataProvider="testName", dataProviderClass=AbstractServiceTestImpl.class) + @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void keywordSearchNonExistentKeyword(String testName) throws Exception { if (logger.isDebugEnabled()) { @@ -382,7 +376,7 @@ public class CollectionObjectSearchTest extends BaseServiceTest { testSetup(STATUS_OK, ServiceRequestType.SEARCH); // Send the search request and receive a response - ClientResponse res = doSearch(NON_EXISTENT_KEYWORD); + ClientResponse res = doSearch(NON_EXISTENT_KEYWORD); int statusCode = res.getStatus(); // Check the status code of the response: does it match @@ -397,7 +391,7 @@ public class CollectionObjectSearchTest extends BaseServiceTest { // Verify that the number of resources matched by the search // is identical to the expected result long NUM_MATCHES_EXPECTED = 0; - long numMatched = getNumMatched(res, NUM_MATCHES_EXPECTED); + long numMatched = getNumMatched(res, NUM_MATCHES_EXPECTED, testName); Assert.assertEquals(numMatched, NUM_MATCHES_EXPECTED); } @@ -405,7 +399,6 @@ public class CollectionObjectSearchTest extends BaseServiceTest { // --------------------------------------------------------------- // Cleanup of resources created during testing // --------------------------------------------------------------- - /** * Deletes all resources created by setup and tests, after all tests have been run. * @@ -414,15 +407,15 @@ public class CollectionObjectSearchTest extends BaseServiceTest { * at any point during testing, even if some of those resources * may be expected to be deleted by certain tests. */ - @AfterClass(alwaysRun=true) + @AfterClass(alwaysRun = true) public void cleanUp() { String noTest = System.getProperty("noTestCleanup"); - if(Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { + if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { if (logger.isDebugEnabled()) { logger.debug("Skipping Cleanup phase ..."); } return; - } + } if (logger.isDebugEnabled()) { logger.debug("Cleaning up temporary resources created for testing ..."); } @@ -436,14 +429,13 @@ public class CollectionObjectSearchTest extends BaseServiceTest { // --------------------------------------------------------------- // Utility methods used by tests above // --------------------------------------------------------------- - private void createCollectionObjects(long numToCreate, String keyword) { List keywords = new ArrayList(); keywords.add(keyword); boolean keywordsInSameField = true; createCollectionObjects(numToCreate, keywords, keywordsInSameField); } - + private void createCollectionObjects(long numToCreate, List keywords, boolean keywordsInSameField) { testSetup(STATUS_CREATED, ServiceRequestType.CREATE); @@ -465,7 +457,7 @@ public class CollectionObjectSearchTest extends BaseServiceTest { } } } - + private PoxPayloadOut createCollectionObjectInstance(long i, List keywords, boolean keywordsInSameField) { CollectionobjectsCommon collectionObject = new CollectionobjectsCommon(); @@ -493,7 +485,7 @@ public class CollectionObjectSearchTest extends BaseServiceTest { StringBuffer sb = new StringBuffer(); if (list.size() > 0) { sb.append(list.get(0)); - for (int i=1; i < list.size(); i++) { + for (int i = 1; i < list.size(); i++) { sb.append(separator); sb.append(list.get(i)); } @@ -501,55 +493,54 @@ public class CollectionObjectSearchTest extends BaseServiceTest { return sb.toString(); } - private ClientResponse doSearch(List keywords) { + private ClientResponse doSearch(List keywords) { String searchParamValue = listToString(keywords, KEYWORD_SEPARATOR); return doSearch(searchParamValue); } - private ClientResponse doSearch(String keyword) { - String searchParamValue = keyword; + private ClientResponse doSearch(String keyword) { + String searchParamValue = keyword; if (logger.isDebugEnabled()) { logger.debug("Searching on keyword(s): " + searchParamValue + " ..."); } CollectionObjectClient client = new CollectionObjectClient(); - ClientResponse res = - client.keywordSearch(searchParamValue); + final boolean NOT_INCLUDING_DELETED_RESOURCES = false; + ClientResponse res = + client.keywordSearchIncludeDeleted(searchParamValue, NOT_INCLUDING_DELETED_RESOURCES); return res; } - private long getNumMatched(ClientResponse res, - long numExpectedMatches) { - CollectionobjectsCommonList list = (CollectionobjectsCommonList) - res.getEntity(CollectionobjectsCommonList.class); + private long getNumMatched(ClientResponse res, + long numExpectedMatches, String testName) { + AbstractCommonList list = (AbstractCommonList) res.getEntity(AbstractCommonList.class); long numMatched = list.getTotalItems(); - if (logger.isDebugEnabled()) { - logger.debug("Keyword search matched " + numMatched + - " resources, expected to match " + numExpectedMatches); + logger.debug("Keyword search matched " + numMatched + + " resources, expected to match " + numExpectedMatches); } // Optionally output additional data about list members for debugging. - boolean iterateThroughList = false; - if (iterateThroughList && logger.isDebugEnabled()) { - itemizeListItems(list); + if(logger.isTraceEnabled()){ + AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); } + return numMatched; } - private void itemizeListItems(CollectionobjectsCommonList list) { - List items = - list.getCollectionObjectListItem(); + private void itemizeListItems(AbstractCommonList list) { + List items = + list.getListItem(); int i = 0; - for (CollectionobjectsCommonList.CollectionObjectListItem item : items) { + for (AbstractCommonList.ListItem item : items) { logger.debug("list-item[" + i + "] title=" - + item.getTitle()); + + AbstractCommonListUtils.ListItemGetElementValue(item, "title")); logger.debug("list-item[" + i + "] URI=" - + item.getUri()); + + AbstractCommonListUtils.ListItemGetElementValue(item, "uri")); i++; } } public static String getSystemTimeIdentifier() { - return Long.toString(System.currentTimeMillis()); + return Long.toString(System.currentTimeMillis()); } } diff --git a/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java index 27ff8075b..79b7fc9b8 100644 --- a/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java +++ b/services/collectionobject/client/src/test/java/org/collectionspace/services/client/test/CollectionObjectServiceTest.java @@ -37,7 +37,6 @@ import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.collectionobject.BriefDescriptionList; import org.collectionspace.services.collectionobject.CollectionobjectsCommon; import org.collectionspace.services.collectionobject.domain.naturalhistory.CollectionobjectsNaturalhistory; -import org.collectionspace.services.collectionobject.CollectionobjectsCommonList; import org.collectionspace.services.collectionobject.ResponsibleDepartmentList; import org.collectionspace.services.collectionobject.DimensionGroup; import org.collectionspace.services.collectionobject.DimensionList; @@ -47,11 +46,10 @@ import org.collectionspace.services.collectionobject.OtherNumber; import org.collectionspace.services.collectionobject.OtherNumberList; import org.collectionspace.services.collectionobject.TitleGroup; import org.collectionspace.services.collectionobject.TitleGroupList; - +import org.collectionspace.services.common.AbstractCommonListUtils; import org.collectionspace.services.jaxb.AbstractCommonList; import org.jboss.resteasy.client.ClientResponse; -import org.jboss.resteasy.plugins.providers.multipart.OutputPart; import org.testng.Assert; import org.testng.annotations.Test; @@ -107,7 +105,7 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { @Override protected AbstractCommonList getAbstractCommonList( ClientResponse response) { - return response.getEntity(CollectionobjectsCommonList.class); + return response.getEntity(AbstractCommonList.class); } // --------------------------------------------------------------- @@ -696,8 +694,8 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. CollectionObjectClient client = new CollectionObjectClient(); - ClientResponse res = client.readList(); - CollectionobjectsCommonList list = res.getEntity(); + ClientResponse res = client.readList(); + AbstractCommonList list = res.getEntity(); int statusCode = res.getStatus(); // Check the status code of the response: does it match @@ -708,25 +706,13 @@ public class CollectionObjectServiceTest extends AbstractServiceTestImpl { Assert.assertTrue(REQUEST_TYPE.isValidStatusCode(statusCode), invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - + // Optionally output additional data about list members for debugging. - boolean iterateThroughList = false; - if (iterateThroughList && logger.isDebugEnabled()) { - List items = - list.getCollectionObjectListItem(); - int i = 0; - - for (CollectionobjectsCommonList.CollectionObjectListItem item : items) { - logger.debug(testName + ": list-item[" + i + "] csid=" - + item.getCsid()); - logger.debug(testName + ": list-item[" + i + "] objectNumber=" - + item.getObjectNumber()); - logger.debug(testName + ": list-item[" + i + "] URI=" - + item.getUri()); - i++; - - } + // the expected response(s)? + if(logger.isTraceEnabled()){ + AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); } + } // Failure outcomes diff --git a/services/collectionobject/jaxb/src/main/resources/collectionobjects_common.xsd b/services/collectionobject/jaxb/src/main/resources/collectionobjects_common.xsd index 82faac2c4..6766e65d6 100644 --- a/services/collectionobject/jaxb/src/main/resources/collectionobjects_common.xsd +++ b/services/collectionobject/jaxb/src/main/resources/collectionobjects_common.xsd @@ -776,45 +776,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java b/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java index 69ff10747..228f34e79 100644 --- a/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java +++ b/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/CollectionObjectResource.java @@ -108,6 +108,7 @@ public class CollectionObjectResource extends ResourceBase { * * @return the collectionobjects common list */ + /* @GET @Path("/search") @Produces("application/xml") @@ -116,6 +117,8 @@ public class CollectionObjectResource extends ResourceBase { @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS) String keywords) { MultivaluedMap queryParams = ui.getQueryParameters(); return search(queryParams, keywords); - } + } + * + */ } diff --git a/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectDocumentModelHandler.java b/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectDocumentModelHandler.java index f173fdf73..1bfb82e8b 100644 --- a/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectDocumentModelHandler.java +++ b/services/collectionobject/service/src/main/java/org/collectionspace/services/collectionobject/nuxeo/CollectionObjectDocumentModelHandler.java @@ -23,28 +23,8 @@ */ package org.collectionspace.services.collectionobject.nuxeo; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; - -//import org.collectionspace.services.jaxb.AbstractCommonList; - -import org.collectionspace.services.CollectionObjectJAXBSchema; -import org.collectionspace.services.CollectionObjectListItemJAXBSchema; import org.collectionspace.services.collectionobject.CollectionobjectsCommon; -import org.collectionspace.services.collectionobject.CollectionobjectsCommonList; -import org.collectionspace.services.collectionobject.CollectionobjectsCommonList.CollectionObjectListItem; -import org.collectionspace.services.common.document.DocumentUtils; -import org.collectionspace.services.common.document.DocumentWrapper; -import org.collectionspace.services.jaxb.AbstractCommonList; -import org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl; -import org.collectionspace.services.nuxeo.util.NuxeoUtils; -import org.nuxeo.ecm.core.api.DocumentModel; -import org.nuxeo.ecm.core.api.DocumentModelList; -import org.nuxeo.ecm.core.api.model.Property; -import org.nuxeo.ecm.core.schema.types.ComplexType; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.collectionspace.services.nuxeo.client.java.DocHandlerBase; /** * CollectionObjectDocumentModelHandler @@ -53,151 +33,6 @@ import org.slf4j.LoggerFactory; * $LastChangedDate: $ */ public class CollectionObjectDocumentModelHandler - extends RemoteDocumentModelHandlerImpl { - - /** The logger. */ - private final Logger logger = LoggerFactory.getLogger(CollectionObjectDocumentModelHandler.class); - /** - * collectionObject is used to stash JAXB object to use when handle is called - * for Action.CREATE, Action.UPDATE or Action.GET - */ - private CollectionobjectsCommon collectionObject; - /** - * collectionObjectList is stashed when handle is called - * for ACTION.GET_ALL - */ - private CollectionobjectsCommonList collectionObjectList; - - /** - * getCommonPart get associated CollectionobjectsCommon - * @return - */ - @Override - public CollectionobjectsCommon getCommonPart() { - return collectionObject; - } - - /** - * setCommonPart set associated collectionobject - * @param collectionObject - */ - @Override - public void setCommonPart(CollectionobjectsCommon collectionObject) { - this.collectionObject = collectionObject; - } - - /** - * getCollectionobjectsCommonList get associated CollectionobjectsCommon (for index/GET_ALL) - * @return - */ - @Override - public CollectionobjectsCommonList getCommonPartList() { - return collectionObjectList; - } - - /* (non-Javadoc) - * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#setCommonPartList(java.lang.Object) - */ - @Override - public void setCommonPartList(CollectionobjectsCommonList collectionObjectList) { - this.collectionObjectList = collectionObjectList; - } - - /* (non-Javadoc) - * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPart(org.collectionspace.services.common.document.DocumentWrapper) - */ - @Override - public CollectionobjectsCommon extractCommonPart(DocumentWrapper wrapDoc) - throws Exception { - throw new UnsupportedOperationException(); - } - - /* (non-Javadoc) - * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#fillCommonPart(java.lang.Object, org.collectionspace.services.common.document.DocumentWrapper) - */ - @Override - public void fillCommonPart(CollectionobjectsCommon co, DocumentWrapper wrapDoc) throws Exception { - throw new UnsupportedOperationException(); - } - - /* (non-Javadoc) - * @see org.collectionspace.services.nuxeo.client.java.DocumentModelHandler#extractCommonPartList(org.collectionspace.services.common.document.DocumentWrapper) - */ - @Override - public CollectionobjectsCommonList extractCommonPartList(DocumentWrapper wrapDoc) throws Exception { - CollectionobjectsCommonList coList = this.extractPagingInfo(new CollectionobjectsCommonList(), - wrapDoc); - AbstractCommonList commonList = (AbstractCommonList) coList; - commonList.setFieldsReturned("objectNumber|objectName|title|responsibleDepartment|uri|csid"); - List list = coList.getCollectionObjectListItem(); - Iterator iter = wrapDoc.getWrappedObject().iterator(); - String label = getServiceContext().getCommonPartLabel(); - while(iter.hasNext()){ - DocumentModel docModel = iter.next(); - CollectionObjectListItem coListItem = new CollectionObjectListItem(); - try { - String objNumber = getSimpleStringProperty(docModel, label, - CollectionObjectListItemJAXBSchema.OBJECT_NUMBER); - coListItem.setObjectNumber(objNumber); - - String primaryObjectName = getStringValueInPrimaryRepeatingComplexProperty( - docModel, label, CollectionObjectListItemJAXBSchema.OBJECT_NAME_LIST, - CollectionObjectListItemJAXBSchema.OBJECT_NAME); - coListItem.setObjectName(primaryObjectName); - - String primaryTitle = getStringValueInPrimaryRepeatingComplexProperty( - docModel, label, CollectionObjectListItemJAXBSchema.TITLE_GROUP_LIST, - CollectionObjectListItemJAXBSchema.TITLE); - coListItem.setTitle(primaryTitle); - - String primaryRespDept = this.getFirstRepeatingStringProperty( - docModel, label, CollectionObjectListItemJAXBSchema.RESPONSIBLE_DEPARTMENTS); - coListItem.setResponsibleDepartment(primaryRespDept); - - String id = getCsid(docModel); - coListItem.setUri(getServiceContextPath() + id); - coListItem.setCsid(id); - } catch (ClassCastException cce) { - throw new RuntimeException("Unexpected schema structure encountered", cce); - } catch (Exception e) { - throw new RuntimeException("Problem encountered retrieving values", e); - } - list.add(coListItem); - } - - return coList; - } - - /* (non-Javadoc) - * @see org.collectionspace.services.nuxeo.client.java.RemoteDocumentModelHandlerImpl#fillAllParts(org.collectionspace.services.common.document.DocumentWrapper) - */ - @Override - public void fillAllParts(DocumentWrapper wrapDoc, Action action) throws Exception { - - super.fillAllParts(wrapDoc, action); - fillDublinCoreObject(wrapDoc); //dublincore might not be needed in future - } - - /** - * Fill dublin core object. - * - * @param wrapDoc the wrap doc - * @throws Exception the exception - */ - private void fillDublinCoreObject(DocumentWrapper wrapDoc) throws Exception { - DocumentModel docModel = wrapDoc.getWrappedObject(); - //FIXME property setter should be dynamically set using schema inspection - //so it does not require hard coding - // a default title for the Dublin Core schema - docModel.setPropertyValue("dublincore:title", CollectionObjectConstants.NUXEO_DC_TITLE); - } - - /* (non-Javadoc) - * @see org.collectionspace.services.common.document.AbstractMultipartDocumentHandlerImpl#getQProperty(java.lang.String) - */ - @Override - public String getQProperty(String prop) { - return CollectionObjectConstants.NUXEO_SCHEMA_NAME + ":" + prop; - } + extends DocHandlerBase { } diff --git a/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml b/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml index 6281f22a6..e328bf609 100644 --- a/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml +++ b/services/common/src/main/cspace/config/services/tenants/tenant-bindings-proto.xml @@ -51,6 +51,31 @@ --> default-domain org.collectionspace.services.collectionobject.nuxeo.CollectionObjectDocumentModelHandler + + org.collectionspace.services.blob.nuxeo.BlobDocumentModelHandler + + collectionobjects + getCollectionObjectListItem + + + objectNumber + objectNumber + + + objectName + objectNameList/[0]/objectName + + + title + titleGroupList/[0]/title + + + responsibleDepartment + responsibleDepartments/[0] + + + + org.collectionspace.services.collectionobject.nuxeo.CollectionObjectValidatorHandler org.collectionspace.services.common.init.ModifyFieldDatatypes -- 2.47.3