From 3c6f6c492f6dda7e34ad13faf0d9030dbf6fa8e6 Mon Sep 17 00:00:00 2001 From: Aron Roberts Date: Mon, 23 Aug 2010 20:40:32 +0000 Subject: [PATCH] CSPACE-2677: Services document framework (and Movement service, in which date fields are first being prototyped) once again allows entry of blank / empty dates in date fields, an obvious requirement in retrospect. --- .../common/document/DocumentUtils.java | 31 +++++++++++-------- .../client/test/MovementServiceTest.java | 25 ++++++++++++--- 2 files changed, 38 insertions(+), 18 deletions(-) diff --git a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java index dbb5019f7..d4334cc34 100644 --- a/services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java +++ b/services/common/src/main/java/org/collectionspace/services/common/document/DocumentUtils.java @@ -1111,19 +1111,24 @@ public class DocumentUtils { if (type.isSimpleType()) { if (isDateType(type)) { - // Dates or date/times in ISO 8601-based representations - // directly supported by Nuxeo will be successfully decoded. - result = type.decode(element.getText()); - // All other date or date/time values must first be converted - // to a supported ISO 8601-based representation. - if (result == null) { - dateStr = DateTimeFormatUtils.toIso8601Timestamp(element.getText(), - ctx.getTenantId()); - if (dateStr != null) { - result = type.decode(dateStr); - } else { - throw new IllegalArgumentException("Unrecognized date value '" - + element.getText() + "' in field '" + element.getName() + "'"); + String value = element.getText(); + if (value == null || value.trim().isEmpty()) { + result = type.decode(""); + } else { + // Dates or date/times in ISO 8601-based representations + // directly supported by Nuxeo will be successfully decoded. + result = type.decode(element.getText()); + // All other date or date/time values must first be converted + // to a supported ISO 8601-based representation. + if (result == null) { + dateStr = DateTimeFormatUtils.toIso8601Timestamp(element.getText(), + ctx.getTenantId()); + if (dateStr != null) { + result = type.decode(dateStr); + } else { + throw new IllegalArgumentException("Unrecognized date value '" + + element.getText() + "' in field '" + element.getName() + "'"); + } } } } else { 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 e3e08fde6..b8d2c9368 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 @@ -315,7 +315,7 @@ public class MovementServiceTest extends AbstractServiceTestImpl { } Assert.assertTrue(movement.getLocationDate().equals(TIMESTAMP_UTC)); Assert.assertTrue(movement.getPlannedRemovalDate().equals(TIMESTAMP_UTC)); - Assert.assertTrue(movement.getRemovalDate().equals(TIMESTAMP_UTC)); + Assert.assertNull(movement.getRemovalDate()); } // Failure outcomes @@ -446,6 +446,10 @@ public class MovementServiceTest extends AbstractServiceTestImpl { logger.debug("to be updated object"); logger.debug(objectAsXmlString(movement, MovementsCommon.class)); } + String currentTimestamp = GregorianCalendarDateTimeUtils.timestampUTC(); + movement.setPlannedRemovalDate(""); // Test deletion of existing date or date/time value + movement.setRemovalDate(currentTimestamp); + // Submit the request to the service and store the response. MultipartOutput output = new MultipartOutput(); OutputPart commonPart = output.addPart(movement, MediaType.APPLICATION_XML_TYPE); @@ -461,16 +465,27 @@ public class MovementServiceTest extends AbstractServiceTestImpl { invalidStatusCodeMessage(REQUEST_TYPE, statusCode)); Assert.assertEquals(statusCode, EXPECTED_STATUS_CODE); - input = (MultipartInput) res.getEntity(); MovementsCommon updatedMovement = (MovementsCommon) extractPart(input, client.getCommonPartName(), MovementsCommon.class); Assert.assertNotNull(updatedMovement); + if(logger.isDebugEnabled()){ + logger.debug("updated object"); + logger.debug(objectAsXmlString(movement, MovementsCommon.class)); + } + + Assert.assertEquals(updatedMovement.getMovementReferenceNumber(), + movement.getMovementReferenceNumber(), + "Data in updated object did not match submitted data."); Assert.assertEquals(updatedMovement.getMovementNote(), - movement.getMovementNote(), - "Data in updated object did not match submitted data."); + movement.getMovementNote(), + "Data in updated object did not match submitted data."); + Assert.assertNull(updatedMovement.getPlannedRemovalDate()); + Assert.assertEquals(updatedMovement.getRemovalDate(), + movement.getRemovalDate(), + "Data in updated object did not match submitted data."); } @@ -763,7 +778,7 @@ public class MovementServiceTest extends AbstractServiceTestImpl { movement.setMovementNote("movementNote value"); movement.setMovementReferenceNumber(movementReferenceNumber); movement.setPlannedRemovalDate(TIMESTAMP_UTC); - movement.setRemovalDate(TIMESTAMP_UTC); + movement.setRemovalDate(""); // Test empty date value movement.setReasonForMove("reasonForMove value"); MultipartOutput multipart = new MultipartOutput(); OutputPart commonPart = -- 2.47.3