/*
  * (non-Javadoc)
  *
  * @see com.aof.service.business.rule.FlowManager#removeFlow(java.lang.Integer)
  */
 public void removeFlow(Integer id) {
   Flow f = getFlow(id, true);
   for (Iterator itor = f.getRules().iterator(); itor.hasNext(); ) {
     dao.removeFlowRule((FlowRule) itor.next());
   }
   dao.removeFlow(id);
   if (EnabledDisabled.ENABLED.equals(f.getEnabled())) {
     Site s = f.getSite();
     RuleType rt = f.getType();
     workspace.removeFlow(s.getId() + rt.getPrefixUrl());
   }
 }
  /*
   * (non-Javadoc)
   *
   * @see com.aof.service.business.rule.FlowManager#saveFlow(com.aof.model.business.rule.Flow,
   *      java.util.Set)
   */
  public Flow[] saveFlow(Flow f, Set flowRules) {
    Flow[] result = null;
    boolean needUpdateWorkspace = false;

    Flow f2 = getSiteEnabledFlow(f.getSite().getId(), f.getType());
    if (f.equals(f2)) {
      f2.setDescription(f.getDescription());
      f2.setEnabled(f.getEnabled());
      f = f2;
      needUpdateWorkspace = true;
    } else {
      if (EnabledDisabled.ENABLED.equals(f.getEnabled())) {
        if (f2 != null) {
          result = new Flow[2];
          f2.setEnabled(EnabledDisabled.DISABLED);
          result[1] = dao.saveFlow(f2);
        }
        needUpdateWorkspace = true;
      }
    }

    if (result == null) result = new Flow[1];
    result[0] = dao.saveFlow(f);
    if (flowRules != null) {
      for (Iterator itor = dao.getRulesForFlow(f.getId()).iterator(); itor.hasNext(); ) {
        dao.removeFlowRule((FlowRule) itor.next());
      }
      for (Iterator itor = flowRules.iterator(); itor.hasNext(); ) {
        dao.saveFlowRule((FlowRule) itor.next());
      }
    }
    if (needUpdateWorkspace) {
      constructEngineFlow(f.getSite().getId(), f.getType());
    }
    return result;
  }