Skip to content

Commit

Permalink
Rework JGalaxy to use new FileUploadRequest style blend4j uploads.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed May 29, 2013
1 parent 5b44686 commit 59dc5e4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 33 deletions.
46 changes: 35 additions & 11 deletions src/main/java/com/github/jmchilton/jgalaxy/UploadDisplay.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.github.jmchilton.jgalaxy;

import com.github.jmchilton.blend4j.galaxy.ToolsClient.FileUploadRequest;
import com.github.jmchilton.blend4j.galaxy.ToolsClient.UploadFile;
import com.github.jmchilton.jgalaxy.mvp.DialogDisplay;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.io.File;
import java.util.List;
import java.util.Map;
import javax.swing.table.DefaultTableModel;

Expand Down Expand Up @@ -198,8 +202,27 @@ private void fileTypeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRS
}//GEN-LAST:event_fileTypeActionPerformed

private void uploadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_uploadButtonActionPerformed
final Map<String, String> uploads = getUploads();
new UploadTask(uploads, model.getGalaxyInstance().getToolsClient(), model.getHistory().getId(), fileType.getText(), dbKeyTextField.getText(), new IndexedProgressUpdater() {
final List<UploadFile> uploads = getUploads();
final String historyId = model.getHistory().getId();
final boolean multipleFile = this.namePanel.isVisible();
final List<FileUploadRequest> uploadRequests = Lists.newArrayList();
if(multipleFile) {
final FileUploadRequest request = new FileUploadRequest(historyId, uploads);
request.setToolId("multi_upload1");
request.setDatasetName(this.datasetName.getText());
uploadRequests.add(request);
} else {
for(UploadFile file : uploads) {
final FileUploadRequest request = new FileUploadRequest(historyId, file);
uploadRequests.add(request);
}
}
for(final FileUploadRequest request : uploadRequests) {
request.setDbKey(dbKeyTextField.getText());
request.setFileType(fileType.getText());
}

new UploadTask(uploadRequests, model.getGalaxyInstance().getToolsClient(), new IndexedProgressUpdater() {

public void setProgress(int index, int percentComplete) {
uploadTable.setValueAt(percentComplete, index, 2);
Expand Down Expand Up @@ -228,15 +251,16 @@ private DefaultTableModel getUploadModel() {
return model;
}

private Map<String, String> getUploads() {
final Map<String, String> uploads = Maps.newLinkedHashMap();
final DefaultTableModel model = getUploadModel();
final int rowCount = model.getRowCount();
for(int i = 0; i < rowCount; i++) {
final String datasetName = (String) model.getValueAt(i, 0);
final String filename = (String) model.getValueAt(i, 1);
uploads.put(filename, datasetName);
}
private List<UploadFile> getUploads() {
final List<UploadFile> uploads = Lists.newArrayList();
final DefaultTableModel tableModel = getUploadModel();
final int rowCount = tableModel.getRowCount();
for(int i = 0; i < rowCount; i++) {
final String fileName = (String) tableModel.getValueAt(i, 0);
final String filename = (String) tableModel.getValueAt(i, 1);
final UploadFile file = new UploadFile(new File(filename), fileName);
uploads.add(file);
}
return uploads;
}

Expand Down
29 changes: 7 additions & 22 deletions src/main/java/com/github/jmchilton/jgalaxy/UploadTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,26 @@

import com.github.jmchilton.blend4j.galaxy.ToolsClient;
import com.sun.jersey.api.client.ClientResponse;

import java.io.IOException;
import java.io.File;
import java.util.Map;
import java.util.List;

public class UploadTask extends javax.swing.SwingWorker {
private static final int BUFFER_SIZE = 4096;
private final Map<String, String> uploads;
private final IndexedProgressUpdater progressUpdater;
private final ToolsClient toolsClient;
private final String historyId;
private final String dbKey;
private final String fileType;

UploadTask(final Map<String, String> uploads,
private final List<ToolsClient.FileUploadRequest> uploadRequests;

UploadTask(final List<ToolsClient.FileUploadRequest> uploadRequests,
final ToolsClient toolsClient,
final String historyId,
final String fileType,
final String dbKey,
final IndexedProgressUpdater progressUpdater) {
this.uploads = uploads;
this.uploadRequests = uploadRequests;
this.progressUpdater = progressUpdater;
this.historyId = historyId;
this.toolsClient = toolsClient;
this.fileType = fileType;
this.dbKey = dbKey;
}

private void uploadFiles() throws IOException {
int i = 0;
for (Map.Entry<String, String> entry : uploads.entrySet()) {
final File filename = new File(entry.getKey());
final String datasetName = entry.getValue();
System.out.println("upload to history with id " + historyId);
final ClientResponse response = toolsClient.fileUploadRequest(historyId, fileType, dbKey, filename);
for (ToolsClient.FileUploadRequest request : uploadRequests) {
final ClientResponse response = toolsClient.uploadRequest(request);
progressUpdater.setProgress(i++, 100);
}

Expand Down

0 comments on commit 59dc5e4

Please sign in to comment.