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

View File

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

View File

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