33import java .net .URL ;
44import java .text .SimpleDateFormat ;
55import java .util .ArrayList ;
6+ import java .util .Arrays ;
67import java .util .Date ;
78import java .util .List ;
89
2021import org .diskproject .shared .classes .hypothesis .GoalResult ;
2122import org .diskproject .shared .classes .loi .DataQueryResult ;
2223import org .diskproject .shared .classes .loi .DataQueryTemplate ;
24+ import org .diskproject .shared .classes .loi .LOICommon ;
2325import org .diskproject .shared .classes .loi .LineOfInquiry ;
2426import org .diskproject .shared .classes .loi .TriggeredLOI ;
2527import org .diskproject .shared .classes .question .Question ;
@@ -507,8 +509,10 @@ private KBObject _writeDataQueryTemplate (DataQueryTemplate dataQuery, KBObject
507509 domainKB .setPropertyValue (dq , DISKOnt .getProperty (DISK .HAS_DATA_SOURCE ), domainKB .getIndividual (dataQuery .getEndpoint ().getId ()));
508510 if (dataQuery .getTemplate () != null )
509511 domainKB .setPropertyValue (dq , DISKOnt .getProperty (DISK .HAS_QUERY_TEMPLATE ), domainKB .createLiteral (dataQuery .getTemplate ()));
510- if (dataQuery .getVariablesToShow () != null )
511- domainKB .setPropertyValue (dq , DISKOnt .getProperty (DISK .HAS_TABLE_VARIABLES ), domainKB .createLiteral (dataQuery .getVariablesToShow ()));
512+ if (dataQuery .getVariablesToShow () != null ) {
513+ String arrString = "[" + String .join ("," ,dataQuery .getVariablesToShow ()) + "]" ;
514+ domainKB .setPropertyValue (dq , DISKOnt .getProperty (DISK .HAS_TABLE_VARIABLES ), domainKB .createLiteral (arrString ));
515+ }
512516 if (dataQuery .getFootnote () != null )
513517 domainKB .setPropertyValue (dq , DISKOnt .getProperty (DISK .HAS_TABLE_DESCRIPTION ), domainKB .createLiteral (dataQuery .getFootnote ()));
514518 return dq ;
@@ -521,8 +525,14 @@ private DataQueryTemplate loadDataQueryTemplate (KBObject objTemplate) {
521525 if (domainKB .getComment (objTemplate ) != null )
522526 dataQuery .setDescription (domainKB .getComment (objTemplate ));
523527 KBObject objVars = domainKB .getPropertyValue (objTemplate , DISKOnt .getProperty (DISK .HAS_TABLE_VARIABLES ));
524- if (objVars != null )
525- dataQuery .setVariablesToShow (objVars .getValueAsString ());
528+ if (objVars != null ) {
529+ String raw = objVars .getValueAsString ();
530+ if (raw .startsWith ("[" ) && raw .endsWith ("]" )) {
531+ dataQuery .setVariablesToShow (Arrays .asList (raw .substring (1 , raw .length ()-1 ).split ("," )));
532+ } else {
533+ System .out .println ("Could not read table variables: " + raw );
534+ }
535+ }
526536 KBObject objFootnotes = domainKB .getPropertyValue (objTemplate , DISKOnt .getProperty (DISK .HAS_TABLE_DESCRIPTION ));
527537 if (objFootnotes != null )
528538 dataQuery .setFootnote (objFootnotes .getValueAsString ());
@@ -583,7 +593,24 @@ public boolean writeLOI(LineOfInquiry loi) {
583593 this .rdf .startWrite ();
584594
585595 KBObject loiItem = writeCommonResource (loi , loiId , DISKOnt .getClass (DISK .LINE_OF_INQUIRY ));
586- writeLOIExtras (loi , loiItem );
596+ writeLOICommon (loi , loiItem );
597+ if (loi .getDataQueryTemplate () != null ) {
598+ KBObject dqt = writeDataQueryTemplate (loi .getDataQueryTemplate ());
599+ domainKB .setPropertyValue (loiItem , DISKOnt .getProperty (DISK .HAS_DATA_QUERY ), dqt );
600+ }
601+ List <WorkflowSeed > wf = loi .getWorkflowSeeds (), mwf = loi .getMetaWorkflowSeeds ();
602+ if (wf != null && wf .size () > 0 ) {
603+ for (WorkflowSeed wfSeed : wf ) {
604+ domainKB .addPropertyValue (loiItem , DISKOnt .getProperty (DISK .HAS_WORKFLOW_SEED ),
605+ writeWorkflowSeed (wfSeed , loi .getId ()));
606+ }
607+ }
608+ if (mwf != null && mwf .size () > 0 ) {
609+ for (WorkflowSeed wfSeed : mwf ) {
610+ domainKB .addPropertyValue (loiItem , DISKOnt .getProperty (DISK .HAS_META_WORKFLOW_SEED ),
611+ writeWorkflowSeed (wfSeed , loi .getId ()));
612+ }
613+ }
587614 this .rdf .save (domainKB );
588615 this .rdf .end ();
589616
@@ -602,71 +629,56 @@ public LineOfInquiry loadLOI(String id) {
602629 }
603630
604631 LineOfInquiry loi = new LineOfInquiry (loadCommonResource (loiItem ));
605- loadLOIExtras (loi , loiItem );
632+ loadLOICommon (loi , loiItem );
633+ KBObject dataQueryObj = domainKB .getPropertyValue (loiItem , DISKOnt .getProperty (DISK .HAS_DATA_QUERY ));
634+ if (dataQueryObj != null )
635+ loi .setDataQueryTemplate (loadDataQueryTemplate (dataQueryObj ));
636+ List <KBObject > wfSeeds = domainKB .getPropertyValues (loiItem , DISKOnt .getProperty (DISK .HAS_WORKFLOW_SEED ));
637+ List <KBObject > mwfSeeds = domainKB .getPropertyValues (loiItem , DISKOnt .getProperty (DISK .HAS_META_WORKFLOW_SEED ));
638+ List <WorkflowSeed > wList = new ArrayList <WorkflowSeed >(), mList = new ArrayList <WorkflowSeed >();
639+
640+ if (wfSeeds != null && wfSeeds .size () > 0 ) {
641+ for (KBObject t : wfSeeds ) {
642+ wList .add (loadWorkflowSeed (t ));
643+ }
644+ }
645+ if (mwfSeeds != null && mwfSeeds .size () > 0 ) {
646+ for (KBObject t : mwfSeeds ) {
647+ mList .add (loadWorkflowSeed (t ));
648+ }
649+ }
650+ loi .setWorkflowSeeds (wList );
651+ loi .setMetaWorkflowSeeds (mList );
652+
606653 this .rdf .end ();
607654 return loi ;
608655 }
609656
610- private void writeLOIExtras ( LineOfInquiry loi , KBObject loiItem ) {
657+ private void writeLOICommon ( LOICommon loi , KBObject loiItem ) {
611658 domainKB .setPropertyValue (loiItem , DISKOnt .getProperty (DISK .HAS_UPDATE_CONDITION ),
612659 domainKB .createLiteral (loi .getUpdateCondition ()));
613660 if (loi .getGoalQuery () != null ) {
614661 domainKB .setPropertyValue (loiItem , DISKOnt .getProperty (DISK .HAS_GOAL_QUERY ),
615662 domainKB .createLiteral (loi .getGoalQuery ()));
616663 }
617- if (loi .getDataQueryTemplate () != null ) {
618- KBObject dqt = writeDataQueryTemplate (loi .getDataQueryTemplate ());
619- domainKB .setPropertyValue (loiItem , DISKOnt .getProperty (DISK .HAS_DATA_QUERY ), dqt );
620- }
621664 String questionId = loi .getQuestion ().getId ();
622665 if (questionId != null )
623666 domainKB .setPropertyValue (loiItem , DISKOnt .getProperty (DISK .HAS_QUESTION ),
624667 domainKB .createLiteral (questionId ));
625- List <WorkflowSeed > wf = loi .getWorkflowSeeds (), mwf = loi .getMetaWorkflowSeeds ();
626- if (wf != null && wf .size () > 0 ) {
627- for (WorkflowSeed wfSeed : wf ) {
628- domainKB .addPropertyValue (loiItem , DISKOnt .getProperty (DISK .HAS_WORKFLOW_SEED ),
629- writeWorkflowSeed (wfSeed , loi .getId ()));
630- }
631- }
632- if (mwf != null && mwf .size () > 0 ) {
633- for (WorkflowSeed wfSeed : mwf ) {
634- domainKB .addPropertyValue (loiItem , DISKOnt .getProperty (DISK .HAS_META_WORKFLOW_SEED ),
635- writeWorkflowSeed (wfSeed , loi .getId ()));
636- }
637- }
668+
638669 }
639670
640- private void loadLOIExtras ( LineOfInquiry loi , KBObject loiItem ) {
671+ private void loadLOICommon ( LOICommon loi , KBObject loiItem ) {
641672 KBObject goalQueryObj = domainKB .getPropertyValue (loiItem , DISKOnt .getProperty (DISK .HAS_GOAL_QUERY ));
642673 if (goalQueryObj != null )
643674 loi .setGoalQuery (goalQueryObj .getValueAsString ());
644- KBObject dataQueryObj = domainKB .getPropertyValue (loiItem , DISKOnt .getProperty (DISK .HAS_DATA_QUERY ));
645- if (dataQueryObj != null )
646- loi .setDataQueryTemplate (loadDataQueryTemplate (dataQueryObj ));
647675 KBObject questionobj = domainKB .getPropertyValue (loiItem , DISKOnt .getProperty (DISK .HAS_QUESTION ));
648676 if (questionobj != null )
649677 loi .setQuestion (new Question (questionobj .getValueAsString ()));
650678 KBObject updateCondObj = domainKB .getPropertyValue (loiItem , DISKOnt .getProperty (DISK .HAS_UPDATE_CONDITION ));
651679 if (updateCondObj != null )
652680 loi .setUpdateCondition ( Integer .parseInt (updateCondObj .getValueAsString ()) );
653681
654- List <KBObject > wfSeeds = domainKB .getPropertyValues (loiItem , DISKOnt .getProperty (DISK .HAS_WORKFLOW_SEED ));
655- List <KBObject > mwfSeeds = domainKB .getPropertyValues (loiItem , DISKOnt .getProperty (DISK .HAS_META_WORKFLOW_SEED ));
656- List <WorkflowSeed > wList = new ArrayList <WorkflowSeed >(), mList = new ArrayList <WorkflowSeed >();
657-
658- if (wfSeeds != null && wfSeeds .size () > 0 ) {
659- for (KBObject t : wfSeeds ) {
660- wList .add (loadWorkflowSeed (t ));
661- }
662- }
663- if (mwfSeeds != null && mwfSeeds .size () > 0 ) {
664- for (KBObject t : mwfSeeds ) {
665- mList .add (loadWorkflowSeed (t ));
666- }
667- }
668- loi .setWorkflowSeeds (wList );
669- loi .setMetaWorkflowSeeds (mList );
670682 }
671683
672684 public boolean deleteLOI (String id ) {
@@ -1058,7 +1070,7 @@ public boolean writeTLOI(TriggeredLOI tloi) {
10581070
10591071 this .rdf .startWrite ();
10601072 KBObject tloiItem = writeCommonResource (tloi , tloiId , DISKOnt .getClass (DISK .TRIGGERED_LINE_OF_INQUIRY ));
1061- writeLOIExtras (tloi , tloiItem );
1073+ writeLOICommon (tloi , tloiItem );
10621074 if (tloi .getParentLoi () != null ) {
10631075 KBObject loiObj = domainKB .getResource (tloi .getParentLoi ().getId ());
10641076 domainKB .setPropertyValue (tloiItem , DISKOnt .getProperty (DISK .HAS_LINE_OF_INQUIRY ), loiObj );
@@ -1103,7 +1115,7 @@ public TriggeredLOI loadTLOI(String id) {
11031115 KBObject obj = domainKB .getIndividual (tloiId );
11041116 if (obj != null && obj .getName () != null ) {
11051117 TriggeredLOI tloi = new TriggeredLOI (loadCommonResource (obj ));
1106- loadLOIExtras (tloi , obj );
1118+ loadLOICommon (tloi , obj );
11071119
11081120 KBObject parentLOI = domainKB .getPropertyValue (obj , DISKOnt .getProperty (DISK .HAS_LINE_OF_INQUIRY ));
11091121 if (parentLOI != null ) // We do not load the LOI
0 commit comments