diff --git a/dspace-api/src/main/java/org/dspace/content/DCDate.java b/dspace-api/src/main/java/org/dspace/content/DCDate.java index ae72c954b7..05483793e6 100644 --- a/dspace-api/src/main/java/org/dspace/content/DCDate.java +++ b/dspace-api/src/main/java/org/dspace/content/DCDate.java @@ -150,7 +150,7 @@ public class DCDate * @param ss * the seconds */ - public DCDate(int yyyy, int mm, int dd, int hh, int mn, int ss) throws DCDateIllegalArgumentException + public DCDate(int yyyy, int mm, int dd, int hh, int mn, int ss) { setUTCForFormatting(); @@ -194,20 +194,8 @@ public class DCDate } // Set the local calendar. - localCalendar = new GregorianCalendar(); - localCalendar.setLenient(false); - localCalendar.set(lyear, lmonth - 1, lday, lhours, lminutes, lseconds); - try - { - // Unfortunately GregorianCalendar doesn't throw an exception when you 'set' an invalid value so - // we have to call a method that causes all the values to be inspected in order to check that they are valid. - localCalendar.get(Calendar.YEAR); - } - catch (IllegalArgumentException e) - { - // Re-throw exception as a checked exception so that the calling classes have to deal with it. - throw new DCDateIllegalArgumentException("Invalid parameter", e); - } + localCalendar = new GregorianCalendar(lyear, lmonth - 1, lday, + lhours, lminutes, lseconds); if (granularity == DateGran.TIME) { diff --git a/dspace-api/src/main/java/org/dspace/content/DCDateIllegalArgumentException.java b/dspace-api/src/main/java/org/dspace/content/DCDateIllegalArgumentException.java deleted file mode 100644 index 83710c9d64..0000000000 --- a/dspace-api/src/main/java/org/dspace/content/DCDateIllegalArgumentException.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.dspace.content; - - -public class DCDateIllegalArgumentException extends Exception -{ - - public DCDateIllegalArgumentException() - { - super(); - } - - public DCDateIllegalArgumentException(String arg0, Throwable arg1) - { - super(arg0, arg1); - } - - public DCDateIllegalArgumentException(String arg0) - { - super(arg0); - } - - public DCDateIllegalArgumentException(Throwable arg0) - { - super(arg0); - } - -} diff --git a/dspace-api/src/main/java/org/dspace/content/InstallItem.java b/dspace-api/src/main/java/org/dspace/content/InstallItem.java index 0f7e9f40dd..9fbb2f04a1 100644 --- a/dspace-api/src/main/java/org/dspace/content/InstallItem.java +++ b/dspace-api/src/main/java/org/dspace/content/InstallItem.java @@ -203,18 +203,7 @@ public class InstallItem if (currentDateIssued.length == 0) { - DCDate issued = null; - try - { - issued = new DCDate(now.getYear(),now.getMonth(),now.getDay(),-1,-1,-1); - } - catch (DCDateIllegalArgumentException e) - { - // The parameters should never be invalid since they are generated from the current date, - // but we still have to deal with the exception anyway. - throw new RuntimeException(e); - } - + DCDate issued = new DCDate(now.getYear(),now.getMonth(),now.getDay(),-1,-1,-1); item.addDC("date", "issued", null, issued.toString()); } diff --git a/dspace-api/src/main/java/org/dspace/submit/step/DescribeStep.java b/dspace-api/src/main/java/org/dspace/submit/step/DescribeStep.java index 0e4130755d..ff21be3b98 100644 --- a/dspace-api/src/main/java/org/dspace/submit/step/DescribeStep.java +++ b/dspace-api/src/main/java/org/dspace/submit/step/DescribeStep.java @@ -55,7 +55,13 @@ import org.dspace.app.util.DCInput; import org.dspace.app.util.SubmissionInfo; import org.dspace.app.util.Util; import org.dspace.authorize.AuthorizeException; -import org.dspace.content.*; +import org.dspace.content.Collection; +import org.dspace.content.DCDate; +import org.dspace.content.DCPersonName; +import org.dspace.content.DCSeriesNumber; +import org.dspace.content.DCValue; +import org.dspace.content.Item; +import org.dspace.content.MetadataField; import org.dspace.content.authority.MetadataAuthorityManager; import org.dspace.content.authority.ChoiceAuthorityManager; import org.dspace.content.authority.Choices; @@ -787,7 +793,9 @@ public class DescribeStep extends AbstractProcessingStep int month = Util.getIntParameter(request, metadataField + "_month"); int day = Util.getIntParameter(request, metadataField + "_day"); - + // FIXME: Probably should be some more validation + // Make a standard format date + DCDate d = new DCDate(year, month, day, -1, -1, -1); // already done in doProcessing see also bug DS-203 // item.clearMetadata(schema, element, qualifier, Item.ANY); @@ -795,17 +803,7 @@ public class DescribeStep extends AbstractProcessingStep if (year > 0) { // Only put in date if there is one! - - try - { - DCDate d = new DCDate(year, month, day, -1, -1, -1); - item.addMetadata(schema, element, qualifier, null, d.toString()); - } - catch (DCDateIllegalArgumentException e) - { - // One or more of the DCDate parameters was invalid so don't add it to the metadata. - } - + item.addMetadata(schema, element, qualifier, null, d.toString()); } } diff --git a/dspace-api/src/test/java/org/dspace/content/DCDateTest.java b/dspace-api/src/test/java/org/dspace/content/DCDateTest.java index 13edc82f9f..0c42c4c22b 100644 --- a/dspace-api/src/test/java/org/dspace/content/DCDateTest.java +++ b/dspace-api/src/test/java/org/dspace/content/DCDateTest.java @@ -161,9 +161,8 @@ public class DCDateTest extends AbstractUnitTest * Test of DCDate constructor, of class DCDate. */ @Test - public void testDCDateIntBits() throws DCDateIllegalArgumentException + public void testDCDateIntBits() { - dc = new DCDate(2010,1,1,-1,-1,-1); assertThat("testDCDateIntBits 1", dc.getYear(), equalTo(2010)); @@ -195,17 +194,7 @@ public class DCDateTest extends AbstractUnitTest assertThat("testDCDateIntBits 22", dc.getHourUTC(), equalTo(2)); assertThat("testDCDateIntBits 23", dc.getMinuteUTC(), equalTo(30)); assertThat("testDCDateIntBits 24", dc.getSecondUTC(), equalTo(5)); - - } - - /** - * Additional tests of DCDate constructor checking for dodgy parameters. - */ - @Test (expected=DCDateIllegalArgumentException.class) - public void testDCDateIntBits1() throws DCDateIllegalArgumentException - { - dc = new DCDate(2010,2,29,18,30,5); - + } /** diff --git a/dspace/config/input-forms.xml b/dspace/config/input-forms.xml index cf1d49c593..6d111a2eb2 100644 --- a/dspace/config/input-forms.xml +++ b/dspace/config/input-forms.xml @@ -81,7 +81,7 @@ Please give the date of previous publication or public distribution below. You can leave out the day and/or month if they aren't applicable. - You must enter a valid complete or partial date. + You must enter at least the year.