@@ -547,6 +547,7 @@ public String runWorkflow(String wflowname, List<VariableBinding> vbindings, Map
547547 String toPost = null , getData = null , getParams = null , getExpansions = null ;
548548 JsonObject response = null ;
549549 try {
550+ // GET DATA is suggest data on WINGS, this can add inputs, I'm not sure is necessary.
550551 toPost = toPlanAcceptableFormat (wflowname , vbindings , inputVariables );
551552 getData = postWithSpecifiedMediaType ("users/" + getUsername () + "/" + domain + "/plan/getData" ,
552553 toPost , "application/json" , "application/json" );
@@ -571,6 +572,7 @@ public String runWorkflow(String wflowname, List<VariableBinding> vbindings, Map
571572 }
572573
573574 try {
575+ // GET PARAMETERS is suggest parameters in WINGS, this adds the default parameters.
574576 vbindings = addDataBindings (inputVariables , vbindings , getData , false );
575577 toPost = toPlanAcceptableFormat (wflowname , vbindings , inputVariables );
576578 getParams = postWithSpecifiedMediaType (
@@ -633,6 +635,7 @@ public String runWorkflow(String wflowname, List<VariableBinding> vbindings, Map
633635 System .err .println ("No templates found" );
634636 return null ;
635637 }
638+ System .out .println (templatesobj .size ());
636639 JsonObject templateobj = templatesobj .get (0 ).getAsJsonObject ();
637640 jsonTemplate = templateobj .get ("template" ) .toString ();
638641 jsonConstraints = templateobj .get ("constraints" ).toString ();
@@ -654,8 +657,8 @@ public String runWorkflow(String wflowname, List<VariableBinding> vbindings, Map
654657 formdata .add (new BasicNameValuePair ("seed_json" , jsonSeed ));
655658 formdata .add (new BasicNameValuePair ("seed_constraints_json" , jsonSeedConstraints ));
656659 String pageid = "users/" + getUsername () + "/" + domain + "/executions/runWorkflow" ;
657- System .out .println (pageid );
658- System .out .println (formdata );
660+ // System.out.println(pageid);
661+ // System.out.println(formdata);
659662 return post (pageid , formdata );
660663 //} catch (Exception e) {
661664 // e.printStackTrace();
@@ -1126,6 +1129,7 @@ private List<VariableBinding> addDataBindings(
11261129 }
11271130
11281131 private String toPlanAcceptableFormat (String wfname , List <VariableBinding > vbl , Map <String , Variable > ivm ) {
1132+ // We are creating a json here, should be a better way to do it.
11291133 String output = "" ;
11301134
11311135 // Set Template ID first
@@ -1146,7 +1150,7 @@ private String toPlanAcceptableFormat(String wfname, List<VariableBinding> vbl,
11461150 }
11471151 }
11481152 if (paramTypes .length () > 0 )
1149- paramTypes = paramTypes .substring (0 , paramTypes .length () - 1 );
1153+ paramTypes = paramTypes .substring (0 , paramTypes .length () - 1 ); // Removing comma
11501154 output += "\" parameterTypes\" : {" + paramTypes + "}," ;
11511155
11521156 // Set Inputs (Parameters and Data)
@@ -1155,52 +1159,39 @@ private String toPlanAcceptableFormat(String wfname, List<VariableBinding> vbl,
11551159 String dataBindings = "\" dataBindings\" : {" ;
11561160 boolean dataAdded = false ;
11571161 String dataID = this .internal_server + "/export/users/" + getUsername () + "/" + domain + "/data/library.owl#" ;
1162+
11581163 for (String key : ivm .keySet ()) {
11591164 Variable v = ivm .get (key );
1160- if (v .isParam ()) {
1161- for (int i = 0 ; i < vbl .size (); i ++) {
1162- VariableBinding vb = vbl .get (i );
1163- if (vb .getVariable ().equals (v .getName ())) {
1164- paramBindings += "\" " + wfname + v .getName () + "\" :" ;
1165- // If theres no version, or the version if 5 or later, add as array
1166- if (this .getVersion () == null || this .getVersion () > 5 )
1167- paramBindings += "[" ;
1168- paramBindings += "\" " + vb .getBinding () + "\" " ;
1169- if (this .getVersion () == null || this .getVersion () > 5 )
1170- paramBindings += "]" ;
1171- paramBindings += "," ;
1172- paramAdded = true ;
1173- }
1174- }
1175- } else {
1176- for (int i = 0 ; i < vbl .size (); i ++) {
1177- VariableBinding vb = vbl .get (i );
1178- if (vb .getVariable ().equals (v .getName ())) {
1179- dataBindings += "\" " + wfname + v .getName () + "\" :[" ;
1180- String [] dBs = vb .getBinding ()
1181- .replaceFirst ("^\\ [" , "" )
1182- .replaceFirst ("\\ ]$" , "" ).split ("\\ s*,\\ s*" );
1183- for (int j = 0 ; j < dBs .length ; j ++) {
1184- if (dBs [j ].length () > 0 )
1185- dataBindings += "\" " + dataID + dBs [j ] + "\" ," ;
1165+ for (int i = 0 ; i < vbl .size (); i ++) {
1166+ VariableBinding vb = vbl .get (i );
1167+ if (vb .getVariable ().equals (v .getName ())) {
1168+ String curBinding = "\" " + wfname + v .getName () + "\" :[" ;
1169+ String [] dBs = vb .getBinding ()
1170+ .replaceFirst ("^\\ [" , "" )
1171+ .replaceFirst ("\\ ]$" , "" )
1172+ .split ("\\ s*,\\ s*" );
1173+ for (int j = 0 ; j < dBs .length ; j ++) {
1174+ if (dBs [j ].length () > 0 ) {
1175+ curBinding += "\" " + (v .isParam () ? "" : dataID ) + dBs [j ] + "\" ," ;
11861176 }
1187- dataBindings = dataBindings .substring (0 ,
1188- dataBindings .length () - 1 );
1189- dataBindings += "]," ;
1177+ }
1178+ curBinding = curBinding .substring (0 , curBinding .length () - 1 ); //rm comma
1179+ if (v .isParam ()) {
1180+ paramBindings += curBinding + "]," ;
1181+ paramAdded = true ;
1182+ } else {
1183+ dataBindings += curBinding + "]," ;
11901184 dataAdded = true ;
1185+
11911186 }
11921187 }
11931188 }
1194-
11951189 }
1196- if (paramAdded )
1197- paramBindings = paramBindings .substring (0 ,
1198- paramBindings .length () - 1 );
1199- if (dataAdded )
1200- dataBindings = dataBindings .substring (0 , dataBindings .length () - 1 );
1190+ //Removing commas again
1191+ if (paramAdded ) paramBindings = paramBindings .substring (0 , paramBindings .length () - 1 );
1192+ if (dataAdded ) dataBindings = dataBindings .substring (0 , dataBindings .length () - 1 );
12011193
12021194 output += paramBindings + "}," + dataBindings + "}}" ;
1203-
12041195 return output ;
12051196 }
12061197
0 commit comments