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)
- Manakin eperson.patch adds API methods for searching epeople & groups.

View File

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

View File

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

View File

@@ -41,6 +41,7 @@ package org.dspace.eperson;
import java.io.IOException;
import java.sql.SQLException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
@@ -343,70 +344,76 @@ public class Subscribe
{
Collection c = (Collection) collections.get(i);
List itemInfos = Harvest.harvest(context, c, startDate, endDate, 0, // Limit
// and
// offset
// zero,
// get
// everything
0, true, // Need item objects
false, // But not containers
false); // Or withdrawals
// Only add to buffer if there are new items
if (itemInfos.size() > 0)
{
if (!isFirst)
try {
List itemInfos = Harvest.harvest(context, c, startDate, endDate, 0, // Limit
// and
// offset
// zero,
// get
// everything
0, true, // Need item objects
false, // But not containers
false); // Or withdrawals
// Only add to buffer if there are new items
if (itemInfos.size() > 0)
{
emailText
.append("\n---------------------------------------\n");
}
else
{
isFirst = false;
}
emailText.append("New items in collection ").append(
c.getMetadata("name")).append(": ").append(
itemInfos.size()).append("\n\n");
for (int j = 0; j < itemInfos.size(); j++)
{
HarvestedItemInfo hii = (HarvestedItemInfo) itemInfos
.get(j);
DCValue[] titles = hii.item.getDC("title", null, Item.ANY);
emailText.append(" Title: ");
if (titles.length > 0)
if (!isFirst)
{
emailText.append(titles[0].value);
emailText
.append("\n---------------------------------------\n");
}
else
{
emailText.append("Untitled");
isFirst = false;
}
DCValue[] authors = hii.item.getDC("contributor", Item.ANY,
Item.ANY);
if (authors.length > 0)
emailText.append("New items in collection ").append(
c.getMetadata("name")).append(": ").append(
itemInfos.size()).append("\n\n");
for (int j = 0; j < itemInfos.size(); j++)
{
emailText.append("\n Authors: ").append(
authors[0].value);
for (int k = 1; k < authors.length; k++)
HarvestedItemInfo hii = (HarvestedItemInfo) itemInfos
.get(j);
DCValue[] titles = hii.item.getDC("title", null, Item.ANY);
emailText.append(" Title: ");
if (titles.length > 0)
{
emailText.append("\n ").append(
authors[k].value);
emailText.append(titles[0].value);
}
else
{
emailText.append("Untitled");
}
DCValue[] authors = hii.item.getDC("contributor", Item.ANY,
Item.ANY);
if (authors.length > 0)
{
emailText.append("\n Authors: ").append(
authors[0].value);
for (int k = 1; k < authors.length; k++)
{
emailText.append("\n ").append(
authors[k].value);
}
}
emailText.append("\n ID: ").append(
HandleManager.getCanonicalForm(hii.handle)).append(
"\n\n");
}
emailText.append("\n ID: ").append(
HandleManager.getCanonicalForm(hii.handle)).append(
"\n\n");
}
}
catch (ParseException pe)
{
// This should never get thrown as the Dates are auto-generated
}
}
// Send an e-mail if there were any new items

View File

@@ -39,10 +39,16 @@
*/
package org.dspace.search;
import java.sql.Date;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.LinkedList;
import java.util.List;
import java.util.TimeZone;
import org.apache.log4j.Logger;
import org.dspace.content.DSpaceObject;
@@ -108,11 +114,12 @@ public class Harvest
* included
* @return List of <code>HarvestedItemInfo</code> objects
* @throws SQLException
* @throws ParseException If the date is not in a supported format
*/
public static List harvest(Context context, DSpaceObject scope,
String startDate, String endDate, int offset, int limit,
boolean items, boolean collections, boolean withdrawn)
throws SQLException
throws SQLException, ParseException
{
// Put together our query. Note there is no need for an
@@ -170,8 +177,8 @@ public class Harvest
}
else //postgres
{
query = query + " AND item.last_modified >= ? ";
parameters.add(startDate);
query = query + " AND item.last_modified >= ? ";
parameters.add(toTimestamp(startDate, false));
}
}
@@ -195,9 +202,11 @@ public class Harvest
*
* Got that? ;-)
*/
boolean selfGenerated = false;
if (endDate.length() == 20)
{
endDate = endDate.substring(0, 19) + ".999Z";
selfGenerated = true;
}
if ("oracle".equals(ConfigurationManager.getProperty("db.name")))
@@ -209,11 +218,11 @@ public class Harvest
}
else //postgres
{
query += " AND item.last_modified <= ? ";
parameters.add(endDate);
query += " AND item.last_modified <= ? ";
parameters.add(toTimestamp(endDate, selfGenerated));
}
}
if (withdrawn == false)
{
// Exclude withdrawn items
@@ -356,8 +365,43 @@ public class Harvest
itemInfo.collectionHandles.add(r.getStringColumn("handle"));
}
}
/**
* 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