/*
   * (non-Javadoc)
   *
   * @see org.talend.gwtadministrator.server.remoterepositorymgt.view.AbstractViewAdapter#hib2Gwt(java.lang.Object)
   */
  @Override
  public ExecutionPlanPartBean hib2Gwt(ExecutionPlanPart hibPlanPart) {
    ExecutionPlanPartBean executionPlanPartBean = new ExecutionPlanPartBean();
    executionPlanPartBean.setId(hibPlanPart.getId());
    if (hibPlanPart.getTask() != null) {
      ExecutionTaskBean taskBean =
          ExecutionTaskViewAdapter.getInstance().hib2Gwt(hibPlanPart.getTask(), false);
      executionPlanPartBean.setTaskBean(taskBean);
    }
    ExecutionPlan executionPlan = hibPlanPart.getExecutionPlan();
    ExecutionPlanBean planBean = PlanViewAdapter.getInstance().hib2Gwt(executionPlan);
    executionPlanPartBean.setPlanBean(planBean);
    executionPlanPartBean.setType(ActionType.get(hibPlanPart.getType()));
    executionPlanPartBean.setStatus(hibPlanPart.getStatus());
    executionPlanPartBean.setStartDate(hibPlanPart.getStartDate());
    executionPlanPartBean.setEndDate(hibPlanPart.getEndDate());
    executionPlanPartBean.setUseParallel(hibPlanPart.isUseParallel());
    executionPlanPartBean.setMaxThreads(hibPlanPart.getMaxThreads());

    if (hibPlanPart.isUseParallel()) {
      List<ExecutionPlanPart> childrenParallelPartsFromDb =
          new ArrayList<ExecutionPlanPart>(
              ExecutionPlanPartHelper.getInstance()
                  .getChildrenParts(hibPlanPart, ActionType.PARALLEL));
      final List<ExecutionPlanPartBean> parallelParts = new ArrayList<ExecutionPlanPartBean>();
      for (ExecutionPlanPart executionPlanPartDb : childrenParallelPartsFromDb) {
        parallelParts.add(hib2Gwt(executionPlanPartDb));
      }
      executionPlanPartBean.setParallelParts(parallelParts);
    }

    PlanPartWrapper partWrapper = new PlanPartWrapper(hibPlanPart);
    TaskExecutionBasicStatus taskExecutionBasicStatus = partWrapper.getExecutionBasicStatus();
    if (taskExecutionBasicStatus != null) {
      executionPlanPartBean.setTaskExecutionHistoryBasicStatus(taskExecutionBasicStatus.toString());
    }

    return executionPlanPartBean;
  }
 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()]);
 }