SF Patch #1594208 for bug #1592984 Date comparisons strip time in org.dspace.harvest.Harvest

git-svn-id: http://scm.dspace.org/svn/repo/trunk@1686 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
Scott Yeadon
2006-11-24 00:44:03 +00:00
parent ec66150373
commit 52cc683e55
5 changed files with 131 additions and 60 deletions

View File

@@ -1,3 +1,6 @@
(Stuart Lewis)
- SF Patch #1594208 for bug #1592984 Date comparisons strip time in org.dspace.harvest.Harvest
(Scott Phillips) (Scott Phillips)
- Manakin eperson.patch adds API methods for searching epeople & groups. - Manakin eperson.patch adds API methods for searching epeople & groups.

View File

@@ -40,6 +40,7 @@
package org.dspace.app.oai; package org.dspace.app.oai;
import java.sql.SQLException; import java.sql.SQLException;
import java.text.ParseException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
@@ -268,6 +269,10 @@ public class DSpaceOAICatalog extends AbstractCatalog
throw new OAIInternalServerError(se.toString()); throw new OAIInternalServerError(se.toString());
} }
catch (ParseException pe)
{
throw new OAIInternalServerError(pe.toString());
}
finally finally
{ {
if (context != null) if (context != null)
@@ -621,6 +626,10 @@ public class DSpaceOAICatalog extends AbstractCatalog
throw new OAIInternalServerError(se.toString()); throw new OAIInternalServerError(se.toString());
} }
catch (ParseException pe)
{
throw new OAIInternalServerError(pe.toString());
}
finally finally
{ {
if (context != null) if (context != null)

View File

@@ -43,6 +43,7 @@ package org.dspace.app.webui.servlet;
import java.io.IOException; import java.io.IOException;
import java.sql.SQLException; import java.sql.SQLException;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.text.ParseException;
import java.util.Date; import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.Locale; import java.util.Locale;
@@ -271,9 +272,16 @@ public class FeedServlet extends DSpaceServlet
String endDate = dcEndDate.toString().substring(0, 10); String endDate = dcEndDate.toString().substring(0, 10);
// this invocation should return a non-empty list if even 1 item has changed // this invocation should return a non-empty list if even 1 item has changed
try {
return (Harvest.harvest(context, dso, startDate, endDate, return (Harvest.harvest(context, dso, startDate, endDate,
0, 1, false, false, false).size() > 0); 0, 1, false, false, false).size() > 0);
} }
catch (ParseException pe)
{
// This should never get thrown as we have generated the dates ourselves
return false;
}
}
/** /**
* Generate a syndication feed for a collection or community * Generate a syndication feed for a collection or community

View File

@@ -41,6 +41,7 @@ package org.dspace.eperson;
import java.io.IOException; import java.io.IOException;
import java.sql.SQLException; import java.sql.SQLException;
import java.text.ParseException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@@ -343,6 +344,7 @@ public class Subscribe
{ {
Collection c = (Collection) collections.get(i); Collection c = (Collection) collections.get(i);
try {
List itemInfos = Harvest.harvest(context, c, startDate, endDate, 0, // Limit List itemInfos = Harvest.harvest(context, c, startDate, endDate, 0, // Limit
// and // and
// offset // offset
@@ -408,6 +410,11 @@ public class Subscribe
} }
} }
} }
catch (ParseException pe)
{
// This should never get thrown as the Dates are auto-generated
}
}
// Send an e-mail if there were any new items // Send an e-mail if there were any new items
if (emailText.length() > 0) if (emailText.length() > 0)

View File

@@ -39,10 +39,16 @@
*/ */
package org.dspace.search; package org.dspace.search;
import java.sql.Date;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.TimeZone;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.dspace.content.DSpaceObject; import org.dspace.content.DSpaceObject;
@@ -108,11 +114,12 @@ public class Harvest
* included * included
* @return List of <code>HarvestedItemInfo</code> objects * @return List of <code>HarvestedItemInfo</code> objects
* @throws SQLException * @throws SQLException
* @throws ParseException If the date is not in a supported format
*/ */
public static List harvest(Context context, DSpaceObject scope, public static List harvest(Context context, DSpaceObject scope,
String startDate, String endDate, int offset, int limit, String startDate, String endDate, int offset, int limit,
boolean items, boolean collections, boolean withdrawn) boolean items, boolean collections, boolean withdrawn)
throws SQLException throws SQLException, ParseException
{ {
// Put together our query. Note there is no need for an // Put together our query. Note there is no need for an
@@ -171,7 +178,7 @@ public class Harvest
else //postgres else //postgres
{ {
query = query + " AND item.last_modified >= ? "; query = query + " AND item.last_modified >= ? ";
parameters.add(startDate); parameters.add(toTimestamp(startDate, false));
} }
} }
@@ -195,9 +202,11 @@ public class Harvest
* *
* Got that? ;-) * Got that? ;-)
*/ */
boolean selfGenerated = false;
if (endDate.length() == 20) if (endDate.length() == 20)
{ {
endDate = endDate.substring(0, 19) + ".999Z"; endDate = endDate.substring(0, 19) + ".999Z";
selfGenerated = true;
} }
if ("oracle".equals(ConfigurationManager.getProperty("db.name"))) if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
@@ -210,7 +219,7 @@ public class Harvest
else //postgres else //postgres
{ {
query += " AND item.last_modified <= ? "; query += " AND item.last_modified <= ? ";
parameters.add(endDate); parameters.add(toTimestamp(endDate, selfGenerated));
} }
} }
@@ -358,6 +367,41 @@ public class Harvest
} }
/**
* Convert a String to a java.sql.Timestamp object
*
* @param t The timestamp String
* @param selfGenerated Is this a self generated timestamp (e.g. it has .999 on the end)
* @return The converted Timestamp
* @throws ParseException
*/
private static Timestamp toTimestamp(String t, boolean selfGenerated) throws ParseException
{
SimpleDateFormat df;
// Choose the correct date format based on string length
if (t.length() == 10)
{
df = new SimpleDateFormat("yyyy-MM-dd");
}
else if (t.length() == 20)
{
df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
}
else if (selfGenerated)
{
df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
}
else {
// Not self generated, and not in a guessable format
throw new ParseException("", 0);
}
// Parse the date
df.setCalendar(Calendar.getInstance(TimeZone.getTimeZone("UTC")));
return new Timestamp(df.parse(t).getTime());
}
/** /**
* Create an oracle to_timestamp function for the given iso date. It must be * Create an oracle to_timestamp function for the given iso date. It must be