Skip to content

Commit f56e394

Browse files
committed
Download files as bytes
1 parent 4a13b6b commit f56e394

6 files changed

Lines changed: 49 additions & 15 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
server-local.properties
2+
public
23
!.gitkeep
34
*.egg
45
*.egg-info

server/src/main/java/org/diskproject/server/adapters/AirFlowAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public WorkflowRun getRunStatus(String runId) {
117117
}
118118

119119
@Override
120-
public String fetchData(String dataId) {
120+
public byte[] fetchData(String dataId) {
121121
// Auto-generated method stub
122122
return null;
123123
}

server/src/main/java/org/diskproject/server/api/impl/DiskResource.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.diskproject.server.api.impl;
22

33
import java.io.IOException;
4+
import java.nio.charset.StandardCharsets;
45
import java.util.List;
56
import java.util.Map;
67

@@ -573,11 +574,13 @@ public Map<String, String> getNarratives(
573574
@Override
574575
public String getOutputData(
575576
@JsonProperty("request") ExternalDataRequest r) {
576-
String result = this.repo.getOutputData(r.getSource(), r.getDataId());
577+
byte[] result = this.repo.getOutputData(r.getSource(), r.getDataId());
578+
String tmp = ""; // FIXME: this should not be an string.
577579
if (result == null) {
578580
System.out.println("ERROR: " + r.getDataId() + " not available on " + r.getSource() + ".");
579-
result = "";
581+
} else {
582+
tmp = new String(result, StandardCharsets.UTF_8);
580583
}
581-
return result;
584+
return tmp;
582585
}
583586
}

server/src/main/java/org/diskproject/server/repository/DiskRepository.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.diskproject.server.repository;
22

33
import java.io.Serializable;
4+
import java.nio.charset.StandardCharsets;
45
import java.text.DecimalFormat;
56
import java.text.SimpleDateFormat;
67
import java.util.ArrayList;
@@ -1929,7 +1930,7 @@ public WorkflowRun getWorkflowRunStatus(String source, String id) {
19291930
return methodAdapter.getRunStatus(id);
19301931
}
19311932

1932-
public String getOutputData(String source, String id) {
1933+
public byte[] getOutputData(String source, String id) {
19331934
MethodAdapter methodAdapter = getMethodAdapterByName(source);
19341935
if (methodAdapter == null)
19351936
return null;
@@ -2067,14 +2068,15 @@ public void run() {
20672068
for (String outname : outputs.keySet()) {
20682069
if (outname.equals("p_value") || outname.equals("pval") || outname.equals("p_val")) {
20692070
String dataid = outputs.get(outname);
2070-
String wingsP = methodAdapter.fetchData(dataid);
2071-
Double pval = 0.0;
2071+
byte[] byteConf = methodAdapter.fetchData(dataid);
2072+
String wingsP = byteConf != null ? new String(byteConf, StandardCharsets.UTF_8) : null;
2073+
Double pval = null;
20722074
try {
20732075
pval = Double.valueOf(wingsP);
20742076
} catch (Exception e) {
20752077
System.err.println("[M] Error: " + dataid + " is a non valid p-value");
20762078
}
2077-
if (pval > 0) {
2079+
if (pval != null) {
20782080
System.out.println("[M] Detected p-value: " + pval);
20792081
tloi.setConfidenceValue(pval);
20802082
tloi.setConfidenceType("P-VALUE");

server/src/main/java/org/diskproject/server/repository/WingsAdapter.java

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -663,13 +663,41 @@ public String runWorkflow(String wflowname, List<VariableBinding> vbindings, Map
663663
//return null;
664664
}
665665

666-
public String fetchDataFromWings(String dataid) {
667-
String getpage = "users/" + getUsername() + "/" + domain + "/data/fetch";
668-
669-
// Check for data already present on the server
666+
public byte[] fetchDataFromWings(String dataid) {
667+
String url = this.server + "/users/" + getUsername() + "/" + domain + "/data/fetch";
668+
// Download data already present on the server
670669
List<NameValuePair> formdata = new ArrayList<NameValuePair>();
671670
formdata.add(new BasicNameValuePair("data_id", dataid));
672-
return this.get(getpage, formdata);
671+
url += "?" + URLEncodedUtils.format(formdata, "UTF-8");
672+
673+
this.login();
674+
CloseableHttpClient client = HttpClientBuilder.create().build();
675+
byte[] bytes = null;
676+
try {
677+
HttpGet securedResource = new HttpGet(url);
678+
CloseableHttpResponse httpResponse = client.execute(securedResource);
679+
try {
680+
HttpEntity responseEntity = httpResponse.getEntity();
681+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
682+
responseEntity.writeTo(baos);
683+
bytes = baos.toByteArray();
684+
EntityUtils.consume(responseEntity);
685+
httpResponse.close();
686+
} catch (Exception e) {
687+
throw e;
688+
} finally {
689+
httpResponse.close();
690+
}
691+
} catch (Exception e) {
692+
e.printStackTrace();
693+
} finally {
694+
try {
695+
client.close();
696+
} catch (IOException e) {
697+
}
698+
}
699+
700+
return bytes;
673701
}
674702

675703
public String addOrUpdateData(String id, String type, String contents, boolean addServer) {
@@ -1310,7 +1338,7 @@ public WorkflowRun getRunStatus(String runId) {
13101338
}
13111339

13121340
@Override
1313-
public String fetchData(String dataId) {
1341+
public byte[] fetchData(String dataId) {
13141342
return this.fetchDataFromWings(dataId);
13151343
}
13161344

shared/src/main/java/org/diskproject/shared/classes/adapters/MethodAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public String toString () {
8787

8888
public abstract WorkflowRun getRunStatus (String runId);
8989

90-
public abstract String fetchData (String dataId);
90+
public abstract byte[] fetchData (String dataId);
9191

9292
public abstract Map<String, String> getRunVariableBindings (String runId);
9393

0 commit comments

Comments
 (0)