diff --git a/dspace-api/src/main/java/org/dspace/app/itemimport/ItemImport.java b/dspace-api/src/main/java/org/dspace/app/itemimport/ItemImport.java index 64f220c85e..6522c38fe2 100644 --- a/dspace-api/src/main/java/org/dspace/app/itemimport/ItemImport.java +++ b/dspace-api/src/main/java/org/dspace/app/itemimport/ItemImport.java @@ -2196,20 +2196,20 @@ public class ItemImport final Collection theOwningCollection = owningCollection; final String zipurl = url; -/* Thread go = new Thread() + Thread go = new Thread() { public void run() { Context context = null; -*/ + String importDir = null; try { // create a new dspace context - // context = new Context(); - // context.setCurrentUser(eperson); - // context.setIgnoreAuthorization(true); + context = new Context(); + context.setCurrentUser(eperson); + context.setIgnoreAuthorization(true); InputStream is = new URL(zipurl).openStream(); @@ -2255,7 +2255,7 @@ public class ItemImport } else { - System.out.println("Extracting file: " + entry.getName()); + //System.out.println("Extracting file: " + entry.getName()); int index = entry.getName().lastIndexOf('/'); if (index == -1) { @@ -2352,12 +2352,190 @@ public class ItemImport context.abort(); } } -/* } + } }; go.isDaemon(); - go.start();*/ + go.start(); + } + + public static void processResumableImport(String url, Collection owningCollection, Collection[] collections, String resumeDir, Context context) throws Exception + { + final EPerson eperson = context.getCurrentUser(); + final Collection[] otherCollections = collections; + final Collection theOwningCollection = owningCollection; + final String zipurl = url; + final String resumePath = resumeDir; + + Thread go = new Thread() + { + public void run() + { + Context context = null; + + String importDir = null; + + try { + + // create a new dspace context + context = new Context(); + context.setCurrentUser(eperson); + context.setIgnoreAuthorization(true); + + InputStream is = new URL(zipurl).openStream(); + + importDir = ConfigurationManager.getProperty("org.dspace.app.batchitemimport.work.dir") + File.separator + "batchuploads" + File.separator + context.getCurrentUser().getID() + File.separator + resumePath; + File importDirFile = new File(importDir); + if (!importDirFile.exists()){ + boolean success = importDirFile.mkdirs(); + if (!success) { + log.info("Cannot create batch import directory!"); + throw new Exception("Cannot create batch import directory!"); + } + } + + String dataZipPath = importDirFile + File.separator + "data.zip"; + String dataZipDir = importDirFile + File.separator + "data_unzipped" + File.separator; + + //Clear these files, since it is a resume + (new File(dataZipPath)).delete(); + (new File(dataZipDir)).delete(); + + OutputStream os = new FileOutputStream(dataZipPath); + + byte[] b = new byte[2048]; + int length; + + while ((length = is.read(b)) != -1) { + os.write(b, 0, length); + } + + is.close(); + os.close(); + + + + ZipFile zf = new ZipFile(dataZipPath); + ZipEntry entry; + Enumeration entries = zf.entries(); + while (entries.hasMoreElements()) + { + entry = entries.nextElement(); + if (entry.isDirectory()) + { + if (!new File(dataZipDir + entry.getName()).mkdir()) + { + log.error("Unable to create contents directory"); + } + } + else + { + //System.out.println("Extracting file: " + entry.getName()); + int index = entry.getName().lastIndexOf('/'); + if (index == -1) + { + // Was it created on Windows instead? + index = entry.getName().lastIndexOf('\\'); + } + if (index > 0) + { + File dir = new File(dataZipDir + entry.getName().substring(0, index)); + if (!dir.mkdirs()) + { + log.error("Unable to create directory"); + } + } + byte[] buffer = new byte[1024]; + int len; + InputStream in = zf.getInputStream(entry); + BufferedOutputStream out = new BufferedOutputStream( + new FileOutputStream(dataZipDir + entry.getName())); + while((len = in.read(buffer)) >= 0) + { + out.write(buffer, 0, len); + } + in.close(); + out.close(); + } + } + zf.close(); + + + String sourcePath = dataZipDir; + String mapFilePath = importDirFile + File.separator + "mapfile"; + + + ItemImport myloader = new ItemImport(); + myloader.isResume = true; + + Collection[] finalCollections = null; + if (theOwningCollection != null){ + finalCollections = new Collection[otherCollections.length + 1]; + finalCollections[0] = theOwningCollection; + for (int i=0; i collections = Arrays.asList(Collection.findAll(context)); + request.setAttribute("collections", collections); + + // Forward to main mydspace page + JSPManager.showJSP(request, response, "/dspace-admin/batchimport.jsp"); + } + else { + showMainPage(context, request, response); + } + } + + // **************************************************************** // **************************************************************** // METHODS FOR SHOWING FORMS diff --git a/dspace-jspui/src/main/webapp/dspace-admin/batchimport.jsp b/dspace-jspui/src/main/webapp/dspace-admin/batchimport.jsp index 7c1e9b1c0e..3a185360cd 100644 --- a/dspace-jspui/src/main/webapp/dspace-admin/batchimport.jsp +++ b/dspace-jspui/src/main/webapp/dspace-admin/batchimport.jsp @@ -24,7 +24,9 @@ List collections = (List)request.getAttribute("collections"); String hasErrorS = (String)request.getAttribute("has-error"); - boolean hasError = (hasErrorS==null) ? true : (Boolean.parseBoolean((String)request.getAttribute("has-error"))); + boolean hasError = (hasErrorS==null) ? false : (Boolean.parseBoolean((String)request.getAttribute("has-error"))); + + String uploadId = (String)request.getAttribute("uploadId"); String message = (String)request.getAttribute("message"); @@ -63,10 +65,14 @@ } %> -
+ + <% if (uploadId != null) { %> + + <% } %> +

diff --git a/dspace-jspui/src/main/webapp/mydspace/main.jsp b/dspace-jspui/src/main/webapp/mydspace/main.jsp index 1db14a825f..a248d33fbd 100644 --- a/dspace-jspui/src/main/webapp/mydspace/main.jsp +++ b/dspace-jspui/src/main/webapp/mydspace/main.jsp @@ -405,13 +405,54 @@ <%if(importsAvailable!=null && importsAvailable.size()>0){ %>

-
    - <%for(BatchUpload batchUpload : importsAvailable){%> -
  1. <%= batchUpload.getDateFormatted() + " --- " + (batchUpload.isSuccessful()?"Success":"Unsuccess") %>
  2. - <% } %> -
+
    + <% int i=0; + for(BatchUpload batchUpload : importsAvailable){ + %> +
  • +
    <%= batchUpload.getDateFormatted() %>
    + <% if (batchUpload.isSuccessful()){ %> +
      -->
    + <% } else { %> +
      -->
    + <% } %> +
    +
  • + <% i++; + } + %> +
<%} %> + +