mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-16 14:33:09 +00:00
[DS-2707] Throw an exception if a working directory cannot be created, report it in UI.
Add lots of debug logging, including duplication of some console output that of course won't appear when running in a webapp. Also realigned some nearby code that was hard to read.
This commit is contained in:
@@ -273,23 +273,25 @@ public class ItemImportServiceImpl implements ItemImportService, InitializingBea
|
||||
// mode
|
||||
|
||||
System.out.println("Adding items from directory: " + sourceDir);
|
||||
log.debug("Adding items from directory: " + sourceDir);
|
||||
System.out.println("Generating mapfile: " + mapFile);
|
||||
log.debug("Generating mapfile: " + mapFile);
|
||||
|
||||
boolean directoryFileCollections = false;
|
||||
if (mycollections == null)
|
||||
{
|
||||
directoryFileCollections = true;
|
||||
}
|
||||
|
||||
if (!isTest)
|
||||
{
|
||||
// get the directory names of items to skip (will be in keys of
|
||||
// hash)
|
||||
if (isResume)
|
||||
boolean directoryFileCollections = false;
|
||||
if (mycollections == null)
|
||||
{
|
||||
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
|
||||
outFile = new File(mapFile);
|
||||
mapOut = new PrintWriter(new FileWriter(outFile, isResume));
|
||||
@@ -312,39 +314,39 @@ public class ItemImportServiceImpl implements ItemImportService, InitializingBea
|
||||
|
||||
Arrays.sort(dircontents, ComparatorUtils.naturalComparator());
|
||||
|
||||
for (int i = 0; i < dircontents.length; i++)
|
||||
{
|
||||
if (skipItems.containsKey(dircontents[i]))
|
||||
for (int i = 0; i < dircontents.length; i++)
|
||||
{
|
||||
System.out.println("Skipping import of " + dircontents[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
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;
|
||||
}
|
||||
if (skipItems.containsKey(dircontents[i]))
|
||||
{
|
||||
System.out.println("Skipping import of " + dircontents[i]);
|
||||
}
|
||||
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 {
|
||||
if(mapOut!=null) {
|
||||
@@ -466,6 +468,7 @@ public class ItemImportServiceImpl implements ItemImportService, InitializingBea
|
||||
String mapOutputString = null;
|
||||
|
||||
System.out.println("Adding item from directory " + itemname);
|
||||
log.debug("adding item from directory " + itemname);
|
||||
|
||||
// create workspace item
|
||||
Item myitem = null;
|
||||
@@ -1652,7 +1655,7 @@ public class ItemImportServiceImpl implements ItemImportService, InitializingBea
|
||||
entry = entries.nextElement();
|
||||
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());
|
||||
}
|
||||
@@ -2040,17 +2043,28 @@ public class ItemImportServiceImpl implements ItemImportService, InitializingBea
|
||||
}
|
||||
|
||||
@Override
|
||||
public File getTempWorkDirFile() {
|
||||
public File getTempWorkDirFile()
|
||||
throws IOException
|
||||
{
|
||||
File tempDirFile = new File(getTempWorkDir());
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanupZipTemp() {
|
||||
System.out.println("Deleting temporary zip directory: " + tempWorkDir);
|
||||
log.debug("Deleting temporary zip directory: " + tempWorkDir);
|
||||
deleteDirectory(new File(tempWorkDir));
|
||||
}
|
||||
|
||||
|
@@ -199,8 +199,9 @@ public interface ItemImportService {
|
||||
/**
|
||||
* Get temporary work 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
|
||||
|
Reference in New Issue
Block a user