Skip to content

Commit 78e5788

Browse files
committed
Workflow inst data & fix var binding id issues
1 parent e823e77 commit 78e5788

File tree

16 files changed

+545
-414
lines changed

16 files changed

+545
-414
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import org.diskproject.shared.classes.util.WorkflowTemplateResponse;
4141
import org.diskproject.shared.classes.vocabulary.Vocabulary;
4242
import org.diskproject.shared.classes.workflow.WorkflowVariable;
43-
import org.diskproject.shared.classes.workflow.WorkflowTemplate;
4443
import org.diskproject.shared.classes.workflow.WorkflowRun;
4544

4645
import com.fasterxml.jackson.annotation.JsonProperty;
@@ -174,7 +173,7 @@ public List<TriggeredLOI> queryGoal(
174173
response.setContentType("application/json");
175174
response.setCharacterEncoding("utf-8");
176175
try {
177-
return this.repo.queryHypothesis(id);
176+
return this.repo.queryGoal(id);
178177
} catch (NotFoundException e) {
179178
try {
180179
ErrorMessage error = new ErrorMessage(e.getMessage());

server/src/main/java/org/diskproject/server/db/DiskDB.java

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import java.util.Date;
77
import java.util.List;
88

9+
import org.checkerframework.checker.units.qual.t;
10+
911
import org.diskproject.server.repository.DiskRDF;
1012
import org.diskproject.server.util.KBCache;
1113
import org.diskproject.server.util.KBUtils;
@@ -530,7 +532,7 @@ private DataQueryTemplate loadDataQueryTemplate (KBObject objTemplate) {
530532
}
531533

532534
private KBObject writeDataQueryResults (DataQueryResult queryResults) {
533-
KBObject dq = domainKB.createObjectOfClass(GUID.randomId("dqt"), DISKOnt.getClass(DISK.DATA_QUERY_TEMPLATE));
535+
KBObject dq = domainKB.createObjectOfClass(GUID.randomId("dqr"), DISKOnt.getClass(DISK.DATA_QUERY_RESULTS));
534536
KBObject qr = _writeDataQueryTemplate(queryResults, dq);
535537
if (queryResults.getQuery() != null)
536538
domainKB.setPropertyValue(qr, DISKOnt.getProperty(DISK.HAS_QUERY), domainKB.createLiteral(queryResults.getQuery()));
@@ -700,10 +702,10 @@ public List<LineOfInquiry> listLOIPreviews() {
700702
private KBObject writeWorkflowSeed (WorkflowSeed seed, String parentId) {
701703
String prefix = parentId != null ? parentId + "/seeds/" : null;
702704
KBObject seedObj = domainKB.createObjectOfClass(prefix != null ? prefix + GUID.randomId("") : null , DISKOnt.getClass(DISK.WORKFLOW_SEED));
703-
return _writeWorkflowSeed(seed, seedObj, parentId);
705+
return _writeWorkflowSeed(seed, seedObj);
704706
}
705707

706-
private KBObject _writeWorkflowSeed (WorkflowSeed seed, KBObject seedObj, String parentId) {
708+
private KBObject _writeWorkflowSeed (WorkflowSeed seed, KBObject seedObj) {
707709
if (seed.getName() != null)
708710
domainKB.setLabel(seedObj, seed.getName());
709711
if (seed.getDescription() != null)
@@ -717,19 +719,19 @@ private KBObject _writeWorkflowSeed (WorkflowSeed seed, KBObject seedObj, String
717719
if (parameters != null && parameters.size() > 0) {
718720
for (VariableBinding vBinding: parameters) {
719721
domainKB.addPropertyValue(seedObj, DISKOnt.getProperty(DISK.HAS_PARAMETER),
720-
writeVariableBinding(vBinding, parentId));
722+
writeVariableBinding(vBinding, seedObj.getID()));
721723
}
722724
}
723725
if (inputs != null && inputs.size() > 0) {
724726
for (VariableBinding vBinding: inputs) {
725727
domainKB.addPropertyValue(seedObj, DISKOnt.getProperty(DISK.HAS_INPUT),
726-
writeVariableBinding(vBinding, parentId));
728+
writeVariableBinding(vBinding, seedObj.getID()));
727729
}
728730
}
729731
if (outputs != null && outputs.size() > 0) {
730732
for (VariableBinding vBinding: outputs) {
731733
domainKB.addPropertyValue(seedObj, DISKOnt.getProperty(DISK.HAS_OUTPUT),
732-
writeVariableBinding(vBinding, parentId));
734+
writeVariableBinding(vBinding, seedObj.getID()));
733735
}
734736
}
735737
return seedObj;
@@ -775,7 +777,8 @@ private WorkflowSeed loadWorkflowSeed (KBObject seedObj) {
775777
private KBObject writeWorkflowInstantiation (WorkflowInstantiation inst, String parentId) {
776778
String prefix = parentId != null ? parentId + "/instantiations/" : null;
777779
KBObject seedObj = domainKB.createObjectOfClass(prefix != null ? prefix + GUID.randomId("") : null , DISKOnt.getClass(DISK.WORKFLOW_INSTANTIATION));
778-
KBObject instObj = _writeWorkflowSeed(inst, seedObj, parentId);
780+
KBObject instObj = _writeWorkflowSeed(inst, seedObj);
781+
String instId = instObj.getID();
779782

780783
if (inst.getStatus() != null)
781784
domainKB.setPropertyValue(instObj, DISKOnt.getClass(DISK.HAS_STATUS), domainKB.createLiteral(getStringFromStatus(inst.getStatus())) );
@@ -784,15 +787,15 @@ private KBObject writeWorkflowInstantiation (WorkflowInstantiation inst, String
784787
if (data != null && data.size() > 0) {
785788
for (VariableBinding vBinding: data) {
786789
domainKB.addPropertyValue(instObj, DISKOnt.getProperty(DISK.HAS_DATA_BINDINGS),
787-
writeVariableBinding(vBinding, parentId));
790+
writeVariableBinding(vBinding, instId));
788791
}
789792
}
790793

791794
List<Execution> execs = inst.getExecutions();
792795
if (execs != null && execs.size() > 0) {
793796
for (Execution exec: execs) {
794797
domainKB.addPropertyValue(instObj, DISKOnt.getProperty(DISK.HAS_EXECUTION),
795-
writeExecution(exec, parentId));
798+
writeExecution(exec, instId));
796799
}
797800
}
798801
return instObj;
@@ -1052,7 +1055,6 @@ public boolean writeTLOI(TriggeredLOI tloi) {
10521055
Boolean newTLOI = tloi.getId() == null || tloi.getId().equals("");
10531056
if (newTLOI) tloi.setId(createTloiURI(GUID.randomId("TriggeredLOI")));
10541057
String tloiId = tloi.getId();
1055-
//if (domainKB == null) return false;
10561058

10571059
this.rdf.startWrite();
10581060
KBObject tloiItem = writeCommonResource(tloi, tloiId, DISKOnt.getClass(DISK.TRIGGERED_LINE_OF_INQUIRY));
@@ -1112,27 +1114,27 @@ public TriggeredLOI loadTLOI(String id) {
11121114
KBObject status = domainKB.getPropertyValue(obj, DISKOnt.getProperty(DISK.HAS_STATUS));
11131115
if (status != null)
11141116
tloi.setStatus(getStatusFromString(status.getValueAsString()));
1115-
KBObject queryResult = domainKB.getPropertyValue(obj, DISKOnt.getProperty(DISK.HAS_RESULT));
1117+
KBObject queryResult = domainKB.getPropertyValue(obj, DISKOnt.getProperty(DISK.HAS_QUERY_RESULTS));
11161118
if (queryResult != null)
11171119
tloi.setQueryResults(loadDataQueryResult(queryResult));
11181120

11191121
List<KBObject> wfInst = domainKB.getPropertyValues(obj, DISKOnt.getProperty(DISK.HAS_WORKFLOW_INST));
11201122
List<KBObject> mwfInst = domainKB.getPropertyValues(obj, DISKOnt.getProperty(DISK.HAS_META_WORKFLOW_INST));
1123+
List<WorkflowInstantiation> wfList = new ArrayList<WorkflowInstantiation>();
1124+
List<WorkflowInstantiation> metaWfList = new ArrayList<WorkflowInstantiation>();
11211125

11221126
if (wfInst != null && wfInst.size() > 0) {
1123-
List<WorkflowInstantiation> list = new ArrayList<WorkflowInstantiation>();
11241127
for (KBObject t : wfInst) {
1125-
list.add(loadWorkflowInstantiation(t));
1128+
wfList.add(loadWorkflowInstantiation(t));
11261129
}
1127-
tloi.setWorkflows(list);
11281130
}
11291131
if (mwfInst != null && mwfInst.size() > 0) {
1130-
List<WorkflowInstantiation> list = new ArrayList<WorkflowInstantiation>();
11311132
for (KBObject t : mwfInst) {
1132-
list.add(loadWorkflowInstantiation(t));
1133+
metaWfList.add(loadWorkflowInstantiation(t));
11331134
}
1134-
tloi.setMetaWorkflows(list);
11351135
}
1136+
tloi.setWorkflows(wfList);
1137+
tloi.setMetaWorkflows(metaWfList);
11361138

11371139
this.rdf.end();
11381140
return tloi;
@@ -1167,9 +1169,11 @@ public List<TriggeredLOI> listTLOIs() {
11671169
List<String> ids = listObjectIdPerClass(DISKOnt.getClass(DISK.TRIGGERED_LINE_OF_INQUIRY));
11681170
for (String fullId: ids) {
11691171
String id = getLocalId(fullId);
1170-
list.add(this.loadTLOI(id));
1172+
TriggeredLOI cur = this.loadTLOI(id);
1173+
if (cur != null) {
1174+
list.add(cur);
1175+
}
11711176
}
1172-
//TriggeredLOI tloi = loadTLOI(username, tloiId.replaceAll("^.*\\/", ""));
11731177
return list;
11741178
}
11751179

server/src/main/java/org/diskproject/server/db/DiskOrchestrator.java

Lines changed: 0 additions & 5 deletions
This file was deleted.

server/src/main/java/org/diskproject/server/db/QuestionDB.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ public QuestionVariable LoadQuestionVariableFromKB (KBObject var, KBAPI kb) {
280280
return null;
281281
}
282282

283-
public List<Question> listHypothesesQuestions() {
283+
public List<Question> listQuestions() {
284284
return new ArrayList<Question>(this.allQuestions.values());
285285
}
286286

@@ -356,6 +356,14 @@ private List<VariableOption> queryForOptions (String varName, String query) thro
356356
return options;
357357
}
358358

359+
public Question getQuestion (String id) {
360+
return this.allQuestions.get(id);
361+
}
362+
363+
public QuestionVariable getVariable (String id) {
364+
return this.allVariables.get(id);
365+
}
366+
359367
public String createQuestionOptionsQuery (Question q, List<QuestionVariable> includedVariables) {
360368
if (q != null) {
361369
String queryConstraint = q.getConstraint();

server/src/main/java/org/diskproject/server/managers/DataAdapterManager.java

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@
1212
import org.diskproject.server.util.ConfigKeys;
1313
import org.diskproject.shared.classes.adapters.DataAdapter;
1414
import org.diskproject.shared.classes.common.Endpoint;
15+
import org.diskproject.shared.classes.loi.DataQueryTemplate;
16+
import org.diskproject.shared.classes.loi.LineOfInquiry;
1517

1618
public class DataAdapterManager {
1719
protected Map<String, DataAdapter> byUrl, byName;
20+
protected Map<String, DataAdapter> byId; // By endpoints ID
1821

1922
public DataAdapterManager () {
2023
this.byUrl = new HashMap<String, DataAdapter>();
@@ -87,10 +90,53 @@ public Collection<DataAdapter> values () {
8790
return this.byUrl.values();
8891
}
8992

93+
/**
94+
* Create records for each adapter into the RDF database.
95+
* @param db Diskdb where to register the adapters.
96+
*/
9097
public void registerAdapters (DiskDB db) {
98+
this.byId = new HashMap<String, DataAdapter>();
9199
for (DataAdapter adp: this.values()) {
92100
Endpoint cur = db.registerEndpoint(new Endpoint(adp.getName(), adp.getEndpointUrl()));
93-
adp.setId(cur.getId());
101+
String id = cur.getId();
102+
adp.setId(id);
103+
this.byId.put(id, adp);
94104
}
95105
}
106+
107+
/**
108+
* Finds a data adapter by their endpoint id.
109+
* Only works after registerAdapters, as the id is dependent of the database.
110+
* @param id Id of the endpoint that represents the data adapter.
111+
* @return The data adater with that endpoint id.
112+
*/
113+
public DataAdapter getMethodAdapterById (String id) {
114+
if (this.byId != null && this.byId.containsKey(id))
115+
return this.byId.get(id);
116+
return null;
117+
}
118+
119+
/**
120+
* Finds a data adapter by their endpoint.
121+
* Only works after registerAdapters, as endpoints are dependent of the database.
122+
* @param endpoint Endpoint that represents the data adapter.
123+
* @return The data adater for that endpoint.
124+
*/
125+
public DataAdapter getMethodAdapterByEndpoint (Endpoint endpoint) {
126+
if (endpoint != null && endpoint.getId() != null)
127+
return this.getMethodAdapterById(endpoint.getId());
128+
return null;
129+
}
130+
131+
/**
132+
* Finds a data adapter by their endpoint.
133+
* Only works after registerAdapters, as endpoints are dependent of the database.
134+
* @param endpoint Endpoint that represents the data adapter.
135+
* @return The data adater for that endpoint.
136+
*/
137+
public DataAdapter getMethodAdapterByLOI (LineOfInquiry loi) {
138+
DataQueryTemplate dqt = loi.getDataQueryTemplate();
139+
Endpoint e = dqt == null ? null : dqt.getEndpoint();
140+
return e == null ? null : getMethodAdapterByEndpoint(e);
141+
}
96142
}

server/src/main/java/org/diskproject/server/managers/MethodAdapterManager.java

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020

2121
public class MethodAdapterManager {
2222
protected Map<String, MethodAdapter> byUrl, byName;
23+
protected Map<String, MethodAdapter> byId; // By endpoints ID
2324

25+
/**
26+
* Manages and indexes a group of method adapters.
27+
*/
2428
public MethodAdapterManager () {
2529
this.byUrl = new HashMap<String, MethodAdapter>();
2630
this.byName = new HashMap<String, MethodAdapter>();
@@ -63,6 +67,11 @@ public MethodAdapter getMethodAdapterByUrl (String url) {
6367
return null;
6468
}
6569

70+
/**
71+
* Finds a method adapter by its name.
72+
* @param name Name of the method adapter.
73+
* @return The method adater with that name.
74+
*/
6675
public MethodAdapter getMethodAdapterByName (String name) {
6776
if (this.byName.containsKey(name))
6877
return this.byName.get(name);
@@ -107,10 +116,41 @@ public String toString () {
107116
return txt;
108117
}
109118

119+
/**
120+
* Create records for each adapter into the RDF database.
121+
* @param db Diskdb where to register the adapters.
122+
*/
110123
public void registerAdapters (DiskDB db) {
124+
this.byId = new HashMap<String, MethodAdapter>();
111125
for (MethodAdapter adp: this.values()) {
112126
Endpoint cur = db.registerEndpoint(new Endpoint(adp.getName(), adp.getEndpointUrl()));
113-
adp.setId(cur.getId());
127+
String id = cur.getId();
128+
adp.setId(id);
129+
byId.put(id, adp);
114130
}
115131
}
132+
133+
/**
134+
* Finds a method adapter by their endpoint id.
135+
* Only works after registerAdapters, as the id is dependent of the database.
136+
* @param id Id of the endpoint that represents the method adapter.
137+
* @return The method adater with that endpoint id.
138+
*/
139+
public MethodAdapter getMethodAdapterById (String id) {
140+
if (this.byId != null && this.byId.containsKey(id))
141+
return this.byId.get(id);
142+
return null;
143+
}
144+
145+
/**
146+
* Finds a method adapter by their endpoint.
147+
* Only works after registerAdapters, as endpoints are dependent of the database.
148+
* @param endpoint Endpoint that represents the method adapter.
149+
* @return The method adater for that endpoint.
150+
*/
151+
public MethodAdapter getMethodAdapterByEndpoint (Endpoint endpoint) {
152+
if (endpoint != null && endpoint.getId() != null)
153+
return this.getMethodAdapterById(endpoint.getId());
154+
return null;
155+
}
116156
}

server/src/main/java/org/diskproject/server/managers/VocabularyManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ private Vocabulary initializeVocabularyFromKB(KBAPI kb, String ns, String prefix
106106
public String getPrefixes() {
107107
String txt = "";
108108
for (Vocabulary v: this.vocabularies.values()) {
109-
txt += String.format("PREFIX %s: <%s>\n", v.getNamespace(), v.getPrefix());
109+
txt += String.format("PREFIX %s: <%s>\n", v.getPrefix(), v.getNamespace());
110110
}
111111
return txt;
112112
}

0 commit comments

Comments
 (0)