Skip to content

Commit

Permalink
Merge branch 'DS-2177-JSPUI-batchimport' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
helix84 committed Oct 20, 2014
2 parents 35d9fff + c51da34 commit d288e58
Show file tree
Hide file tree
Showing 10 changed files with 1,294 additions and 256 deletions.
109 changes: 109 additions & 0 deletions dspace-api/src/main/java/org/dspace/app/itemimport/BatchUpload.java
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);
}
}
Loading

0 comments on commit d288e58

Please sign in to comment.