Skip to content

Commit

Permalink
Workflow inst data & fix var binding id issues
Browse files Browse the repository at this point in the history
  • Loading branch information
hvarg committed Feb 20, 2024
1 parent e823e77 commit 78e5788
Show file tree
Hide file tree
Showing 16 changed files with 545 additions and 414 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.diskproject.shared.classes.util.WorkflowTemplateResponse;
import org.diskproject.shared.classes.vocabulary.Vocabulary;
import org.diskproject.shared.classes.workflow.WorkflowVariable;
import org.diskproject.shared.classes.workflow.WorkflowTemplate;
import org.diskproject.shared.classes.workflow.WorkflowRun;

import com.fasterxml.jackson.annotation.JsonProperty;
Expand Down Expand Up @@ -174,7 +173,7 @@ public List<TriggeredLOI> queryGoal(
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
try {
return this.repo.queryHypothesis(id);
return this.repo.queryGoal(id);
} catch (NotFoundException e) {
try {
ErrorMessage error = new ErrorMessage(e.getMessage());
Expand Down
42 changes: 23 additions & 19 deletions server/src/main/java/org/diskproject/server/db/DiskDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import java.util.Date;
import java.util.List;

import org.checkerframework.checker.units.qual.t;

import org.diskproject.server.repository.DiskRDF;
import org.diskproject.server.util.KBCache;
import org.diskproject.server.util.KBUtils;
Expand Down Expand Up @@ -530,7 +532,7 @@ private DataQueryTemplate loadDataQueryTemplate (KBObject objTemplate) {
}

private KBObject writeDataQueryResults (DataQueryResult queryResults) {
KBObject dq = domainKB.createObjectOfClass(GUID.randomId("dqt"), DISKOnt.getClass(DISK.DATA_QUERY_TEMPLATE));
KBObject dq = domainKB.createObjectOfClass(GUID.randomId("dqr"), DISKOnt.getClass(DISK.DATA_QUERY_RESULTS));
KBObject qr = _writeDataQueryTemplate(queryResults, dq);
if (queryResults.getQuery() != null)
domainKB.setPropertyValue(qr, DISKOnt.getProperty(DISK.HAS_QUERY), domainKB.createLiteral(queryResults.getQuery()));
Expand Down Expand Up @@ -700,10 +702,10 @@ public List<LineOfInquiry> listLOIPreviews() {
private KBObject writeWorkflowSeed (WorkflowSeed seed, String parentId) {
String prefix = parentId != null ? parentId + "/seeds/" : null;
KBObject seedObj = domainKB.createObjectOfClass(prefix != null ? prefix + GUID.randomId("") : null , DISKOnt.getClass(DISK.WORKFLOW_SEED));
return _writeWorkflowSeed(seed, seedObj, parentId);
return _writeWorkflowSeed(seed, seedObj);
}

private KBObject _writeWorkflowSeed (WorkflowSeed seed, KBObject seedObj, String parentId) {
private KBObject _writeWorkflowSeed (WorkflowSeed seed, KBObject seedObj) {
if (seed.getName() != null)
domainKB.setLabel(seedObj, seed.getName());
if (seed.getDescription() != null)
Expand All @@ -717,19 +719,19 @@ private KBObject _writeWorkflowSeed (WorkflowSeed seed, KBObject seedObj, String
if (parameters != null && parameters.size() > 0) {
for (VariableBinding vBinding: parameters) {
domainKB.addPropertyValue(seedObj, DISKOnt.getProperty(DISK.HAS_PARAMETER),
writeVariableBinding(vBinding, parentId));
writeVariableBinding(vBinding, seedObj.getID()));
}
}
if (inputs != null && inputs.size() > 0) {
for (VariableBinding vBinding: inputs) {
domainKB.addPropertyValue(seedObj, DISKOnt.getProperty(DISK.HAS_INPUT),
writeVariableBinding(vBinding, parentId));
writeVariableBinding(vBinding, seedObj.getID()));
}
}
if (outputs != null && outputs.size() > 0) {
for (VariableBinding vBinding: outputs) {
domainKB.addPropertyValue(seedObj, DISKOnt.getProperty(DISK.HAS_OUTPUT),
writeVariableBinding(vBinding, parentId));
writeVariableBinding(vBinding, seedObj.getID()));
}
}
return seedObj;
Expand Down Expand Up @@ -775,7 +777,8 @@ private WorkflowSeed loadWorkflowSeed (KBObject seedObj) {
private KBObject writeWorkflowInstantiation (WorkflowInstantiation inst, String parentId) {
String prefix = parentId != null ? parentId + "/instantiations/" : null;
KBObject seedObj = domainKB.createObjectOfClass(prefix != null ? prefix + GUID.randomId("") : null , DISKOnt.getClass(DISK.WORKFLOW_INSTANTIATION));
KBObject instObj = _writeWorkflowSeed(inst, seedObj, parentId);
KBObject instObj = _writeWorkflowSeed(inst, seedObj);
String instId = instObj.getID();

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

List<Execution> execs = inst.getExecutions();
if (execs != null && execs.size() > 0) {
for (Execution exec: execs) {
domainKB.addPropertyValue(instObj, DISKOnt.getProperty(DISK.HAS_EXECUTION),
writeExecution(exec, parentId));
writeExecution(exec, instId));
}
}
return instObj;
Expand Down Expand Up @@ -1052,7 +1055,6 @@ public boolean writeTLOI(TriggeredLOI tloi) {
Boolean newTLOI = tloi.getId() == null || tloi.getId().equals("");
if (newTLOI) tloi.setId(createTloiURI(GUID.randomId("TriggeredLOI")));
String tloiId = tloi.getId();
//if (domainKB == null) return false;

this.rdf.startWrite();
KBObject tloiItem = writeCommonResource(tloi, tloiId, DISKOnt.getClass(DISK.TRIGGERED_LINE_OF_INQUIRY));
Expand Down Expand Up @@ -1112,27 +1114,27 @@ public TriggeredLOI loadTLOI(String id) {
KBObject status = domainKB.getPropertyValue(obj, DISKOnt.getProperty(DISK.HAS_STATUS));
if (status != null)
tloi.setStatus(getStatusFromString(status.getValueAsString()));
KBObject queryResult = domainKB.getPropertyValue(obj, DISKOnt.getProperty(DISK.HAS_RESULT));
KBObject queryResult = domainKB.getPropertyValue(obj, DISKOnt.getProperty(DISK.HAS_QUERY_RESULTS));
if (queryResult != null)
tloi.setQueryResults(loadDataQueryResult(queryResult));

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

if (wfInst != null && wfInst.size() > 0) {
List<WorkflowInstantiation> list = new ArrayList<WorkflowInstantiation>();
for (KBObject t : wfInst) {
list.add(loadWorkflowInstantiation(t));
wfList.add(loadWorkflowInstantiation(t));
}
tloi.setWorkflows(list);
}
if (mwfInst != null && mwfInst.size() > 0) {
List<WorkflowInstantiation> list = new ArrayList<WorkflowInstantiation>();
for (KBObject t : mwfInst) {
list.add(loadWorkflowInstantiation(t));
metaWfList.add(loadWorkflowInstantiation(t));
}
tloi.setMetaWorkflows(list);
}
tloi.setWorkflows(wfList);
tloi.setMetaWorkflows(metaWfList);

this.rdf.end();
return tloi;
Expand Down Expand Up @@ -1167,9 +1169,11 @@ public List<TriggeredLOI> listTLOIs() {
List<String> ids = listObjectIdPerClass(DISKOnt.getClass(DISK.TRIGGERED_LINE_OF_INQUIRY));
for (String fullId: ids) {
String id = getLocalId(fullId);
list.add(this.loadTLOI(id));
TriggeredLOI cur = this.loadTLOI(id);
if (cur != null) {
list.add(cur);
}
}
//TriggeredLOI tloi = loadTLOI(username, tloiId.replaceAll("^.*\\/", ""));
return list;
}

Expand Down

This file was deleted.

10 changes: 9 additions & 1 deletion server/src/main/java/org/diskproject/server/db/QuestionDB.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public QuestionVariable LoadQuestionVariableFromKB (KBObject var, KBAPI kb) {
return null;
}

public List<Question> listHypothesesQuestions() {
public List<Question> listQuestions() {
return new ArrayList<Question>(this.allQuestions.values());
}

Expand Down Expand Up @@ -356,6 +356,14 @@ private List<VariableOption> queryForOptions (String varName, String query) thro
return options;
}

public Question getQuestion (String id) {
return this.allQuestions.get(id);
}

public QuestionVariable getVariable (String id) {
return this.allVariables.get(id);
}

public String createQuestionOptionsQuery (Question q, List<QuestionVariable> includedVariables) {
if (q != null) {
String queryConstraint = q.getConstraint();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
import org.diskproject.server.util.ConfigKeys;
import org.diskproject.shared.classes.adapters.DataAdapter;
import org.diskproject.shared.classes.common.Endpoint;
import org.diskproject.shared.classes.loi.DataQueryTemplate;
import org.diskproject.shared.classes.loi.LineOfInquiry;

public class DataAdapterManager {
protected Map<String, DataAdapter> byUrl, byName;
protected Map<String, DataAdapter> byId; // By endpoints ID

public DataAdapterManager () {
this.byUrl = new HashMap<String, DataAdapter>();
Expand Down Expand Up @@ -87,10 +90,53 @@ public Collection<DataAdapter> values () {
return this.byUrl.values();
}

/**
* Create records for each adapter into the RDF database.
* @param db Diskdb where to register the adapters.
*/
public void registerAdapters (DiskDB db) {
this.byId = new HashMap<String, DataAdapter>();
for (DataAdapter adp: this.values()) {
Endpoint cur = db.registerEndpoint(new Endpoint(adp.getName(), adp.getEndpointUrl()));
adp.setId(cur.getId());
String id = cur.getId();
adp.setId(id);
this.byId.put(id, adp);
}
}

/**
* Finds a data adapter by their endpoint id.
* Only works after registerAdapters, as the id is dependent of the database.
* @param id Id of the endpoint that represents the data adapter.
* @return The data adater with that endpoint id.
*/
public DataAdapter getMethodAdapterById (String id) {
if (this.byId != null && this.byId.containsKey(id))
return this.byId.get(id);
return null;
}

/**
* Finds a data adapter by their endpoint.
* Only works after registerAdapters, as endpoints are dependent of the database.
* @param endpoint Endpoint that represents the data adapter.
* @return The data adater for that endpoint.
*/
public DataAdapter getMethodAdapterByEndpoint (Endpoint endpoint) {
if (endpoint != null && endpoint.getId() != null)
return this.getMethodAdapterById(endpoint.getId());
return null;
}

/**
* Finds a data adapter by their endpoint.
* Only works after registerAdapters, as endpoints are dependent of the database.
* @param endpoint Endpoint that represents the data adapter.
* @return The data adater for that endpoint.
*/
public DataAdapter getMethodAdapterByLOI (LineOfInquiry loi) {
DataQueryTemplate dqt = loi.getDataQueryTemplate();
Endpoint e = dqt == null ? null : dqt.getEndpoint();
return e == null ? null : getMethodAdapterByEndpoint(e);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@

public class MethodAdapterManager {
protected Map<String, MethodAdapter> byUrl, byName;
protected Map<String, MethodAdapter> byId; // By endpoints ID

/**
* Manages and indexes a group of method adapters.
*/
public MethodAdapterManager () {
this.byUrl = new HashMap<String, MethodAdapter>();
this.byName = new HashMap<String, MethodAdapter>();
Expand Down Expand Up @@ -63,6 +67,11 @@ public MethodAdapter getMethodAdapterByUrl (String url) {
return null;
}

/**
* Finds a method adapter by its name.
* @param name Name of the method adapter.
* @return The method adater with that name.
*/
public MethodAdapter getMethodAdapterByName (String name) {
if (this.byName.containsKey(name))
return this.byName.get(name);
Expand Down Expand Up @@ -107,10 +116,41 @@ public String toString () {
return txt;
}

/**
* Create records for each adapter into the RDF database.
* @param db Diskdb where to register the adapters.
*/
public void registerAdapters (DiskDB db) {
this.byId = new HashMap<String, MethodAdapter>();
for (MethodAdapter adp: this.values()) {
Endpoint cur = db.registerEndpoint(new Endpoint(adp.getName(), adp.getEndpointUrl()));
adp.setId(cur.getId());
String id = cur.getId();
adp.setId(id);
byId.put(id, adp);
}
}

/**
* Finds a method adapter by their endpoint id.
* Only works after registerAdapters, as the id is dependent of the database.
* @param id Id of the endpoint that represents the method adapter.
* @return The method adater with that endpoint id.
*/
public MethodAdapter getMethodAdapterById (String id) {
if (this.byId != null && this.byId.containsKey(id))
return this.byId.get(id);
return null;
}

/**
* Finds a method adapter by their endpoint.
* Only works after registerAdapters, as endpoints are dependent of the database.
* @param endpoint Endpoint that represents the method adapter.
* @return The method adater for that endpoint.
*/
public MethodAdapter getMethodAdapterByEndpoint (Endpoint endpoint) {
if (endpoint != null && endpoint.getId() != null)
return this.getMethodAdapterById(endpoint.getId());
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private Vocabulary initializeVocabularyFromKB(KBAPI kb, String ns, String prefix
public String getPrefixes() {
String txt = "";
for (Vocabulary v: this.vocabularies.values()) {
txt += String.format("PREFIX %s: <%s>\n", v.getNamespace(), v.getPrefix());
txt += String.format("PREFIX %s: <%s>\n", v.getPrefix(), v.getNamespace());
}
return txt;
}
Expand Down
Loading

0 comments on commit 78e5788

Please sign in to comment.