Merge pull request #1575 from mwoodiupui/DS-2707

[DS-2707] Poor messaging when batch upload directory cannot be created
This commit is contained in:
Mark H. Wood
2016-12-14 10:16:35 -05:00
committed by GitHub
3 changed files with 63 additions and 47 deletions

View File

@@ -273,23 +273,25 @@ public class ItemImportServiceImpl implements ItemImportService, InitializingBea
// mode // mode
System.out.println("Adding items from directory: " + sourceDir); System.out.println("Adding items from directory: " + sourceDir);
log.debug("Adding items from directory: " + sourceDir);
System.out.println("Generating mapfile: " + mapFile); System.out.println("Generating mapfile: " + mapFile);
log.debug("Generating mapfile: " + mapFile);
boolean directoryFileCollections = false; boolean directoryFileCollections = false;
if (mycollections == null) if (mycollections == null)
{
directoryFileCollections = true;
}
if (!isTest)
{
// get the directory names of items to skip (will be in keys of
// hash)
if (isResume)
{ {
skipItems = readMapFile(mapFile); directoryFileCollections = true;
} }
if (!isTest)
{
// get the directory names of items to skip (will be in keys of
// hash)
if (isResume)
{
skipItems = readMapFile(mapFile);
}
// sneaky isResume == true means open file in append mode // sneaky isResume == true means open file in append mode
outFile = new File(mapFile); outFile = new File(mapFile);
mapOut = new PrintWriter(new FileWriter(outFile, isResume)); mapOut = new PrintWriter(new FileWriter(outFile, isResume));
@@ -312,39 +314,39 @@ public class ItemImportServiceImpl implements ItemImportService, InitializingBea
Arrays.sort(dircontents, ComparatorUtils.naturalComparator()); Arrays.sort(dircontents, ComparatorUtils.naturalComparator());
for (int i = 0; i < dircontents.length; i++) for (int i = 0; i < dircontents.length; i++)
{
if (skipItems.containsKey(dircontents[i]))
{ {
System.out.println("Skipping import of " + dircontents[i]); if (skipItems.containsKey(dircontents[i]))
} {
else System.out.println("Skipping import of " + dircontents[i]);
{
List<Collection> clist;
if (directoryFileCollections) {
String path = sourceDir + File.separatorChar + dircontents[i];
try {
List<Collection> cols = processCollectionFile(c, path, "collections");
if (cols == null) {
System.out.println("No collections specified for item " + dircontents[i] + ". Skipping.");
continue;
}
clist = cols;
}
catch (IllegalArgumentException e)
{
System.out.println(e.getMessage() + " Skipping." );
continue;
}
} }
else else
{ {
clist = mycollections; List<Collection> clist;
if (directoryFileCollections) {
String path = sourceDir + File.separatorChar + dircontents[i];
try {
List<Collection> cols = processCollectionFile(c, path, "collections");
if (cols == null) {
System.out.println("No collections specified for item " + dircontents[i] + ". Skipping.");
continue;
}
clist = cols;
}
catch (IllegalArgumentException e)
{
System.out.println(e.getMessage() + " Skipping." );
continue;
}
}
else
{
clist = mycollections;
}
addItem(c, clist, sourceDir, dircontents[i], mapOut, template);
System.out.println(i + " " + dircontents[i]);
} }
addItem(c, clist, sourceDir, dircontents[i], mapOut, template);
System.out.println(i + " " + dircontents[i]);
} }
}
} finally { } finally {
if(mapOut!=null) { if(mapOut!=null) {
@@ -466,6 +468,7 @@ public class ItemImportServiceImpl implements ItemImportService, InitializingBea
String mapOutputString = null; String mapOutputString = null;
System.out.println("Adding item from directory " + itemname); System.out.println("Adding item from directory " + itemname);
log.debug("adding item from directory " + itemname);
// create workspace item // create workspace item
Item myitem = null; Item myitem = null;
@@ -1652,7 +1655,7 @@ public class ItemImportServiceImpl implements ItemImportService, InitializingBea
entry = entries.nextElement(); entry = entries.nextElement();
if (entry.isDirectory()) if (entry.isDirectory())
{ {
if (!new File(zipDir + entry.getName()).mkdir()) if (!new File(zipDir + entry.getName()).mkdirs())
{ {
log.error("Unable to create contents directory: " + zipDir + entry.getName()); log.error("Unable to create contents directory: " + zipDir + entry.getName());
} }
@@ -2040,17 +2043,28 @@ public class ItemImportServiceImpl implements ItemImportService, InitializingBea
} }
@Override @Override
public File getTempWorkDirFile() { public File getTempWorkDirFile()
throws IOException
{
File tempDirFile = new File(getTempWorkDir()); File tempDirFile = new File(getTempWorkDir());
if(!tempDirFile.exists()) { if(!tempDirFile.exists()) {
tempDirFile.mkdirs(); boolean success = tempDirFile.mkdirs();
if (!success)
{
throw new IOException("Work directory "
+ tempDirFile.getAbsolutePath()
+ " could not be created.");
}
else log.debug("Created directory " + tempDirFile.getAbsolutePath());
} }
else log.debug("Work directory exists: " + tempDirFile.getAbsolutePath());
return tempDirFile; return tempDirFile;
} }
@Override @Override
public void cleanupZipTemp() { public void cleanupZipTemp() {
System.out.println("Deleting temporary zip directory: " + tempWorkDir); System.out.println("Deleting temporary zip directory: " + tempWorkDir);
log.debug("Deleting temporary zip directory: " + tempWorkDir);
deleteDirectory(new File(tempWorkDir)); deleteDirectory(new File(tempWorkDir));
} }

View File

@@ -199,8 +199,9 @@ public interface ItemImportService {
/** /**
* Get temporary work directory (as File) * Get temporary work directory (as File)
* @return directory as File * @return directory as File
* @throws java.io.IOException if the directory cannot be created.
*/ */
public File getTempWorkDirFile(); public File getTempWorkDirFile() throws IOException;
/** /**
* Cleanup * Cleanup

View File

@@ -13,7 +13,6 @@ import org.apache.cocoon.servlet.multipart.PartOnDisk;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.dspace.app.itemimport.ItemImportServiceImpl;
import org.dspace.app.itemimport.factory.ItemImportServiceFactory; import org.dspace.app.itemimport.factory.ItemImportServiceFactory;
import org.dspace.app.itemimport.service.ItemImportService; import org.dspace.app.itemimport.service.ItemImportService;
import org.dspace.app.xmlui.wing.Message; import org.dspace.app.xmlui.wing.Message;
@@ -21,7 +20,6 @@ import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Collection; import org.dspace.content.Collection;
import org.dspace.core.Context; import org.dspace.core.Context;
import org.dspace.core.LogManager; import org.dspace.core.LogManager;
import org.dspace.handle.HandleServiceImpl;
import org.dspace.handle.factory.HandleServiceFactory; import org.dspace.handle.factory.HandleServiceFactory;
import org.dspace.handle.service.HandleService; import org.dspace.handle.service.HandleService;
@@ -51,7 +49,7 @@ public class FlowBatchImportUtils {
private static final Message T_failed_no_collection = new Message("default", "xmlui.administrative.batchimport.flow.failed_no_collection"); private static final Message T_failed_no_collection = new Message("default", "xmlui.administrative.batchimport.flow.failed_no_collection");
// Other variables // Other variables
private static Logger log = Logger.getLogger(FlowBatchImportUtils.class); private static final Logger log = Logger.getLogger(FlowBatchImportUtils.class);
protected static final HandleService handleService = HandleServiceFactory.getInstance().getHandleService(); protected static final HandleService handleService = HandleServiceFactory.getInstance().getHandleService();
protected static final ItemImportService itemImportService = ItemImportServiceFactory.getInstance().getItemImportService(); protected static final ItemImportService itemImportService = ItemImportServiceFactory.getInstance().getItemImportService();
@@ -138,17 +136,19 @@ public class FlowBatchImportUtils {
File mapFile = null; File mapFile = null;
try { try {
mapFile = File.createTempFile(file.getName(), ".map", itemImportService.getTempWorkDirFile()); mapFile = File.createTempFile(file.getName(), ".map", itemImportService.getTempWorkDirFile());
log.debug("Temporary map file " + mapFile.getAbsolutePath());
} catch (IOException e) { } catch (IOException e) {
log.error("BatchImportUI Unable to create mapfile", e); log.error("BatchImportUI Unable to create mapfile", e);
result.setContinue(false); result.setContinue(false);
result.setOutcome(false); result.setOutcome(false);
result.setMessage(T_import_failed); result.setMessage(T_import_failed);
result.setCharacters("On server: " + e.getMessage());
return result; return result;
} }
log.info("Attempt UIBatchImport to collection: " + collections.get(0).getName() log.info("Attempt UIBatchImport to collection: " + collections.get(0).getName()
+ ", zip: " + file.getName() + ", zip: " + file.getAbsolutePath()
+ ", map: " + mapFile.getAbsolutePath()); + ", map: " + mapFile.getAbsolutePath());
/* /*
@@ -176,6 +176,7 @@ public class FlowBatchImportUtils {
String sourceBatchDir = null; String sourceBatchDir = null;
try { try {
sourceBatchDir = itemImportService.unzip(file); sourceBatchDir = itemImportService.unzip(file);
log.debug("Unzipped to " + sourceBatchDir);
} catch (IOException e) { } catch (IOException e) {
log.error("BatchImportUI Unable to unzip", e); log.error("BatchImportUI Unable to unzip", e);
result.setContinue(false); result.setContinue(false);