[DS-401] Backed out as it raised more questions than it answered.

git-svn-id: http://scm.dspace.org/svn/repo/dspace/trunk@5822 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
Robin Taylor
2010-11-10 20:00:42 +00:00
parent 05a85b7b0e
commit 8f3419b09a
6 changed files with 18 additions and 81 deletions

View File

@@ -150,7 +150,7 @@ public class DCDate
* @param ss * @param ss
* the seconds * 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(); setUTCForFormatting();
@@ -194,20 +194,8 @@ public class DCDate
} }
// Set the local calendar. // Set the local calendar.
localCalendar = new GregorianCalendar(); localCalendar = new GregorianCalendar(lyear, lmonth - 1, lday,
localCalendar.setLenient(false); lhours, lminutes, lseconds);
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);
}
if (granularity == DateGran.TIME) if (granularity == DateGran.TIME)
{ {

View File

@@ -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);
}
}

View File

@@ -203,18 +203,7 @@ public class InstallItem
if (currentDateIssued.length == 0) if (currentDateIssued.length == 0)
{ {
DCDate issued = null; DCDate issued = new DCDate(now.getYear(),now.getMonth(),now.getDay(),-1,-1,-1);
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);
}
item.addDC("date", "issued", null, issued.toString()); item.addDC("date", "issued", null, issued.toString());
} }

View File

@@ -55,7 +55,13 @@ import org.dspace.app.util.DCInput;
import org.dspace.app.util.SubmissionInfo; import org.dspace.app.util.SubmissionInfo;
import org.dspace.app.util.Util; import org.dspace.app.util.Util;
import org.dspace.authorize.AuthorizeException; 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.MetadataAuthorityManager;
import org.dspace.content.authority.ChoiceAuthorityManager; import org.dspace.content.authority.ChoiceAuthorityManager;
import org.dspace.content.authority.Choices; import org.dspace.content.authority.Choices;
@@ -787,7 +793,9 @@ public class DescribeStep extends AbstractProcessingStep
int month = Util.getIntParameter(request, metadataField + "_month"); int month = Util.getIntParameter(request, metadataField + "_month");
int day = Util.getIntParameter(request, metadataField + "_day"); 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 // already done in doProcessing see also bug DS-203
// item.clearMetadata(schema, element, qualifier, Item.ANY); // item.clearMetadata(schema, element, qualifier, Item.ANY);
@@ -795,17 +803,7 @@ public class DescribeStep extends AbstractProcessingStep
if (year > 0) if (year > 0)
{ {
// Only put in date if there is one! // Only put in date if there is one!
item.addMetadata(schema, element, qualifier, null, d.toString());
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.
}
} }
} }

View File

@@ -161,9 +161,8 @@ public class DCDateTest extends AbstractUnitTest
* Test of DCDate constructor, of class DCDate. * Test of DCDate constructor, of class DCDate.
*/ */
@Test @Test
public void testDCDateIntBits() throws DCDateIllegalArgumentException public void testDCDateIntBits()
{ {
dc = new DCDate(2010,1,1,-1,-1,-1); dc = new DCDate(2010,1,1,-1,-1,-1);
assertThat("testDCDateIntBits 1", dc.getYear(), equalTo(2010)); assertThat("testDCDateIntBits 1", dc.getYear(), equalTo(2010));
@@ -198,16 +197,6 @@ public class DCDateTest extends AbstractUnitTest
} }
/**
* 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);
}
/** /**
* Test of DCDate constructor, of class DCDate. * Test of DCDate constructor, of class DCDate.
*/ */

View File

@@ -81,7 +81,7 @@
<hint>Please give the date of previous publication or public distribution <hint>Please give the date of previous publication or public distribution
below. You can leave out the day and/or month if they aren't below. You can leave out the day and/or month if they aren't
applicable.</hint> applicable.</hint>
<required>You must enter a valid complete or partial date.</required> <required>You must enter at least the year.</required>
</field> </field>
<field> <field>