-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'DS-2177-JSPUI-batchimport' into master
- Loading branch information
Showing
10 changed files
with
1,294 additions
and
256 deletions.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
dspace-api/src/main/java/org/dspace/app/itemimport/BatchUpload.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/** | ||
* The contents of this file are subject to the license and copyright | ||
* detailed in the LICENSE and NOTICE files at the root of the source | ||
* tree and available online at | ||
* | ||
* http://www.dspace.org/license/ | ||
*/ | ||
package org.dspace.app.itemimport; | ||
|
||
import java.io.File; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.io.LineNumberReader; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Calendar; | ||
import java.util.Date; | ||
import java.util.GregorianCalendar; | ||
|
||
/** | ||
* @author kstamatis | ||
* | ||
*/ | ||
public class BatchUpload { | ||
|
||
private Date date; | ||
private File dir; | ||
private boolean successful; | ||
private int itemsImported; | ||
private int totalItems = 0; | ||
|
||
/** | ||
* | ||
*/ | ||
public BatchUpload(String dirPath) { | ||
|
||
this.initializeWithFile(new File(dirPath)); | ||
|
||
} | ||
|
||
public BatchUpload(File dir) { | ||
|
||
this.initializeWithFile(dir); | ||
|
||
} | ||
|
||
|
||
private void initializeWithFile(File dir){ | ||
|
||
this.dir = dir; | ||
|
||
String dirName = dir.getName(); | ||
long timeMillis = Long.parseLong(dirName); | ||
Calendar calendar = new GregorianCalendar(); | ||
calendar.setTimeInMillis(timeMillis); | ||
this.date = calendar.getTime(); | ||
|
||
try { | ||
this.itemsImported = BatchUpload.countLines(dir + File.separator + "mapfile"); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
|
||
for (File file : dir.listFiles()){ | ||
if (file.isDirectory()){ | ||
this.totalItems = file.list().length; | ||
} | ||
} | ||
|
||
this.successful = this.totalItems == this.itemsImported; | ||
|
||
} | ||
|
||
static private int countLines(String filename) throws IOException { | ||
LineNumberReader reader = new LineNumberReader(new FileReader(filename)); | ||
int cnt = 0; | ||
String lineRead = ""; | ||
while ((lineRead = reader.readLine()) != null) {} | ||
|
||
cnt = reader.getLineNumber(); | ||
reader.close(); | ||
return cnt; | ||
} | ||
|
||
public Date getDate() { | ||
return date; | ||
} | ||
|
||
public File getDir() { | ||
return dir; | ||
} | ||
|
||
public boolean isSuccessful() { | ||
return successful; | ||
} | ||
|
||
public int getItemsImported() { | ||
return itemsImported; | ||
} | ||
|
||
public int getTotalItems() { | ||
return totalItems; | ||
} | ||
|
||
public String getDateFormatted(){ | ||
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy - HH:mm"); | ||
|
||
return df.format(date); | ||
} | ||
} |
Oops, something went wrong.