Fix DS-2593 : Withdrawn items are now given a "tombstone" in OAI-PMH. Also fix Context mgmt issues & authorization code.

This commit is contained in:
Tim Donohue
2015-07-06 12:37:20 -05:00
parent edb0555924
commit db0c994e46
3 changed files with 41 additions and 34 deletions

View File

@@ -167,10 +167,11 @@ public class XOAI {
System.out System.out
.println("Incremental import. Searching for documents modified after: " .println("Incremental import. Searching for documents modified after: "
+ last.toString()); + last.toString());
// Index both in_archive items AND withdrawn items. Withdrawn items will be flagged withdrawn
String sqlQuery = "SELECT item_id FROM item WHERE in_archive=TRUE AND discoverable=TRUE AND last_modified > ?"; // (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()){ if(DatabaseManager.isOracle()){
sqlQuery = "SELECT item_id FROM item WHERE in_archive=1 AND discoverable=1 AND last_modified > ?"; sqlQuery = "SELECT item_id FROM item WHERE (in_archive=1 OR withdrawn=1) AND discoverable=1 AND last_modified > ?";
} }
try { try {
@@ -187,10 +188,11 @@ public class XOAI {
private int indexAll() throws DSpaceSolrIndexerException { private int indexAll() throws DSpaceSolrIndexerException {
System.out.println("Full import"); System.out.println("Full import");
try { try {
// Index both in_archive items AND withdrawn items. Withdrawn items will be flagged withdrawn
String sqlQuery = "SELECT item_id FROM item WHERE in_archive=TRUE AND discoverable=TRUE"; // (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()){ if(DatabaseManager.isOracle()){
sqlQuery = "SELECT item_id FROM item WHERE in_archive=1 AND discoverable=1"; sqlQuery = "SELECT item_id FROM item WHERE (in_archive=1 OR withdrawn=1) AND discoverable=1";
} }
TableRowIterator iterator = DatabaseManager.query(context, TableRowIterator iterator = DatabaseManager.query(context,
@@ -287,17 +289,14 @@ public class XOAI {
} }
private boolean isPublic(Item item) { private boolean isPublic(Item item) {
boolean pub = false;
try { try {
AuthorizeManager.authorizeAction(context, item, Constants.READ); //Check if READ access allowed on this Item
for (Bundle b : item.getBundles()) pub = AuthorizeManager.authorizeActionBoolean(context, item, Constants.READ);
AuthorizeManager.authorizeAction(context, b, Constants.READ);
return true;
} catch (AuthorizeException ex) {
log.debug(ex.getMessage());
} catch (SQLException ex) { } catch (SQLException ex) {
log.error(ex.getMessage()); log.error(ex.getMessage());
} }
return false; return pub;
} }
@@ -355,6 +354,8 @@ public class XOAI {
XOAICacheService cacheService = applicationContext.getBean(XOAICacheService.class); XOAICacheService cacheService = applicationContext.getBean(XOAICacheService.class);
XOAIItemCacheService itemCacheService = applicationContext.getBean(XOAIItemCacheService.class); XOAIItemCacheService itemCacheService = applicationContext.getBean(XOAIItemCacheService.class);
Context ctx = null;
try { try {
CommandLineParser parser = new PosixParser(); CommandLineParser parser = new PosixParser();
Options options = new Options(); Options options = new Options();
@@ -394,7 +395,7 @@ public class XOAI {
String command = line.getArgs()[0]; String command = line.getArgs()[0];
if (COMMAND_IMPORT.equals(command)) { if (COMMAND_IMPORT.equals(command)) {
Context ctx = new Context(); ctx = new Context();
XOAI indexer = new XOAI(ctx, XOAI indexer = new XOAI(ctx,
line.hasOption('o'), line.hasOption('o'),
line.hasOption('c'), line.hasOption('c'),
@@ -404,21 +405,17 @@ public class XOAI {
int imported = indexer.index(); int imported = indexer.index();
if (imported > 0) cleanCache(itemCacheService, cacheService); if (imported > 0) cleanCache(itemCacheService, cacheService);
ctx.abort();
} else if (COMMAND_CLEAN_CACHE.equals(command)) { } else if (COMMAND_CLEAN_CACHE.equals(command)) {
cleanCache(itemCacheService, cacheService); cleanCache(itemCacheService, cacheService);
} else if (COMMAND_COMPILE_ITEMS.equals(command)) { } else if (COMMAND_COMPILE_ITEMS.equals(command)) {
Context ctx = new Context(); ctx = new Context();
XOAI indexer = new XOAI(ctx, line.hasOption('v')); XOAI indexer = new XOAI(ctx, line.hasOption('v'));
applicationContext.getAutowireCapableBeanFactory().autowireBean(indexer); applicationContext.getAutowireCapableBeanFactory().autowireBean(indexer);
indexer.compile(); indexer.compile();
cleanCache(itemCacheService, cacheService); cleanCache(itemCacheService, cacheService);
ctx.abort();
} else if (COMMAND_ERASE_COMPILED_ITEMS.equals(command)) { } else if (COMMAND_ERASE_COMPILED_ITEMS.equals(command)) {
cleanCompiledItems(itemCacheService); cleanCompiledItems(itemCacheService);
cleanCache(itemCacheService, cacheService); cleanCache(itemCacheService, cacheService);
@@ -436,6 +433,12 @@ public class XOAI {
} }
log.error(ex.getMessage(), ex); log.error(ex.getMessage(), ex);
} }
finally
{
// Abort our context, if still open
if(ctx!=null && ctx.isValid())
ctx.abort();
}
} }
private static void cleanCompiledItems(XOAIItemCacheService itemCacheService) throws IOException { private static void cleanCompiledItems(XOAIItemCacheService itemCacheService) throws IOException {

View File

@@ -145,7 +145,7 @@ public class DSpaceOAIDataProvider
} }
private void closeContext(Context context) { private void closeContext(Context context) {
if (context != null) if (context != null && context.isValid())
context.abort(); context.abort();
} }

View File

@@ -49,29 +49,33 @@ public class DSpaceAuthorizationFilter extends DSpaceFilter
@Override @Override
public boolean isShown(DSpaceItem item) public boolean isShown(DSpaceItem item)
{ {
boolean pub = false;
try try
{ {
String handle = DSpaceItem.parseHandle(item.getIdentifier()); // For DSpace, if an Item is withdrawn, "isDeleted()" will be true.
if (handle == null) return false; // In this scenario, we want a withdrawn item to be *shown* so that
Item dspaceItem = (Item) HandleManager.resolveToObject(context, handle); // we can properly respond with a "deleted" status via OAI-PMH.
AuthorizeManager.authorizeAction(context, dspaceItem, Constants.READ); // Don't worry, this does NOT make the metadata public for withdrawn items,
for (Bundle b : dspaceItem.getBundles()) // it merely provides an item "tombstone" via OAI-PMH.
AuthorizeManager.authorizeAction(context, b, Constants.READ); if (item.isDeleted())
return true; return true;
}
catch (AuthorizeException ex) // If Handle or Item are not found, return false
{ String handle = DSpaceItem.parseHandle(item.getIdentifier());
log.error(ex.getMessage(), ex); if (handle == null)
return false;
Item dspaceItem = (Item) HandleManager.resolveToObject(context, handle);
if (dspaceItem == null)
return false;
// Check if READ access allowed on Item
pub = AuthorizeManager.authorizeActionBoolean(context, dspaceItem, Constants.READ);
} }
catch (SQLException ex) catch (SQLException ex)
{ {
log.error(ex.getMessage(), ex); log.error(ex.getMessage(), ex);
} }
catch (Exception ex) return pub;
{
log.error(ex.getMessage(), ex);
}
return false;
} }
@Override @Override