mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 23:13:10 +00:00
[DS-811] Delete / withdraw items via bulk csv editing
git-svn-id: http://scm.dspace.org/svn/repo/dspace/trunk@6562 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
@@ -51,6 +51,15 @@ public class BulkEditChange
|
||||
/** Is this a new item */
|
||||
private boolean newItem;
|
||||
|
||||
/** Has this item been deleted? */
|
||||
private boolean deleted;
|
||||
|
||||
/** Has this item been withdrawn? */
|
||||
private boolean withdrawn;
|
||||
|
||||
/** Has this item been reinstated? */
|
||||
private boolean reinstated;
|
||||
|
||||
/** Have any changes actually been made? */
|
||||
private boolean empty;
|
||||
|
||||
@@ -326,6 +335,66 @@ public class BulkEditChange
|
||||
return newItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this change object represent a deleted item?
|
||||
*
|
||||
* @return Whether or not this is for a deleted item
|
||||
*/
|
||||
public boolean isDeleted()
|
||||
{
|
||||
// Return the new item status
|
||||
return deleted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set that this item has been deleted
|
||||
*/
|
||||
public void setDeleted() {
|
||||
// Store the setting
|
||||
deleted = true;
|
||||
empty = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this change object represent a withdrawn item?
|
||||
*
|
||||
* @return Whether or not this is for a withdrawn item
|
||||
*/
|
||||
public boolean isWithdrawn()
|
||||
{
|
||||
// Return the new item status
|
||||
return withdrawn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set that this item has been withdrawn
|
||||
*/
|
||||
public void setWithdrawn() {
|
||||
// Store the setting
|
||||
withdrawn = true;
|
||||
empty = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this change object represent a reinstated item?
|
||||
*
|
||||
* @return Whether or not this is for a reinstated item
|
||||
*/
|
||||
public boolean isReinstated()
|
||||
{
|
||||
// Return the new item status
|
||||
return reinstated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set that this item has been deleted
|
||||
*/
|
||||
public void setReinstated() {
|
||||
// Store the setting
|
||||
reinstated = true;
|
||||
empty = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Have any changes actually been recorded, or is this empty?
|
||||
*
|
||||
|
@@ -114,6 +114,12 @@ public class DSpaceCSV implements Serializable
|
||||
// Store the heading
|
||||
headings.add(element);
|
||||
}
|
||||
// Store the action
|
||||
else if ("action".equals(element))
|
||||
{
|
||||
// Store the heading
|
||||
headings.add(element);
|
||||
}
|
||||
else if (!"id".equals(element))
|
||||
{
|
||||
// Verify that the heading is valid in the metadata registry
|
||||
@@ -248,6 +254,21 @@ public class DSpaceCSV implements Serializable
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Decide if this CSV file has an 'action' (case-dependent!) header.
|
||||
*
|
||||
* @return Whether or not there is an 'action' header
|
||||
*/
|
||||
public boolean hasActions() {
|
||||
// Look for a heading called 'action'
|
||||
for (String header : headings) {
|
||||
if (header.equals("action")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value separator for multiple values stored in one csv value.
|
||||
*
|
||||
@@ -575,12 +596,6 @@ public class DSpaceCSV implements Serializable
|
||||
*/
|
||||
private final boolean okToExport(DCValue md)
|
||||
{
|
||||
// First check the metadata format, and K all non DC elements
|
||||
if (!"dc".equals(md.schema))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// Now compare with the list to ignore
|
||||
String key = md.schema + "." + md.element;
|
||||
if (md.qualifier != null)
|
||||
|
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
package org.dspace.app.bulkedit;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -18,7 +19,7 @@ import java.util.Set;
|
||||
*
|
||||
* @author Stuart Lewis
|
||||
*/
|
||||
public class DSpaceCSVLine
|
||||
public class DSpaceCSVLine implements Serializable
|
||||
{
|
||||
/** The item id of the item represented by this line. -1 is for a new item */
|
||||
private int id;
|
||||
@@ -92,6 +93,22 @@ public class DSpaceCSVLine
|
||||
return items.get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get any action associated with this line
|
||||
*
|
||||
* @return The action (may be blank, 'withdraw', 'reinstate' or 'delete')
|
||||
*/
|
||||
public String getAction()
|
||||
{
|
||||
if (items.containsKey("action")) {
|
||||
ArrayList actions = items.get("action");
|
||||
if (actions.size() > 0) {
|
||||
return ((String)actions.get(0)).trim();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all the metadata keys that are represented in this line
|
||||
*
|
||||
|
@@ -39,6 +39,9 @@ public class MetadataImport
|
||||
/** The Context */
|
||||
Context c;
|
||||
|
||||
/** The DSpaceCSV object we're processing */
|
||||
DSpaceCSV csv;
|
||||
|
||||
/** The lines to import */
|
||||
List<DSpaceCSVLine> toImport;
|
||||
|
||||
@@ -53,11 +56,12 @@ public class MetadataImport
|
||||
* @param c The context
|
||||
* @param toImport An array of CSV lines to examine
|
||||
*/
|
||||
public MetadataImport(Context c, List<DSpaceCSVLine> toImport)
|
||||
public MetadataImport(Context c, DSpaceCSV toImport)
|
||||
{
|
||||
// Store the import settings
|
||||
this.c = c;
|
||||
this.toImport = toImport;
|
||||
csv = toImport;
|
||||
this.toImport = toImport.getCSVLines();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,6 +93,12 @@ public class MetadataImport
|
||||
// Get the DSpace item to compare with
|
||||
int id = line.getID();
|
||||
|
||||
// Is there an action column?
|
||||
if (csv.hasActions() && (!"".equals(line.getAction())) && (id == -1))
|
||||
{
|
||||
throw new MetadataImportException("'action' not allowed for new items!");
|
||||
}
|
||||
|
||||
// Is this a new item?
|
||||
if (id != -1)
|
||||
{
|
||||
@@ -98,6 +108,8 @@ public class MetadataImport
|
||||
{
|
||||
throw new MetadataImportException("Unknown item ID " + id);
|
||||
}
|
||||
|
||||
// Record changes
|
||||
BulkEditChange whatHasChanged = new BulkEditChange(item);
|
||||
|
||||
// Has it moved collection?
|
||||
@@ -127,6 +139,63 @@ public class MetadataImport
|
||||
}
|
||||
}
|
||||
|
||||
if (csv.hasActions())
|
||||
{
|
||||
// Perform the action
|
||||
String action = line.getAction();
|
||||
if ("".equals(action))
|
||||
{
|
||||
// Do nothing
|
||||
}
|
||||
else if ("expunge".equals(action))
|
||||
{
|
||||
// Does the configuration allow deletes?
|
||||
if (!ConfigurationManager.getBooleanProperty("bulkedit.allowexpunge", false))
|
||||
{
|
||||
throw new MetadataImportException("'expunge' action denied by configuration");
|
||||
}
|
||||
|
||||
// Remove the item
|
||||
Collection[] owners = item.getCollections();
|
||||
for (Collection owner : owners)
|
||||
{
|
||||
if (change)
|
||||
{
|
||||
owner.removeItem(item);
|
||||
}
|
||||
}
|
||||
whatHasChanged.setDeleted();
|
||||
}
|
||||
else if ("withdraw".equals(action))
|
||||
{
|
||||
// Withdraw the item
|
||||
if (!item.isWithdrawn())
|
||||
{
|
||||
if (change)
|
||||
{
|
||||
item.withdraw();
|
||||
}
|
||||
whatHasChanged.setWithdrawn();
|
||||
}
|
||||
}
|
||||
else if ("reinstate".equals(action))
|
||||
{
|
||||
// Reinstate the item
|
||||
if (item.isWithdrawn())
|
||||
{
|
||||
if (change)
|
||||
{
|
||||
item.reinstate();
|
||||
}
|
||||
whatHasChanged.setReinstated();
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Unknown action!
|
||||
throw new MetadataImportException("Unknown action: " + action);
|
||||
}
|
||||
}
|
||||
|
||||
// Only record if changes have been made
|
||||
if (whatHasChanged.hasChanges())
|
||||
{
|
||||
@@ -164,7 +233,7 @@ public class MetadataImport
|
||||
{
|
||||
throw new MetadataImportException("New items must have a 'collection' assigned in the form of a handle");
|
||||
}
|
||||
|
||||
|
||||
// Check collections are really collections
|
||||
ArrayList<Collection> check = new ArrayList<Collection>();
|
||||
Collection collection;
|
||||
@@ -204,7 +273,7 @@ public class MetadataImport
|
||||
Collection extra = (Collection)HandleManager.resolveToObject(c, handle);
|
||||
if (first)
|
||||
{
|
||||
whatHasChanged.setOwningCollection(extra);
|
||||
whatHasChanged.setOwningCollection(extra);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -227,7 +296,7 @@ public class MetadataImport
|
||||
{
|
||||
item.addMetadata(dcv.schema,
|
||||
dcv.element,
|
||||
dcv.qualifier,
|
||||
dcv.qualifier,
|
||||
dcv.language,
|
||||
dcv.value);
|
||||
}
|
||||
@@ -253,7 +322,7 @@ public class MetadataImport
|
||||
// Install the item
|
||||
InstallItem.installItem(c, wsItem);
|
||||
}
|
||||
|
||||
|
||||
// Add to extra collections
|
||||
if (line.get("collection").size() > 0)
|
||||
{
|
||||
@@ -313,8 +382,8 @@ public class MetadataImport
|
||||
log.debug(LogManager.getHeader(c, "metadata_import",
|
||||
"item_id=" + item.getID() + ",fromCSV=" + all));
|
||||
|
||||
// Don't compare collections
|
||||
if ("collection".equals(md))
|
||||
// Don't compare collections or actions
|
||||
if (("collection".equals(md)) || ("action".equals(md)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -633,8 +702,8 @@ public class MetadataImport
|
||||
private void add(String[] fromCSV, String md, BulkEditChange changes)
|
||||
throws SQLException, AuthorizeException
|
||||
{
|
||||
// Don't add owning collection
|
||||
if ("collection".equals(md))
|
||||
// Don't add owning collection or action
|
||||
if (("collection".equals(md)) || ("action".equals(md)))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -759,7 +828,8 @@ public class MetadataImport
|
||||
List<Collection> oldCollections = change.getOldMappedCollections();
|
||||
if ((adds.size() > 0) || (removes.size() > 0) ||
|
||||
(newCollections.size() > 0) || (oldCollections.size() > 0) ||
|
||||
(change.getNewOwningCollection() != null) || (change.getOldOwningCollection() != null))
|
||||
(change.getNewOwningCollection() != null) || (change.getOldOwningCollection() != null) ||
|
||||
(change.isDeleted()) || (change.isWithdrawn()) || (change.isReinstated()))
|
||||
{
|
||||
// Show the item
|
||||
Item i = change.getItem();
|
||||
@@ -788,6 +858,41 @@ public class MetadataImport
|
||||
changeCounter++;
|
||||
}
|
||||
|
||||
// Show actions
|
||||
if (change.isDeleted())
|
||||
{
|
||||
if (changed)
|
||||
{
|
||||
System.out.println(" - EXPUNGED!");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println(" - EXPUNGE!");
|
||||
}
|
||||
}
|
||||
if (change.isWithdrawn())
|
||||
{
|
||||
if (changed)
|
||||
{
|
||||
System.out.println(" - WITHDRAWN!");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println(" - WITHDRAW!");
|
||||
}
|
||||
}
|
||||
if (change.isReinstated())
|
||||
{
|
||||
if (changed)
|
||||
{
|
||||
System.out.println(" - REINSTATED!");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println(" - REINSTATE!");
|
||||
}
|
||||
}
|
||||
|
||||
if (change.getNewOwningCollection() != null)
|
||||
{
|
||||
Collection c = change.getNewOwningCollection();
|
||||
@@ -846,7 +951,7 @@ public class MetadataImport
|
||||
String cName = c.getName();
|
||||
if (!changed)
|
||||
{
|
||||
System.out.print(" + Um-map from collection (" + cHandle + "): ");
|
||||
System.out.print(" + Un-map from collection (" + cHandle + "): ");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1040,7 +1145,7 @@ public class MetadataImport
|
||||
}
|
||||
|
||||
// Perform the first import - just highlight differences
|
||||
MetadataImport importer = new MetadataImport(c, csv.getCSVLines());
|
||||
MetadataImport importer = new MetadataImport(c, csv);
|
||||
List<BulkEditChange> changes;
|
||||
|
||||
if (!line.hasOption('s'))
|
||||
@@ -1126,7 +1231,7 @@ public class MetadataImport
|
||||
catch (Exception e)
|
||||
{
|
||||
c.abort();
|
||||
System.err.println("Error commiting changes to database: " + e.getMessage());
|
||||
System.err.println("Error committing changes to database: " + e.getMessage());
|
||||
System.err.println("Aborting most recent changes.");
|
||||
System.exit(1);
|
||||
}
|
||||
|
@@ -312,6 +312,12 @@ jsp.dspace-admin.metadataimport.add = Add
|
||||
jsp.dspace-admin.metadataimport.added = Added
|
||||
jsp.dspace-admin.metadataimport.remove = Remove
|
||||
jsp.dspace-admin.metadataimport.removed = Removed
|
||||
jsp.dspace-admin.metadataimport.delete = Expunge Item
|
||||
jsp.dspace-admin.metadataimport.deleted = Item Expunged
|
||||
jsp.dspace-admin.metadataimport.withdraw = Withdraw Item
|
||||
jsp.dspace-admin.metadataimport.withdrawn = Item Withdrawn
|
||||
jsp.dspace-admin.metadataimport.reinstate = Reinstate Item
|
||||
jsp.dspace-admin.metadataimport.reinstated = Item Reinstated
|
||||
jsp.dspace-admin.metadataimport.toomany = There are too many changes. Please import fewer changes, adjust the limit, or perform the input directly on the server.
|
||||
jsp.dspace-admin.metadataimport.finished = {0} changes completed successfully.
|
||||
jsp.dspace-admin.index.heading = Administration Tools
|
||||
|
Reference in New Issue
Block a user