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.
*/
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> 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<CollectionobjectsCommonList> 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> 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<String> 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<AbstractCommonList> response;
-
- List<CollectionObjectListItem> 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<Response> 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<AbstractCommonList> response;
-
- List<CollectionObjectListItem> 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> 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<AbstractCommonList> 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> 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<String> 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<AbstractCommonList> response;
+
+ List<AbstractCommonList.ListItem> 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<Response> 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<AbstractCommonList> response;
+
+ List<AbstractCommonList.ListItem> 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);
+ }
}
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<CollectionobjectsCommonList, CollectionObjectProxy> {
- 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<CollectionObjectProxy> {
- @Override
- public Class<CollectionObjectProxy> 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<CollectionobjectsCommonList> 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<CollectionObjectProxy> getProxyClass() {
+ return CollectionObjectProxy.class;
}
+
/**
* Roundtrip.
*
* @return the client response< response>
*/
public ClientResponse<Response> roundtrip(int ms) {
- getLogger().debug(">>>>Roundtrip start.");
- ClientResponse<Response> result = getProxy().roundtrip(ms);
- getLogger().debug("<<<<Roundtrip stop.");
- return result;
+ getLogger().debug(">>>>Roundtrip start.");
+ ClientResponse<Response> result = getProxy().roundtrip(ms);
+ getLogger().debug("<<<<Roundtrip stop.");
+ return result;
}
-
+
/**
* Keyword search.
*
* @see org.collectionspace.services.client.CollectionObjectProxy#keywordSearch()
* @return the client response< collectionobjects common list>
*/
+ /*
public ClientResponse<CollectionobjectsCommonList> keywordSearch(String keywords) {
return getProxy().keywordSearch(keywords);
}
+ *
+ */
}
*/
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<CollectionobjectsCommonList> {
+public interface CollectionObjectProxy extends CollectionSpaceCommonListPoxProxy {
/**
* Roundtrip.
@Path("/{ms}/roundtrip")
@Produces({"application/xml"})
ClientResponse<Response> roundtrip(@PathParam("ms") int ms);
-
- /**
- * Read list.
- *
- * @return the client response
- */
- @GET
- @Produces({"application/xml"})
- ClientResponse<CollectionobjectsCommonList> readList();
-
- @Override
- @GET
- @Produces({"application/xml"})
- ClientResponse<CollectionobjectsCommonList> readIncludeDeleted(
- @QueryParam(WorkflowClient.WORKFLOW_QUERY_NONDELETED) String includeDeleted);
/**
* Keyword search.
* @param keywords the keywords
* @return the client response
*/
+ /*
@GET
@Produces({"application/xml"})
ClientResponse<CollectionobjectsCommonList> keywordSearch(
@QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords);
+ *
+ */
- @Override
- @GET
- @Produces({"application/xml"})
- ClientResponse<CollectionobjectsCommonList> keywordSearchIncludeDeleted(
- @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords,
- @QueryParam(WorkflowClient.WORKFLOW_QUERY_NONDELETED) String includeDeleted);
}
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;
*/
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<String> allResourceIdsCreated = new ArrayList<String>();
+
+ // 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<String> TWO_KEYWORDS =
Arrays.asList(new String[]{"Cheggarra" + IDENTIFIER, "Ahoggya" + IDENTIFIER});
// Ж : 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<String> allResourceIdsCreated = new ArrayList<String>();
+ @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()
*/
@Override
protected CollectionSpaceClient getClientInstance() {
- return new CollectionObjectClient();
+ return new CollectionObjectClient();
}
/* (non-Javadoc)
*/
@Override
protected AbstractCommonList getAbstractCommonList(ClientResponse<AbstractCommonList> response) {
- return response.getEntity(CollectionobjectsCommonList.class);
+ return response.getEntity(AbstractCommonList.class);
}
/**
* 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()) {
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<CollectionobjectsCommonList> res = doSearch(KEYWORD);
+ ClientResponse<AbstractCommonList> res = doSearch(KEYWORD);
int statusCode = res.getStatus();
// Check the status code of the response: does it match
// 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()) {
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);
// Search using both terms
// Send the search request and receive a response
- ClientResponse<CollectionobjectsCommonList> res = doSearch(TWO_KEYWORDS);
+ ClientResponse<AbstractCommonList> res = doSearch(TWO_KEYWORDS);
int statusCode = res.getStatus();
// Check the status code of the response: does it match
// 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
// 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()) {
// 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);
// Search using both terms
// Send the search request and receive a response
- ClientResponse<CollectionobjectsCommonList> res = doSearch(TWO_MORE_KEYWORDS);
+ ClientResponse<AbstractCommonList> res = doSearch(TWO_MORE_KEYWORDS);
int statusCode = res.getStatus();
// Check the status code of the response: does it match
// 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
// 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);
}
// 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()) {
// 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);
testSetup(STATUS_OK, ServiceRequestType.SEARCH);
// Send the search request and receive a response
- ClientResponse<CollectionobjectsCommonList> res = doSearch(UTF8_KEYWORD);
+ ClientResponse<AbstractCommonList> res = doSearch(UTF8_KEYWORD);
int statusCode = res.getStatus();
// Check the status code of the response: does it match
// 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()) {
testSetup(STATUS_OK, ServiceRequestType.SEARCH);
// Send the search request and receive a response
- ClientResponse<CollectionobjectsCommonList> res = doSearch(NON_EXISTENT_KEYWORD);
+ ClientResponse<AbstractCommonList> res = doSearch(NON_EXISTENT_KEYWORD);
int statusCode = res.getStatus();
// Check the status code of the response: does it match
// 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);
}
// ---------------------------------------------------------------
// Cleanup of resources created during testing
// ---------------------------------------------------------------
-
/**
* Deletes all resources created by setup and tests, after all tests have been run.
*
* 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 ...");
}
// ---------------------------------------------------------------
// Utility methods used by tests above
// ---------------------------------------------------------------
-
private void createCollectionObjects(long numToCreate, String keyword) {
List keywords = new ArrayList<String>();
keywords.add(keyword);
boolean keywordsInSameField = true;
createCollectionObjects(numToCreate, keywords, keywordsInSameField);
}
-
+
private void createCollectionObjects(long numToCreate, List<String> keywords,
boolean keywordsInSameField) {
testSetup(STATUS_CREATED, ServiceRequestType.CREATE);
}
}
}
-
+
private PoxPayloadOut createCollectionObjectInstance(long i, List<String> keywords,
boolean keywordsInSameField) {
CollectionobjectsCommon collectionObject = new CollectionobjectsCommon();
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));
}
return sb.toString();
}
- private ClientResponse<CollectionobjectsCommonList> doSearch(List<String> keywords) {
+ private ClientResponse<AbstractCommonList> doSearch(List<String> keywords) {
String searchParamValue = listToString(keywords, KEYWORD_SEPARATOR);
return doSearch(searchParamValue);
}
- private ClientResponse<CollectionobjectsCommonList> doSearch(String keyword) {
- String searchParamValue = keyword;
+ private ClientResponse<AbstractCommonList> doSearch(String keyword) {
+ String searchParamValue = keyword;
if (logger.isDebugEnabled()) {
logger.debug("Searching on keyword(s): " + searchParamValue + " ...");
}
CollectionObjectClient client = new CollectionObjectClient();
- ClientResponse<CollectionobjectsCommonList> res =
- client.keywordSearch(searchParamValue);
+ final boolean NOT_INCLUDING_DELETED_RESOURCES = false;
+ ClientResponse<AbstractCommonList> res =
+ client.keywordSearchIncludeDeleted(searchParamValue, NOT_INCLUDING_DELETED_RESOURCES);
return res;
}
- private long getNumMatched(ClientResponse<CollectionobjectsCommonList> res,
- long numExpectedMatches) {
- CollectionobjectsCommonList list = (CollectionobjectsCommonList)
- res.getEntity(CollectionobjectsCommonList.class);
+ private long getNumMatched(ClientResponse<AbstractCommonList> 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<CollectionobjectsCommonList.CollectionObjectListItem> items =
- list.getCollectionObjectListItem();
+ private void itemizeListItems(AbstractCommonList list) {
+ List<AbstractCommonList.ListItem> 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());
}
}
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;
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;
@Override
protected AbstractCommonList getAbstractCommonList(
ClientResponse<AbstractCommonList> response) {
- return response.getEntity(CollectionobjectsCommonList.class);
+ return response.getEntity(AbstractCommonList.class);
}
// ---------------------------------------------------------------
// Submit the request to the service and store the response.
CollectionObjectClient client = new CollectionObjectClient();
- ClientResponse<CollectionobjectsCommonList> res = client.readList();
- CollectionobjectsCommonList list = res.getEntity();
+ ClientResponse<AbstractCommonList> res = client.readList();
+ AbstractCommonList list = res.getEntity();
int statusCode = res.getStatus();
// Check the status code of the response: does it match
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<CollectionobjectsCommonList.CollectionObjectListItem> 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
<xs:element name="fieldColEventName" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
-
- <!-- This is the base class for paginated lists -->
- <xs:complexType name="abstractCommonList">
- <xs:annotation>
- <xs:appinfo>
- <jaxb:class ref="org.collectionspace.services.jaxb.AbstractCommonList"/>
- </xs:appinfo>
- </xs:annotation>
- </xs:complexType>
-
- <xs:element name="collectionobjects-common-list">
- <xs:complexType>
- <xs:complexContent>
- <xs:extension base="abstractCommonList">
- <xs:sequence>
- <xs:element name="collection-object-list-item" maxOccurs="unbounded">
- <xs:complexType>
- <xs:sequence>
- <xs:element name="objectNumber" type="xs:string"
- minOccurs="1"/>
- <xs:element name="objectName" type="xs:string"
- minOccurs="1"/>
- <xs:element name="title" type="xs:string"
- minOccurs="1"/>
- <xs:element name="responsibleDepartment" type="xs:string"
- minOccurs="1"/>
- <!-- uri to retrive collection object details -->
- <xs:element name="uri" type="xs:anyURI"
- minOccurs="1"/>
- <xs:element name="csid" type="xs:string"
- minOccurs="1"/>
- </xs:sequence>
- </xs:complexType>
- </xs:element>
- </xs:sequence>
- </xs:extension>
- </xs:complexContent>
- </xs:complexType>
- </xs:element>
</xs:schema>
*
* @return the collectionobjects common list
*/
+ /*
@GET
@Path("/search")
@Produces("application/xml")
@QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS) String keywords) {
MultivaluedMap<String, String> queryParams = ui.getQueryParameters();
return search(queryParams, keywords);
- }
+ }
+ *
+ */
}
*/
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
* $LastChangedDate: $
*/
public class CollectionObjectDocumentModelHandler
- extends RemoteDocumentModelHandlerImpl<CollectionobjectsCommon, CollectionobjectsCommonList> {
-
- /** 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<DocumentModel> 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<DocumentModel> 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<DocumentModelList> wrapDoc) throws Exception {
- CollectionobjectsCommonList coList = this.extractPagingInfo(new CollectionobjectsCommonList(),
- wrapDoc);
- AbstractCommonList commonList = (AbstractCommonList) coList;
- commonList.setFieldsReturned("objectNumber|objectName|title|responsibleDepartment|uri|csid");
- List<CollectionobjectsCommonList.CollectionObjectListItem> list = coList.getCollectionObjectListItem();
- Iterator<DocumentModel> 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<DocumentModel> 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<DocumentModel> 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<CollectionobjectsCommon> {
}
</service:uriPath> -->
<service:repositoryDomain xmlns:service="http://collectionspace.org/services/common/service">default-domain</service:repositoryDomain>
<service:documentHandler xmlns:service="http://collectionspace.org/services/common/service">org.collectionspace.services.collectionobject.nuxeo.CollectionObjectDocumentModelHandler</service:documentHandler>
+ <service:DocHandlerParams xmlns:service="http://collectionspace.org/services/common/service">
+ <service:classname>org.collectionspace.services.blob.nuxeo.BlobDocumentModelHandler</service:classname>
+ <service:params>
+ <service:DublinCoreTitle>collectionobjects</service:DublinCoreTitle>
+ <service:ListResultsItemMethodName>getCollectionObjectListItem</service:ListResultsItemMethodName>
+ <service:ListResultsFields>
+ <service:ListResultField>
+ <service:element>objectNumber</service:element>
+ <service:xpath>objectNumber</service:xpath>
+ </service:ListResultField>
+ <service:ListResultField>
+ <service:element>objectName</service:element>
+ <service:xpath>objectNameList/[0]/objectName</service:xpath>
+ </service:ListResultField>
+ <service:ListResultField>
+ <service:element>title</service:element>
+ <service:xpath>titleGroupList/[0]/title</service:xpath>
+ </service:ListResultField>
+ <service:ListResultField>
+ <service:element>responsibleDepartment</service:element>
+ <service:xpath>responsibleDepartments/[0]</service:xpath>
+ </service:ListResultField>
+ </service:ListResultsFields>
+ </service:params>
+ </service:DocHandlerParams>
<service:validatorHandler xmlns:service="http://collectionspace.org/services/common/service">org.collectionspace.services.collectionobject.nuxeo.CollectionObjectValidatorHandler</service:validatorHandler>
<service:initHandler xmlns:service="http://collectionspace.org/services/common/service">
<service:classname>org.collectionspace.services.common.init.ModifyFieldDatatypes</service:classname>