[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);
}
@Override
public Iterator<Item> findInArchiveOrWithdrawnDiscoverableModifiedSince(Context context, Date since)
throws SQLException
{
return itemDAO.findInArchiveOrWithdrawnDiscoverableModifiedSince(context, since);
}
@Override
public void updateLastModified(Context context, Item item) throws SQLException, AuthorizeException {
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 {
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 java.sql.SQLException;
import java.util.Date;
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;
/**
* 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, 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 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.util.Collections;
import java.util.Date;
import java.util.Iterator;
/**
@@ -126,4 +127,36 @@ public class ItemDAOImpl extends AbstractHibernateDSODAO<Item> implements ItemDA
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.InputStream;
import java.sql.SQLException;
import java.util.Date;
import java.util.Iterator;
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;
/**
* 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.
*
@@ -429,4 +439,14 @@ public interface ItemService extends DSpaceObjectService<Item>, DSpaceObjectLega
* @return total items
*/
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());
// 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)
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 {
TableRowIterator iterator = DatabaseManager
.query(context,
sqlQuery,
new java.sql.Timestamp(last.getTime()));
Iterator<Item> iterator = itemService.findInArchiveOrWithdrawnDiscoverableModifiedSince(
context, last);
return this.index(iterator);
} catch (SQLException ex) {
throw new DSpaceSolrIndexerException(ex.getMessage(), ex);
@@ -189,38 +182,25 @@ public class XOAI {
try {
// 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)
String sqlQuery = "SELECT item_id FROM item WHERE (in_archive=TRUE OR withdrawn=TRUE) AND discoverable=TRUE";
if(DatabaseManager.isOracle()){
sqlQuery = "SELECT item_id FROM item WHERE (in_archive=1 OR withdrawn=1) AND discoverable=1";
}
TableRowIterator iterator = DatabaseManager.query(context,
sqlQuery);
Iterator<Item> iterator = itemService.findInArchiveOrWithdrawnDiscoverableModifiedSince(
context, null);
return this.index(iterator);
} catch (SQLException ex) {
throw new DSpaceSolrIndexerException(ex.getMessage(), ex);
}
}
private int index(TableRowIterator iterator)
private int index(Iterator<Item> iterator)
throws DSpaceSolrIndexerException {
try {
int i = 0;
SolrServer server = solrServerResolver.getServer();
while (iterator.hasNext()) {
try {
server.add(this.index(find(context, iterator.next().getIntColumn("item_id"))));
context.clearCache();
} catch (SQLException ex) {
server.add(this.index(iterator.next()));
} catch (SQLException | MetadataBindException | ParseException
| XMLStreamException | WritingXmlException 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++;
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");
server.commit();
return i;
} catch (SQLException ex) {
throw new DSpaceSolrIndexerException(ex.getMessage(), ex);
} catch (SolrServerException ex) {
throw new DSpaceSolrIndexerException(ex.getMessage(), ex);
} catch (IOException ex) {
} catch (SolrServerException | IOException ex) {
throw new DSpaceSolrIndexerException(ex.getMessage(), ex);
}
}
@@ -458,8 +434,7 @@ public class XOAI {
iterator = itemService.findAll(context);
} else {
System.out.println("Retrieving items modified after " + last + " to be compiled");
String query = "SELECT * FROM item WHERE last_modified>?";
iterator = new ItemIterator(context, DatabaseManager.query(context, query, new java.sql.Date(last.getTime())));
iterator = itemService.findByLastModifiedSince(context, last);
}
while (iterator.hasNext()) {