Skip to content

Commit 0a2b1b2

Browse files
committed
Fixing workflow execution
1 parent 2366cf8 commit 0a2b1b2

File tree

7 files changed

+87
-67
lines changed

7 files changed

+87
-67
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public static Set<String> interceptVariables(final String queryA, final String q
6565

6666
@Override
6767
public List<DataResult> query(String queryString) throws Exception, QueryParseException, QueryExceptionHTTP {
68-
System.out.println("SparqlAdapter.query: " + queryString);
68+
//System.out.println("SparqlAdapter.query: " + queryString);
6969
ArrayList<ArrayList<SparqlQuerySolution>> solutions = null;
7070
try {
7171
String user = this.getUsername(), pass = this.getPassword();

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -659,9 +659,8 @@ public Hypothesis addHypothesis(String username, Hypothesis hypothesis) {
659659
// Check required inputs and set ID if necessary
660660
String name = hypothesis.getName();
661661
String desc = hypothesis.getDescription();
662-
String question = hypothesis.getQuestion();
662+
String question = hypothesis.getQuestionId();
663663
String dateCreated = hypothesis.getDateCreated();
664-
System.out.println(dateCreated);
665664
if (dateCreated == null || dateCreated.equals("")) {
666665
// SET DATE
667666
hypothesis.setDateCreated(dateformatter.format(new Date()));
@@ -694,7 +693,7 @@ public Hypothesis getHypothesis(String username, String id) {
694693
public Hypothesis updateHypothesis(String username, String id, Hypothesis hypothesis) {
695694
String name = hypothesis.getName();
696695
String desc = hypothesis.getDescription();
697-
String question = hypothesis.getQuestion();
696+
String question = hypothesis.getQuestionId();
698697
if (name != null && desc != null && question != null && !name.equals("") && !desc.equals("")
699698
&& !question.equals("") &&
700699
hypothesis.getId().equals(id) && this.deleteHypothesis(username, id))
@@ -713,7 +712,7 @@ public List<Hypothesis> listHypotheses(String username) {
713712
public LineOfInquiry addLOI(String username, LineOfInquiry loi) {
714713
String name = loi.getName();
715714
String desc = loi.getDescription();
716-
String question = loi.getQuestion();
715+
String question = loi.getQuestionId();
717716
String dateCreated = loi.getDateCreated();
718717
if (dateCreated == null || dateCreated.equals("")) {
719718
// SET DATE
@@ -753,8 +752,8 @@ public List<TreeItem> listLOIs(String username) {
753752
null, l.getDateCreated(), l.getAuthor());
754753
if (l.getDateModified() != null)
755754
item.setDateModified(l.getDateModified());
756-
if (l.getQuestion() != null)
757-
item.setQuestion(l.getQuestion());
755+
if (l.getQuestionId() != null)
756+
item.setQuestion(l.getQuestionId());
758757
list.add(item);
759758
}
760759
return list;
@@ -998,7 +997,6 @@ public List<VariableOption> listVariableOptions(String sid) throws Exception {
998997
}
999998

1000999
private List<VariableOption> loadVariableOptions(String sid) throws Exception {
1001-
System.out.println("ID: " + sid);
10021000
QuestionVariable variable = null;
10031001
// FIXME: Find a better way to handle url prefix or change the request to
10041002
// include the full URI
@@ -1116,6 +1114,7 @@ public Map<String,List<VariableOption>> listDynamicOptions (QuestionOptionsReque
11161114
}
11171115

11181116
for (QuestionVariable qv: q.getVariables()) {
1117+
//System.out.println(qv.getId());
11191118
if (qv.getSubType() == null) {
11201119
String varName = qv.getVariableName();
11211120
String curQuery = query;
@@ -1126,7 +1125,7 @@ public Map<String,List<VariableOption>> listDynamicOptions (QuestionOptionsReque
11261125
}
11271126
}
11281127
}
1129-
//System.out.println("Variable " + varName + ":\n" + curQuery);
1128+
//System.out.println(query);
11301129
List<VariableOption> options = curQuery != null ?
11311130
queryForOptions(varName, curQuery)
11321131
: listVariableOptions(qv.getId().replaceAll("^.*\\/", ""));
@@ -1435,7 +1434,6 @@ public List<TriggeredLOI> queryHypothesis(String username, String id) throws Exc
14351434
// One hypothesis can match the same LOI in more than one way, the following
14361435
// for-loop handles that
14371436
for (Map<String, String> values : matchingBindings.get(loi)) {
1438-
14391437
// Creating query
14401438
String dq = getQueryBindings(loi.getDataQuery(), varPattern, values);
14411439
String query = this.getAllPrefixes() + "SELECT DISTINCT ";
@@ -1505,9 +1503,8 @@ public List<TriggeredLOI> queryHypothesis(String username, String id) throws Exc
15051503
tloi.setDataQuery(dq); // Updated data query
15061504
tloi.setDateCreated(dateformatter.format(new Date()));
15071505
tlois.add(tloi);
1508-
}
1509-
else {
1510-
System.out.println("LOI " + loi.getId() + " got no results");
1506+
} else {
1507+
System.out.println("LOI " + loi.getId() + " got no results. " + values);
15111508
}
15121509
}
15131510
}
@@ -2072,7 +2069,7 @@ public void run() {
20722069
// Start monitoring
20732070
if (allok) {
20742071
TLOIMonitoringThread monitorThread = new TLOIMonitoringThread(username, tloi, metamode);
2075-
monitor.schedule(monitorThread, 10, TimeUnit.SECONDS);
2072+
monitor.schedule(monitorThread, 15, TimeUnit.SECONDS);
20762073
} else {
20772074
System.out.println("[E] Finished: Something when wrong.");
20782075
}
@@ -2115,7 +2112,9 @@ public void run() {
21152112
WorkflowRun wstatus = methodAdapter.getRunStatus(rname);
21162113
bindings.setRun(wstatus);
21172114

2118-
if (wstatus.getStatus().equals("FAILURE")) {
2115+
if (wstatus.getStatus() == null || wstatus.getStatus().equals("FAILURE")) {
2116+
if (wstatus.getStatus() == null)
2117+
System.out.println("[E] Cannot get status for " + tloi.getId() + " - RUN " + rname);
21192118
overallStatus = Status.FAILED;
21202119
numFinished++;
21212120
continue;
@@ -2139,9 +2138,10 @@ public void run() {
21392138
String wingsP = byteConf != null ? new String(byteConf, StandardCharsets.UTF_8) : null;
21402139
Double pval = null;
21412140
try {
2142-
pval = Double.valueOf(wingsP);
2141+
String strPVal = wingsP != null ? wingsP.split("\n",2)[0] : "";
2142+
pval = Double.valueOf(strPVal);
21432143
} catch (Exception e) {
2144-
System.err.println("[M] Error: " + dataid + " is a non valid p-value");
2144+
System.err.println("[M] Error: " + dataid + " is a non valid p-value: " + wingsP);
21452145
}
21462146
if (pval != null) {
21472147
System.out.println("[M] Detected p-value: " + pval);

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

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,14 @@ private List<String> getSubClasses(String superClass) {
205205
formdata.add(new BasicNameValuePair("format", "json"));
206206
String resultjson = get(pageid, formdata);
207207
if (resultjson != null && !resultjson.equals("")) {
208-
JsonObject result = jsonParser.parse(resultjson).getAsJsonObject();
208+
JsonObject result = null;
209+
try {
210+
result = jsonParser.parse(resultjson).getAsJsonObject();
211+
} catch (Exception e) {
212+
System.out.println("Could not decode: " + resultjson);
213+
return subClasses;
214+
}
215+
209216
JsonArray bindings = result.get("results").getAsJsonObject().get("bindings").getAsJsonArray();
210217

211218
for (JsonElement binding : bindings) {
@@ -594,19 +601,25 @@ public String runWorkflow(String wflowname, List<VariableBinding> vbindings, Map
594601
}
595602

596603
//At this point we could use /expandAndRunWorkflow
597-
try {
604+
/*try {
598605
vbindings = addDataBindings(inputVariables, vbindings, getParams, true);
599606
toPost = toPlanAcceptableFormat(wflowname, vbindings, inputVariables);
600607
601608
String expandAndRun = postWithSpecifiedMediaType("users/" + getUsername() + "/" + domain + "/executions/expandAndRunWorkflow",
602609
toPost, "application/json", "application/json");
610+
611+
System.out.println("\n");
612+
System.out.println(toPost);
613+
System.out.println(expandAndRun);
614+
System.out.println("##########");
615+
603616
if (expandAndRun != null && expandAndRun.length() > 0) {
604617
return expandAndRun;
605618
}
606619
} catch (Exception e) {
607620
System.err.println("Error expanding and running " + e.getMessage());
608621
System.err.println("REQUEST: " + toPost);
609-
}
622+
}*/
610623

611624
try {
612625
vbindings = addDataBindings(inputVariables, vbindings, getParams, true);
@@ -650,7 +663,7 @@ public String runWorkflow(String wflowname, List<VariableBinding> vbindings, Map
650663
System.err.println("No templates found");
651664
return null;
652665
}
653-
System.out.println(templatesobj.size());
666+
//System.out.println(templatesobj.size());
654667
JsonObject templateobj = templatesobj.get(0).getAsJsonObject();
655668
jsonTemplate = templateobj.get("template") .toString();
656669
jsonConstraints = templateobj.get("constraints").toString();
@@ -664,7 +677,7 @@ public String runWorkflow(String wflowname, List<VariableBinding> vbindings, Map
664677
return null;
665678
}
666679

667-
// Run the first Expanded workflow
680+
// Run the first Expanded workflow
668681
List<NameValuePair> formdata = new ArrayList<NameValuePair>();
669682
formdata.add(new BasicNameValuePair("template_id", wflowname));
670683
formdata.add(new BasicNameValuePair("json", jsonTemplate));
@@ -1181,23 +1194,27 @@ private String toPlanAcceptableFormat(String wfname, List<VariableBinding> vbl,
11811194
VariableBinding vb = vbl.get(i);
11821195
if (vb.getVariable().equals(v.getName())) {
11831196
String curBinding = "\"" + wfname + v.getName() + "\":[";
1184-
String[] dBs = vb.getBinding()
1185-
.replaceFirst("^\\[", "")
1186-
.replaceFirst("\\]$", "")
1187-
.split("\\s*,\\s*");
1188-
for (int j = 0; j < dBs.length; j++) {
1189-
if (dBs[j].length() > 0) {
1190-
curBinding += "\"" + (v.isParam() ? "" : dataID) + dBs[j] + "\",";
1197+
if (v.getDimensionality() == 0) {
1198+
curBinding += "\"" + vb.getBinding() + "\"";
1199+
} else {
1200+
String[] dBs = vb.getBinding()
1201+
.replaceFirst("^\\[", "")
1202+
.replaceFirst("\\]$", "")
1203+
.split("\\s*,\\s*");
1204+
for (int j = 0; j < dBs.length; j++) {
1205+
if (dBs[j].length() > 0) {
1206+
curBinding += "\"" + (v.isParam() ? "" : dataID) + dBs[j] + "\",";
1207+
}
11911208
}
1209+
curBinding = curBinding.substring(0, curBinding.length() - 1); //rm extra comma
11921210
}
1193-
curBinding = curBinding.substring(0, curBinding.length() - 1); //rm comma
1211+
11941212
if (v.isParam()) {
11951213
paramBindings += curBinding + "],";
11961214
paramAdded = true;
11971215
} else {
11981216
dataBindings += curBinding + "],";
11991217
dataAdded = true;
1200-
12011218
}
12021219
}
12031220
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -245,9 +245,9 @@ protected boolean writeHypothesis(String username, Hypothesis hypothesis) {
245245
}
246246

247247
// Adding question template details
248-
if (hypothesis.getQuestion() != null)
248+
if (hypothesis.getQuestionId() != null)
249249
userKB.setPropertyValue(hypitem, DISKOnt.getProperty(DISK.HAS_QUESTION),
250-
userKB.createLiteral(hypothesis.getQuestion()));
250+
userKB.createLiteral(hypothesis.getQuestionId()));
251251
List<VariableBinding> questionBindings = hypothesis.getQuestionBindings();
252252
if (questionBindings != null) {
253253
for (VariableBinding vb : questionBindings) {
@@ -348,7 +348,7 @@ protected Hypothesis loadHypothesis(String username, String id) {
348348
// Question template info
349349
KBObject questionobj = userKB.getPropertyValue(hypitem, DISKOnt.getProperty(DISK.HAS_QUESTION));
350350
if (questionobj != null)
351-
hypothesis.setQuestion(questionobj.getValueAsString());
351+
hypothesis.setQuestionId(questionobj.getValueAsString());
352352

353353
ArrayList<KBObject> questionBindings = userKB.getPropertyValues(hypitem,
354354
DISKOnt.getProperty(DISK.HAS_VARIABLE_BINDING));
@@ -484,7 +484,7 @@ protected List<Hypothesis> listHypothesesPreviews(String username) {
484484
if (author != null)
485485
item.setAuthor(author);
486486
if (question != null)
487-
item.setQuestion(question);
487+
item.setQuestionId(question);
488488

489489
if (variableBindings.size() > 0)
490490
item.setQuestionBindings(variableBindings);
@@ -545,9 +545,9 @@ protected boolean writeLOI(String username, LineOfInquiry loi) {
545545
if (loi.getTableDescription() != null)
546546
userKB.setPropertyValue(loiItem, DISKOnt.getProperty(DISK.HAS_TABLE_DESCRIPTION),
547547
userKB.createLiteral(loi.getTableDescription()));
548-
if (loi.getQuestion() != null)
548+
if (loi.getQuestionId() != null)
549549
userKB.setPropertyValue(loiItem, DISKOnt.getProperty(DISK.HAS_QUESTION),
550-
userKB.createLiteral(loi.getQuestion()));
550+
userKB.createLiteral(loi.getQuestionId()));
551551
if (loi.getExplanation() != null)
552552
userKB.setPropertyValue(loiItem, DISKOnt.getProperty(DISK.HAS_DATA_QUERY_DESCRIPTION),
553553
userKB.createLiteral(loi.getExplanation()));
@@ -637,7 +637,7 @@ protected LineOfInquiry loadLOI(String username, String id) {
637637

638638
KBObject questionobj = userKB.getPropertyValue(loiItem, DISKOnt.getProperty(DISK.HAS_QUESTION));
639639
if (questionobj != null)
640-
loi.setQuestion(questionobj.getValueAsString());
640+
loi.setQuestionId(questionobj.getValueAsString());
641641

642642
KBObject explobj = userKB.getPropertyValue(loiItem, DISKOnt.getProperty(DISK.HAS_DATA_QUERY_DESCRIPTION));
643643
if (explobj != null) {
@@ -710,7 +710,7 @@ protected List<LineOfInquiry> listLOIPreviews(String username) {
710710
if (hypothesisQuery != null)
711711
item.setHypothesisQuery(hypothesisQuery);
712712
if (questionId != null)
713-
item.setQuestion(questionId);
713+
item.setQuestionId(questionId);
714714

715715
list.add(item);
716716
}

shared/src/main/java/org/diskproject/shared/classes/hypothesis/Hypothesis.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ public class Hypothesis {
1313
String dateModified;
1414
String author;
1515
String notes;
16-
String question;
16+
String questionId;
1717
List<VariableBinding> questionBindings;
1818
Graph graph; // The actual hypothesis.
1919
//For revised hypotheses
2020
String parentId;
2121

22-
public void setQuestion (String q) {
23-
this.question = q;
22+
public void setQuestionId (String q) {
23+
this.questionId = q;
2424
}
2525

26-
public String getQuestion () {
27-
return this.question;
26+
public String getQuestionId () {
27+
return this.questionId;
2828
}
2929

3030
public Hypothesis (String id, String name, String description, String parentId, Graph graph){

shared/src/main/java/org/diskproject/shared/classes/loi/LineOfInquiry.java

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,22 @@
66
import java.util.Set;
77

88
public class LineOfInquiry {
9-
String id, name, description;
10-
String hypothesisQuery, dataQuery;
11-
List<WorkflowBindings> workflows, metaWorkflows;
12-
String notes;
13-
String author;
14-
String dateCreated, dateModified;
15-
9+
public static enum UpdateStatus {
10+
ON_DATA_UPDATE, ON_METHOD_UPDATE, BOTH, DISABLED
11+
};
12+
13+
// Metadata
14+
String id, name, description, notes;
15+
// PROV
16+
String author, dateCreated, dateModified;
17+
// Data query
18+
String dataSource, dataQuery, dataQueryExplanation;
1619
String tableVariables, tableDescription;
17-
String dataQueryExplanation;
18-
String dataSource;
19-
String question;
20-
21-
Boolean active;
20+
// Methods
21+
List<WorkflowBindings> workflows, metaWorkflows;
22+
// Linking with the hypothesis (question)
23+
String hypothesisQuery, questionId;
24+
UpdateStatus active;
2225

2326
public LineOfInquiry() {
2427
this.workflows = new ArrayList<WorkflowBindings>();
@@ -29,7 +32,7 @@ public LineOfInquiry(String id, String name, String description){
2932
this.id = id;
3033
this.name = name;
3134
this.description = description;
32-
this.active = true;
35+
this.active = UpdateStatus.ON_DATA_UPDATE;
3336
}
3437

3538
public LineOfInquiry(String id,
@@ -48,23 +51,23 @@ public LineOfInquiry(String id,
4851
this.dataQuery = dataQuery;
4952
this.workflows = workflows;
5053
this.metaWorkflows = metaWorkflows;
51-
this.active = true;
54+
this.active = UpdateStatus.ON_DATA_UPDATE;
5255
}
53-
56+
5457
public void setDataSource (String ds) {
5558
this.dataSource = ds;
5659
}
57-
60+
5861
public String getDataSource () {
5962
return this.dataSource;
6063
}
6164

62-
public void setQuestion (String q) {
63-
this.question = q;
65+
public void setQuestionId (String q) {
66+
this.questionId = q;
6467
}
6568

66-
public String getQuestion () {
67-
return this.question;
69+
public String getQuestionId () {
70+
return this.questionId;
6871
}
6972

7073
public String getExplanation () {
@@ -222,11 +225,11 @@ public void setDataQueryExplanation (String v) {
222225
this.dataQueryExplanation = v;
223226
}
224227

225-
public void setActive (Boolean b) {
228+
public void setActive (UpdateStatus b) {
226229
this.active = b;
227230
}
228231

229-
public Boolean getActive () {
232+
public UpdateStatus getActive () {
230233
return this.active;
231234
}
232235
}

0 commit comments

Comments
 (0)