/**
  * merge.
  *
  * @param project the project to merge
  * @param ITransactionHolder
  */
 public void merge(Project project, ITransactionHolder transactionHolder) throws DBException {
   if (transactionHolder == null) {
     PersistenceUtil.getPersistenceAdapter().merge(project);
   } else {
     PersistenceUtil.getPersistenceAdapter().merge(project, transactionHolder);
   }
 }
 /**
  * saveOrUpdate.
  *
  * @param project project to save
  * @return ture if save is ok
  */
 public void saveOrUpdate(Project project, ITransactionHolder transactionHolder)
     throws SystemException {
   if (transactionHolder == null) {
     PersistenceUtil.getPersistenceAdapter().saveOrUpdate(project);
   } else {
     PersistenceUtil.getPersistenceAdapter().saveOrUpdate(project, transactionHolder);
   }
 }
 /**
  * findByName.
  *
  * @param name the name of the project to find
  * @param ITransactionHolder
  * @return the found project
  * @throws BusinessException
  * @throws DBException
  */
 public Project findByName(ITransactionHolder transactionHolder, String name)
     throws BusinessException, DBException {
   Project project = AdminFactory.eINSTANCE.createProject();
   project.setLabel(name);
   if (transactionHolder == null)
     return PersistenceUtil.getPersistenceAdapter()
         .retrieveUnique(project, new String[] {"label"}, getDependentObjectsWithFolders());
   else
     return PersistenceUtil.getPersistenceAdapter()
         .retrieveUnique(
             transactionHolder, project, new String[] {"label"}, getDependentObjectsWithFolders());
 }
  public ExecutionPlanPartBean saveExecutionPlanPartBean(
      ExecutionPlanPartBean viewBean, User user, ITransactionHolder transactionPrm)
      throws BusinessException, ClientBusinessException {
    HibernatePersistenceAdapter persistenceAdapter = PersistenceUtil.getPersistenceAdapter();
    ExecutionPlanPart planPart = null;
    ITransactionHolder transaction = null;
    boolean isLocalTransaction = transactionPrm == null;
    try {
      if (isLocalTransaction) {
        transaction = persistenceAdapter.createTransaction();
      } else {
        transaction = transactionPrm;
      }
      planPart = gwt2Hib(viewBean, transaction);

      ActionType actionType = ActionType.get(planPart.getType());
      if (viewBean.getId() == null && actionType != ActionType.PARALLEL) {
        ExecutionPlanPart executionPlanPart =
            ExecutionPlanPartHelper.getInstance().findWithSameParentsAndType(planPart, transaction);
        if (executionPlanPart != null)
          throw new BusinessException(
              "executionPlan.part.saveError.uniqueType", planPart.getType());
      }
      if (planPart.isUseParallel()) {
        planPart.setTask(null);
        viewBean.setTaskBean(null);
      }

      ExecutionPlanPartHandler.getInstance().saveOrUpdate(planPart, user, transaction);

      viewBean.setId(planPart.getId());
      saveOrUpdateParallelParts(viewBean, planPart, user, transaction);

    } catch (BusinessException e) {
      throw e;
    } catch (Throwable ex) {
      if (isLocalTransaction && transaction != null && !transaction.isClosed()) {
        try {
          transaction.rollbackAndClose();
        } catch (DBException e1) {
          log.error(e1.getMessage(), e1);
        }
      }
      throw new SystemException(ex);
    } finally {
      if (isLocalTransaction && transaction != null && !transaction.isClosed()) {
        try {
          transaction.commitAndClose();
        } catch (Exception e) {
          log.error(e.getMessage(), e);
        }
      }
    }

    return hib2Gwt(planPart);
  }
 /**
  * DOC gwu Comment method "findByAuthor".
  *
  * @param author
  * @param transaction
  * @return List<Project>
  * @throws DBException
  */
 public List<Project> findByAuthor(User author, ITransactionHolder transaction)
     throws DBException {
   Project project = AdminFactory.eINSTANCE.createProject();
   project.setAuthor(author);
   return PersistenceUtil.getPersistenceAdapter()
       .retrieve(
           transaction,
           project,
           HibernatePersistenceAdapter.createCriterions(project, new String[] {"author"}),
           dependentObjects);
 }
  private List<Project> listProjects(
      boolean loadActiveProjectsOnly,
      boolean loadFolders,
      User sessionUser,
      ITransactionHolder transactionHolder)
      throws DBException {
    Project project = AdminFactory.eINSTANCE.createProject();
    List<String> matches = new ArrayList<String>();
    Criterion[] criterions = null;
    if (loadActiveProjectsOnly) {
      project.setDeleted(false);
      matches.add("deleted");
    }
    if (matches != null) {
      criterions =
          HibernatePersistenceAdapter.createCriterions(project, matches.toArray(new String[] {}));
    }

    String[] projectDependantObjects;
    if (loadFolders) {
      projectDependantObjects = getDependentObjectsWithFolders();
    } else {
      projectDependantObjects = dependentObjects;
    }
    List<Project> retrieve = null;

    if (transactionHolder == null) {
      retrieve =
          PersistenceUtil.getPersistenceAdapter()
              .retrieve(project, criterions, projectDependantObjects);
    } else {
      retrieve =
          PersistenceUtil.getPersistenceAdapter()
              .retrieve(transactionHolder, project, criterions, projectDependantObjects);
    }

    ProjectFilter<Project> projectFilter = new EmfProjectFilter(sessionUser);
    retrieve = projectFilter.filter(retrieve);
    return retrieve;
  }
  public void deleteExecutionPlanPart(
      ExecutionPlanPartBean executionPlanPartBean, boolean deleteAllRelatedDatas)
      throws ClientBusinessException {
    ExecutionPlanPart planPart = gwt2Hib(executionPlanPartBean);

    ITransactionHolder transactionHolder = null;
    try {
      transactionHolder = PersistenceUtil.getPersistenceAdapter().createTransaction();
      ExecutionPlanPartHelper.getInstance().delete(planPart, transactionHolder);
      transactionHolder.commitAndClose();
    } catch (Exception e) {
      transactionHolder.rollbackAndClose();
      throw new RuntimeException(e);
    }
    /*
     * List<ExecutionPlanPart> children = ExecutionPlanPartHelper.getInstance().findChildrenByPart(planPart); if
     * (children != null && children.size() > 0) { throw new
     * ClientBusinessException("executionPlan.part.delete.children.firstly"); } else {
     * ExecutionPlanPartHelper.getInstance().delete(planPart, deleteAllRelatedDatas); }
     */
  }
  /**
   * DOC kpchen Comment method "listReferenceProjects".
   *
   * @param sessionUser
   * @return List<Project>
   * @throws DBException
   */
  public List<Project> listReferenceProjects(User sessionUser) throws DBException {
    Project project = AdminFactory.eINSTANCE.createProject();
    List<String> matches = new ArrayList<String>();
    Criterion[] criterions = null;

    project.setReference(true);
    matches.add("reference");

    if (matches != null) {
      criterions =
          HibernatePersistenceAdapter.createCriterions(project, matches.toArray(new String[] {}));
    }

    String[] projectDependantObjects = dependentObjects;

    List<Project> toReturn =
        PersistenceUtil.getPersistenceAdapter()
            .retrieve(project, criterions, projectDependantObjects);
    ProjectFilter<Project> projectFilter = new EmfProjectFilter(sessionUser);
    toReturn = projectFilter.filter(toReturn);
    return toReturn;
  }
 public PartStatusBean[] getPartsStatusByIds(Integer[] ids) {
   List<PartStatusBean> statuses = new ArrayList<PartStatusBean>();
   HibernatePersistenceAdapter persistenceAdapter = PersistenceUtil.getPersistenceAdapter();
   ITransactionHolder transaction = null;
   try {
     transaction = persistenceAdapter.createTransaction();
     if (ids != null) {
       for (Integer id : ids) {
         ExecutionPlanPart part = ExecutionPlanPartHelper.getInstance().findById(id, transaction);
         if (part != null) {
           PartStatusBean bean = new PartStatusBean();
           bean.setId(part.getId());
           bean.setStatus(part.getStatus());
           PlanPartWrapper wrapper = new PlanPartWrapper(part);
           TaskExecutionBasicStatus taskExecutionBasicStatus =
               wrapper.getExecutionBasicStatus(transaction);
           if (taskExecutionBasicStatus != null) {
             bean.setTaskExecutionHistoryBasicStatus(taskExecutionBasicStatus.toString());
           }
           statuses.add(bean);
         }
       }
     }
   } catch (Throwable ex) {
     throw new SystemException(ex);
   } finally {
     if (transaction != null && !transaction.isClosed()) {
       try {
         transaction.commitAndClose();
       } catch (Exception e) {
         log.error(e.getMessage(), e);
       }
     }
   }
   return statuses.toArray(new PartStatusBean[statuses.size()]);
 }
 /**
  * DOC kpchen Comment method "deleteProject".
  *
  * @param project
  * @param transactionHolder
  * @throws Exception
  */
 public void deleteProject(Project project, ITransactionHolder transactionHolder)
     throws BusinessException {
   ProjectManager projectManager = ProjectManagerFactory.getProjectManager(project);
   projectManager.deleteProject(transactionHolder);
   PersistenceUtil.getPersistenceAdapter().delete(project, transactionHolder);
 }
 /**
  * findById.
  *
  * @param id the id of the project to find
  * @return the found project
  * @throws BusinessException
  * @throws DBException
  */
 public Project findById(int id) throws BusinessException, DBException {
   Project project = AdminFactory.eINSTANCE.createProject();
   project.setId(id);
   return PersistenceUtil.getPersistenceAdapter()
       .retrieveUnique(project, new String[] {"id"}, getDependentObjectsWithFolders());
 }