oodt-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mattm...@apache.org
Subject svn commit: r1157470 [2/3] - in /oodt/trunk/workflow/src: main/java/org/apache/oodt/cas/workflow/engine/ main/java/org/apache/oodt/cas/workflow/instrepo/ main/java/org/apache/oodt/cas/workflow/repository/ main/java/org/apache/oodt/cas/workflow/structs/...
Date Sun, 14 Aug 2011 05:39:57 GMT
Modified: oodt/trunk/workflow/src/main/java/org/apache/oodt/cas/workflow/repository/DataSourceWorkflowRepository.java
URL: http://svn.apache.org/viewvc/oodt/trunk/workflow/src/main/java/org/apache/oodt/cas/workflow/repository/DataSourceWorkflowRepository.java?rev=1157470&r1=1157469&r2=1157470&view=diff
==============================================================================
--- oodt/trunk/workflow/src/main/java/org/apache/oodt/cas/workflow/repository/DataSourceWorkflowRepository.java (original)
+++ oodt/trunk/workflow/src/main/java/org/apache/oodt/cas/workflow/repository/DataSourceWorkflowRepository.java Sun Aug 14 05:39:56 2011
@@ -1,4 +1,4 @@
-/*
+/**
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
  * this work for additional information regarding copyright ownership.
@@ -15,1172 +15,1280 @@
  * limitations under the License.
  */
 
+package org.apache.oodt.cas.workflow.repository;
+
+//OODT imports
+import org.apache.oodt.cas.workflow.util.DbStructFactory;
+import org.apache.oodt.cas.workflow.structs.Workflow;
+import org.apache.oodt.cas.workflow.structs.WorkflowConditionConfiguration;
+import org.apache.oodt.cas.workflow.structs.WorkflowTask;
+import org.apache.oodt.cas.workflow.structs.WorkflowTaskConfiguration;
+import org.apache.oodt.cas.workflow.structs.WorkflowCondition;
+import org.apache.oodt.cas.workflow.structs.exceptions.RepositoryException;
+
+//JDK imports
+import java.util.List;
+import java.util.Vector;
+import java.util.logging.Logger;
+import java.util.logging.Level;
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+/**
+ * 
+ * A {@link DataSource}-based implementation of a workflow repository.
+ * 
+ * @author mattmann
+ * @version $Revision$
+ */
+public class DataSourceWorkflowRepository implements WorkflowRepository {
+
+  /* our data source */
+  private DataSource dataSource = null;
+
+  /* our log stream */
+  private Logger LOG = Logger.getLogger(DataSourceWorkflowRepository.class
+      .getName());
+
+  /**
+   * <p>
+   * Default Constructor
+   * </p>
+   * .
+   */
+  public DataSourceWorkflowRepository(DataSource ds) {
+    dataSource = ds;
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.oodt.cas.workflow.repository.WorkflowRepository#getWorkflowByName
+   * (java.lang.String)
+   */
+  public Workflow getWorkflowByName(String workflowName)
+      throws RepositoryException {
+    return getWorkflowByName(workflowName, true, true);
+  }
+
+  public Workflow getWorkflowByName(String workflowName, boolean getTasks,
+      boolean getConditions) throws RepositoryException {
+    Connection conn = null;
+    Statement statement = null;
+    ResultSet rs = null;
+
+    Workflow workflow = null;
+
+    try {
+      conn = dataSource.getConnection();
+      statement = conn.createStatement();
+
+      String getWorkflowSql = "SELECT * from workflows WHERE workflow_name = '"
+          + workflowName + "'";
+
+      LOG.log(Level.FINE, "getWorkflowByName: Executing: " + getWorkflowSql);
+      rs = statement.executeQuery(getWorkflowSql);
+
+      while (rs.next()) {
+        workflow = DbStructFactory.getWorkflow(rs);
+
+        if (getTasks) {
+          workflow.setTasks(getTasksByWorkflowId(workflow.getId()));
+        }
+
+        if (getConditions) {
+          workflow.setConditions(getConditionsByWorkflowId(workflow.getId()));
+        }
+      }
+
+    } catch (Exception e) {
+      e.printStackTrace();
+      LOG.log(Level.WARNING,
+          "Exception getting workflow. Message: " + e.getMessage());
+      try {
+        conn.rollback();
+      } catch (SQLException e2) {
+        LOG.log(
+            Level.SEVERE,
+            "Unable to rollback getWorkflowByName transaction. Message: "
+                + e2.getMessage());
+      }
+      throw new RepositoryException(e.getMessage());
+    } finally {
+
+      if (rs != null) {
+        try {
+          rs.close();
+        } catch (SQLException ignore) {
+        }
+
+        rs = null;
+      }
+
+      if (statement != null) {
+        try {
+          statement.close();
+        } catch (SQLException ignore) {
+        }
+
+        statement = null;
+      }
+
+      if (conn != null) {
+        try {
+          conn.close();
+
+        } catch (SQLException ignore) {
+        }
+
+        conn = null;
+      }
+    }
+
+    return workflow;
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.oodt.cas.workflow.repository.WorkflowRepository#getWorkflowById
+   * (java.lang.String)
+   */
+  public Workflow getWorkflowById(String workflowId) throws RepositoryException {
+    return getWorkflowById(workflowId, true, true);
+  }
+
+  public Workflow getWorkflowById(String workflowId, boolean getTasks,
+      boolean getConditions) throws RepositoryException {
+    Connection conn = null;
+    Statement statement = null;
+    ResultSet rs = null;
+
+    Workflow workflow = null;
+
+    try {
+      conn = dataSource.getConnection();
+      statement = conn.createStatement();
+
+      String getWorkflowSql = "SELECT * from workflows WHERE workflow_id = '"
+          + workflowId + "'";
+
+      LOG.log(Level.FINE, "getWorkflowById: Executing: " + getWorkflowSql);
+      rs = statement.executeQuery(getWorkflowSql);
+
+      while (rs.next()) {
+        workflow = DbStructFactory.getWorkflow(rs);
+
+        if (getTasks) {
+          workflow.setTasks(getTasksByWorkflowId(workflow.getId()));
+        }
+
+        if (getConditions) {
+          workflow.setConditions(getConditionsByWorkflowId(workflow.getId()));
+        }
+      }
+
+    } catch (Exception e) {
+      e.printStackTrace();
+      LOG.log(Level.WARNING,
+          "Exception getting workflow. Message: " + e.getMessage());
+      try {
+        conn.rollback();
+      } catch (SQLException e2) {
+        LOG.log(
+            Level.SEVERE,
+            "Unable to rollback getWorkflowById transaction. Message: "
+                + e2.getMessage());
+      }
+      throw new RepositoryException(e.getMessage());
+    } finally {
+
+      if (rs != null) {
+        try {
+          rs.close();
+        } catch (SQLException ignore) {
+        }
+
+        rs = null;
+      }
+
+      if (statement != null) {
+        try {
+          statement.close();
+        } catch (SQLException ignore) {
+        }
+
+        statement = null;
+      }
+
+      if (conn != null) {
+        try {
+          conn.close();
+
+        } catch (SQLException ignore) {
+        }
+
+        conn = null;
+      }
+    }
+
+    return workflow;
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.oodt.cas.workflow.repository.WorkflowRepository#getWorkflows()
+   */
+  public List getWorkflows() throws RepositoryException {
+    return getWorkflows(true, true);
+  }
+
+  public List getWorkflows(boolean getTasks, boolean getConditions)
+      throws RepositoryException {
+    Connection conn = null;
+    Statement statement = null;
+    ResultSet rs = null;
+
+    List workflows = null;
+
+    try {
+      conn = dataSource.getConnection();
+      statement = conn.createStatement();
+
+      String getWorkflowSql = "SELECT * from workflows";
+
+      LOG.log(Level.FINE, "getWorkflows: Executing: " + getWorkflowSql);
+      rs = statement.executeQuery(getWorkflowSql);
+      workflows = new Vector();
+
+      while (rs.next()) {
+        Workflow workflow = DbStructFactory.getWorkflow(rs);
+
+        if (getTasks) {
+          workflow.setTasks(getTasksByWorkflowId(workflow.getId()));
+        }
+
+        if (getConditions) {
+          workflow.setConditions(getConditionsByWorkflowId(workflow.getId()));
+        }
+
+        workflows.add(workflow);
+      }
+
+      if (workflows.size() == 0) {
+        workflows = null;
+      }
+
+    } catch (Exception e) {
+      e.printStackTrace();
+      LOG.log(Level.WARNING,
+          "Exception getting workflows. Message: " + e.getMessage());
+      try {
+        conn.rollback();
+      } catch (SQLException e2) {
+        LOG.log(
+            Level.SEVERE,
+            "Unable to rollback getWorkflows transaction. Message: "
+                + e2.getMessage());
+      }
+      throw new RepositoryException(e.getMessage());
+    } finally {
+
+      if (rs != null) {
+        try {
+          rs.close();
+        } catch (SQLException ignore) {
+        }
+
+        rs = null;
+      }
+
+      if (statement != null) {
+        try {
+          statement.close();
+        } catch (SQLException ignore) {
+        }
+
+        statement = null;
+      }
+
+      if (conn != null) {
+        try {
+          conn.close();
+
+        } catch (SQLException ignore) {
+        }
+
+        conn = null;
+      }
+    }
+
+    return workflows;
+  }
+
+  public List getTasksByWorkflowId(String workflowId)
+      throws RepositoryException {
+    Connection conn = null;
+    Statement statement = null;
+    ResultSet rs = null;
+
+    List tasks = null;
+
+    try {
+      conn = dataSource.getConnection();
+      statement = conn.createStatement();
+
+      String getTasksSql = "SELECT workflow_tasks.*, workflow_task_map.task_order "
+          + "FROM workflow_tasks, workflow_task_map "
+          + "WHERE workflow_task_map.workflow_task_id = workflow_tasks.workflow_task_id "
+          + "AND workflow_task_map.workflow_id = "
+          + workflowId
+          + " "
+          + "ORDER BY workflow_task_map.task_order";
+
+      LOG.log(Level.FINE, "getTasksByWorkflowId: Executing: " + getTasksSql);
+      rs = statement.executeQuery(getTasksSql);
+      tasks = new Vector();
+
+      while (rs.next()) {
+        // get an instance of the class name
+
+        WorkflowTask task = DbStructFactory.getWorkflowTask(rs, true);
+
+        if (task != null) {
+          task.setConditions(getConditionsByTaskId(task.getTaskId()));
+          task.setTaskConfig(getConfigurationByTaskId(task.getTaskId()));
+          tasks.add(task);
+        }
+      }
+
+      if (tasks.size() == 0) {
+        tasks = null;
+      }
+
+    } catch (Exception e) {
+      e.printStackTrace();
+      LOG.log(Level.WARNING, "Exception getting tasks for workflow. Message: "
+          + e.getMessage());
+      try {
+        conn.rollback();
+      } catch (SQLException e2) {
+        LOG.log(Level.SEVERE,
+            "Unable to rollback getTasksByWorkflowId transaction. Message: "
+                + e2.getMessage());
+      }
+      throw new RepositoryException(e.getMessage());
+    } finally {
+
+      if (rs != null) {
+        try {
+          rs.close();
+        } catch (SQLException ignore) {
+        }
+
+        rs = null;
+      }
+
+      if (statement != null) {
+        try {
+          statement.close();
+        } catch (SQLException ignore) {
+        }
+
+        statement = null;
+      }
+
+      if (conn != null) {
+        try {
+          conn.close();
+
+        } catch (SQLException ignore) {
+        }
+
+        conn = null;
+      }
+    }
+
+    return tasks;
+  }
+
+  public List getTasksByWorkflowName(String workflowName)
+      throws RepositoryException {
+    Connection conn = null;
+    Statement statement = null;
+    ResultSet rs = null;
+
+    List tasks = null;
+
+    try {
+      conn = dataSource.getConnection();
+      statement = conn.createStatement();
+
+      String getTasksSql = "SELECT workflow_tasks.*, workflow_task_map.task_order "
+          + "FROM workflow_tasks, workflow_task_map, workflows "
+          + "WHERE workflow_task_map.workflow_task_id = workflow_tasks.workflow_task_id "
+          + "AND workflow_task_map.workflow_id = workflows.workflow_id "
+          + "AND workflows.workflow_name = '"
+          + workflowName
+          + "' "
+          + "ORDER BY workflow_task_map.task_order";
+
+      LOG.log(Level.FINE, "getTasksByWorkflowName: Executing: " + getTasksSql);
+      rs = statement.executeQuery(getTasksSql);
+      tasks = new Vector();
+
+      while (rs.next()) {
+        // get an instance of the class name
+        WorkflowTask task = DbStructFactory.getWorkflowTask(rs, true);
+
+        if (task != null) {
+          task.setConditions(getConditionsByTaskId(task.getTaskId()));
+          task.setTaskConfig(getConfigurationByTaskId(task.getTaskId()));
+          tasks.add(task);
+        }
+      }
+
+      if (tasks.size() == 0) {
+        tasks = null;
+      }
+
+    } catch (Exception e) {
+      e.printStackTrace();
+      LOG.log(Level.WARNING, "Exception getting tasks for workflow. Message: "
+          + e.getMessage());
+      try {
+        conn.rollback();
+      } catch (SQLException e2) {
+        LOG.log(Level.SEVERE,
+            "Unable to rollback getTasksByWorkflowName transaction. Message: "
+                + e2.getMessage());
+      }
+      throw new RepositoryException(e.getMessage());
+    } finally {
+
+      if (rs != null) {
+        try {
+          rs.close();
+        } catch (SQLException ignore) {
+        }
+
+        rs = null;
+      }
+
+      if (statement != null) {
+        try {
+          statement.close();
+        } catch (SQLException ignore) {
+        }
+
+        statement = null;
+      }
+
+      if (conn != null) {
+        try {
+          conn.close();
+
+        } catch (SQLException ignore) {
+        }
+
+        conn = null;
+      }
+    }
+
+    return tasks;
+  }
+
+  public List getWorkflowsForEvent(String eventName) throws RepositoryException {
+    return getWorkflowsForEvent(eventName, true, true);
+  }
+
+  public List getWorkflowsForEvent(String eventName, boolean getTasks,
+      boolean getConditions) throws RepositoryException {
+    Connection conn = null;
+    Statement statement = null;
+    ResultSet rs = null;
+
+    List workflows = null;
+
+    try {
+      conn = dataSource.getConnection();
+      statement = conn.createStatement();
+
+      String getWorkflowSql = "SELECT * from workflows, event_workflow_map WHERE event_workflow_map.workflow_id = workflows.workflow_id  "
+          + "AND event_workflow_map.event_name = '" + eventName + "'";
+
+      LOG.log(Level.FINE, "getWorkflowsForEvent: Executing: " + getWorkflowSql);
+      rs = statement.executeQuery(getWorkflowSql);
+      workflows = new Vector();
+
+      while (rs.next()) {
+        Workflow workflow = DbStructFactory.getWorkflow(rs);
+
+        if (getTasks) {
+          workflow.setTasks(getTasksByWorkflowId(workflow.getId()));
+        }
+
+        if (getConditions) {
+          workflow.setConditions(getConditionsByWorkflowId(workflow.getId()));
+        }
+
+        workflows.add(workflow);
+      }
+
+      if (workflows.size() == 0) {
+        workflows = null;
+      }
+
+    } catch (Exception e) {
+      e.printStackTrace();
+      LOG.log(Level.WARNING, "Exception getting workflows for event. Message: "
+          + e.getMessage());
+      try {
+        conn.rollback();
+      } catch (SQLException e2) {
+        LOG.log(Level.SEVERE,
+            "Unable to rollback getWorkflowsForEvent transaction. Message: "
+                + e2.getMessage());
+      }
+      throw new RepositoryException(e.getMessage());
+    } finally {
+
+      if (rs != null) {
+        try {
+          rs.close();
+        } catch (SQLException ignore) {
+        }
+
+        rs = null;
+      }
+
+      if (statement != null) {
+        try {
+          statement.close();
+        } catch (SQLException ignore) {
+        }
+
+        statement = null;
+      }
+
+      if (conn != null) {
+        try {
+          conn.close();
+
+        } catch (SQLException ignore) {
+        }
+
+        conn = null;
+      }
+    }
+
+    return workflows;
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.oodt.cas.workflow.repository.WorkflowRepository#
+   * getConditionsByTaskName(java.lang.String)
+   */
+  public List getConditionsByTaskName(String taskName)
+      throws RepositoryException {
+    Connection conn = null;
+    Statement statement = null;
+    ResultSet rs = null;
+
+    List conditions = null;
+
+    try {
+      conn = dataSource.getConnection();
+      statement = conn.createStatement();
+
+      String getConditionsSql = "SELECT workflow_conditions.*, task_condition_map.condition_order "
+          + "FROM workflow_conditions, task_condition_map, workflow_tasks "
+          + "WHERE task_condition_map.workflow_condition_id = workflow_conditions.workflow_condition_id "
+          + "AND task_condition_map.workflow_task_id = workflow_tasks.workflow_task_id "
+          + "AND workflow_tasks.workflow_task_name = '"
+          + taskName
+          + "' "
+          + "ORDER BY task_condition_map.condition_order";
+
+      LOG.log(Level.FINE, "getConditionsByTaskName: Executing: "
+          + getConditionsSql);
+      rs = statement.executeQuery(getConditionsSql);
+      conditions = new Vector();
+
+      while (rs.next()) {
+        // get an instance of the class name
+        WorkflowCondition condition = DbStructFactory.getWorkflowCondition(rs,
+            true);
+        conditions.add(condition);
+      }
+
+      if (conditions.size() == 0) {
+        conditions = null;
+      }
+
+    } catch (Exception e) {
+      e.printStackTrace();
+      LOG.log(Level.WARNING, "Exception getting conditions for task. Message: "
+          + e.getMessage());
+      try {
+        conn.rollback();
+      } catch (SQLException e2) {
+        LOG.log(Level.SEVERE,
+            "Unable to rollback getConditionsByTaskName transaction. Message: "
+                + e2.getMessage());
+      }
+      throw new RepositoryException(e.getMessage());
+    } finally {
+
+      if (rs != null) {
+        try {
+          rs.close();
+        } catch (SQLException ignore) {
+        }
+
+        rs = null;
+      }
+
+      if (statement != null) {
+        try {
+          statement.close();
+        } catch (SQLException ignore) {
+        }
+
+        statement = null;
+      }
+
+      if (conn != null) {
+        try {
+          conn.close();
+
+        } catch (SQLException ignore) {
+        }
+
+        conn = null;
+      }
+    }
+
+    return conditions;
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.oodt.cas.workflow.repository.WorkflowRepository#
+   * getConditionsByTaskId(java.lang.String)
+   */
+  public List getConditionsByTaskId(String taskId) throws RepositoryException {
+    Connection conn = null;
+    Statement statement = null;
+    ResultSet rs = null;
+
+    List conditions = null;
+
+    try {
+      conn = dataSource.getConnection();
+      statement = conn.createStatement();
+
+      String getConditionsSql = "SELECT workflow_conditions.*, task_condition_map.condition_order "
+          + "FROM workflow_conditions, task_condition_map "
+          + "WHERE task_condition_map.workflow_condition_id = workflow_conditions.workflow_condition_id "
+          + "AND task_condition_map.workflow_task_id = "
+          + taskId
+          + " "
+          + "ORDER BY task_condition_map.condition_order";
+
+      LOG.log(Level.FINE, "getConditionsByTaskId: Executing: "
+          + getConditionsSql);
+      rs = statement.executeQuery(getConditionsSql);
+      conditions = new Vector();
+
+      while (rs.next()) {
+        // get an instance of the class name
+        WorkflowCondition condition = DbStructFactory.getWorkflowCondition(rs,
+            true);
+        conditions.add(condition);
+      }
+
+      if (conditions.size() == 0) {
+        conditions = null;
+      }
+
+    } catch (Exception e) {
+      e.printStackTrace();
+      LOG.log(Level.WARNING, "Exception getting conditions for task. Message: "
+          + e.getMessage());
+      try {
+        conn.rollback();
+      } catch (SQLException e2) {
+        LOG.log(Level.SEVERE,
+            "Unable to rollback getConditionsByTaskId transaction. Message: "
+                + e2.getMessage());
+      }
+      throw new RepositoryException(e.getMessage());
+    } finally {
+
+      if (rs != null) {
+        try {
+          rs.close();
+        } catch (SQLException ignore) {
+        }
+
+        rs = null;
+      }
+
+      if (statement != null) {
+        try {
+          statement.close();
+        } catch (SQLException ignore) {
+        }
+
+        statement = null;
+      }
+
+      if (conn != null) {
+        try {
+          conn.close();
+
+        } catch (SQLException ignore) {
+        }
+
+        conn = null;
+      }
+    }
+
+    return conditions;
+  }
+
+  public WorkflowTaskConfiguration getConfigurationByTaskId(String taskId)
+      throws RepositoryException {
+    Connection conn = null;
+    Statement statement = null;
+    ResultSet rs = null;
+
+    WorkflowTaskConfiguration config = null;
+
+    try {
+      conn = dataSource.getConnection();
+      statement = conn.createStatement();
+
+      String getConfigurationSql = "SELECT * from workflow_task_configuration WHERE workflow_task_id = "
+          + taskId;
+
+      LOG.log(Level.FINE, "getConfigurationByTaskId: Executing: "
+          + getConfigurationSql);
+      rs = statement.executeQuery(getConfigurationSql);
+
+      config = new WorkflowTaskConfiguration();
+      while (rs.next()) {
+        config.getProperties().put(rs.getString("property_name"),
+            rs.getString("property_value"));
+      }
+
+      if (config.getProperties().keySet().size() == 0) {
+        config = null;
+      }
+
+    } catch (Exception e) {
+      e.printStackTrace();
+      LOG.log(Level.WARNING,
+          "Exception getting task configuration for taskId: " + taskId
+              + " Message: " + e.getMessage());
+      try {
+        conn.rollback();
+      } catch (SQLException e2) {
+        LOG.log(Level.SEVERE,
+            "Unable to rollback getConfigurationBytaskId transaction. Message: "
+                + e2.getMessage());
+      }
+      throw new RepositoryException(e.getMessage());
+    } finally {
+
+      if (rs != null) {
+        try {
+          rs.close();
+        } catch (SQLException ignore) {
+        }
+
+        rs = null;
+      }
+
+      if (statement != null) {
+        try {
+          statement.close();
+        } catch (SQLException ignore) {
+        }
+
+        statement = null;
+      }
+
+      if (conn != null) {
+        try {
+          conn.close();
+
+        } catch (SQLException ignore) {
+        }
+
+        conn = null;
+      }
+    }
+
+    return config;
+  }
+
+  public WorkflowConditionConfiguration getConfigurationByConditionId(
+      String condId) throws RepositoryException {
+    Connection conn = null;
+    Statement statement = null;
+    ResultSet rs = null;
+
+    WorkflowConditionConfiguration config = null;
+
+    try {
+      conn = dataSource.getConnection();
+      statement = conn.createStatement();
+
+      String getConfigurationSql = "SELECT * from workflow_condition_configuration WHERE workflow_condition_id = "
+          + condId;
 
-package org.apache.oodt.cas.workflow.repository;
+      LOG.log(Level.FINE, "getConfigurationByConfigurationId: Executing: "
+          + getConfigurationSql);
+      rs = statement.executeQuery(getConfigurationSql);
 
-//OODT imports
-import org.apache.oodt.cas.workflow.util.DbStructFactory;
-import org.apache.oodt.cas.workflow.structs.Workflow;
-import org.apache.oodt.cas.workflow.structs.WorkflowConditionConfiguration;
-import org.apache.oodt.cas.workflow.structs.WorkflowTask;
-import org.apache.oodt.cas.workflow.structs.WorkflowTaskConfiguration;
-import org.apache.oodt.cas.workflow.structs.WorkflowCondition;
-import org.apache.oodt.cas.workflow.structs.exceptions.RepositoryException;
+      config = new WorkflowConditionConfiguration();
+      while (rs.next()) {
+        config.getProperties().put(rs.getString("property_name"),
+            rs.getString("property_value"));
+      }
 
-//JDK imports
-import java.util.List;
-import java.util.Vector;
-import java.util.logging.Logger;
-import java.util.logging.Level;
-import javax.sql.DataSource;
-import java.sql.Connection;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
+      if (config.getProperties().keySet().size() == 0) {
+        config = null;
+      }
 
-/**
- * @author mattmann
- * @version $Revision$
- * 
- * <p>
- * A {@link DataSource}-based implementation of a workflow repository.
- * </p>
- * 
- */
-public class DataSourceWorkflowRepository implements WorkflowRepository {
+    } catch (Exception e) {
+      e.printStackTrace();
+      LOG.log(Level.WARNING,
+          "Exception getting task configuration for condId: " + condId
+              + " Message: " + e.getMessage());
+      try {
+        conn.rollback();
+      } catch (SQLException e2) {
+        LOG.log(Level.SEVERE,
+            "Unable to rollback getConfigurationByConfigurationId transaction. Message: "
+                + e2.getMessage());
+      }
+      throw new RepositoryException(e.getMessage());
+    } finally {
 
-    /* our data source */
-    private DataSource dataSource = null;
+      if (rs != null) {
+        try {
+          rs.close();
+        } catch (SQLException ignore) {
+        }
 
-    /* our log stream */
-    private Logger LOG = Logger.getLogger(DataSourceWorkflowRepository.class
-            .getName());
-
-    /**
-     * <p>
-     * Default Constructor
-     * </p>.
-     */
-    public DataSourceWorkflowRepository(DataSource ds) {
-        dataSource = ds;
-    }
+        rs = null;
+      }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.oodt.cas.workflow.repository.WorkflowRepository#getWorkflowByName(java.lang.String)
-     */
-    public Workflow getWorkflowByName(String workflowName)
-            throws RepositoryException {
-        return getWorkflowByName(workflowName, true);
-    }
+      if (statement != null) {
+        try {
+          statement.close();
+        } catch (SQLException ignore) {
+        }
 
-    public Workflow getWorkflowByName(String workflowName, boolean getTasks)
-            throws RepositoryException {
-        Connection conn = null;
-        Statement statement = null;
-        ResultSet rs = null;
-
-        Workflow workflow = null;
-
-        try {
-            conn = dataSource.getConnection();
-            statement = conn.createStatement();
-
-            String getWorkflowSql = "SELECT * from workflows WHERE workflow_name = '"
-                    + workflowName + "'";
-
-            LOG.log(Level.FINE, "getWorkflowByName: Executing: "
-                    + getWorkflowSql);
-            rs = statement.executeQuery(getWorkflowSql);
-
-            while (rs.next()) {
-                workflow = DbStructFactory.getWorkflow(rs);
-
-                if (getTasks) {
-                    workflow.setTasks(getTasksByWorkflowId(workflow.getId()));
-                }
-            }
-
-        } catch (Exception e) {
-            e.printStackTrace();
-            LOG.log(Level.WARNING, "Exception getting workflow. Message: "
-                    + e.getMessage());
-            try {
-                conn.rollback();
-            } catch (SQLException e2) {
-                LOG.log(Level.SEVERE,
-                        "Unable to rollback getWorkflowByName transaction. Message: "
-                                + e2.getMessage());
-            }
-            throw new RepositoryException(e.getMessage());
-        } finally {
-
-            if (rs != null) {
-                try {
-                    rs.close();
-                } catch (SQLException ignore) {
-                }
-
-                rs = null;
-            }
-
-            if (statement != null) {
-                try {
-                    statement.close();
-                } catch (SQLException ignore) {
-                }
-
-                statement = null;
-            }
-
-            if (conn != null) {
-                try {
-                    conn.close();
+        statement = null;
+      }
 
-                } catch (SQLException ignore) {
-                }
+      if (conn != null) {
+        try {
+          conn.close();
 
-                conn = null;
-            }
+        } catch (SQLException ignore) {
         }
 
-        return workflow;
+        conn = null;
+      }
     }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.oodt.cas.workflow.repository.WorkflowRepository#getWorkflowById(java.lang.String)
-     */
-    public Workflow getWorkflowById(String workflowId)
-            throws RepositoryException {
-        return getWorkflowById(workflowId, true);
-    }
+    return config;
+  }
 
-    public Workflow getWorkflowById(String workflowId, boolean getTasks)
-            throws RepositoryException {
-        Connection conn = null;
-        Statement statement = null;
-        ResultSet rs = null;
-
-        Workflow workflow = null;
-
-        try {
-            conn = dataSource.getConnection();
-            statement = conn.createStatement();
-
-            String getWorkflowSql = "SELECT * from workflows WHERE workflow_id = '"
-                    + workflowId + "'";
-
-            LOG
-                    .log(Level.FINE, "getWorkflowById: Executing: "
-                            + getWorkflowSql);
-            rs = statement.executeQuery(getWorkflowSql);
-
-            while (rs.next()) {
-                workflow = DbStructFactory.getWorkflow(rs);
-
-                if (getTasks) {
-                    workflow.setTasks(getTasksByWorkflowId(workflow.getId()));
-                }
-            }
-
-        } catch (Exception e) {
-            e.printStackTrace();
-            LOG.log(Level.WARNING, "Exception getting workflow. Message: "
-                    + e.getMessage());
-            try {
-                conn.rollback();
-            } catch (SQLException e2) {
-                LOG.log(Level.SEVERE,
-                        "Unable to rollback getWorkflowById transaction. Message: "
-                                + e2.getMessage());
-            }
-            throw new RepositoryException(e.getMessage());
-        } finally {
-
-            if (rs != null) {
-                try {
-                    rs.close();
-                } catch (SQLException ignore) {
-                }
-
-                rs = null;
-            }
-
-            if (statement != null) {
-                try {
-                    statement.close();
-                } catch (SQLException ignore) {
-                }
-
-                statement = null;
-            }
-
-            if (conn != null) {
-                try {
-                    conn.close();
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.oodt.cas.workflow.repository.WorkflowRepository#getWorkflowTaskById
+   * (java.lang.String)
+   */
+  public WorkflowTask getWorkflowTaskById(String taskId)
+      throws RepositoryException {
+    Connection conn = null;
+    Statement statement = null;
+    ResultSet rs = null;
 
-                } catch (SQLException ignore) {
-                }
+    WorkflowTask task = null;
 
-                conn = null;
-            }
-        }
+    try {
+      conn = dataSource.getConnection();
+      statement = conn.createStatement();
 
-        return workflow;
-    }
+      String getTaskSql = "SELECT * FROM workflow_tasks WHERE workflow_task_id = "
+          + taskId;
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.oodt.cas.workflow.repository.WorkflowRepository#getWorkflows()
-     */
-    public List getWorkflows() throws RepositoryException {
-        return getWorkflows(true);
-    }
+      LOG.log(Level.FINE, "getWorkflowTaskById: Executing: " + getTaskSql);
+      rs = statement.executeQuery(getTaskSql);
 
-    public List getWorkflows(boolean getTasks) throws RepositoryException {
-        Connection conn = null;
-        Statement statement = null;
-        ResultSet rs = null;
+      while (rs.next()) {
+        // get an instance of the class name
+        task = DbStructFactory.getWorkflowTask(rs, false);
+        task.setConditions(getConditionsByTaskId(task.getTaskId()));
+        task.setTaskConfig(getConfigurationByTaskId(task.getTaskId()));
+      }
 
-        List workflows = null;
+    } catch (Exception e) {
+      e.printStackTrace();
+      LOG.log(Level.WARNING,
+          "Exception getting task by id. Message: " + e.getMessage());
+      try {
+        conn.rollback();
+      } catch (SQLException e2) {
+        LOG.log(Level.SEVERE,
+            "Unable to rollback getWorkflowTaskById transaction. Message: "
+                + e2.getMessage());
+      }
+      throw new RepositoryException(e.getMessage());
+    } finally {
 
+      if (rs != null) {
         try {
-            conn = dataSource.getConnection();
-            statement = conn.createStatement();
+          rs.close();
+        } catch (SQLException ignore) {
+        }
 
-            String getWorkflowSql = "SELECT * from workflows";
+        rs = null;
+      }
+
+      if (statement != null) {
+        try {
+          statement.close();
+        } catch (SQLException ignore) {
+        }
 
-            LOG.log(Level.FINE, "getWorkflows: Executing: " + getWorkflowSql);
-            rs = statement.executeQuery(getWorkflowSql);
-            workflows = new Vector();
+        statement = null;
+      }
 
-            while (rs.next()) {
-                Workflow workflow = DbStructFactory.getWorkflow(rs);
+      if (conn != null) {
+        try {
+          conn.close();
 
-                if (getTasks) {
-                    workflow.setTasks(getTasksByWorkflowId(workflow.getId()));
-                }
+        } catch (SQLException ignore) {
+        }
 
-                workflows.add(workflow);
-            }
+        conn = null;
+      }
+    }
 
-            if (workflows.size() == 0) {
-                workflows = null;
-            }
+    return task;
+  }
 
-        } catch (Exception e) {
-            e.printStackTrace();
-            LOG.log(Level.WARNING, "Exception getting workflows. Message: "
-                    + e.getMessage());
-            try {
-                conn.rollback();
-            } catch (SQLException e2) {
-                LOG.log(Level.SEVERE,
-                        "Unable to rollback getWorkflows transaction. Message: "
-                                + e2.getMessage());
-            }
-            throw new RepositoryException(e.getMessage());
-        } finally {
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.oodt.cas.workflow.repository.WorkflowRepository#
+   * getWorkflowConditionById(java.lang.String)
+   */
+  public WorkflowCondition getWorkflowConditionById(String conditionId)
+      throws RepositoryException {
+    Connection conn = null;
+    Statement statement = null;
+    ResultSet rs = null;
 
-            if (rs != null) {
-                try {
-                    rs.close();
-                } catch (SQLException ignore) {
-                }
+    WorkflowCondition condition = null;
 
-                rs = null;
-            }
+    try {
+      conn = dataSource.getConnection();
+      statement = conn.createStatement();
 
-            if (statement != null) {
-                try {
-                    statement.close();
-                } catch (SQLException ignore) {
-                }
+      String getConditionsSql = "SELECT * FROM workflow_conditions WHERE workflow_condition_id = "
+          + conditionId;
 
-                statement = null;
-            }
+      LOG.log(Level.FINE, "getWorkflowConditionById: Executing: "
+          + getConditionsSql);
+      rs = statement.executeQuery(getConditionsSql);
 
-            if (conn != null) {
-                try {
-                    conn.close();
+      while (rs.next()) {
+        // get an instance of the class name
+        condition = DbStructFactory.getWorkflowCondition(rs, false);
+        condition.setCondConfig(getConfigurationByConditionId(conditionId));
+      }
 
-                } catch (SQLException ignore) {
-                }
+    } catch (Exception e) {
+      e.printStackTrace();
+      LOG.log(Level.WARNING,
+          "Exception getting condition by id. Message: " + e.getMessage());
+      try {
+        conn.rollback();
+      } catch (SQLException e2) {
+        LOG.log(Level.SEVERE,
+            "Unable to rollback getWorkflowConditionById transaction. Message: "
+                + e2.getMessage());
+      }
+      throw new RepositoryException(e.getMessage());
+    } finally {
 
-                conn = null;
-            }
+      if (rs != null) {
+        try {
+          rs.close();
+        } catch (SQLException ignore) {
         }
 
-        return workflows;
-    }
+        rs = null;
+      }
+
+      if (statement != null) {
+        try {
+          statement.close();
+        } catch (SQLException ignore) {
+        }
 
-    public List getTasksByWorkflowId(String workflowId)
-            throws RepositoryException {
-        Connection conn = null;
-        Statement statement = null;
-        ResultSet rs = null;
-
-        List tasks = null;
-
-        try {
-            conn = dataSource.getConnection();
-            statement = conn.createStatement();
-
-            String getTasksSql = "SELECT workflow_tasks.*, workflow_task_map.task_order "
-                    + "FROM workflow_tasks, workflow_task_map "
-                    + "WHERE workflow_task_map.workflow_task_id = workflow_tasks.workflow_task_id "
-                    + "AND workflow_task_map.workflow_id = "
-                    + workflowId
-                    + " "
-                    + "ORDER BY workflow_task_map.task_order";
-
-            LOG.log(Level.FINE, "getTasksByWorkflowId: Executing: "
-                    + getTasksSql);
-            rs = statement.executeQuery(getTasksSql);
-            tasks = new Vector();
-
-            while (rs.next()) {
-                // get an instance of the class name
-
-                WorkflowTask task = DbStructFactory.getWorkflowTask(rs, true);
-
-                if (task != null) {
-                    task.setConditions(getConditionsByTaskId(task.getTaskId()));
-                    task.setTaskConfig(getConfigurationByTaskId(task
-                            .getTaskId()));
-                    tasks.add(task);
-                }
-            }
-
-            if (tasks.size() == 0) {
-                tasks = null;
-            }
-
-        } catch (Exception e) {
-            e.printStackTrace();
-            LOG.log(Level.WARNING,
-                    "Exception getting tasks for workflow. Message: "
-                            + e.getMessage());
-            try {
-                conn.rollback();
-            } catch (SQLException e2) {
-                LOG.log(Level.SEVERE,
-                        "Unable to rollback getTasksByWorkflowId transaction. Message: "
-                                + e2.getMessage());
-            }
-            throw new RepositoryException(e.getMessage());
-        } finally {
-
-            if (rs != null) {
-                try {
-                    rs.close();
-                } catch (SQLException ignore) {
-                }
-
-                rs = null;
-            }
-
-            if (statement != null) {
-                try {
-                    statement.close();
-                } catch (SQLException ignore) {
-                }
-
-                statement = null;
-            }
-
-            if (conn != null) {
-                try {
-                    conn.close();
+        statement = null;
+      }
 
-                } catch (SQLException ignore) {
-                }
+      if (conn != null) {
+        try {
+          conn.close();
 
-                conn = null;
-            }
+        } catch (SQLException ignore) {
         }
 
-        return tasks;
+        conn = null;
+      }
     }
 
-    public List getTasksByWorkflowName(String workflowName)
-            throws RepositoryException {
-        Connection conn = null;
-        Statement statement = null;
-        ResultSet rs = null;
-
-        List tasks = null;
-
-        try {
-            conn = dataSource.getConnection();
-            statement = conn.createStatement();
-
-            String getTasksSql = "SELECT workflow_tasks.*, workflow_task_map.task_order "
-                    + "FROM workflow_tasks, workflow_task_map, workflows "
-                    + "WHERE workflow_task_map.workflow_task_id = workflow_tasks.workflow_task_id "
-                    + "AND workflow_task_map.workflow_id = workflows.workflow_id "
-                    + "AND workflows.workflow_name = '"
-                    + workflowName
-                    + "' "
-                    + "ORDER BY workflow_task_map.task_order";
-
-            LOG.log(Level.FINE, "getTasksByWorkflowName: Executing: "
-                    + getTasksSql);
-            rs = statement.executeQuery(getTasksSql);
-            tasks = new Vector();
-
-            while (rs.next()) {
-                // get an instance of the class name
-                WorkflowTask task = DbStructFactory.getWorkflowTask(rs, true);
-
-                if (task != null) {
-                    task.setConditions(getConditionsByTaskId(task.getTaskId()));
-                    task.setTaskConfig(getConfigurationByTaskId(task
-                            .getTaskId()));
-                    tasks.add(task);
-                }
-            }
-
-            if (tasks.size() == 0) {
-                tasks = null;
-            }
-
-        } catch (Exception e) {
-            e.printStackTrace();
-            LOG.log(Level.WARNING,
-                    "Exception getting tasks for workflow. Message: "
-                            + e.getMessage());
-            try {
-                conn.rollback();
-            } catch (SQLException e2) {
-                LOG.log(Level.SEVERE,
-                        "Unable to rollback getTasksByWorkflowName transaction. Message: "
-                                + e2.getMessage());
-            }
-            throw new RepositoryException(e.getMessage());
-        } finally {
-
-            if (rs != null) {
-                try {
-                    rs.close();
-                } catch (SQLException ignore) {
-                }
-
-                rs = null;
-            }
-
-            if (statement != null) {
-                try {
-                    statement.close();
-                } catch (SQLException ignore) {
-                }
-
-                statement = null;
-            }
-
-            if (conn != null) {
-                try {
-                    conn.close();
+    return condition;
+  }
 
-                } catch (SQLException ignore) {
-                }
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.oodt.cas.workflow.repository.WorkflowRepository#getRegisteredEvents
+   * ()
+   */
+  public List getRegisteredEvents() throws RepositoryException {
+    Connection conn = null;
+    Statement statement = null;
+    ResultSet rs = null;
 
-                conn = null;
-            }
-        }
+    List events = null;
 
-        return tasks;
-    }
+    try {
+      conn = dataSource.getConnection();
+      statement = conn.createStatement();
 
-    public List getWorkflowsForEvent(String eventName)
-            throws RepositoryException {
-        return getWorkflowsForEvent(eventName, true);
-    }
+      String getEventSql = "SELECT DISTINCT event_name FROM event_workflow_map ORDER BY event_name ASC";
 
-    public List getWorkflowsForEvent(String eventName, boolean getTasks)
-            throws RepositoryException {
-        Connection conn = null;
-        Statement statement = null;
-        ResultSet rs = null;
-
-        List workflows = null;
-
-        try {
-            conn = dataSource.getConnection();
-            statement = conn.createStatement();
-
-            String getWorkflowSql = "SELECT * from workflows, event_workflow_map WHERE event_workflow_map.workflow_id = workflows.workflow_id  "
-                    + "AND event_workflow_map.event_name = '" + eventName + "'";
-
-            LOG.log(Level.FINE, "getWorkflowsForEvent: Executing: "
-                    + getWorkflowSql);
-            rs = statement.executeQuery(getWorkflowSql);
-            workflows = new Vector();
-
-            while (rs.next()) {
-                Workflow workflow = DbStructFactory.getWorkflow(rs);
-
-                if (getTasks) {
-                    workflow.setTasks(getTasksByWorkflowId(workflow.getId()));
-                }
-                workflows.add(workflow);
-            }
-
-            if (workflows.size() == 0) {
-                workflows = null;
-            }
-
-        } catch (Exception e) {
-            e.printStackTrace();
-            LOG.log(Level.WARNING,
-                    "Exception getting workflows for event. Message: "
-                            + e.getMessage());
-            try {
-                conn.rollback();
-            } catch (SQLException e2) {
-                LOG.log(Level.SEVERE,
-                        "Unable to rollback getWorkflowsForEvent transaction. Message: "
-                                + e2.getMessage());
-            }
-            throw new RepositoryException(e.getMessage());
-        } finally {
-
-            if (rs != null) {
-                try {
-                    rs.close();
-                } catch (SQLException ignore) {
-                }
-
-                rs = null;
-            }
-
-            if (statement != null) {
-                try {
-                    statement.close();
-                } catch (SQLException ignore) {
-                }
-
-                statement = null;
-            }
-
-            if (conn != null) {
-                try {
-                    conn.close();
+      LOG.log(Level.FINE, "getRegisteredEvents: Executing: " + getEventSql);
+      rs = statement.executeQuery(getEventSql);
+      events = new Vector();
 
-                } catch (SQLException ignore) {
-                }
+      while (rs.next()) {
+        // get an instance of the class name
+        String event = DbStructFactory.getEvent(rs);
+        events.add(event);
+      }
 
-                conn = null;
-            }
-        }
+      if (events.size() == 0) {
+        events = null;
+      }
 
-        return workflows;
-    }
+    } catch (Exception e) {
+      e.printStackTrace();
+      LOG.log(Level.WARNING, "Exception getting registered events. Message: "
+          + e.getMessage());
+      try {
+        conn.rollback();
+      } catch (SQLException e2) {
+        LOG.log(Level.SEVERE,
+            "Unable to rollback getRegisteredEvents transaction. Message: "
+                + e2.getMessage());
+      }
+      throw new RepositoryException(e.getMessage());
+    } finally {
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.oodt.cas.workflow.repository.WorkflowRepository#getConditionsByTaskName(java.lang.String)
-     */
-    public List getConditionsByTaskName(String taskName)
-            throws RepositoryException {
-        Connection conn = null;
-        Statement statement = null;
-        ResultSet rs = null;
-
-        List conditions = null;
-
-        try {
-            conn = dataSource.getConnection();
-            statement = conn.createStatement();
-
-            String getConditionsSql = "SELECT workflow_conditions.*, workflow_condition_map.condition_order "
-                    + "FROM workflow_conditions, workflow_condition_map, workflow_tasks "
-                    + "WHERE workflow_condition_map.workflow_condition_id = workflow_conditions.workflow_condition_id "
-                    + "AND workflow_condition_map.workflow_task_id = workflow_tasks.workflow_task_id "
-                    + "AND workflow_tasks.workflow_task_name = '"
-                    + taskName
-                    + "' " + "ORDER BY workflow_condition_map.condition_order";
-
-            LOG.log(Level.FINE, "getConditionsByTaskName: Executing: "
-                    + getConditionsSql);
-            rs = statement.executeQuery(getConditionsSql);
-            conditions = new Vector();
-
-            while (rs.next()) {
-                // get an instance of the class name
-                WorkflowCondition condition = DbStructFactory
-                        .getWorkflowCondition(rs, true);
-                conditions.add(condition);
-            }
-
-            if (conditions.size() == 0) {
-                conditions = null;
-            }
-
-        } catch (Exception e) {
-            e.printStackTrace();
-            LOG.log(Level.WARNING,
-                    "Exception getting conditions for task. Message: "
-                            + e.getMessage());
-            try {
-                conn.rollback();
-            } catch (SQLException e2) {
-                LOG.log(Level.SEVERE,
-                        "Unable to rollback getConditionsByTaskName transaction. Message: "
-                                + e2.getMessage());
-            }
-            throw new RepositoryException(e.getMessage());
-        } finally {
-
-            if (rs != null) {
-                try {
-                    rs.close();
-                } catch (SQLException ignore) {
-                }
-
-                rs = null;
-            }
-
-            if (statement != null) {
-                try {
-                    statement.close();
-                } catch (SQLException ignore) {
-                }
-
-                statement = null;
-            }
-
-            if (conn != null) {
-                try {
-                    conn.close();
+      if (rs != null) {
+        try {
+          rs.close();
+        } catch (SQLException ignore) {
+        }
 
-                } catch (SQLException ignore) {
-                }
+        rs = null;
+      }
 
-                conn = null;
-            }
+      if (statement != null) {
+        try {
+          statement.close();
+        } catch (SQLException ignore) {
         }
 
-        return conditions;
-    }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.oodt.cas.workflow.repository.WorkflowRepository#getConditionsByTaskId(java.lang.String)
-     */
-    public List getConditionsByTaskId(String taskId) throws RepositoryException {
-        Connection conn = null;
-        Statement statement = null;
-        ResultSet rs = null;
-
-        List conditions = null;
-
-        try {
-            conn = dataSource.getConnection();
-            statement = conn.createStatement();
-
-            String getConditionsSql = "SELECT workflow_conditions.*, workflow_condition_map.condition_order "
-                    + "FROM workflow_conditions, workflow_condition_map "
-                    + "WHERE workflow_condition_map.workflow_condition_id = workflow_conditions.workflow_condition_id "
-                    + "AND workflow_condition_map.workflow_task_id = "
-                    + taskId
-                    + " " + "ORDER BY workflow_condition_map.condition_order";
-
-            LOG.log(Level.FINE, "getConditionsByTaskId: Executing: "
-                    + getConditionsSql);
-            rs = statement.executeQuery(getConditionsSql);
-            conditions = new Vector();
-
-            while (rs.next()) {
-                // get an instance of the class name
-                WorkflowCondition condition = DbStructFactory
-                        .getWorkflowCondition(rs, true);
-                conditions.add(condition);
-            }
-
-            if (conditions.size() == 0) {
-                conditions = null;
-            }
-
-        } catch (Exception e) {
-            e.printStackTrace();
-            LOG.log(Level.WARNING,
-                    "Exception getting conditions for task. Message: "
-                            + e.getMessage());
-            try {
-                conn.rollback();
-            } catch (SQLException e2) {
-                LOG.log(Level.SEVERE,
-                        "Unable to rollback getConditionsByTaskId transaction. Message: "
-                                + e2.getMessage());
-            }
-            throw new RepositoryException(e.getMessage());
-        } finally {
-
-            if (rs != null) {
-                try {
-                    rs.close();
-                } catch (SQLException ignore) {
-                }
-
-                rs = null;
-            }
-
-            if (statement != null) {
-                try {
-                    statement.close();
-                } catch (SQLException ignore) {
-                }
-
-                statement = null;
-            }
-
-            if (conn != null) {
-                try {
-                    conn.close();
+        statement = null;
+      }
 
-                } catch (SQLException ignore) {
-                }
+      if (conn != null) {
+        try {
+          conn.close();
 
-                conn = null;
-            }
+        } catch (SQLException ignore) {
         }
 
-        return conditions;
+        conn = null;
+      }
     }
 
-    public WorkflowTaskConfiguration getConfigurationByTaskId(String taskId)
-            throws RepositoryException {
-        Connection conn = null;
-        Statement statement = null;
-        ResultSet rs = null;
-
-        WorkflowTaskConfiguration config = null;
-
-        try {
-            conn = dataSource.getConnection();
-            statement = conn.createStatement();
-
-            String getConfigurationSql = "SELECT * from workflow_task_configuration WHERE workflow_task_id = "
-                    + taskId;
-
-            LOG.log(Level.FINE, "getConfigurationByTaskId: Executing: "
-                    + getConfigurationSql);
-            rs = statement.executeQuery(getConfigurationSql);
-
-            config = new WorkflowTaskConfiguration();
-            while (rs.next()) {
-                config.getProperties().put(rs.getString("property_name"),
-                        rs.getString("property_value"));
-            }
-
-            if (config.getProperties().keySet().size() == 0) {
-                config = null;
-            }
-
-        } catch (Exception e) {
-            e.printStackTrace();
-            LOG.log(Level.WARNING,
-                    "Exception getting task configuration for taskId: "
-                            + taskId + " Message: " + e.getMessage());
-            try {
-                conn.rollback();
-            } catch (SQLException e2) {
-                LOG.log(Level.SEVERE,
-                        "Unable to rollback getConfigurationBytaskId transaction. Message: "
-                                + e2.getMessage());
-            }
-            throw new RepositoryException(e.getMessage());
-        } finally {
-
-            if (rs != null) {
-                try {
-                    rs.close();
-                } catch (SQLException ignore) {
-                }
-
-                rs = null;
-            }
-
-            if (statement != null) {
-                try {
-                    statement.close();
-                } catch (SQLException ignore) {
-                }
-
-                statement = null;
-            }
-
-            if (conn != null) {
-                try {
-                    conn.close();
+    return events;
+  }
 
-                } catch (SQLException ignore) {
-                }
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * org.apache.oodt.cas.workflow.repository.WorkflowRepository#addWorkflow(
+   * org.apache.oodt.cas.workflow.structs.Workflow)
+   */
+  @Override
+  public String addWorkflow(Workflow workflow) throws RepositoryException {
+    // first check to see that its tasks are all present
+    if (workflow.getTasks() == null
+        || (workflow.getTasks() != null && workflow.getTasks().size() == 0)) {
+      throw new RepositoryException("Attempt to define a new worklfow: ["
+          + workflow.getName() + "] with no tasks.");
+    }
+
+    List<WorkflowTask> allTasks = this.getTasks();
+
+    for (WorkflowTask task : (List<WorkflowTask>) workflow.getTasks()) {
+      if (!this.hasTaskId(allTasks, task.getTaskId())) {
+        throw new RepositoryException("Reference in new workflow: ["
+            + workflow.getName() + "] to undefined task with id: ["
+            + task.getTaskId() + "]");
+      }
 
-                conn = null;
-            }
+      // check its conditions
+      if (task.getConditions() != null && task.getConditions().size() > 0) {
+        List<WorkflowCondition> conditions = this.getConditionsByTaskId(task
+            .getTaskId());
+        for (WorkflowCondition cond : (List<WorkflowCondition>) task
+            .getConditions()) {
+          if (!this.hasConditionId(conditions, cond.getConditionId())) {
+            throw new RepositoryException("Reference in new workflow: ["
+                + workflow.getName() + "] to undefined condition ith id: ["
+                + cond.getConditionId() + "]");
+          }
         }
-
-        return config;
+      }
     }
 
-    public WorkflowConditionConfiguration getConfigurationByConditionId(String condId)
-            throws RepositoryException {
-        Connection conn = null;
-        Statement statement = null;
-        ResultSet rs = null;
-
-        WorkflowConditionConfiguration config = null;
-
-        try {
-            conn = dataSource.getConnection();
-            statement = conn.createStatement();
-
-            String getConfigurationSql = "SELECT * from workflow_condition_configuration WHERE workflow_condition_id = "
-                    + condId;
-
-            LOG.log(Level.FINE, "getConfigurationByConfigurationId: Executing: "
-                    + getConfigurationSql);
-            rs = statement.executeQuery(getConfigurationSql);
-
-            config = new WorkflowConditionConfiguration();
-            while (rs.next()) {
-                config.getProperties().put(rs.getString("property_name"),
-                        rs.getString("property_value"));
-            }
-
-            if (config.getProperties().keySet().size() == 0) {
-                config = null;
-            }
-
-        } catch (Exception e) {
-            e.printStackTrace();
-            LOG.log(Level.WARNING,
-                    "Exception getting task configuration for condId: "
-                            + condId + " Message: " + e.getMessage());
-            try {
-                conn.rollback();
-            } catch (SQLException e2) {
-                LOG.log(Level.SEVERE,
-                        "Unable to rollback getConfigurationByConfigurationId transaction. Message: "
-                                + e2.getMessage());
-            }
-            throw new RepositoryException(e.getMessage());
-        } finally {
-
-            if (rs != null) {
-                try {
-                    rs.close();
-                } catch (SQLException ignore) {
-                }
-
-                rs = null;
-            }
-
-            if (statement != null) {
-                try {
-                    statement.close();
-                } catch (SQLException ignore) {
-                }
-
-                statement = null;
-            }
-
-            if (conn != null) {
-                try {
-                    conn.close();
-
-                } catch (SQLException ignore) {
-                }
+    String workflowId = this.commitWorkflow(workflow);
+    return workflowId;
+  }
 
-                conn = null;
-            }
-        }
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.oodt.cas.workflow.repository.WorkflowRepository#
+   * getConditionsByWorkflowId(java.lang.String)
+   */
+  @Override
+  public List<WorkflowCondition> getConditionsByWorkflowId(String workflowId)
+      throws RepositoryException {
+    Connection conn = null;
+    Statement statement = null;
+    ResultSet rs = null;
 
-        return config;
-    }
-    
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.oodt.cas.workflow.repository.WorkflowRepository#getWorkflowTaskById(java.lang.String)
-     */
-    public WorkflowTask getWorkflowTaskById(String taskId)
-            throws RepositoryException {
-        Connection conn = null;
-        Statement statement = null;
-        ResultSet rs = null;
-
-        WorkflowTask task = null;
-
-        try {
-            conn = dataSource.getConnection();
-            statement = conn.createStatement();
-
-            String getTaskSql = "SELECT * FROM workflow_tasks WHERE workflow_task_id = "
-                    + taskId;
-
-            LOG
-                    .log(Level.FINE, "getWorkflowTaskById: Executing: "
-                            + getTaskSql);
-            rs = statement.executeQuery(getTaskSql);
-
-            while (rs.next()) {
-                // get an instance of the class name
-                task = DbStructFactory.getWorkflowTask(rs, false);
-                task.setConditions(getConditionsByTaskId(task.getTaskId()));
-                task.setTaskConfig(getConfigurationByTaskId(task.getTaskId()));
-            }
-
-        } catch (Exception e) {
-            e.printStackTrace();
-            LOG.log(Level.WARNING, "Exception getting task by id. Message: "
-                    + e.getMessage());
-            try {
-                conn.rollback();
-            } catch (SQLException e2) {
-                LOG.log(Level.SEVERE,
-                        "Unable to rollback getWorkflowTaskById transaction. Message: "
-                                + e2.getMessage());
-            }
-            throw new RepositoryException(e.getMessage());
-        } finally {
-
-            if (rs != null) {
-                try {
-                    rs.close();
-                } catch (SQLException ignore) {
-                }
-
-                rs = null;
-            }
-
-            if (statement != null) {
-                try {
-                    statement.close();
-                } catch (SQLException ignore) {
-                }
-
-                statement = null;
-            }
-
-            if (conn != null) {
-                try {
-                    conn.close();
+    List<WorkflowCondition> conditions = null;
 
-                } catch (SQLException ignore) {
-                }
+    try {
+      conn = dataSource.getConnection();
+      statement = conn.createStatement();
 
-                conn = null;
-            }
-        }
+      String getConditionsSql = "SELECT workflow_conditions.*, workflow_condition_map.condition_order "
+          + "FROM workflow_conditions, workflow_condition_map "
+          + "WHERE workflow_condition_map.workflow_condition_id = workflow_conditions.workflow_condition_id "
+          + "AND workflow_condition_map.workflow_id = "
+          + workflowId
+          + " "
+          + "ORDER BY workflow_condition_map.condition_order";
+
+      LOG.log(Level.FINE, "getConditionsByWorkflowId: Executing: "
+          + getConditionsSql);
+      rs = statement.executeQuery(getConditionsSql);
+      conditions = new Vector<WorkflowCondition>();
 
-        return task;
-    }
+      while (rs.next()) {
+        // get an instance of the class name
+        WorkflowCondition condition = DbStructFactory.getWorkflowCondition(rs,
+            true);
+        conditions.add(condition);
+      }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.oodt.cas.workflow.repository.WorkflowRepository#getWorkflowConditionById(java.lang.String)
-     */
-    public WorkflowCondition getWorkflowConditionById(String conditionId)
-            throws RepositoryException {
-        Connection conn = null;
-        Statement statement = null;
-        ResultSet rs = null;
-
-        WorkflowCondition condition = null;
-
-        try {
-            conn = dataSource.getConnection();
-            statement = conn.createStatement();
-
-            String getConditionsSql = "SELECT * FROM workflow_conditions WHERE workflow_condition_id = "
-                    + conditionId;
-
-            LOG.log(Level.FINE, "getWorkflowConditionById: Executing: "
-                    + getConditionsSql);
-            rs = statement.executeQuery(getConditionsSql);
-
-            while (rs.next()) {
-                // get an instance of the class name
-                condition = DbStructFactory.getWorkflowCondition(rs, false);
-                condition.setCondConfig(getConfigurationByConditionId(conditionId));
-            }
-
-        } catch (Exception e) {
-            e.printStackTrace();
-            LOG.log(Level.WARNING,
-                    "Exception getting condition by id. Message: "
-                            + e.getMessage());
-            try {
-                conn.rollback();
-            } catch (SQLException e2) {
-                LOG.log(Level.SEVERE,
-                        "Unable to rollback getWorkflowConditionById transaction. Message: "
-                                + e2.getMessage());
-            }
-            throw new RepositoryException(e.getMessage());
-        } finally {
-
-            if (rs != null) {
-                try {
-                    rs.close();
-                } catch (SQLException ignore) {
-                }
-
-                rs = null;
-            }
-
-            if (statement != null) {
-                try {
-                    statement.close();
-                } catch (SQLException ignore) {
-                }
-
-                statement = null;
-            }
-
-            if (conn != null) {
-                try {
-                    conn.close();
+      if (conditions.size() == 0) {
+        conditions = null;
+      }
 
-                } catch (SQLException ignore) {
-                }
+    } catch (Exception e) {
+      e.printStackTrace();
+      LOG.log(
+          Level.WARNING,
+          "Exception getting conditions for workflow. Message: "
+              + e.getMessage());
+      try {
+        conn.rollback();
+      } catch (SQLException e2) {
+        LOG.log(Level.SEVERE,
+            "Unable to rollback getConditionsByWorkflowId transaction. Message: "
+                + e2.getMessage());
+      }
+      throw new RepositoryException(e.getMessage());
+    } finally {
 
-                conn = null;
-            }
+      if (rs != null) {
+        try {
+          rs.close();
+        } catch (SQLException ignore) {
         }
 
-        return condition;
-    }
+        rs = null;
+      }
+
+      if (statement != null) {
+        try {
+          statement.close();
+        } catch (SQLException ignore) {
+        }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.apache.oodt.cas.workflow.repository.WorkflowRepository#getRegisteredEvents()
-     */
-    public List getRegisteredEvents() throws RepositoryException {
-        Connection conn = null;
-        Statement statement = null;
-        ResultSet rs = null;
-
-        List events = null;
-
-        try {
-            conn = dataSource.getConnection();
-            statement = conn.createStatement();
-
-            String getEventSql = "SELECT DISTINCT event_name FROM event_workflow_map ORDER BY event_name ASC";
-
-            LOG.log(Level.FINE, "getRegisteredEvents: Executing: "
-                    + getEventSql);
-            rs = statement.executeQuery(getEventSql);
-            events = new Vector();
-
-            while (rs.next()) {
-                // get an instance of the class name
-                String event = DbStructFactory.getEvent(rs);
-                events.add(event);
-            }
-
-            if (events.size() == 0) {
-                events = null;
-            }
-
-        } catch (Exception e) {
-            e.printStackTrace();
-            LOG.log(Level.WARNING,
-                    "Exception getting registered events. Message: "
-                            + e.getMessage());
-            try {
-                conn.rollback();
-            } catch (SQLException e2) {
-                LOG.log(Level.SEVERE,
-                        "Unable to rollback getRegisteredEvents transaction. Message: "
-                                + e2.getMessage());
-            }
-            throw new RepositoryException(e.getMessage());
-        } finally {
-
-            if (rs != null) {
-                try {
-                    rs.close();
-                } catch (SQLException ignore) {
-                }
-
-                rs = null;
-            }
-
-            if (statement != null) {
-                try {
-                    statement.close();
-                } catch (SQLException ignore) {
-                }
-
-                statement = null;
-            }
-
-            if (conn != null) {
-                try {
-                    conn.close();
+        statement = null;
+      }
 
-                } catch (SQLException ignore) {
-                }
+      if (conn != null) {
+        try {
+          conn.close();
 
-                conn = null;
-            }
+        } catch (SQLException ignore) {
         }
 
-        return events;
+        conn = null;
+      }
     }
-    
 
-    /* (non-Javadoc)
-     * @see org.apache.oodt.cas.workflow.repository.WorkflowRepository#addWorkflow(org.apache.oodt.cas.workflow.structs.Workflow)
-     */
-    @Override
-    public String addWorkflow(Workflow workflow) throws RepositoryException {
-      // first check to see that its tasks are all present
-      if (workflow.getTasks() == null
-          || (workflow.getTasks() != null && workflow.getTasks().size() == 0)) {
-        throw new RepositoryException("Attempt to define a new worklfow: ["
-            + workflow.getName() + "] with no tasks.");
-      }
-      
-      List<WorkflowTask> allTasks = this.getTasks();
-
-      for (WorkflowTask task : (List<WorkflowTask>) workflow.getTasks()) {
-        if (!this.hasTaskId(allTasks, task.getTaskId())) {
-          throw new RepositoryException("Reference in new workflow: ["
-              + workflow.getName() + "] to undefined task with id: ["
-              + task.getTaskId() + "]");
-        }
-
-        // check its conditions
-        if (task.getConditions() != null && task.getConditions().size() > 0) {
-          List<WorkflowCondition> conditions = this.getConditionsByTaskId(task.getTaskId());          
-          for (WorkflowCondition cond : (List<WorkflowCondition>) task
-              .getConditions()) {
-            if (!this.hasConditionId(conditions, cond.getConditionId())) {
-              throw new RepositoryException("Reference in new workflow: ["
-                  + workflow.getName() + "] to undefined condition ith id: ["
-                  + cond.getConditionId() + "]");
-            }
-          }
-        }
-      }
-      
-      String workflowId = this.commitWorkflow(workflow);
-      return workflowId;
-    }    
+    return conditions;
+  }
 
   private String commitWorkflow(Workflow workflow) throws RepositoryException {
     Connection conn = null;
@@ -1258,10 +1366,10 @@ public class DataSourceWorkflowRepositor
         conn = null;
       }
     }
-    
+
     return workflowId;
   }
-    
+
   private List<WorkflowTask> getTasks() throws RepositoryException {
     Connection conn = null;
     Statement statement = null;
@@ -1342,7 +1450,7 @@ public class DataSourceWorkflowRepositor
 
     return tasks;
   }
-  
+
   private boolean hasTaskId(List<WorkflowTask> tasks, String id) {
     if (tasks == null || (tasks != null && tasks.size() == 0))
       return false;

Modified: oodt/trunk/workflow/src/main/java/org/apache/oodt/cas/workflow/repository/PackagedWorkflowRepository.java
URL: http://svn.apache.org/viewvc/oodt/trunk/workflow/src/main/java/org/apache/oodt/cas/workflow/repository/PackagedWorkflowRepository.java?rev=1157470&r1=1157469&r2=1157470&view=diff
==============================================================================
--- oodt/trunk/workflow/src/main/java/org/apache/oodt/cas/workflow/repository/PackagedWorkflowRepository.java (original)
+++ oodt/trunk/workflow/src/main/java/org/apache/oodt/cas/workflow/repository/PackagedWorkflowRepository.java Sun Aug 14 05:39:56 2011
@@ -29,6 +29,7 @@ import org.apache.oodt.cas.workflow.stru
 import org.apache.oodt.cas.workflow.structs.exceptions.WorkflowTaskInstanceException;
 import org.apache.oodt.cas.workflow.system.XmlRpcWorkflowManagerClient;
 import org.apache.oodt.cas.workflow.util.XmlStructFactory;
+import org.apache.oodt.commons.xml.XMLUtils;
 
 //JDK imports
 import java.io.File;
@@ -310,13 +311,30 @@ public class PackagedWorkflowRepository 
     pcw.setName(workflow.getName());
     pcw.setTasks(workflow.getTasks());
     pcw.setId(workflow.getId());
-    this.workflows.put(pcw.getId(), pcw);    
+    this.workflows.put(pcw.getId(), pcw);
     this.eventWorkflowMap.put(workflowId, Collections.singletonList(pcw));
 
     // generate its ID
     return workflowId;
   }
 
+  /*
+   * (non-Javadoc)
+   * 
+   * @see org.apache.oodt.cas.workflow.repository.WorkflowRepository#
+   * getConditionsByWorkflowId(java.lang.String)
+   */
+  @Override
+  public List<WorkflowCondition> getConditionsByWorkflowId(String workflowId)
+      throws RepositoryException {
+    if (!this.workflows.containsKey(workflowId))
+      throw new RepositoryException(
+          "Attempt to obtain conditions for a workflow: " + "[" + workflowId
+              + "] that does not exist!");
+
+    return this.workflows.get(workflowId).getConditions();
+  }
+
   private void init() throws RepositoryException {
     this.workflows = new HashMap<String, ParentChildWorkflow>();
     this.tasks = new HashMap<String, WorkflowTask>();
@@ -445,14 +463,18 @@ public class PackagedWorkflowRepository 
         }
       } else {
         if (processorType.equals("condition")) {
-          NodeList procTypeBlockNodes = graphElem
-              .getElementsByTagName("condition");
-          if (procTypeBlockNodes != null && procTypeBlockNodes.getLength() > 0) {
-            LOG.log(Level.FINE, "Found: [" + procTypeBlockNodes.getLength()
-                + "] linked condition definitions");
-            for (int i = 0; i < procTypeBlockNodes.getLength(); i++) {
-              loadGraphs(rootElements, (Element) procTypeBlockNodes.item(i),
-                  graph, staticMetadata);
+          Element conditionsElem = XMLUtils.getFirstElement("conditions",
+              graphElem);
+          if (conditionsElem != null) {
+            List<Element> procTypeBlockNodes = this.getChildrenByTagName(
+                conditionsElem, "condition");
+            if (procTypeBlockNodes != null && procTypeBlockNodes.size() > 0) {
+              LOG.log(Level.FINE, "Found: [" + procTypeBlockNodes.size()
+                  + "] linked condition definitions");
+              for (int i = 0; i < procTypeBlockNodes.size(); i++) {
+                loadGraphs(rootElements, procTypeBlockNodes.get(i), graph,
+                    staticMetadata);
+              }
             }
           }
         }
@@ -565,11 +587,10 @@ public class PackagedWorkflowRepository 
       graph.setCond(cond);
       if (graph.getParent() != null) {
         if (graph.getParent().getWorkflow() != null) {
-          LOG.log(
-              Level.WARNING,
-              "wengine feature not supported yet: condition: ["
-                  + cond.getConditionId() + "] has workflow parent: ["
-                  + graph.getParent().getWorkflow().getId() + "]");
+          System.out.println("Adding condition: [" + cond.getConditionName()
+              + "] to parent workflow: ["
+              + graph.getParent().getWorkflow().getName() + "]");
+          graph.getParent().getWorkflow().getConditions().add(cond);
         } else if (graph.getParent().getTask() != null) {
           graph.getParent().getTask().getConditions().add(cond);
         } else {
@@ -703,7 +724,7 @@ public class PackagedWorkflowRepository 
     private String clazz;
 
     private long timeout;
-    
+
     private boolean optional;
 
     private Graph parent;
@@ -724,7 +745,7 @@ public class PackagedWorkflowRepository 
       this.timeout = Long.valueOf(graphElem.getAttribute("timeout") != null
           && !graphElem.getAttribute("timeout").equals("") ? graphElem
           .getAttribute("timeout") : "-1");
-      this.optional = Boolean.valueOf(graphElem.getAttribute("optional")); 
+      this.optional = Boolean.valueOf(graphElem.getAttribute("optional"));
 
       NamedNodeMap attrMap = graphElem.getAttributes();
       for (int i = 0; i < attrMap.getLength(); i++) {
@@ -997,7 +1018,8 @@ public class PackagedWorkflowRepository 
     }
 
     /**
-     * @param optional the optional to set
+     * @param optional
+     *          the optional to set
      */
     public void setOptional(boolean optional) {
       this.optional = optional;



Mime
View raw message