[DS-2701] oai make commandline tool compile.

This commit is contained in:
Mark H. Wood
2015-08-20 16:18:25 -04:00
parent 021fba9d40
commit dd838ca5f5
5 changed files with 98 additions and 35 deletions

View File

@@ -207,6 +207,13 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
return itemDAO.findAllByCollection(context, collection); return itemDAO.findAllByCollection(context, collection);
} }
@Override
public Iterator<Item> findInArchiveOrWithdrawnDiscoverableModifiedSince(Context context, Date since)
throws SQLException
{
return itemDAO.findInArchiveOrWithdrawnDiscoverableModifiedSince(context, since);
}
@Override @Override
public void updateLastModified(Context context, Item item) throws SQLException, AuthorizeException { public void updateLastModified(Context context, Item item) throws SQLException, AuthorizeException {
item.setLastModified(new Date()); item.setLastModified(new Date());
@@ -1132,4 +1139,11 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
public Item findByLegacyId(Context context, int id) throws SQLException { public Item findByLegacyId(Context context, int id) throws SQLException {
return itemDAO.findByLegacyId(context, id, Item.class); return itemDAO.findByLegacyId(context, id, Item.class);
} }
@Override
public Iterator<Item> findByLastModifiedSince(Context context, Date last)
throws SQLException
{
return itemDAO.findByLastModifiedSince(context, last);
}
} }

View File

@@ -14,6 +14,7 @@ import org.dspace.core.Context;
import org.dspace.eperson.EPerson; import org.dspace.eperson.EPerson;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
/** /**
@@ -29,6 +30,16 @@ public interface ItemDAO extends DSpaceObjectLegacySupportDAO<Item>
public Iterator<Item> findAll(Context context, boolean archived, boolean withdrawn) throws SQLException; public Iterator<Item> findAll(Context context, boolean archived, boolean withdrawn) throws SQLException;
/**
* Find all Items modified since a Date.
*
* @param context
* @param since Earliest interesting last-modified date.
* @return
*/
public Iterator<Item> findByLastModifiedSince(Context context, Date since)
throws SQLException;
public Iterator<Item> findBySubmitter(Context context, EPerson eperson) throws SQLException; public Iterator<Item> findBySubmitter(Context context, EPerson eperson) throws SQLException;
public Iterator<Item> findBySubmitter(Context context, EPerson eperson, MetadataField metadataField, int limit) throws SQLException; public Iterator<Item> findBySubmitter(Context context, EPerson eperson, MetadataField metadataField, int limit) throws SQLException;
@@ -42,4 +53,14 @@ public interface ItemDAO extends DSpaceObjectLegacySupportDAO<Item>
public Iterator<Item> findAllByCollection(Context context, Collection collection) throws SQLException; public Iterator<Item> findAllByCollection(Context context, Collection collection) throws SQLException;
public int countItems(Context context, Collection collection, boolean includeArchived, boolean includeWithdrawn) throws SQLException; public int countItems(Context context, Collection collection, boolean includeArchived, boolean includeWithdrawn) throws SQLException;
/**
* Get all Items installed or withdrawn, discoverable, and modified since a Date.
* @param context
* @param since earliest interesting last-modified date, or null for no date test.
* @return
*/
public Iterator<Item> findInArchiveOrWithdrawnDiscoverableModifiedSince(
Context context, Date since)
throws SQLException;
} }

View File

@@ -18,6 +18,7 @@ import org.hibernate.Query;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Collections; import java.util.Collections;
import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
/** /**
@@ -126,4 +127,36 @@ public class ItemDAOImpl extends AbstractHibernateDSODAO<Item> implements ItemDA
return count(query); return count(query);
} }
private static final String FIND_ALL
= "select item_id FROM item WHERE (in_archive=TRUE OR withdrawn=TRUE)"
+ " AND discoverable=TRUE";
private static final String FIND_SINCE
= "select item_id FROM item WHERE (in_archive=TRUE OR withdrawn=TRUE)"
+ " AND discoverable=TRUE AND last_modified > :last_modified";
@Override
public Iterator<Item> findInArchiveOrWithdrawnDiscoverableModifiedSince(
Context context, Date since)
throws SQLException
{
Query query;
if (null == since){
query = createQuery(context, FIND_ALL);
}
else
{
query = createQuery(context, FIND_SINCE);
query.setParameter("last_modified", since);
}
return iterate(query);
}
@Override
public Iterator<Item> findByLastModifiedSince(Context context, Date since)
throws SQLException
{
Query query = createQuery(context, "SELECT * FROM item WHERE last_modified > :last_modified");
query.setParameter("last_modified", since);
return iterate(query);
}
} }

View File

@@ -17,6 +17,7 @@ import org.dspace.eperson.Group;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@@ -116,6 +117,15 @@ public interface ItemService extends DSpaceObjectService<Item>, DSpaceObjectLega
*/ */
public Iterator<Item> findByCollection(Context context, Collection collection, Integer limit, Integer offset) throws SQLException; public Iterator<Item> findByCollection(Context context, Collection collection, Integer limit, Integer offset) throws SQLException;
/**
* Get all Items installed or withdrawn, discoverable, and modified since a Date.
* @param context
* @param since earliest interesting last-modified date, or null for no date test.
* @return
*/
public Iterator<Item> findInArchiveOrWithdrawnDiscoverableModifiedSince(Context context, Date since)
throws SQLException;
/** /**
* Get all the items in this collection. The order is indeterminate. * Get all the items in this collection. The order is indeterminate.
* *
@@ -429,4 +439,14 @@ public interface ItemService extends DSpaceObjectService<Item>, DSpaceObjectLega
* @return total items * @return total items
*/ */
public int countItems(Context context, Collection collection) throws SQLException; public int countItems(Context context, Collection collection) throws SQLException;
/**
* Find all Items modified since a Date.
*
* @param context
* @param last Earliest interesting last-modified date.
* @return
*/
public Iterator<Item> findByLastModifiedSince(Context context, Date last)
throws SQLException;
} }

View File

@@ -168,16 +168,9 @@ public class XOAI {
+ last.toString()); + last.toString());
// Index both in_archive items AND withdrawn items. Withdrawn items will be flagged withdrawn // Index both in_archive items AND withdrawn items. Withdrawn items will be flagged withdrawn
// (in order to notify external OAI harvesters of their new status) // (in order to notify external OAI harvesters of their new status)
String sqlQuery = "SELECT item_id FROM item WHERE (in_archive=TRUE OR withdrawn=TRUE) AND discoverable=TRUE AND last_modified > ?";
if(DatabaseManager.isOracle()){
sqlQuery = "SELECT item_id FROM item WHERE (in_archive=1 OR withdrawn=1) AND discoverable=1 AND last_modified > ?";
}
try { try {
TableRowIterator iterator = DatabaseManager Iterator<Item> iterator = itemService.findInArchiveOrWithdrawnDiscoverableModifiedSince(
.query(context, context, last);
sqlQuery,
new java.sql.Timestamp(last.getTime()));
return this.index(iterator); return this.index(iterator);
} catch (SQLException ex) { } catch (SQLException ex) {
throw new DSpaceSolrIndexerException(ex.getMessage(), ex); throw new DSpaceSolrIndexerException(ex.getMessage(), ex);
@@ -189,38 +182,25 @@ public class XOAI {
try { try {
// Index both in_archive items AND withdrawn items. Withdrawn items will be flagged withdrawn // Index both in_archive items AND withdrawn items. Withdrawn items will be flagged withdrawn
// (in order to notify external OAI harvesters of their new status) // (in order to notify external OAI harvesters of their new status)
String sqlQuery = "SELECT item_id FROM item WHERE (in_archive=TRUE OR withdrawn=TRUE) AND discoverable=TRUE"; Iterator<Item> iterator = itemService.findInArchiveOrWithdrawnDiscoverableModifiedSince(
if(DatabaseManager.isOracle()){ context, null);
sqlQuery = "SELECT item_id FROM item WHERE (in_archive=1 OR withdrawn=1) AND discoverable=1";
}
TableRowIterator iterator = DatabaseManager.query(context,
sqlQuery);
return this.index(iterator); return this.index(iterator);
} catch (SQLException ex) { } catch (SQLException ex) {
throw new DSpaceSolrIndexerException(ex.getMessage(), ex); throw new DSpaceSolrIndexerException(ex.getMessage(), ex);
} }
} }
private int index(TableRowIterator iterator) private int index(Iterator<Item> iterator)
throws DSpaceSolrIndexerException { throws DSpaceSolrIndexerException {
try { try {
int i = 0; int i = 0;
SolrServer server = solrServerResolver.getServer(); SolrServer server = solrServerResolver.getServer();
while (iterator.hasNext()) { while (iterator.hasNext()) {
try { try {
server.add(this.index(find(context, iterator.next().getIntColumn("item_id")))); server.add(this.index(iterator.next()));
context.clearCache(); } catch (SQLException | MetadataBindException | ParseException
} catch (SQLException ex) { | XMLStreamException | WritingXmlException ex) {
log.error(ex.getMessage(), ex); log.error(ex.getMessage(), ex);
} catch (MetadataBindException e) {
log.error(e.getMessage(), e);
} catch (ParseException e) {
log.error(e.getMessage(), e);
} catch (XMLStreamException e) {
log.error(e.getMessage(), e);
} catch (WritingXmlException e) {
log.error(e.getMessage(), e);
} }
i++; i++;
if (i % 100 == 0) System.out.println(i + " items imported so far..."); if (i % 100 == 0) System.out.println(i + " items imported so far...");
@@ -228,11 +208,7 @@ public class XOAI {
System.out.println("Total: " + i + " items"); System.out.println("Total: " + i + " items");
server.commit(); server.commit();
return i; return i;
} catch (SQLException ex) { } catch (SolrServerException | IOException ex) {
throw new DSpaceSolrIndexerException(ex.getMessage(), ex);
} catch (SolrServerException ex) {
throw new DSpaceSolrIndexerException(ex.getMessage(), ex);
} catch (IOException ex) {
throw new DSpaceSolrIndexerException(ex.getMessage(), ex); throw new DSpaceSolrIndexerException(ex.getMessage(), ex);
} }
} }
@@ -458,8 +434,7 @@ public class XOAI {
iterator = itemService.findAll(context); iterator = itemService.findAll(context);
} else { } else {
System.out.println("Retrieving items modified after " + last + " to be compiled"); System.out.println("Retrieving items modified after " + last + " to be compiled");
String query = "SELECT * FROM item WHERE last_modified>?"; iterator = itemService.findByLastModifiedSince(context, last);
iterator = new ItemIterator(context, DatabaseManager.query(context, query, new java.sql.Date(last.getTime())));
} }
while (iterator.hasNext()) { while (iterator.hasNext()) {