/* (non-Javadoc)
   * @see org.gridchem.service.impl.WorkflowService#createWorkflow(java.lang.String, java.lang.String)
   */
  public String createWorkflow(String sessionId, String sWorkflowBean)
      throws JobException, PermissionException, SessionException, WorkflowException {

    if (!ServiceUtil.isValid(sessionId)) {
      throw new SessionException("Invalid session id");
    }

    if (!ServiceUtil.isValid(sWorkflowBean)) {
      throw new WorkflowException("Invalid workflow");
    }

    SessionManager manager = new SessionManager(sessionId);

    try {

      Workflow workflow =
          WorkflowManager.add(
              manager.getSession(), (WorkflowBean) ServiceUtil.xstream.fromXML(sWorkflowBean));

      return ServiceUtil.xstream.toXML(workflow.getId());

    } catch (Exception e) {
      throw new WorkflowException("Invalid workflow representation.", e);
    }
  }
  /* (non-Javadoc)
   * @see org.gridchem.service.impl.WorkflowService#removeJobFromWorkflow(java.lang.String, java.lang.String, java.lang.String)
   */
  public void removeJobFromWorkflow(String sessionId, String sWorkflowId, String sJobId)
      throws JobException, PermissionException, SessionException, WorkflowException {
    if (!ServiceUtil.isValid(sessionId)) {
      throw new SessionException("Invalid session id");
    }

    Long jobId = null;
    if (ServiceUtil.isValid(sJobId)) {
      try {
        jobId = Long.valueOf(sJobId);
      } catch (Exception e) {
        throw new JobException("Invalid job id");
      }
    } else {
      throw new JobException("Invalid job id");
    }

    Long workflowId = null;
    if (ServiceUtil.isValid(sWorkflowId)) {
      try {
        workflowId = Long.valueOf(sWorkflowId);
      } catch (Exception e) {
        throw new JobException("Invalid workflow id");
      }
    } else {
      throw new JobException("Invalid workflow id");
    }

    SessionManager manager = new SessionManager(sessionId);

    WorkflowManager.removeJobFromWorkflow(manager.getSession(), workflowId, jobId);
  }
  /* (non-Javadoc)
   * @see org.gridchem.service.impl.WorkflowService#deleteWorkflow(java.lang.String, java.lang.String)
   */
  public void deleteWorkflow(String sessionId, String sWorkflowId) throws WorkflowException {

    if (!ServiceUtil.isValid(sessionId)) {
      throw new SessionException("Invalid session id");
    }

    Long workflowId = null;
    if (ServiceUtil.isValid(sWorkflowId)) {
      try {
        workflowId = Long.valueOf(sWorkflowId);
      } catch (Exception e) {
        throw new JobException("Invalid workflow id");
      }
    } else {
      throw new JobException("Invalid workflow id");
    }

    SessionManager manager = new SessionManager(sessionId);

    WorkflowManager.delete(manager.getSession(), workflowId);
  }