2525import java .util .Map ;
2626
2727import net .sourceforge .seqware .common .factory .DBAccess ;
28- import net .sourceforge .seqware .webservice . resources . BasicResource ;
28+ import net .sourceforge .seqware .common . util . Log ;
2929import net .sourceforge .seqware .webservice .resources .BasicRestlet ;
3030
3131import org .apache .commons .dbutils .ResultSetHandler ;
4242 * @author boconnor
4343 * @version $Id: $Id
4444 */
45- public class WorkflowRuntimeResource
46- extends BasicRestlet {
47-
48- // processing IDs
49- HashMap <Integer , Boolean > seen = new HashMap <Integer , Boolean >();
50- // main data structure
51- HashMap <String , HashMap <String , HashMap <String , HashMap <String , Integer >>>> d = new HashMap <String , HashMap <String , HashMap <String , HashMap <String , Integer >>>>();
52- // algos
53- HashMap <String , Boolean > algos = new HashMap <String , Boolean >();
54- // workflow run IDs
55- HashMap <Integer , Boolean > wrIds = new HashMap <Integer , Boolean >();
45+ public class WorkflowRuntimeResource extends BasicRestlet {
5646
5747 /**
5848 * <p>Constructor for WorkflowRuntimeResource.</p>
@@ -67,19 +57,25 @@ public WorkflowRuntimeResource(Context context) {
6757 @ Override
6858 public void handle (Request request , Response response ) {
6959 authenticate (request .getChallengeResponse ().getIdentifier ());
60+ init (request );
7061 if (request .getMethod ().compareTo (Method .GET ) == 0 ) {
62+ // processing IDs
63+ HashMap <Integer , Boolean > seen = new HashMap <Integer , Boolean >();
64+ // main data structure
65+ HashMap <String , HashMap <String , HashMap <String , HashMap <String , Integer >>>> d = new HashMap <String , HashMap <String , HashMap <String , HashMap <String , Integer >>>>();
66+ // algos
67+ HashMap <String , Boolean > algos = new HashMap <String , Boolean >();
68+ // workflow run IDs
69+ HashMap <Integer , Boolean > wrIds = new HashMap <Integer , Boolean >();
7170
7271 String workflowAccession = null ;
73- String format = "text" ;
74- if (request != null && request .getAttributes () != null ) {
75- String localWorkflowAccession = (String ) request .getAttributes ().get ("workflowId" );
72+ final String workflowId = "workflowId" ;
73+ if (queryValues .containsKey (workflowId )) {
74+ Log .debug ("Processing attributes for: " + request .getEntityAsText ());
75+ String localWorkflowAccession = queryValues .get (workflowId );
7676 if (localWorkflowAccession != null ) {
7777 workflowAccession = localWorkflowAccession ;
7878 }
79- String localFormat = (String ) request .getAttributes ().get ("workflowId" );
80- if (localFormat != null ) {
81- format = localFormat ;
82- }
8379 }
8480
8581 StringBuilder m = new StringBuilder ();
@@ -106,6 +102,7 @@ public void handle(Request request, Response response) {
106102 if (workflowAccession != null ) {
107103 query = query + " and w.sw_accession = " + workflowAccession ;
108104 }
105+ Log .debug ("Running query: " + query );
109106
110107 query = query + " order by p.create_tstmp" ;
111108
@@ -135,7 +132,7 @@ public Map<Integer, Map<String, String>> handle(ResultSet rs) throws SQLExceptio
135132 String procId = currentProcIds .get (currentProcId ).get ("procId" );
136133 String workflowRunId = currentProcIds .get (currentProcId ).get ("workflowRunId" );
137134 String workflowName = currentProcIds .get (currentProcId ).get ("workflowName" );
138- recursiveFindProcessings (currentProcId , parseClientInt (workflowRunId ), workflowName );
135+ recursiveFindProcessings (currentProcId , parseClientInt (workflowRunId ), workflowName , seen , d , algos , wrIds );
139136 }
140137
141138 // at this point the whole hash should be populated
@@ -162,22 +159,25 @@ public Map<Integer, Map<String, String>> handle(ResultSet rs) throws SQLExceptio
162159 m .append (totalWRuntime ).append ("\n " );
163160 }
164161 }
165-
162+
166163
167164 } catch (Exception e ) {
168165 System .err .print (e .getMessage ());
169- e . printStackTrace ( );
166+ throw new RuntimeException ( e );
170167 } finally {
171168 DBAccess .close ();
172169 }
173-
170+ if (m .toString ().isEmpty ()){
171+ response .setStatus (Status .CLIENT_ERROR_NOT_FOUND );
172+ }
174173 response .setEntity (m .toString (), MediaType .TEXT_PLAIN );
175174 } else {
176175 response .setStatus (Status .CLIENT_ERROR_METHOD_NOT_ALLOWED );
177176 }
178177 }
179178
180- private void recursiveFindProcessings (Integer processingId , Integer workflowRunId , String workflowName ) {
179+ private void recursiveFindProcessings (Integer processingId , Integer workflowRunId , String workflowName , HashMap <Integer , Boolean > seen ,
180+ HashMap <String , HashMap <String , HashMap <String , HashMap <String , Integer >>>> d , HashMap <String , Boolean > algos , HashMap <Integer , Boolean > wrIds ) {
181181 if (seen .get (processingId ) != null && seen .get (processingId )) {
182182 return ;
183183 }
@@ -260,13 +260,12 @@ public Map<Integer, Boolean> handle(ResultSet rs) throws SQLException {
260260
261261 // now recursively call
262262 for (Integer childProcId : childProcessingHash .keySet ()) {
263- recursiveFindProcessings (childProcId , workflowRunId , workflowName );
263+ recursiveFindProcessings (childProcId , workflowRunId , workflowName , seen , d , algos , wrIds );
264264 }
265265
266266 } catch (SQLException e ) {
267- // TODO Auto-generated catch block
268267 System .err .println (e .getMessage ());
269- e . printStackTrace ( );
268+ throw new RuntimeException ( e );
270269 } finally {
271270 DBAccess .close ();
272271 }
0 commit comments