From: Patrick Schmitz Date: Fri, 22 Jul 2011 19:44:36 +0000 (+0000) Subject: CSPACE-3332, CSPACE-3784 Updated Movement to use DocHandlerBase. Refactored some... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=c600ee1ca98efd4e9a1b2b8fd9c537f40035d25d;p=tmp%2Fjakarta-migration.git CSPACE-3332, CSPACE-3784 Updated Movement to use DocHandlerBase. Refactored some utility methods into a new AbstractCommonListUtils class. Fixed a bug in RemoteDocumentModelHandlerImpl.getXPathStringValue that did not handle dates correctly. --- diff --git a/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionServiceTest.java b/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionServiceTest.java index 2bc8e65ce..c43ef9ec7 100644 --- a/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionServiceTest.java +++ b/services/acquisition/client/src/test/java/org/collectionspace/services/client/test/AcquisitionServiceTest.java @@ -31,6 +31,7 @@ import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; +import org.collectionspace.services.common.AbstractCommonListUtils; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.acquisition.AcquisitionsCommon; @@ -81,15 +82,6 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { return new AcquisitionClient(); } - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) - */ - @Override - protected AbstractCommonList getAbstractCommonList( - ClientResponse response) { - return response.getEntity(AbstractCommonList.class); - } - // --------------------------------------------------------------- // CRUD tests : CREATE tests // --------------------------------------------------------------- @@ -412,9 +404,8 @@ public class AcquisitionServiceTest extends AbstractServiceTestImpl { Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); // Optionally output additional data about list members for debugging. - boolean iterateThroughList = true; - if(iterateThroughList && logger.isDebugEnabled()){ - ListItemsInAbstractCommonList(list, logger, testName); + if(logger.isTraceEnabled()){ + AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); } } diff --git a/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java b/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java index d9423b90d..4363ffaa8 100644 --- a/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java +++ b/services/client/src/main/java/org/collectionspace/services/client/test/AbstractServiceTestImpl.java @@ -96,35 +96,6 @@ public abstract class AbstractServiceTestImpl extends BaseServiceTest implements } - protected void ListItemsInAbstractCommonList( - AbstractCommonList list, Logger logger, String testName) { - List items = - list.getListItem(); - int i = 0; - for(AbstractCommonList.ListItem item : items){ - List elList = item.getAny(); - StringBuilder elementStrings = new StringBuilder(); - for(Element el : elList) { - Node textEl = el.getFirstChild(); - elementStrings.append("["+el.getNodeName()+":"+((textEl!=null)?textEl.getNodeValue():"NULL")+"] "); - } - logger.debug(testName + ": list-item[" + i + "]: "+elementStrings.toString()); - i++; - } - } - - protected static String ListItemGetCSID(AbstractCommonList.ListItem item) { - List elList = item.getAny(); - for(Element el : elList) { - if("csid".equalsIgnoreCase(el.getNodeName())) { - Node textEl = el.getFirstChild(); - return textEl.getNodeValue(); - } - } - return null; - } - - /* Use this to keep track of resources to delete */ protected List allResourceIdsCreated = new ArrayList(); /* Use this to track authority items */ diff --git a/services/common/src/main/java/org/collectionspace/services/common/AbstractCommonListUtils.java b/services/common/src/main/java/org/collectionspace/services/common/AbstractCommonListUtils.java new file mode 100644 index 000000000..8430e56d3 --- /dev/null +++ b/services/common/src/main/java/org/collectionspace/services/common/AbstractCommonListUtils.java @@ -0,0 +1,46 @@ +package org.collectionspace.services.common; + +import java.util.List; + +import org.collectionspace.services.jaxb.AbstractCommonList; +import org.slf4j.Logger; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +public class AbstractCommonListUtils { + public static void ListItemsInAbstractCommonList( + AbstractCommonList list, Logger logger, String testName) { + List items = + list.getListItem(); + int i = 0; + for(AbstractCommonList.ListItem item : items){ + List elList = item.getAny(); + StringBuilder elementStrings = new StringBuilder(); + for(Element el : elList) { + Node textEl = el.getFirstChild(); + elementStrings.append("["+el.getNodeName()+":"+((textEl!=null)?textEl.getNodeValue():"NULL")+"] "); + } + logger.debug(testName + ": list-item[" + i + "]: "+elementStrings.toString()); + i++; + } + } + + public static String ListItemGetCSID(AbstractCommonList.ListItem item) { + return ListItemGetElementValue(item, "csid"); + } + + public static String ListItemGetElementValue(AbstractCommonList.ListItem item, + String elName) { + List elList = item.getAny(); + for(Element el : elList) { + if(elName.equalsIgnoreCase(el.getNodeName())) { + Node textEl = el.getFirstChild(); + return textEl.getNodeValue(); + } + } + return null; + } + + + +} diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java index d4fb43596..7bf5fa25d 100644 --- a/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/client/java/RemoteDocumentModelHandlerImpl.java @@ -23,8 +23,8 @@ */ package org.collectionspace.services.nuxeo.client.java; -import java.io.InputStream; import java.util.Collection; +import java.util.GregorianCalendar; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -43,26 +43,21 @@ import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.client.workflow.WorkflowClient; import org.collectionspace.services.common.authorityref.AuthorityRefList; -import org.collectionspace.services.common.authorization_mgt.AuthorizationCommon; import org.collectionspace.services.common.context.JaxRsContext; import org.collectionspace.services.common.context.MultipartServiceContext; import org.collectionspace.services.common.context.ServiceContext; +import org.collectionspace.services.common.datetime.DateTimeFormatUtils; import org.collectionspace.services.common.document.BadRequestException; -import org.collectionspace.services.common.document.DocumentNotFoundException; import org.collectionspace.services.common.document.DocumentUtils; import org.collectionspace.services.common.document.DocumentWrapper; import org.collectionspace.services.common.document.DocumentFilter; import org.collectionspace.services.common.document.DocumentHandler.Action; import org.collectionspace.services.common.security.SecurityUtils; -import org.collectionspace.services.common.security.UnauthorizedException; import org.collectionspace.services.common.service.ObjectPartType; import org.collectionspace.services.common.storage.jpa.JpaStorageUtils; import org.collectionspace.services.common.vocabulary.RefNameUtils; import org.dom4j.Element; -import org.jboss.resteasy.plugins.providers.multipart.InputPart; -import org.jboss.resteasy.plugins.providers.multipart.MultipartInput; - import org.nuxeo.ecm.core.api.DocumentModel; import org.nuxeo.ecm.core.api.DocumentModelList; import org.nuxeo.ecm.core.api.model.Property; @@ -72,7 +67,6 @@ import org.nuxeo.ecm.core.schema.types.Schema; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.dom4j.Document; /** * RemoteDocumentModelHandler @@ -273,8 +267,6 @@ public abstract class RemoteDocumentModelHandlerImpl throws Exception { //check if this is an xml part if (part.getMediaType().equals(MediaType.APPLICATION_XML_TYPE)) { -// Document document = DocumentUtils.parseDocument(payload, partMeta, -// false /*don't validate*/); Element element = part.getElementBody(); Map objectProps = DocumentUtils.parseProperties(partMeta, element, ctx); if (action == Action.UPDATE) { @@ -681,7 +673,16 @@ public abstract class RemoteDocumentModelHandlerImpl protected static String getXPathStringValue(DocumentModel docModel, String schema, String xpath) { xpath = schema+":"+xpath; try { - return (String)docModel.getPropertyValue(xpath); + Object value = docModel.getPropertyValue(xpath); + String returnVal = null; + if(value==null) { + // Nothing to do - leave returnVal null + } else if(value instanceof GregorianCalendar) { + returnVal = DateTimeFormatUtils.formatAsISO8601Timestamp((GregorianCalendar)value); + } else { + returnVal = value.toString(); + } + return returnVal; } catch(PropertyException pe) { throw new RuntimeException("Problem retrieving property {"+xpath+"}. Bad XPath spec?" +pe.getLocalizedMessage()); diff --git a/services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeServiceTest.java b/services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeServiceTest.java index 766d0c5b9..534c1e576 100644 --- a/services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeServiceTest.java +++ b/services/intake/client/src/test/java/org/collectionspace/services/client/test/IntakeServiceTest.java @@ -32,6 +32,7 @@ import org.collectionspace.services.client.PayloadInputPart; import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; +import org.collectionspace.services.common.AbstractCommonListUtils; import org.collectionspace.services.intake.EntryMethodList; import org.collectionspace.services.intake.FieldCollectionEventNameList; import org.collectionspace.services.intake.CurrentLocationGroup; @@ -410,7 +411,7 @@ public class IntakeServiceTest extends AbstractServiceTestImpl { // Optionally output additional data about list members for debugging. boolean iterateThroughList = true; if (iterateThroughList && logger.isDebugEnabled()) { - ListItemsInAbstractCommonList(list, logger, testName); + AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); } } diff --git a/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninServiceTest.java b/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninServiceTest.java index af9b62c68..a101f8823 100644 --- a/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninServiceTest.java +++ b/services/loanin/client/src/test/java/org/collectionspace/services/client/test/LoaninServiceTest.java @@ -33,6 +33,7 @@ import org.collectionspace.services.client.PayloadInputPart; import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; +import org.collectionspace.services.common.AbstractCommonListUtils; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.loanin.LenderGroup; import org.collectionspace.services.loanin.LenderGroupList; @@ -420,7 +421,7 @@ public class LoaninServiceTest extends AbstractServiceTestImpl { // Optionally output additional data about list members for debugging. boolean iterateThroughList = true; if(iterateThroughList && logger.isDebugEnabled()){ - ListItemsInAbstractCommonList(list, logger, testName); + AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); } } diff --git a/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutServiceTest.java b/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutServiceTest.java index 8d8a993f8..960397b64 100644 --- a/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutServiceTest.java +++ b/services/loanout/client/src/test/java/org/collectionspace/services/client/test/LoanoutServiceTest.java @@ -32,6 +32,7 @@ import org.collectionspace.services.client.PayloadInputPart; import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; +import org.collectionspace.services.common.AbstractCommonListUtils; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.loanout.LoanedObjectStatusGroup; import org.collectionspace.services.loanout.LoanedObjectStatusGroupList; @@ -387,7 +388,7 @@ public class LoanoutServiceTest extends AbstractServiceTestImpl { // Optionally output additional data about list members for debugging. boolean iterateThroughList = true; if(iterateThroughList && logger.isDebugEnabled()){ - ListItemsInAbstractCommonList(list, logger, testName); + AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); } } diff --git a/services/movement/client/src/main/java/org/collectionspace/services/client/MovementClient.java b/services/movement/client/src/main/java/org/collectionspace/services/client/MovementClient.java index fe0a52ae4..544d0fcf6 100644 --- a/services/movement/client/src/main/java/org/collectionspace/services/client/MovementClient.java +++ b/services/movement/client/src/main/java/org/collectionspace/services/client/MovementClient.java @@ -17,8 +17,8 @@ package org.collectionspace.services.client; +import org.collectionspace.services.jaxb.AbstractCommonList; import org.jboss.resteasy.client.ClientResponse; -import org.collectionspace.services.movement.MovementsCommonList; /** * MovementClient.java @@ -27,7 +27,7 @@ import org.collectionspace.services.movement.MovementsCommonList; * $LastChangedDate$ * */ -public class MovementClient extends AbstractPoxServiceClientImpl { +public class MovementClient extends AbstractCommonListPoxServiceClientImpl { public static final String SERVICE_NAME = "movements"; public static final String SERVICE_PATH_COMPONENT = SERVICE_NAME; public static final String SERVICE_PATH = "/" + SERVICE_PATH_COMPONENT; @@ -49,24 +49,13 @@ public class MovementClient extends AbstractPoxServiceClientImpl readList() { - return getProxy().readList(); - } /** * @param sortFieldName * @return * @see org.collectionspace.services.client.MovementProxy#readList(java.lang.String) */ - public ClientResponse readListSortedBy(String sortFieldName) { + public ClientResponse readListSortedBy(String sortFieldName) { return getProxy().readListSortedBy(sortFieldName); } @@ -76,7 +65,7 @@ public class MovementClient extends AbstractPoxServiceClientImpl keywordSearchSortedBy(String keywords, String sortFieldName) { + public ClientResponse keywordSearchSortedBy(String keywords, String sortFieldName) { return getProxy().keywordSearchSortedBy(keywords, sortFieldName); } } diff --git a/services/movement/client/src/main/java/org/collectionspace/services/client/MovementProxy.java b/services/movement/client/src/main/java/org/collectionspace/services/client/MovementProxy.java index bdaf3a2c8..3c8ed92ff 100644 --- a/services/movement/client/src/main/java/org/collectionspace/services/client/MovementProxy.java +++ b/services/movement/client/src/main/java/org/collectionspace/services/client/MovementProxy.java @@ -32,7 +32,7 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import org.collectionspace.services.client.workflow.WorkflowClient; -import org.collectionspace.services.movement.MovementsCommonList; +import org.collectionspace.services.jaxb.AbstractCommonList; /** * MovementProxy.java @@ -43,35 +43,30 @@ import org.collectionspace.services.movement.MovementsCommonList; @Path("/movements/") @Produces("application/xml") @Consumes("application/xml") -public interface MovementProxy extends CollectionSpacePoxProxy { +public interface MovementProxy extends CollectionSpaceCommonListPoxProxy { - // List - @GET - @Produces({"application/xml"}) - ClientResponse readList(); - // Sorted list @GET @Produces({"application/xml"}) - ClientResponse readListSortedBy( + ClientResponse readListSortedBy( @QueryParam(IClientQueryParams.SORT_BY_PARAM) String sortFieldName); @Override @GET @Produces({"application/xml"}) - ClientResponse readIncludeDeleted( + ClientResponse readIncludeDeleted( @QueryParam(WorkflowClient.WORKFLOW_QUERY_NONDELETED) String includeDeleted); @Override @GET @Produces({"application/xml"}) - ClientResponse keywordSearchIncludeDeleted( + ClientResponse keywordSearchIncludeDeleted( @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords, @QueryParam(WorkflowClient.WORKFLOW_QUERY_NONDELETED) String includeDeleted); @GET @Produces({"application/xml"}) - ClientResponse keywordSearchSortedBy( + ClientResponse keywordSearchSortedBy( @QueryParam(IQueryManager.SEARCH_TYPE_KEYWORDS_KW) String keywords, @QueryParam(IClientQueryParams.SORT_BY_PARAM) String sortFieldName); } diff --git a/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementServiceTest.java b/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementServiceTest.java index c550bedb3..a2619f28d 100644 --- a/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementServiceTest.java +++ b/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementServiceTest.java @@ -31,12 +31,12 @@ import java.util.TimeZone; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import org.collectionspace.services.common.AbstractCommonListUtils; import org.collectionspace.services.common.datetime.GregorianCalendarDateTimeUtils; import org.collectionspace.services.client.CollectionSpaceClient; import org.collectionspace.services.client.MovementClient; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.movement.MovementsCommon; -import org.collectionspace.services.movement.MovementsCommonList; import org.collectionspace.services.movement.MovementMethodsList; import org.jboss.resteasy.client.ClientResponse; @@ -79,15 +79,6 @@ public class MovementServiceTest extends AbstractServiceTestImpl { return new MovementClient(); } - /* (non-Javadoc) - * @see org.collectionspace.services.client.test.BaseServiceTest#getAbstractCommonList(org.jboss.resteasy.client.ClientResponse) - */ - @Override - protected AbstractCommonList getAbstractCommonList( - ClientResponse response) { - return response.getEntity(MovementsCommonList.class); - } - // --------------------------------------------------------------- // CRUD tests : CREATE tests // --------------------------------------------------------------- @@ -383,8 +374,8 @@ public class MovementServiceTest extends AbstractServiceTestImpl { // Submit the request to the service and store the response. MovementClient client = new MovementClient(); - ClientResponse res = client.readList(); - MovementsCommonList 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 @@ -397,24 +388,9 @@ public class MovementServiceTest extends AbstractServiceTestImpl { Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); // Optionally output additional data about list members for debugging. - boolean iterateThroughList = true; - if(iterateThroughList && logger.isDebugEnabled()){ - List items = - list.getMovementListItem(); - int i = 0; - for(MovementsCommonList.MovementListItem item : items){ - logger.debug(testName + ": list-item[" + i + "] csid=" + - item.getCsid()); - logger.debug(testName + ": list-item[" + i + "] movementReferenceNumber=" + - item.getMovementReferenceNumber()); - logger.debug(testName + ": list-item[" + i + "] locationDate=" + - item.getLocationDate()); - logger.debug(testName + ": list-item[" + i + "] URI=" + - item.getUri()); - i++; - } + if(logger.isTraceEnabled()){ + AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); } - } // Failure outcomes diff --git a/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementSortByTest.java b/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementSortByTest.java index ab59c5900..c2c8a7954 100644 --- a/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementSortByTest.java +++ b/services/movement/client/src/test/java/org/collectionspace/services/client/test/MovementSortByTest.java @@ -37,8 +37,8 @@ import org.collectionspace.services.client.PayloadInputPart; import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; +import org.collectionspace.services.common.AbstractCommonListUtils; import org.collectionspace.services.movement.MovementsCommon; -import org.collectionspace.services.movement.MovementsCommonList; import org.collectionspace.services.jaxb.AbstractCommonList; import org.jboss.resteasy.client.ClientResponse; @@ -72,6 +72,7 @@ public class MovementSortByTest extends BaseServiceTest { private List movementIdsCreated = new ArrayList(); private final String SORT_FIELD_SEPARATOR = ", "; private final Locale LOCALE = Locale.US; + private final String LOCATION_DATE_EL_NAME = "locationDate"; /* (non-Javadoc) * @see org.collectionspace.services.client.test.BaseServiceTest#getClientInstance() @@ -112,20 +113,20 @@ public class MovementSortByTest extends BaseServiceTest { if (logger.isDebugEnabled()) { logger.debug("Sorting on field name=" + sortFieldName); } - MovementsCommonList list = readSortedList(sortFieldName); - List items = - list.getMovementListItem(); + AbstractCommonList list = readSortedList(sortFieldName); + List items = + list.getListItem(); ArrayList values = new ArrayList(); Collator localeSpecificCollator = Collator.getInstance(LOCALE); int i = 0; - for (MovementsCommonList.MovementListItem item : items) { + for (AbstractCommonList.ListItem item : items) { // Because movementNote is not currently a summary field // (returned in summary list items), we will need to verify // sort order by retrieving full records, using the // IDs provided in the summary list items. amd then retriving // the value of that field from each of those records. - MovementsCommon movement = read(item.getCsid()); + MovementsCommon movement = read(AbstractCommonListUtils.ListItemGetCSID(item)); values.add(i, movement.getMovementNote()); if (logger.isDebugEnabled()) { logger.debug("list-item[" + i + "] movementNote=" + values.get(i)); @@ -165,20 +166,20 @@ public class MovementSortByTest extends BaseServiceTest { if (logger.isDebugEnabled()) { logger.debug("Sorting on field name=" + sortFieldName); } - MovementsCommonList list = keywordSearchSortedBy(TEST_SPECIFIC_KEYWORD, sortFieldName); - List items = - list.getMovementListItem(); + AbstractCommonList list = keywordSearchSortedBy(TEST_SPECIFIC_KEYWORD, sortFieldName); + List items = + list.getListItem(); ArrayList values = new ArrayList(); Collator localeSpecificCollator = Collator.getInstance(LOCALE); int i = 0; - for (MovementsCommonList.MovementListItem item : items) { + for (AbstractCommonList.ListItem item : items) { // Because movementNote is not currently a summary field // (returned in summary list items), we will need to verify // sort order by retrieving full records, using the // IDs provided in the summary list items. amd then retriving // the value of that field from each of those records. - MovementsCommon movement = read(item.getCsid()); + MovementsCommon movement = read(AbstractCommonListUtils.ListItemGetCSID(item)); values.add(i, movement.getMovementNote()); if (logger.isDebugEnabled()) { logger.debug("list-item[" + i + "] movementNote=" + values.get(i)); @@ -216,20 +217,20 @@ public class MovementSortByTest extends BaseServiceTest { if (logger.isDebugEnabled()) { logger.debug("Sorting on field name=" + sortFieldName); } - MovementsCommonList list = readSortedList(sortFieldName); - List items = - list.getMovementListItem(); + AbstractCommonList list = readSortedList(sortFieldName); + List items = + list.getListItem(); ArrayList values = new ArrayList(); Collator localeSpecificCollator = Collator.getInstance(LOCALE); int i = 0; - for (MovementsCommonList.MovementListItem item : items) { + for (AbstractCommonList.ListItem item : items) { // Because movementNote is not currently a summary field // (returned in summary list items), we will need to verify // sort order by retrieving full records, using the // IDs provided in the summary list items. amd then retriving // the value of that field from each of those records. - MovementsCommon movement = read(item.getCsid()); + MovementsCommon movement = read(AbstractCommonListUtils.ListItemGetCSID(item)); values.add(i, movement.getMovementNote()); if (logger.isDebugEnabled()) { logger.debug("list-item[" + i + "] movementNote=" + values.get(i)); @@ -266,15 +267,17 @@ public class MovementSortByTest extends BaseServiceTest { if (logger.isDebugEnabled()) { logger.debug("Sorting on field name=" + sortFieldName); } - MovementsCommonList list = readSortedList(sortFieldName); - List items = - list.getMovementListItem(); + AbstractCommonList list = readSortedList(sortFieldName); + List items = + list.getListItem(); ArrayList values = new ArrayList(); Comparator comparator = String.CASE_INSENSITIVE_ORDER; int i = 0; - for (MovementsCommonList.MovementListItem item : items) { - values.add(i, item.getLocationDate()); + for (AbstractCommonList.ListItem item : items) { + String locDate = + AbstractCommonListUtils.ListItemGetElementValue(item, LOCATION_DATE_EL_NAME); + values.add(i, locDate); if (logger.isDebugEnabled()) { logger.debug("list-item[" + i + "] locationDate=" + values.get(i)); } @@ -304,15 +307,17 @@ public class MovementSortByTest extends BaseServiceTest { if (logger.isDebugEnabled()) { logger.debug("Sorting on field name=" + sortFieldName); } - MovementsCommonList list = readSortedList(sortFieldName); - List items = - list.getMovementListItem(); + AbstractCommonList list = readSortedList(sortFieldName); + List items = + list.getListItem(); ArrayList values = new ArrayList(); Comparator comparator = String.CASE_INSENSITIVE_ORDER; int i = 0; - for (MovementsCommonList.MovementListItem item : items) { - values.add(i, item.getLocationDate()); + for (AbstractCommonList.ListItem item : items) { + String locDate = + AbstractCommonListUtils.ListItemGetElementValue(item, LOCATION_DATE_EL_NAME); + values.add(i, locDate); if (logger.isDebugEnabled()) { logger.debug("list-item[" + i + "] locationDate=" + values.get(i)); } @@ -343,22 +348,22 @@ public class MovementSortByTest extends BaseServiceTest { logger.debug("Sorting on field names=" + firstSortFieldName + " and " + secondSortFieldName); } String sortExpression = firstSortFieldName + SORT_FIELD_SEPARATOR + secondSortFieldName; - MovementsCommonList list = readSortedList(sortExpression); - List items = - list.getMovementListItem(); + AbstractCommonList list = readSortedList(sortExpression); + List items = + list.getListItem(); ArrayList firstFieldValues = new ArrayList(); ArrayList secondFieldValues = new ArrayList(); Collator localeSpecificCollator = Collator.getInstance(LOCALE); Comparator comparator = String.CASE_INSENSITIVE_ORDER; int i = 0; - for (MovementsCommonList.MovementListItem item : items) { + for (AbstractCommonList.ListItem item : items) { // Because movementNote is not currently a summary field // (returned in summary list items), we will need to verify // sort order by retrieving full records, using the // IDs provided in the summary list items. amd then retriving // the value of that field from each of those records. - MovementsCommon movement = read(item.getCsid()); + MovementsCommon movement = read(AbstractCommonListUtils.ListItemGetCSID(item)); firstFieldValues.add(i, movement.getMovementNote()); secondFieldValues.add(i, movement.getLocationDate()); if (logger.isDebugEnabled()) { @@ -402,22 +407,22 @@ public class MovementSortByTest extends BaseServiceTest { logger.debug("Sorting on field names=" + firstSortFieldName + " and " + secondSortFieldName); } String sortExpression = firstSortFieldName + SORT_FIELD_SEPARATOR + secondSortFieldName; - MovementsCommonList list = readSortedList(sortExpression); - List items = - list.getMovementListItem(); + AbstractCommonList list = readSortedList(sortExpression); + List items = + list.getListItem(); ArrayList firstFieldValues = new ArrayList(); ArrayList secondFieldValues = new ArrayList(); Collator localeSpecificCollator = Collator.getInstance(LOCALE); Comparator comparator = String.CASE_INSENSITIVE_ORDER; int i = 0; - for (MovementsCommonList.MovementListItem item : items) { + for (AbstractCommonList.ListItem item : items) { // Because movementNote is not currently a summary field // (returned in summary list items), we will need to verify // sort order by retrieving full records, using the // IDs provided in the summary list items. amd then retriving // the value of that field from each of those records. - MovementsCommon movement = read(item.getCsid()); + MovementsCommon movement = read(AbstractCommonListUtils.ListItemGetCSID(item)); firstFieldValues.add(i, movement.getLocationDate()); secondFieldValues.add(i, movement.getMovementNote()); if (logger.isDebugEnabled()) { @@ -459,7 +464,7 @@ public class MovementSortByTest extends BaseServiceTest { // Submit the request to the service and store the response. MovementClient client = new MovementClient(); final String EMPTY_SORT_FIELD_NAME = ""; - ClientResponse res = + ClientResponse res = client.readListSortedBy(EMPTY_SORT_FIELD_NAME); int statusCode = res.getStatus(); @@ -491,7 +496,7 @@ public class MovementSortByTest extends BaseServiceTest { // Submit the request to the service and store the response. MovementClient client = new MovementClient(); - ClientResponse res = + ClientResponse res = client.readListSortedBy(MovementJAXBSchema.LOCATION_DATE); int statusCode = res.getStatus(); @@ -521,7 +526,7 @@ public class MovementSortByTest extends BaseServiceTest { // Submit the request to the service and store the response. MovementClient client = new MovementClient(); final String INVALID_SORT_ORDER_IDENTIFIER = "NO_DIRECTION"; - ClientResponse res = + ClientResponse res = client.readListSortedBy(MovementJAXBSchema.LOCATION_DATE + " " + INVALID_SORT_ORDER_IDENTIFIER); int statusCode = res.getStatus(); @@ -749,7 +754,7 @@ public class MovementSortByTest extends BaseServiceTest { return multipart; } - private MovementsCommonList readSortedList(String sortFieldName) throws Exception { + private AbstractCommonList readSortedList(String sortFieldName) throws Exception { String testName = "readSortedList"; testSetup(STATUS_OK, ServiceRequestType.READ); @@ -757,9 +762,9 @@ public class MovementSortByTest extends BaseServiceTest { // Submit the request to the service and store the response. MovementClient client = new MovementClient(); - ClientResponse res = + ClientResponse res = client.readListSortedBy(sortFieldName); - MovementsCommonList list = res.getEntity(); + AbstractCommonList list = res.getEntity(); int statusCode = res.getStatus(); // Check the status code of the response: does it match @@ -775,7 +780,7 @@ public class MovementSortByTest extends BaseServiceTest { } - private MovementsCommonList keywordSearchSortedBy(String keywords, + private AbstractCommonList keywordSearchSortedBy(String keywords, String sortFieldName) throws Exception { String testName = "keywordSearchSortedBy"; @@ -784,9 +789,9 @@ public class MovementSortByTest extends BaseServiceTest { // Submit the request to the service and store the response. MovementClient client = new MovementClient(); - ClientResponse res = + ClientResponse res = client.keywordSearchSortedBy(keywords, sortFieldName); - MovementsCommonList list = res.getEntity(); + AbstractCommonList list = res.getEntity(); int statusCode = res.getStatus(); // Check the status code of the response: does it match diff --git a/services/movement/jaxb/src/main/resources/movements-common.xsd b/services/movement/jaxb/src/main/resources/movements-common.xsd index 66ea55441..511846092 100644 --- a/services/movement/jaxb/src/main/resources/movements-common.xsd +++ b/services/movement/jaxb/src/main/resources/movements-common.xsd @@ -54,43 +54,5 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/services/movement/service/src/main/java/org/collectionspace/services/movement/nuxeo/MovementDocumentModelHandler.java b/services/movement/service/src/main/java/org/collectionspace/services/movement/nuxeo/MovementDocumentModelHandler.java index 4bb538d31..989d15e97 100644 --- a/services/movement/service/src/main/java/org/collectionspace/services/movement/nuxeo/MovementDocumentModelHandler.java +++ b/services/movement/service/src/main/java/org/collectionspace/services/movement/nuxeo/MovementDocumentModelHandler.java @@ -23,23 +23,8 @@ */ package org.collectionspace.services.movement.nuxeo; -import java.util.GregorianCalendar; -import java.util.Iterator; -import java.util.List; - -import org.collectionspace.services.MovementJAXBSchema; -import org.collectionspace.services.common.datetime.DateTimeFormatUtils; -import org.collectionspace.services.common.document.DocumentWrapper; -import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.movement.MovementsCommon; -import org.collectionspace.services.movement.MovementsCommonList; -import org.collectionspace.services.movement.MovementsCommonList.MovementListItem; -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.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.collectionspace.services.nuxeo.client.java.DocHandlerBase; /** * The Class MovementDocumentModelHandler. @@ -48,126 +33,7 @@ import org.slf4j.LoggerFactory; * $LastChangedDate$ */ public class MovementDocumentModelHandler - extends RemoteDocumentModelHandlerImpl { - - /** The logger. */ - private final Logger logger = LoggerFactory.getLogger(MovementDocumentModelHandler.class); - - /** The Movement. */ - private MovementsCommon Movement; - - /** The Movement list. */ - private MovementsCommonList MovementList; - - /** - * Gets the common part. - * - * @return the common part - */ - @Override - public MovementsCommon getCommonPart() { - return Movement; - } - - /** - * Sets the common part. - * - * @param Movement the new common part - */ - @Override - public void setCommonPart(MovementsCommon Movement) { - this.Movement = Movement; - } - - /** - * Gets the common part list. - * - * @return the common part list - */ - @Override - public MovementsCommonList getCommonPartList() { - return MovementList; - } - - /** - * Sets the common part list. - * - * @param MovementList the new common part list - */ - @Override - public void setCommonPartList(MovementsCommonList MovementList) { - this.MovementList = MovementList; - } - - /** - * Extract common part. - * - * @param wrapDoc the wrap doc - * @return the Movements common - * @throws Exception the exception - */ - @Override - public MovementsCommon extractCommonPart(DocumentWrapper wrapDoc) - throws Exception { - throw new UnsupportedOperationException(); - } - - /** - * Fill common part. - * - * @param MovementObject the Movement object - * @param wrapDoc the wrap doc - * @throws Exception the exception - */ - @Override - public void fillCommonPart(MovementsCommon MovementObject, DocumentWrapper wrapDoc) throws Exception { - throw new UnsupportedOperationException(); - } - - /** - * Extract common part list. - * - * @param wrapDoc the wrap doc - * @return the Movements common list - * @throws Exception the exception - */ - @Override - public MovementsCommonList extractCommonPartList(DocumentWrapper wrapDoc) throws Exception { - MovementsCommonList coList = extractPagingInfo(new MovementsCommonList(), wrapDoc); - AbstractCommonList commonList = (AbstractCommonList) coList; - commonList.setFieldsReturned("movementReferenceNumber|currentLocation|locationDate|uri|csid"); - List list = coList.getMovementListItem(); - Iterator iter = wrapDoc.getWrappedObject().iterator(); - String label = getServiceContext().getCommonPartLabel(); - while(iter.hasNext()){ - DocumentModel docModel = iter.next(); - MovementListItem ilistItem = new MovementListItem(); - ilistItem.setMovementReferenceNumber((String) docModel.getProperty(label, - MovementJAXBSchema.MOVEMENT_REFERENCE_NUMBER)); - ilistItem.setCurrentLocation((String) docModel.getProperty(label, - MovementJAXBSchema.CURRENT_LOCATION)); - GregorianCalendar gcal = (GregorianCalendar) docModel.getProperty(label, - MovementJAXBSchema.LOCATION_DATE); - ilistItem.setLocationDate(DateTimeFormatUtils.formatAsISO8601Timestamp(gcal)); - String id = getCsid(docModel);//NuxeoUtils.extractId(docModel.getPathAsString()); - ilistItem.setUri(getServiceContextPath() + id); - ilistItem.setCsid(id); - list.add(ilistItem); - } - - return coList; - } - - /** - * Gets the q property. - * - * @param prop the prop - * @return the q property - */ - @Override - public String getQProperty(String prop) { - return MovementConstants.NUXEO_SCHEMA_NAME + ":" + prop; - } + extends DocHandlerBase { } diff --git a/services/objectexit/client/src/test/java/org/collectionspace/services/client/test/ObjectExitServiceTest.java b/services/objectexit/client/src/test/java/org/collectionspace/services/client/test/ObjectExitServiceTest.java index f72ef4bc2..5722e26c4 100644 --- a/services/objectexit/client/src/test/java/org/collectionspace/services/client/test/ObjectExitServiceTest.java +++ b/services/objectexit/client/src/test/java/org/collectionspace/services/client/test/ObjectExitServiceTest.java @@ -30,6 +30,7 @@ import org.collectionspace.services.client.ObjectExitClient; import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; +import org.collectionspace.services.common.AbstractCommonListUtils; import org.collectionspace.services.jaxb.AbstractCommonList; import org.collectionspace.services.objectexit.ObjectexitCommon; @@ -130,7 +131,7 @@ public class ObjectExitServiceTest extends AbstractServiceTestImpl { // Optionally output additional data about list members for debugging. boolean iterateThroughList = true; if(iterateThroughList && logger.isDebugEnabled()){ - ListItemsInAbstractCommonList(list, logger, testName); + AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); } } diff --git a/services/report/client/src/test/java/org/collectionspace/services/client/test/ReportServiceTest.java b/services/report/client/src/test/java/org/collectionspace/services/client/test/ReportServiceTest.java index 673b14f47..bfbf7a9ae 100644 --- a/services/report/client/src/test/java/org/collectionspace/services/client/test/ReportServiceTest.java +++ b/services/report/client/src/test/java/org/collectionspace/services/client/test/ReportServiceTest.java @@ -33,6 +33,7 @@ import org.collectionspace.services.client.PayloadOutputPart; import org.collectionspace.services.client.PoxPayloadIn; import org.collectionspace.services.client.PoxPayloadOut; import org.collectionspace.services.client.ReportClient; +import org.collectionspace.services.common.AbstractCommonListUtils; import org.collectionspace.services.report.ReportsCommon; import org.collectionspace.services.jaxb.AbstractCommonList; @@ -286,9 +287,8 @@ public class ReportServiceTest extends AbstractServiceTestImpl { Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); // Optionally output additional data about list members for debugging. - boolean iterateThroughList = false; - if (iterateThroughList && logger.isDebugEnabled()) { - ListItemsInAbstractCommonList(list, logger, testName); + if(logger.isTraceEnabled()){ + AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName); } } @@ -322,7 +322,7 @@ public class ReportServiceTest extends AbstractServiceTestImpl { // We must find the basic one we created boolean fFoundBaseItem = false; for (AbstractCommonList.ListItem item : items) { - if(knownResourceId.equalsIgnoreCase(ListItemGetCSID(item))) { + if(knownResourceId.equalsIgnoreCase(AbstractCommonListUtils.ListItemGetCSID(item))) { fFoundBaseItem = true; break; } @@ -347,7 +347,7 @@ public class ReportServiceTest extends AbstractServiceTestImpl { items = list.getListItem(); // We must NOT find the basic one we created for (AbstractCommonList.ListItem item : items) { - Assert.assertNotSame(ListItemGetCSID(item), knownResourceId, + Assert.assertNotSame(AbstractCommonListUtils.ListItemGetCSID(item), knownResourceId, "readListFiltered(\"Intake\", \"single\") incorrectly returned base item"); } @@ -368,7 +368,7 @@ public class ReportServiceTest extends AbstractServiceTestImpl { items = list.getListItem(); // We must NOT find the basic one we created for (AbstractCommonList.ListItem item : items) { - Assert.assertNotSame(ListItemGetCSID(item), knownResourceId, + Assert.assertNotSame(AbstractCommonListUtils.ListItemGetCSID(item), knownResourceId, "readListFiltered(\""+testDocType+"\", \"group\") incorrectly returned base item"); } }