diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index d291b3d7..ee635a31 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -8,6 +8,12 @@
+
diff --git a/app/build.gradle b/app/build.gradle
index 40bf3a0c..ea746f26 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -109,4 +109,5 @@ dependencies {
implementation 'com.liulishuo.okdownload:sqlite:1.0.5'
implementation 'com.liulishuo.okdownload:okhttp:1.0.5'
implementation 'com.squareup.okhttp3:okhttp:4.2.2'
+ implementation 'commons-net:commons-net:3.6'
}
diff --git a/app/src/main/java/com/mobilegenomics/f5n/activity/DownloadActivity.java b/app/src/main/java/com/mobilegenomics/f5n/activity/DownloadActivity.java
index 952973c9..e9f75a04 100644
--- a/app/src/main/java/com/mobilegenomics/f5n/activity/DownloadActivity.java
+++ b/app/src/main/java/com/mobilegenomics/f5n/activity/DownloadActivity.java
@@ -5,8 +5,10 @@
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.net.Uri;
+import android.os.AsyncTask;
import android.os.Bundle;
import android.text.TextUtils;
+import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
@@ -19,47 +21,135 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
+import com.liulishuo.okdownload.DownloadTask;
+import com.liulishuo.okdownload.core.Util;
import com.liulishuo.okdownload.core.cause.EndCause;
import com.mobilegenomics.f5n.GUIConfiguration;
import com.mobilegenomics.f5n.R;
import com.mobilegenomics.f5n.core.AppMode;
import com.mobilegenomics.f5n.support.DownloadListener;
import com.mobilegenomics.f5n.support.DownloadManager;
+import com.mobilegenomics.f5n.support.PipelineState;
import com.mobilegenomics.f5n.support.PreferenceUtil;
import com.mobilegenomics.f5n.support.ZipListener;
import com.mobilegenomics.f5n.support.ZipManager;
import com.obsez.android.lib.filechooser.ChooserDialog;
import java.io.File;
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+import org.apache.commons.net.ftp.FTP;
+import org.apache.commons.net.ftp.FTPClient;
+import org.apache.commons.net.ftp.FTPFile;
+import org.apache.commons.net.io.CopyStreamAdapter;
public class DownloadActivity extends AppCompatActivity {
- private static final String TAG = DownloadActivity.class.getSimpleName();
+ class FTPDownloadTask extends AsyncTask {
- private String folderPath;
+ long fileSize;
- private static final String ecoliDataSetURL = "https://zanojmobiapps.com/_tmp/genome/ecoli/ecoli-data-set.zip";
+ boolean status;
- LinearLayout linearLayout;
+ @Override
+ protected Boolean doInBackground(String... urls) {
+ FTPClient con;
+ try {
+ con = new FTPClient();
+ con.setDefaultPort(8000);
+ con.connect(urls[0]);
- EditText urlInputPath;
+ con.setCopyStreamListener(new CopyStreamAdapter() {
+ @Override
+ public void bytesTransferred(long totalBytesTransferred, int bytesTransferred, long streamSize) {
+ publishProgress(totalBytesTransferred);
+ }
- EditText folderPathInput;
+ });
- TextView statusTextView;
+ if (con.login("test", "test")) {
+ con.enterLocalPassiveMode(); // important!
+ con.setFileType(FTP.BINARY_FILE_TYPE);
+ con.setBufferSize(1024000);
+ FTPFile[] ff = con.listFiles(urls[1]);
- ProgressBar progressBar;
+ if (ff != null) {
+ fileSize = (ff[0].getSize());
+ }
+
+ OutputStream out = new FileOutputStream(new File(folderPath + "/" + urls[1]));
+ status = con.retrieveFile(urls[1], out);
+ out.close();
+ con.logout();
+ con.disconnect();
+ }
+ } catch (Exception e) {
+ Log.e(TAG, "Error: " + e);
+ status = false;
+ }
+ return status;
+ }
+
+ @Override
+ protected void onPostExecute(final Boolean downloadSuccess) {
+ super.onPostExecute(downloadSuccess);
+ Log.i(TAG, "Download Finished");
+ if (downloadSuccess) {
+ statusTextView.setText("Download Completed");
+ } else {
+ statusTextView.setText("Download Error");
+ }
+ enableButtons();
+ }
+
+ @Override
+ protected void onPreExecute() {
+ super.onPreExecute();
+ Log.i(TAG, "Download Started");
+ statusTextView.setText("Download Started");
+ progressBar.setMax(100);
+ disableButtons();
+ }
+
+ @Override
+ protected void onProgressUpdate(final Long... values) {
+ super.onProgressUpdate(values);
+ String total = Util.humanReadableBytes(fileSize, true);
+ String downloaded = Util.humanReadableBytes(values[0], true);
+ statusTextView.setText("Downloading: " + downloaded + "/" + total);
+ float percent = (float) values[0] / fileSize;
+ progressBar.setProgress((int) percent * progressBar.getMax());
+ }
+ }
+
+ private static final String TAG = DownloadActivity.class.getSimpleName();
+
+ private static String folderPath;
+
+ private static final String ecoliDataSetURL = "https://zanojmobiapps.com/_tmp/genome/ecoli/ecoli-data-set.zip";
Button btnDownload;
Button btnDownloadEcoli;
- EditText filePathInput;
+ Button btnExtract;
+
+ Button btnRunPipeline;
Button btnSelectFilePath;
- Button btnExtract;
+ EditText filePathInput;
- Button btnRunPipeline;
+ EditText folderPathInput;
+
+ LinearLayout linearLayout;
+
+ ProgressBar progressBar;
+
+ TextView statusTextView;
+
+ EditText urlInputPath;
+
+ private DownloadTask downloadTask;
@SuppressLint("ClickableViewAccessibility")
@Override
@@ -75,8 +165,9 @@ protected void onCreate(@Nullable final Bundle savedInstanceState) {
if (getIntent().getExtras() != null) {
String path = getIntent().getExtras().getString("DATA_SET_URL");
+ String fileName = getIntent().getExtras().getString("FILE_NAME");
if (path != null && !TextUtils.isEmpty(path)) {
- urlInputPath.setText(path);
+ urlInputPath.setText(path + "/" + fileName + ".zip");
}
}
@@ -114,7 +205,8 @@ public void onClick(final View v) {
@Override
public void onClick(final View v) {
if (urlInputPath.getText() != null && !TextUtils.isEmpty(urlInputPath.getText().toString().trim())) {
- downloadDataSet(urlInputPath.getText().toString().trim());
+ //downloadDataSet(urlInputPath.getText().toString().trim());
+ downloadDatasetFTP(urlInputPath.getText().toString().trim());
} else {
Toast.makeText(DownloadActivity.this, "Please input a URL", Toast.LENGTH_SHORT).show();
}
@@ -187,6 +279,7 @@ public void onClick(final View v) {
btnRunPipeline.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View v) {
+ GUIConfiguration.setPipelineState(PipelineState.TO_BE_CONFIGURED);
Intent intent = new Intent(DownloadActivity.this, TerminalActivity.class);
intent.putExtra("FOLDER_PATH", folderPath.substring(0, folderPath.lastIndexOf(".")));
startActivity(intent);
@@ -196,26 +289,14 @@ public void onClick(final View v) {
}
- private void openFileManager(boolean dirOnly) {
+ private void enableButtons() {
+ btnDownload.setEnabled(true);
+ btnDownloadEcoli.setEnabled(true);
+ }
- new ChooserDialog(DownloadActivity.this)
- .withFilter(dirOnly, false)
- // to handle the result(s)
- .withChosenListener(new ChooserDialog.Result() {
- @Override
- public void onChoosePath(String path, File pathFile) {
- folderPath = path;
- if (dirOnly) {
- folderPathInput.setText(folderPath);
- enableButtons();
- } else {
- filePathInput.setText(folderPath);
- btnExtract.setEnabled(true);
- }
- }
- })
- .build()
- .show();
+ private void disableButtons() {
+ btnDownload.setEnabled(false);
+ btnDownloadEcoli.setEnabled(false);
}
private void downloadDataSet(String url) {
@@ -234,6 +315,12 @@ public void onComplete(@NonNull final EndCause cause, @Nullable final Exception
downloadManager.download(DownloadActivity.this, treeUri);
}
+ private void downloadDatasetFTP(String url) {
+ String[] urlData = url.split("/");
+ Log.e(TAG, "URL=" + urlData[1]);
+ new FTPDownloadTask().execute(urlData[0], urlData[1]);
+ }
+
private void extractZip(String filepath) {
ZipManager zipManager = new ZipManager(DownloadActivity.this, new ZipListener() {
@@ -284,13 +371,26 @@ public void run() {
zipManager.unzip(treeUri, filepath);
}
- private void enableButtons() {
- btnDownload.setEnabled(true);
- btnDownloadEcoli.setEnabled(true);
- }
+ private void openFileManager(boolean dirOnly) {
- private void disableButtons() {
- btnDownload.setEnabled(false);
- btnDownloadEcoli.setEnabled(false);
+ new ChooserDialog(DownloadActivity.this)
+ .withFilter(dirOnly, false)
+ // to handle the result(s)
+ .withChosenListener(new ChooserDialog.Result() {
+ @Override
+ public void onChoosePath(String path, File pathFile) {
+ folderPath = path;
+ if (dirOnly) {
+ folderPathInput.setText(folderPath);
+ enableButtons();
+ } else {
+ filePathInput.setText(folderPath);
+ btnExtract.setEnabled(true);
+ }
+ }
+ })
+ .build()
+ .show();
}
+
}
diff --git a/app/src/main/java/com/mobilegenomics/f5n/activity/MinITActivity.java b/app/src/main/java/com/mobilegenomics/f5n/activity/MinITActivity.java
index 5583e241..c5e59a48 100644
--- a/app/src/main/java/com/mobilegenomics/f5n/activity/MinITActivity.java
+++ b/app/src/main/java/com/mobilegenomics/f5n/activity/MinITActivity.java
@@ -4,6 +4,7 @@
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
+import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
@@ -28,42 +29,116 @@
import com.mobilegenomics.f5n.support.ZipListener;
import com.mobilegenomics.f5n.support.ZipManager;
import java.io.File;
-import java.io.FileNotFoundException;
-import java.net.MalformedURLException;
+import java.io.FileInputStream;
import java.util.Objects;
-import net.gotev.uploadservice.BinaryUploadRequest;
-import net.gotev.uploadservice.ServerResponse;
-import net.gotev.uploadservice.UploadInfo;
-import net.gotev.uploadservice.UploadNotificationConfig;
import net.gotev.uploadservice.UploadService;
-import net.gotev.uploadservice.UploadServiceSingleBroadcastReceiver;
-import net.gotev.uploadservice.UploadStatusDelegate;
+import org.apache.commons.net.ftp.FTP;
+import org.apache.commons.net.ftp.FTPClient;
+import org.apache.commons.net.io.CopyStreamAdapter;
-public class MinITActivity extends AppCompatActivity implements UploadStatusDelegate {
+public class MinITActivity extends AppCompatActivity {
+
+ class FTPUploadTask extends AsyncTask {
+
+ boolean status;
+
+ long fileSize;
+
+ @Override
+ protected Boolean doInBackground(String... urls) {
+ FTPClient con;
+ try {
+ con = new FTPClient();
+ con.setDefaultPort(8000);
+ con.connect(urls[0]);
+
+ con.setCopyStreamListener(new CopyStreamAdapter() {
+ @Override
+ public void bytesTransferred(long totalBytesTransferred, int bytesTransferred, long streamSize) {
+ //this method will be called every time some bytes are transferred
+// int percent = (int) (totalBytesTransferred * 100 / fileSize);
+ publishProgress(totalBytesTransferred);
+ }
+
+ });
+
+ if (con.login("test", "test")) {
+ con.enterLocalPassiveMode(); // important!
+ con.setFileType(FTP.BINARY_FILE_TYPE);
+ con.setBufferSize(1024000);
+ File fileIn = new File(urls[1]);
+ fileSize = fileIn.length();
+
+ FileInputStream in = new FileInputStream(fileIn);
+ boolean result = con.storeFile(new File(urls[1]).getName(), in);
+ in.close();
+ status = result;
+ con.logout();
+ con.disconnect();
+ }
+ } catch (Exception e) {
+ Log.e(TAG, "Upload Error: ", e);
+ status = false;
+ }
+ return status;
+ }
+
+ @Override
+ protected void onCancelled() {
+ super.onCancelled();
+ statusTextView.setText("Upload cancelled");
+ }
+
+ @Override
+ protected void onPostExecute(final Boolean uploadSuccess) {
+ super.onPostExecute(uploadSuccess);
+ Log.i(TAG, "Upload Finished");
+ if (uploadSuccess) {
+ statusTextView.setText("Upload Completed");
+ sendJobResults();
+ } else {
+ statusTextView.setText("Upload Error");
+ }
+ }
+
+ @Override
+ protected void onPreExecute() {
+ super.onPreExecute();
+ statusTextView.setText("Upload started");
+ }
+
+ @Override
+ protected void onProgressUpdate(final Long... values) {
+ super.onProgressUpdate(values);
+ String total = Util.humanReadableBytes(fileSize, true);
+ String downloaded = Util.humanReadableBytes(values[0], true);
+ statusTextView.setText("Uploading: " + downloaded + "/" + total);
+ float percent = (float) values[0] / fileSize;
+ progressBar.setProgress((int) percent * progressBar.getMax());
+ }
+ }
private static final String TAG = MinITActivity.class.getSimpleName();
private static TextView connectionLogText;
- private String serverIP;
+ ProgressBar progressBar;
- private String zipFileName;
+ TextView statusTextView;
private Button btnSendResult;
+ private String folderPath;
+
private boolean ranPipeline = false;
private String resultsSummary;
- private String folderPath;
+ private String serverIP;
EditText serverAddressInput;
- TextView statusTextView;
-
- ProgressBar progressBar;
-
- private UploadServiceSingleBroadcastReceiver uploadReceiver;
+ private String zipFileName;
public static void logHandler(Handler handler) {
handler.post(new Runnable() {
@@ -87,9 +162,8 @@ protected void onCreate(Bundle savedInstanceState) {
UploadService.NAMESPACE = BuildConfig.APPLICATION_ID;
- uploadReceiver = new UploadServiceSingleBroadcastReceiver(this);
-
serverAddressInput = findViewById(R.id.input_server_address);
+
connectionLogText = findViewById(R.id.text_conn_log);
final Button btnRquestJob = findViewById(R.id.btn_request_job);
btnSendResult = findViewById(R.id.btn_send_result);
@@ -130,7 +204,8 @@ public void onClick(View v) {
Intent intent = new Intent(MinITActivity.this, DownloadActivity.class);
// TODO Fix the following
// Protocol, file server IP and Port
- intent.putExtra("DATA_SET_URL", "http://" + serverIP + ":8000/" + zipFileName);
+ intent.putExtra("DATA_SET_URL", serverIP);
+ intent.putExtra("FILE_NAME", zipFileName);
startActivity(intent);
}
});
@@ -161,6 +236,11 @@ public void pasteIPAddress(View view) {
private void requestJob() {
ServerConnectionUtils.connectToServer(State.REQUEST, new ServerCallback() {
+ @Override
+ public void onError(final WrapperObject job) {
+
+ }
+
@Override
public void onSuccess(final WrapperObject job) {
runOnUiThread(new Runnable() {
@@ -172,17 +252,17 @@ public void run() {
}
});
}
-
- @Override
- public void onError(final WrapperObject job) {
-
- }
});
}
private void sendJobResults() {
ServerConnectionUtils.setResultToWrapperObject(resultsSummary);
ServerConnectionUtils.connectToServer(State.COMPLETED, new ServerCallback() {
+ @Override
+ public void onError(final WrapperObject job) {
+
+ }
+
@Override
public void onSuccess(final WrapperObject job) {
runOnUiThread(new Runnable() {
@@ -192,11 +272,6 @@ public void run() {
}
});
}
-
- @Override
- public void onError(final WrapperObject job) {
-
- }
});
}
@@ -233,25 +308,8 @@ public void onComplete(@NonNull final boolean success, @Nullable final Exception
public void run() {
if (success) {
statusTextView.setText("Zip Successful");
- String path = folderPath + ".zip";
- try {
- String uploadId =
- new BinaryUploadRequest(MinITActivity.this, "http://" + serverIP + ":8000/")
- .setFileToUpload(path)
- .setMethod("POST")
- .addHeader("file-name", new File(path).getName())
- .setNotificationConfig(new UploadNotificationConfig())
- .setMaxRetries(2)
- .startUpload();
- // More info about receivers https://github.com/gotev/android-upload-service/wiki/Monitoring-upload-status
- uploadReceiver.setUploadID(uploadId);
- } catch (FileNotFoundException e) {
- statusTextView.setText("File IO Error");
- Log.e(TAG, "File IO Error: " + e);
- } catch (MalformedURLException e) {
- statusTextView.setText("Malformed URL Exception");
- Log.e(TAG, "URL Error: " + e);
- }
+ String path = folderPath + ".out.zip";
+ new FTPUploadTask().execute(serverIP, path);
} else {
statusTextView.setText("Zip Error");
}
@@ -262,45 +320,6 @@ public void run() {
zipManager.zip(folderPath);
}
- @Override
- public void onProgress(final Context context, final UploadInfo uploadInfo) {
- String totalBytes = Util.humanReadableBytes(uploadInfo.getTotalBytes(), true);
- String uploadedBytes = Util.humanReadableBytes(uploadInfo.getUploadedBytes(), true);
- String status = "Uploading: " + uploadedBytes + "/" + totalBytes;
- statusTextView.setText(status);
- progressBar.setProgress(uploadInfo.getProgressPercent());
- }
-
- @Override
- public void onError(final Context context, final UploadInfo uploadInfo, final ServerResponse serverResponse,
- final Exception exception) {
- statusTextView.setText("Result Upload failed: " + serverResponse.getHttpCode());
- Log.e(TAG, "Upload Failed: " + serverResponse.getBodyAsString());
- }
-
- @Override
- public void onCompleted(final Context context, final UploadInfo uploadInfo, final ServerResponse serverResponse) {
- statusTextView.setText("Result Upload completed: " + serverResponse.getHttpCode());
- sendJobResults();
- }
-
- @Override
- public void onCancelled(final Context context, final UploadInfo uploadInfo) {
- statusTextView.setText("Result Upload cancelled");
- }
-
- @Override
- protected void onResume() {
- super.onResume();
- uploadReceiver.register(this);
- }
-
- @Override
- protected void onPause() {
- super.onPause();
- uploadReceiver.unregister(this);
- }
-
private boolean validateIPAddress(final String ip) {
String PATTERN
= "^((0|1\\d?\\d?|2[0-4]?\\d?|25[0-5]?|[3-9]\\d?)\\.){3}(0|1\\d?\\d?|2[0-4]?\\d?|25[0-5]?|[3-9]\\d?)$";
diff --git a/app/src/main/java/com/mobilegenomics/f5n/support/ZipManager.java b/app/src/main/java/com/mobilegenomics/f5n/support/ZipManager.java
index f1638763..e0648b5e 100644
--- a/app/src/main/java/com/mobilegenomics/f5n/support/ZipManager.java
+++ b/app/src/main/java/com/mobilegenomics/f5n/support/ZipManager.java
@@ -300,7 +300,7 @@ protected void onPreExecute() {
totalBytesToCompress = getDirectorySize(sourceFile);
zipListener.onStarted(totalBytesToCompress);
Log.i(TAG, "Starting to zip");
- zipPath = sourcePath + ".zip";
+ zipPath = sourcePath + ".out.zip";
try {
fos = new FileOutputStream(zipPath);
} catch (FileNotFoundException e) {