mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 10:04:21 +00:00
Print mapFile output to confirm screen, also use batchimport temp dir
This commit is contained in:
@@ -40,7 +40,6 @@ import org.apache.commons.lang.RandomStringUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.xpath.XPathAPI;
|
||||
import org.dspace.app.itemexport.ItemExportException;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.authorize.AuthorizeManager;
|
||||
import org.dspace.authorize.ResourcePolicy;
|
||||
@@ -48,8 +47,6 @@ import org.dspace.content.Bitstream;
|
||||
import org.dspace.content.BitstreamFormat;
|
||||
import org.dspace.content.Bundle;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.content.Community;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.content.FormatIdentifier;
|
||||
import org.dspace.content.InstallItem;
|
||||
import org.dspace.content.Item;
|
||||
@@ -109,9 +106,20 @@ public class ItemImport
|
||||
|
||||
private static boolean template = false;
|
||||
|
||||
private static PrintWriter mapOut = null;
|
||||
private static final String tempWorkDir = ConfigurationManager.getProperty("org.dspace.app.batchitemimport.work.dir");
|
||||
|
||||
private static final String ziptempdir = ConfigurationManager.getProperty("org.dspace.app.itemexport.work.dir");
|
||||
static {
|
||||
//Ensure tempWorkDir exists
|
||||
File tempWorkDirFile = new File(tempWorkDir);
|
||||
if (!tempWorkDirFile.exists()){
|
||||
boolean success = tempWorkDirFile.mkdir();
|
||||
if (success) {
|
||||
log.info("Created org.dspace.app.batchitemimport.work.dir of: " + tempWorkDir);
|
||||
} else {
|
||||
log.error("Cannot create batch import directory! " + tempWorkDir);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// File listing filter to look for metadata files
|
||||
private static FilenameFilter metadataFileFilter = new FilenameFilter()
|
||||
@@ -512,14 +520,6 @@ public class ItemImport
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// abort all operations
|
||||
if (mapOut != null)
|
||||
{
|
||||
mapOut.close();
|
||||
}
|
||||
|
||||
mapOut = null;
|
||||
|
||||
c.abort();
|
||||
e.printStackTrace();
|
||||
System.out.println(e);
|
||||
@@ -532,19 +532,16 @@ public class ItemImport
|
||||
if (zip)
|
||||
{
|
||||
System.gc();
|
||||
System.out.println("Deleting temporary zip directory: " + ziptempdir);
|
||||
ItemImport.deleteDirectory(new File(ziptempdir));
|
||||
System.out.println("Deleting temporary zip directory: " + tempWorkDir);
|
||||
ItemImport.deleteDirectory(new File(tempWorkDir));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.out.println("Unable to delete temporary zip archive location: " + ziptempdir);
|
||||
System.out.println("Unable to delete temporary zip archive location: " + tempWorkDir);
|
||||
}
|
||||
|
||||
if (mapOut != null)
|
||||
{
|
||||
mapOut.close();
|
||||
}
|
||||
|
||||
|
||||
if (isTest)
|
||||
{
|
||||
@@ -661,6 +658,9 @@ public class ItemImport
|
||||
|
||||
// create the mapfile
|
||||
File outFile = null;
|
||||
|
||||
PrintWriter mapOut = null;
|
||||
|
||||
boolean directoryFileCollections = false;
|
||||
if (mycollections == null)
|
||||
{
|
||||
@@ -734,6 +734,10 @@ public class ItemImport
|
||||
c.clearCache();
|
||||
}
|
||||
}
|
||||
|
||||
//TODO null check?
|
||||
mapOut.flush();
|
||||
mapOut.close();
|
||||
}
|
||||
|
||||
private void replaceItems(Context c, Collection[] mycollections,
|
||||
@@ -841,7 +845,7 @@ public class ItemImport
|
||||
private Item addItem(Context c, Collection[] mycollections, String path,
|
||||
String itemname, PrintWriter mapOut, boolean template) throws Exception
|
||||
{
|
||||
String mapOutput = null;
|
||||
String mapOutputString = null;
|
||||
|
||||
System.out.println("Adding item from directory " + itemname);
|
||||
|
||||
@@ -889,7 +893,7 @@ public class ItemImport
|
||||
}
|
||||
|
||||
// send ID to the mapfile
|
||||
mapOutput = itemname + " " + myitem.getID();
|
||||
mapOutputString = itemname + " " + myitem.getID();
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -906,7 +910,7 @@ public class ItemImport
|
||||
// find the handle, and output to map file
|
||||
myhandle = HandleManager.findHandle(c, myitem);
|
||||
|
||||
mapOutput = itemname + " " + myhandle;
|
||||
mapOutputString = itemname + " " + myhandle;
|
||||
}
|
||||
|
||||
// set permissions if specified in contents file
|
||||
@@ -932,7 +936,7 @@ public class ItemImport
|
||||
// made it this far, everything is fine, commit transaction
|
||||
if (mapOut != null)
|
||||
{
|
||||
mapOut.println(mapOutput);
|
||||
mapOut.println(mapOutputString);
|
||||
}
|
||||
|
||||
c.commit();
|
||||
@@ -1979,8 +1983,6 @@ public class ItemImport
|
||||
}
|
||||
|
||||
public static String unzip(File zipfile) throws IOException {
|
||||
log.info("ZIPFILE: " + zipfile.getAbsolutePath());
|
||||
|
||||
// 2
|
||||
// does the zip file exist and can we write to the temp directory
|
||||
if (!zipfile.canRead())
|
||||
@@ -1989,7 +1991,7 @@ public class ItemImport
|
||||
}
|
||||
|
||||
|
||||
File tempdir = new File(ziptempdir);
|
||||
File tempdir = new File(tempWorkDir);
|
||||
if (!tempdir.isDirectory())
|
||||
{
|
||||
log.error("'" + ConfigurationManager.getProperty("org.dspace.app.itemexport.work.dir") +
|
||||
@@ -1999,10 +2001,10 @@ public class ItemImport
|
||||
|
||||
if (!tempdir.exists() && !tempdir.mkdirs())
|
||||
{
|
||||
log.error("Unable to create temporary directory");
|
||||
log.error("Unable to create temporary directory: " + tempdir.getAbsolutePath());
|
||||
}
|
||||
String sourcedir = ziptempdir + System.getProperty("file.separator") + zipfile.getName();
|
||||
String zipDir = ziptempdir + System.getProperty("file.separator") + zipfile.getName() + System.getProperty("file.separator");
|
||||
String sourcedir = tempWorkDir + System.getProperty("file.separator") + zipfile.getName();
|
||||
String zipDir = tempWorkDir + System.getProperty("file.separator") + zipfile.getName() + System.getProperty("file.separator");
|
||||
|
||||
|
||||
// 3
|
||||
@@ -2017,7 +2019,7 @@ public class ItemImport
|
||||
{
|
||||
if (!new File(zipDir + entry.getName()).mkdir())
|
||||
{
|
||||
log.error("Unable to create contents directory");
|
||||
log.error("Unable to create contents directory: " + zipDir + entry.getName());
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -2034,7 +2036,7 @@ public class ItemImport
|
||||
File dir = new File(zipDir + entry.getName().substring(0, index));
|
||||
if (!dir.mkdirs())
|
||||
{
|
||||
log.error("Unable to create directory");
|
||||
log.error("Unable to create directory: " + dir.getAbsolutePath());
|
||||
}
|
||||
|
||||
//Entries could have too many directories, and we need to adjust the sourcedir
|
||||
@@ -2214,7 +2216,7 @@ public class ItemImport
|
||||
{
|
||||
iitems.close();
|
||||
}
|
||||
|
||||
|
||||
// close the mapfile writer
|
||||
if (mapOut != null)
|
||||
{
|
||||
@@ -2569,4 +2571,8 @@ public class ItemImport
|
||||
|
||||
FileDeleteStrategy.FORCE.delete(new File(uploadDir));
|
||||
}
|
||||
|
||||
public static String getTempWorkDir() {
|
||||
return tempWorkDir;
|
||||
}
|
||||
}
|
||||
|
@@ -7,34 +7,25 @@
|
||||
*/
|
||||
package org.dspace.app.xmlui.aspect.administrative;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.sql.SQLException;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.cocoon.environment.Request;
|
||||
import org.apache.cocoon.servlet.multipart.Part;
|
||||
import org.apache.cocoon.servlet.multipart.PartOnDisk;
|
||||
import org.dspace.app.bulkedit.BulkEditChange;
|
||||
import org.dspace.app.bulkedit.DSpaceCSV;
|
||||
import org.dspace.app.bulkedit.MetadataImport;
|
||||
import org.dspace.app.bulkedit.MetadataImportException;
|
||||
import org.dspace.app.bulkedit.MetadataImportInvalidHeadingException;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.dspace.app.itemimport.ItemImport;
|
||||
import org.dspace.app.itemimport.ItemImportOptions;
|
||||
import org.dspace.app.xmlui.utils.HandleUtil;
|
||||
import org.dspace.app.xmlui.wing.Message;
|
||||
import org.dspace.authorize.AuthorizeException;
|
||||
import org.dspace.content.Collection;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.core.ConfigurationManager;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.core.LogManager;
|
||||
import org.dspace.eperson.EPerson;
|
||||
import org.dspace.handle.HandleManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
/**
|
||||
* Utility methods to processes BatchImport actions. These methods are used
|
||||
* exclusively from the administrative flow scripts.
|
||||
@@ -49,16 +40,12 @@ public class FlowBatchImportUtils {
|
||||
*/
|
||||
private static final Message T_upload_successful = new Message("default", "xmlui.administrative.batchimport.flow.upload_successful");
|
||||
private static final Message T_upload_failed = new Message("default", "xmlui.administrative.batchimport.flow.upload_failed");
|
||||
private static final Message T_upload_badschema = new Message("default", "xmlui.administrative.batchimport.flow.upload_badschema");
|
||||
private static final Message T_upload_badelement = new Message("default", "xmlui.administrative.batchimport.flow.upload_badelement");
|
||||
private static final Message T_import_successful = new Message("default", "xmlui.administrative.batchimport.flow.import_successful");
|
||||
private static final Message T_import_failed = new Message("default", "xmlui.administrative.batchimport.flow.import_failed");
|
||||
private static final Message T_over_limit = new Message("default", "xmlui.administrative.batchimport.flow.over_limit");
|
||||
private static final Message T_no_changes = new Message("default", "xmlui.administrative.batchimport.general.no_changes");
|
||||
private static final Message T_failed_no_collection = new Message("default", "xmlui.administrative.batchimport.flow.failed_no_collection");
|
||||
|
||||
// Other variables
|
||||
private static final int limit = ConfigurationManager.getIntProperty("bulkedit", "gui-item-limit", 20);
|
||||
private static Logger log = Logger.getLogger(FlowBatchImportUtils.class);
|
||||
|
||||
public static FlowResult processBatchImport(Context context, Request request) throws SQLException, AuthorizeException, IOException, Exception {
|
||||
@@ -67,7 +54,6 @@ public class FlowBatchImportUtils {
|
||||
result.setContinue(false);
|
||||
|
||||
String zipFile = (String) request.getSession().getAttribute("zip");
|
||||
log.info(zipFile);
|
||||
|
||||
if (zipFile != null) {
|
||||
// Commit the changes
|
||||
@@ -76,6 +62,7 @@ public class FlowBatchImportUtils {
|
||||
|
||||
log.debug(LogManager.getHeader(context, "batchimport", " items changed"));
|
||||
|
||||
//TODO: I don't think this section actually does anything.
|
||||
if (true) {
|
||||
result.setContinue(true);
|
||||
result.setOutcome(true);
|
||||
@@ -124,17 +111,13 @@ public class FlowBatchImportUtils {
|
||||
name = name.substring(name.indexOf('\\') + 1);
|
||||
}
|
||||
|
||||
log.info(LogManager.getHeader(context, "batchimport", "loading file"));
|
||||
|
||||
// Process CSV without import
|
||||
ItemImport itemImport = new ItemImport();
|
||||
|
||||
String collectionHandle = null;
|
||||
if (request.get("collectionHandle") != null) {
|
||||
collectionHandle = request.get("collectionHandle").toString();
|
||||
} else {
|
||||
String collectionHandle = String.valueOf(request.get("collectionHandle"));
|
||||
if (StringUtils.isEmpty(collectionHandle) || !collectionHandle.contains("/")) {
|
||||
//fail
|
||||
log.info("batch fail");
|
||||
log.error("UIBatchImport failed due to no collection.");
|
||||
result.setContinue(false);
|
||||
result.setOutcome(false);
|
||||
result.setMessage(T_failed_no_collection);
|
||||
@@ -145,27 +128,12 @@ public class FlowBatchImportUtils {
|
||||
Collection[] collections = new Collection[1];
|
||||
collections[0] = collection;
|
||||
|
||||
log.info("Batch to collection: " + collection.getName());
|
||||
File tempWorkDir = new File(itemImport.getTempWorkDir());
|
||||
File mapFile = File.createTempFile("batch-", ".map", tempWorkDir);
|
||||
|
||||
/*
|
||||
ItemImportOptions itemImportOptions = new ItemImportOptions();
|
||||
|
||||
itemImportOptions.setZipFilePath(file);
|
||||
|
||||
Collection destCollection = Collection.find(context, 10);
|
||||
itemImportOptions.setCollection(destCollection);
|
||||
|
||||
EPerson epersonSubmitter = EPerson.findByEmail(context, "peter@longsight.com");
|
||||
itemImportOptions.setEpersonSubmitter(epersonSubmitter);
|
||||
|
||||
itemImportOptions.setUseTemplate(true);
|
||||
*/
|
||||
File mapFile = File.createTempFile("batch", "map");
|
||||
/* PrintWriter mapOut = new PrintWriter(new FileWriter(mapFile));
|
||||
itemImportOptions.setMapFileOut(mapOut);
|
||||
log.info("MapFile: " + mapFile.getAbsolutePath());
|
||||
//Process ItemImport with ZIP, and other options.
|
||||
*/
|
||||
log.info("Attempt UIBatchImport to collection: " + collection.getName()
|
||||
+ ", zip: " + file.getName()
|
||||
+ ", map: "+ mapFile.getAbsolutePath());
|
||||
|
||||
/*
|
||||
// equivalent command-line would be:
|
||||
@@ -193,35 +161,23 @@ public class FlowBatchImportUtils {
|
||||
|
||||
itemImport.addItems(context, collections, sourceBatchDir, mapFile.getAbsolutePath(), true);
|
||||
|
||||
if(true)
|
||||
{
|
||||
// Success!
|
||||
// Set session and request attributes
|
||||
// Success!
|
||||
// Set session and request attributes
|
||||
result.setContinue(true);
|
||||
result.setOutcome(true);
|
||||
result.setMessage(T_upload_successful);
|
||||
result.setCharacters(FileUtils.readFileToString(mapFile));
|
||||
|
||||
//request.setAttribute("changes", changes);
|
||||
//request.getSession().setAttribute("csv", csv);
|
||||
log.info("batch success");
|
||||
|
||||
result.setContinue(true);
|
||||
result.setOutcome(true);
|
||||
result.setMessage(T_upload_successful);
|
||||
}
|
||||
else
|
||||
{
|
||||
//fail
|
||||
log.info("batch fail");
|
||||
result.setContinue(false);
|
||||
result.setOutcome(false);
|
||||
result.setMessage(T_no_changes);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
log.info("Success! UIBatchImport to collection: " + collection.getName()
|
||||
+ ", zip: " + file.getName()
|
||||
+ ", map: "+ mapFile.getAbsolutePath());
|
||||
} else {
|
||||
//No ZIP File, or upload failed
|
||||
result.setContinue(false);
|
||||
result.setOutcome(false);
|
||||
result.setMessage(T_upload_failed);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@@ -44,26 +44,10 @@ public class BatchImportUpload extends AbstractDSpaceTransformer {
|
||||
|
||||
/** Language strings */
|
||||
private static final Message T_dspace_home = message("xmlui.general.dspace_home");
|
||||
private static final Message T_submit_return = message("xmlui.general.return");
|
||||
private static final Message T_trail = message("xmlui.administrative.batchimport.general.trail");
|
||||
private static final Message T_no_changes = message("xmlui.administrative.batchimport.general.no_changes");
|
||||
private static final Message T_new_item = message("xmlui.administrative.batchimport.general.new_item");
|
||||
private static final Message T_title = message("xmlui.administrative.batchimport.general.title");
|
||||
private static final Message T_head1 = message("xmlui.administrative.batchimport.general.head1");
|
||||
|
||||
private static final Message T_para = message("xmlui.administrative.batchimport.BatchImportUpload.hint");
|
||||
private static final Message T_submit_confirm = message("xmlui.administrative.batchimport.BatchImportUpload.submit_confirm");
|
||||
private static final Message T_changes_pending = message("xmlui.administrative.batchimport.BatchImportUpload.changes_pending");
|
||||
private static final Message T_item_addition = message("xmlui.administrative.batchimport.BatchImportUpload.item_add");
|
||||
private static final Message T_item_deletion = message("xmlui.administrative.batchimport.BatchImportUpload.item_remove");
|
||||
private static final Message T_collection_newowner = message("xmlui.administrative.batchimport.BatchImportUpload.collection_newowner");
|
||||
private static final Message T_collection_oldowner = message("xmlui.administrative.batchimport.BatchImportUpload.collection_oldowner");
|
||||
private static final Message T_collection_mapped = message("xmlui.administrative.batchimport.BatchImportUpload.collection_mapped");
|
||||
private static final Message T_collection_unmapped = message("xmlui.administrative.batchimport.BatchImportUpload.collection_unmapped");
|
||||
private static final Message T_item_delete = message("xmlui.administrative.batchimport.BatchImportUpload.item_delete");
|
||||
private static final Message T_item_withdraw = message("xmlui.administrative.batchimport.BatchImportUpload.item_withdraw");
|
||||
private static final Message T_item_reinstate = message("xmlui.administrative.batchimport.BatchImportUpload.item_reinstate");
|
||||
|
||||
public void addPageMeta(PageMeta pageMeta) throws WingException
|
||||
{
|
||||
pageMeta.addMetadata("title").addContent(T_title);
|
||||
|
@@ -1454,7 +1454,7 @@
|
||||
<message key="xmlui.administrative.batchimport.general.no_changes">No changes were detected</message>
|
||||
<message key="xmlui.administrative.batchimport.general.new_item">New item</message>
|
||||
<message key="xmlui.administrative.batchimport.flow.upload_successful">Upload successful</message>
|
||||
<message key="xmlui.administrative.batchimport.flow.upload_failed">Upload failed</message>
|
||||
<message key="xmlui.administrative.batchimport.flow.upload_failed">Upload failed or no file selected</message>
|
||||
<message key="xmlui.administrative.batchimport.flow.upload_badschema">Unknown metadata schema in heading</message>
|
||||
<message key="xmlui.administrative.batchimport.flow.upload_badelement">Unknown metadata element in heading</message>
|
||||
<message key="xmlui.administrative.batchimport.flow.import_successful">Import successful</message>
|
||||
|
Reference in New Issue
Block a user