Skip to content

Commit

Permalink
optaional other params support for search. webstart launch support fo…
Browse files Browse the repository at this point in the history
…r search parameters.
  • Loading branch information
suranjayathilaka committed Sep 18, 2018
1 parent 0d3715e commit 3630989
Show file tree
Hide file tree
Showing 9 changed files with 178 additions and 57 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
group 'uk.ac.ebi.ena'
version 'v1.2.1'
version 'v1.2.2'

apply plugin: 'java'
apply plugin: 'idea'
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/uk/ac/ebi/ena/downloader/gui/DownloadTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ protected Void call() throws Exception {
}
}
}
file.updateProgress(1);
log.debug("calling success:" + file.getName());
file.setDownloaded(true);
succeeded();
if (file.getSize() == file.getTransferred()) {
file.updateProgress(1);
log.debug("calling success:" + file.getName());
file.setDownloaded(true);
succeeded();
}

} catch (Exception e) {
log.error("Failed download", e);
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/uk/ac/ebi/ena/downloader/gui/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public void start(Stage primaryStage) throws Exception {
parameters = getParameters();
stage = primaryStage;

log.debug("parameters:" + StringUtils.join(parameters));
System.out.println("parameters:" + StringUtils.join(parameters));
log.info("parameters:" + StringUtils.join(parameters));

FXMLLoader firstPaneLoader = new FXMLLoader(getClass().getClassLoader().getResource("search.fxml"));
Parent searchPane = firstPaneLoader.load();
Expand All @@ -66,7 +67,7 @@ public void start(Stage primaryStage) throws Exception {
firstPaneController.setResultsController(secondPaneController);
secondPaneController.setSearchController(firstPaneController);

primaryStage.setTitle("ENA FTP Downloader");
primaryStage.setTitle("ENA File Downloader");
primaryStage.setScene(searchScene);
primaryStage.setResizable(false);
primaryStage.getIcons().add(new Image("http://www.ebi.ac.uk/web_guidelines/images/logos/ena/ena_100x100.png"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ public class ResultsController implements Initializable {

@Override // This method is called by the FXMLLoader when initialization is complete
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
log.debug("initialize");
assert startDownloadBtn != null : "fx:id=\"startDownloadBtn\" was not injected: check your FXML file 'results.fxml'.";

}
Expand Down Expand Up @@ -579,7 +578,6 @@ public void run() {
int count = 0;
for (int r = 0; r < notDoneFiles.size(); r++) {
RemoteFile file = notDoneFiles.get(r);
log.info(file.getName() + " " + count);
if (file.isDownloaded()) {
count++;
}
Expand All @@ -603,7 +601,7 @@ private class StopDownloadHandler implements EventHandler<ActionEvent> {
public void handle(ActionEvent actionEvent) {
startDownloadBtn.setDisable(false);
stopDownloadBtn.setDisable(true);
log.debug("Stopping downloads");
log.info("Stopping downloads");
showMessage("Downloading stopped by user! Click Start Download to resume.", Images.EXCLAMATION);
if (executor != null) {
List<Runnable> runnables = executor.shutdownNow();
Expand Down Expand Up @@ -654,7 +652,7 @@ private class TaskFailedHandler implements EventHandler<javafx.concurrent.Worker
public void handle(WorkerStateEvent event) {
startDownloadBtn.setDisable(false);
stopDownloadBtn.setDisable(true);
log.debug("Stopping downloads");
log.info("Stopping downloads");
showMessage("Downloading stopped due to an error.", Images.EXCLAMATION);
if (executor != null) {
List<Runnable> runnables = executor.shutdownNow();
Expand Down Expand Up @@ -686,7 +684,6 @@ public void handle(WorkerStateEvent event) {
}

public void showMessage(String message, Images image) {
log.info(message);
Platform.runLater(() -> {
this.selectionLabel.setText(message);
if (image != null) {
Expand Down
152 changes: 116 additions & 36 deletions src/main/java/uk/ac/ebi/ena/downloader/gui/SearchController.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,22 @@
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import java.net.URLDecoder;
import java.util.*;

public class SearchController implements Initializable {

public static final String ERA_ID_PATTERN = "([ESDR]R[ASPXRZ][0-9]{6,}|SAMEA[0-9]{6,}|SAM[ND][0-9]{8,}|PRJ[A-Z]{2}[0-9]+)";
private final static Logger log = LoggerFactory.getLogger(SearchController.class);
public static final String PLEASE_WAIT = "Please wait...";
@FXML
private TextField accession, report, asperaExe, asperaSsh, asperaParams;
private TextField accession, report, asperaExe, asperaSsh, asperaParams, otherParams;

@FXML
private TextArea query;

@FXML
private Button accessionBtn, reportBtn, searchBtn, asperaExeBtn, asperaSshBtn, reportHelpBtn, reportLoadBtn, asperaSaveBtn;
private Button accessionBtn, reportBtn, searchBtn, asperaExeBtn, asperaSshBtn, reportHelpBtn, reportLoadBtn, asperaSaveBtn, otherParamsHelpBtn;

@FXML
private RadioButton runFilesRadio, analysisFilesRadio, ftpRadio, asperaRadio;
Expand Down Expand Up @@ -98,25 +96,90 @@ public class SearchController implements Initializable {
@Override // This method is called by the FXMLLoader when initialization is complete
public void initialize(URL fxmlFileLocation, ResourceBundle resources) {
log.debug("initialize");
boolean isWebstart = Main.parameters.getUnnamed().size() > 0;
// searchLoadingImg.setVisible(false);
setupSettingsPane();
setupSettingsPane(isWebstart);

setupAccBtn();
setupReportBtn();
setupSearchBtn();

// for webstart
String accessionParam = Main.parameters.getUnnamed().size() > 0 ? Main.parameters.getUnnamed().get(0) : Main.parameters.getNamed().get("accession");
if (!isWebstart) {
//nothing more to do here
return;
}

Map<String, String> webstartParams = parseWebstartParams(Main.parameters.getUnnamed().get(0));
String accessionParam = webstartParams.get("accession");
if (StringUtils.isNotBlank(accessionParam)) {
asperaLabel.setVisible(false);
asperaRadio.setVisible(false);
accession.setText(accessionParam);
accessionBtn.fire();
return;
}
doAutoSearch(webstartParams);

}

private void setupSettingsPane() {
private void doAutoSearch(Map<String, String> webstartParams) {
String queryParam = webstartParams.get("query");
String result = webstartParams.get("result");
List<String> params = new ArrayList<>();
String dataPortal = webstartParams.get("dataPortal");
if (StringUtils.isNotBlank(dataPortal)) {
params.add("dataPortal=" + dataPortal);
}
String limit = webstartParams.get("limit");
if (StringUtils.isNotBlank(limit)) {
params.add("limit=" + limit);
}
String includeMetagenomes = webstartParams.get("includeMetagenomes");
if (StringUtils.isNotBlank(includeMetagenomes)) {
params.add("includeMetagenomes=" + includeMetagenomes);
}
String dccDataOnly = webstartParams.get("dccDataOnly");
if (StringUtils.isNotBlank(dccDataOnly)) {
params.add("dccDataOnly=" + dccDataOnly);
}
if (StringUtils.isNotBlank(queryParam)) {
try {
query.setText(URLDecoder.decode(queryParam, "UTF-8"));
} catch (UnsupportedEncodingException e) {
showMessage("Error parsing query string. Please correct any invalid characters and retry", Images.EXCLAMATION);
}
}
if ("read_run".equals(result)) {
runFilesRadio.setSelected(true);
} else if ("analysis".equals(result)) {
analysisFilesRadio.setSelected(true);
}
if (params.size() > 0) {
otherParams.setText(StringUtils.join(params, "&"));
}
searchBtn.fire();
return;
}

private Map<String, String> parseWebstartParams(String text) {
log.info(text);
Map<String, String> map = new HashMap<>();
String[] split = text.split("&");
for (String s : split) {
String[] split1 = s.split("=");
map.put(split1[0], split1[1]);
}
return map;
}

private void setupSettingsPane(boolean isWebstart) {
settingsTPane.heightProperty().addListener((obs, oldHeight, newHeight) -> stage.sizeToScene());

if (isWebstart) {
// no aspera
asperaLabel.setVisible(false);
asperaRadio.setVisible(false);
return;
}
asperaRadio.selectedProperty().addListener((observable, oldValue, newValue) -> {
asperaConfig.setVisible(newValue);
asperaConfig.setExpanded(newValue);
Expand Down Expand Up @@ -147,8 +210,6 @@ private void setupSettingsPane() {
});
asperaSaveBtn.setOnAction(event -> saveAsperaSettings());
loadAsperaSettings();

settingsTPane.heightProperty().addListener((obs, oldHeight, newHeight) -> stage.sizeToScene());
}

private void saveAsperaSettings() {
Expand All @@ -167,7 +228,7 @@ private void saveAsperaSettings() {
showMessage("Configuration saved to " + file.getAbsolutePath(), Images.TICK);
} catch (Exception e) {
log.error("Error saving settings", e);
showMessage(e.getMessage(), Images.EXCLAMATION);
showMessage("Error while saving Aspera settings:" + e.getMessage(), Images.EXCLAMATION);
return;
}
}
Expand Down Expand Up @@ -235,8 +296,8 @@ private void loadAsperaSettings() {
}
}
} catch (Exception e) {
log.error("Error saving settings", e);
showMessage(e.getMessage(), Images.EXCLAMATION);
log.error("Error loading settings", e);
showMessage("Error while loading Aspera settings:" + e.getMessage(), Images.EXCLAMATION);
}
}

Expand All @@ -262,22 +323,13 @@ private void handleAccessionSearch(Event actionEvent) {
try {
downloadSettings = getDownloadSettings();
} catch (Exception e) {
showMessage(e.getMessage(), Images.EXCLAMATION);
showMessage("Error loading download configuration:" + e.getMessage(), Images.EXCLAMATION);
return;
}

showMessage(PLEASE_WAIT, Images.LOADING);

new Thread(() -> {
// Map<String, List<RemoteFile>> stringListMap = null;
/*try {
Future<Map<String, List<RemoteFile>>> stringListMapFuture = new WarehouseQuery().doWarehouseSearch(acc, downloadSettings.getMethod());
stringListMap = stringListMapFuture.get();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}*/
Map<String, List<RemoteFile>> stringListMap = new WarehouseQuery().doWarehouseSearch(acc, downloadSettings.getMethod());
if (stringListMap == null || stringListMap.size() == 0) {
showMessage("No downloadable files were found for the accession " + acc, Images.WARNING);
Expand Down Expand Up @@ -313,17 +365,17 @@ private void setupReportBtn() {
try {
downloadSettings = getDownloadSettings();
} catch (Exception e) {
showMessage(e.getMessage(), Images.EXCLAMATION);
showMessage("Error loading download configuration:" + e.getMessage(), Images.EXCLAMATION);
return;
}
File reportFile = new File(report.getText());
new Thread(() -> {
Map<String, List<RemoteFile>> fileListMap = null;
try {
fileListMap = new ReportParser().parseExternalReportFile(reportFile, downloadSettings.getMethod());
fileListMap = new ReportParser().parseExternalReportFile(reportFile, downloadSettings.getMethod());
} catch (Exception e) {
log.error("Parsing error:", e);
showMessage(e.getMessage(), Images.WARNING);
showMessage("Error parsing report file:" + e.getMessage(), Images.WARNING);
return;
}

Expand Down Expand Up @@ -372,20 +424,31 @@ public void handle(ActionEvent actionEvent) {
showMessage("Please enter search query string.", Images.WARNING);
return;
}
Map<String, String> otherParamsMap = new HashMap<>();
if (!StringUtils.isBlank(otherParams.getText())) {
try {
otherParamsMap = parseOtherParams(otherParams.getText());
} catch (Exception e) {
log.error("Error in other params", e);
showMessage("Invalid parameters found in 'Other Parameters'", Images.EXCLAMATION);
return;
}

}
try {
try {
downloadSettings = getDownloadSettings();
} catch (Exception e) {
showMessage(e.getMessage(), Images.EXCLAMATION);
showMessage("Error loading download configuration:" + e.getMessage(), Images.EXCLAMATION);
return;
}
// Platform.runLater(() -> {
Map<String, String> finalOtherParamsMap = otherParamsMap;
new Thread(() -> {
Map<String, List<RemoteFile>> fileListMap = new HashMap<>();
if (runFilesRadio.isSelected()) {
fileListMap = new WarehouseQuery().doPortalSearch("read_run", query.getText(), downloadSettings.getMethod());
fileListMap = new WarehouseQuery().doPortalSearch("read_run", query.getText(), finalOtherParamsMap, downloadSettings.getMethod());
} else if (analysisFilesRadio.isSelected()) {
fileListMap = new WarehouseQuery().doPortalSearch("analysis", query.getText(), downloadSettings.getMethod());
fileListMap = new WarehouseQuery().doPortalSearch("analysis", query.getText(), finalOtherParamsMap, downloadSettings.getMethod());
} else {
showMessage("Please select result type to search in.", Images.WARNING);
return;
Expand All @@ -403,7 +466,6 @@ public void handle(ActionEvent actionEvent) {
}
);
}).start();
// } );


} finally {
Expand All @@ -417,6 +479,24 @@ public void handle(ActionEvent actionEvent) {
});

searchTPane.heightProperty().addListener((obs, oldHeight, newHeight) -> stage.sizeToScene());

otherParamsHelpBtn.setOnAction(event -> {
this.hostServices.showDocument("http://www.ebi.ac.uk/ena/portal/api/doc");
});
}

private Map<String, String> parseOtherParams(String text) throws Exception {
Map<String, String> map = new HashMap<>();
String[] split = text.split("&");
for (String s : split) {
String[] split1 = s.split("=");
if (!WarehouseQuery.PORTAL_SEARCH_PARAMETERS.contains(split1[0])) {
throw new Exception("Unknown param:" + split1[0]);
}
map.put(split1[0], split1[1]);
}
return map;

}


Expand Down Expand Up @@ -454,11 +534,11 @@ public void clearMessage() {
}

public void clearFields() {
accession.clear();
// accession.clear();
// accessionBtn.setGraphic(null);
// accessionBtn.setDisable(false);
// reportBtn.setGraphic(null);
report.clear();
// report.clear();
clearMessage();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public boolean fileAlreadyDownloaded(RemoteFile remoteFile) throws Exception {
remoteFile.setSuccessIcon(MD5TableCell.SUCCESS_ICON);
if (remoteFile.getSize() == 0) {
remoteFile.setSize(downloadFile.length());
remoteFile.setTransferred(downloadFile.length());
}
return true;
}
Expand Down
Loading

0 comments on commit 3630989

Please sign in to comment.