Пример #1
0
  @SuppressWarnings("rawtypes")
  public static ProcessDefinition findLastProcessDefinition(String name) throws WorkflowException {
    log.debug("findLastProcessDefinition()");
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();
    ProcessDefinition pd = new ProcessDefinition();

    try {
      GraphSession graphSession = jbpmContext.getGraphSession();

      for (Iterator it = graphSession.findLatestProcessDefinitions().iterator(); it.hasNext(); ) {
        org.jbpm.graph.def.ProcessDefinition procDef =
            (org.jbpm.graph.def.ProcessDefinition) it.next();

        if (procDef.getName().equals(name)) {
          pd = WorkflowUtils.copy(procDef);
        }
      }
    } catch (JbpmException e) {
      throw new WorkflowException(e.getMessage(), e);
    } finally {
      jbpmContext.close();
    }

    log.debug("findLastProcessDefinition: {}", pd);
    return pd;
  }
Пример #2
0
  public ProcessDefinition getProcessDefinition(WorkflowProcessDef wfProcessDefEntity) {
    Long l = Long.parseLong(wfProcessDefEntity.getProcessDefEngineKey());
    GraphSession graphSession = jbpmContext.getGraphSession();
    ProcessDefinition processDefinition = graphSession.getProcessDefinition(l);

    return processDefinition;
  }
Пример #3
0
  /** Find Task Instances */
  @SuppressWarnings("rawtypes")
  public static List<TaskInstance> findTaskInstances(long processInstanceId)
      throws WorkflowException {
    log.debug("findTaskInstances({})", processInstanceId);
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();
    ArrayList<TaskInstance> al = new ArrayList<TaskInstance>();

    try {
      GraphSession graphSession = jbpmContext.getGraphSession();
      org.jbpm.graph.exe.ProcessInstance pi = graphSession.getProcessInstance(processInstanceId);
      TaskMgmtInstance taskMgmtInstance = pi.getTaskMgmtInstance();

      if (taskMgmtInstance.getTaskInstances() != null) {
        for (Iterator it = taskMgmtInstance.getTaskInstances().iterator(); it.hasNext(); ) {
          org.jbpm.taskmgmt.exe.TaskInstance ti = (org.jbpm.taskmgmt.exe.TaskInstance) it.next();
          al.add(WorkflowUtils.copy(ti));
        }
      }

      // Sort
      Collections.sort(al);
    } catch (JbpmException e) {
      throw new WorkflowException(e.getMessage(), e);
    } finally {
      jbpmContext.close();
    }

    log.debug("findTaskInstances: {}", al);
    return al;
  }
Пример #4
0
  public List<Extension> getExtensionTasks(JbpmContext jbpmContext, String processName) {
    List<Extension> extensions = new java.util.ArrayList<Extension>();
    SqlExecutor queryExecutor = new SqlExecutor();
    String hql =
        " select a from "
            + Extension.class.getSimpleName()
            + " as a where a.processName = :processName and a.taskName is not null and a.locked = 0 ";
    Map<String, Object> paramMap = new java.util.HashMap<String, Object>();
    paramMap.put("processName", processName);
    queryExecutor.setSql(hql);
    queryExecutor.setParameter(paramMap);

    List<Object> rows = jbpmEntityDAO.getList(jbpmContext, queryExecutor);
    if (rows != null && rows.size() > 0) {
      ProcessDefinition processDefinition =
          jbpmContext.getGraphSession().findLatestProcessDefinition(processName);
      Map<String, Task> taskMap = processDefinition.getTaskMgmtDefinition().getTasks();
      Iterator<Object> iterator = rows.iterator();
      while (iterator.hasNext()) {
        Extension model = (Extension) iterator.next();
        model.setProcessDescription(processDefinition.getDescription());
        Task task = taskMap.get(model.getTaskName());
        model.setTaskDescription(task.getDescription());
        extensions.add(model);
      }
    }
    return extensions;
  }
Пример #5
0
  /** Find All Process Definition Versions */
  @SuppressWarnings("rawtypes")
  public static List<ProcessDefinition> findAllProcessDefinitionVersions(String name)
      throws WorkflowException {
    log.debug("findAllProcessDefinitionVersions({})", name);
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();
    List<ProcessDefinition> al = new ArrayList<ProcessDefinition>();

    try {
      GraphSession graphSession = jbpmContext.getGraphSession();

      for (Iterator it = graphSession.findAllProcessDefinitionVersions(name).iterator();
          it.hasNext(); ) {
        org.jbpm.graph.def.ProcessDefinition procDef =
            (org.jbpm.graph.def.ProcessDefinition) it.next();
        al.add(WorkflowUtils.copy(procDef));
      }
    } catch (JbpmException e) {
      throw new WorkflowException(e.getMessage(), e);
    } finally {
      jbpmContext.close();
    }

    log.debug("findAllProcessDefinitionVersions: {}", al);
    return al;
  }
Пример #6
0
  /** Find Process Instance */
  @SuppressWarnings("rawtypes")
  public static List<ProcessInstance> findProcessInstances(long processDefinitionId)
      throws WorkflowException {
    log.debug("findProcessInstances({})", processDefinitionId);
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();
    List<ProcessInstance> al = new ArrayList<ProcessInstance>();

    try {
      GraphSession graphSession = jbpmContext.getGraphSession();

      for (Iterator it = graphSession.findProcessInstances(processDefinitionId).iterator();
          it.hasNext(); ) {
        org.jbpm.graph.exe.ProcessInstance procInst =
            (org.jbpm.graph.exe.ProcessInstance) it.next();
        al.add(WorkflowUtils.copy(procInst));
      }
    } catch (JbpmException e) {
      throw new WorkflowException(e.getMessage(), e);
    } finally {
      jbpmContext.close();
    }

    log.debug("findProcessInstances: {}", al);
    return al;
  }
Пример #7
0
  /** Send Process Instance Signal */
  public static ProcessInstance sendProcessInstanceSignal(
      long processInstanceId, String transitionName) throws WorkflowException {
    log.debug(
        "sendProcessInstanceSignal({}, {})", new Object[] {processInstanceId, transitionName});
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();
    ProcessInstance vo = new ProcessInstance();

    try {
      GraphSession graphSession = jbpmContext.getGraphSession();
      org.jbpm.graph.exe.ProcessInstance pi = graphSession.getProcessInstance(processInstanceId);
      org.jbpm.graph.exe.Token t = pi.getRootToken();

      if (transitionName != null && !transitionName.equals("")) {
        t.signal(transitionName);
      } else {
        t.signal();
      }

      jbpmContext.getSession().flush();
      vo = WorkflowUtils.copy(pi);
    } catch (JbpmException e) {
      throw new WorkflowException(e.getMessage(), e);
    } finally {
      jbpmContext.close();
    }

    log.debug("sendProcessInstanceSignal: {}", vo);
    return vo;
  }
Пример #8
0
  /** Get Process Definition Forms */
  public static Map<String, List<FormElement>> getProcessDefinitionForms(long processDefinitionId)
      throws ParseException {
    log.debug("getProcessDefinitionForms({})", processDefinitionId);
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();
    Map<String, List<FormElement>> forms = new HashMap<String, List<FormElement>>();
    InputStream is = null;

    try {
      GraphSession graphSession = jbpmContext.getGraphSession();
      org.jbpm.graph.def.ProcessDefinition pd =
          graphSession.getProcessDefinition(processDefinitionId);
      FileDefinition fileDef = pd.getFileDefinition();
      is = fileDef.getInputStream("forms.xml");

      if (is != null) {
        forms = FormUtils.parseWorkflowForms(is);
      } else {
        log.warn("Process definition '{}' has no forms.xml file", processDefinitionId);
      }
    } finally {
      IOUtils.closeQuietly(is);
      jbpmContext.close();
    }

    log.debug("getProcessDefinitionForms: {}", forms);
    return forms;
  }
Пример #9
0
 public void undeployProcessDefinition(WorkflowProcessDef wfProcessDefEntity)
     throws OperationException {
   Long l = Long.parseLong(wfProcessDefEntity.getProcessDefEngineKey());
   GraphSession graphSession = jbpmContext.getGraphSession();
   ProcessDefinition processDefinition = graphSession.getProcessDefinition(l);
   if (processDefinition != null) {
     graphSession.deleteProcessDefinition(processDefinition);
   } else {
     throw new OperationException("Could not find process definition with (engine) key ID: " + l);
   }
 }
Пример #10
0
  /** Start Process Definition */
  public static ProcessInstance runProcessDefinition(
      String user, long processDefinitionId, String uuid, List<FormElement> variables)
      throws WorkflowException {
    log.debug(
        "runProcessDefinition({}, {}, {}, {})",
        new Object[] {user, processDefinitionId, uuid, variables});
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();
    ProcessInstance vo = new ProcessInstance();

    if (Config.SYSTEM_READONLY) {
      throw new WorkflowException("System is in read-only mode");
    }

    try {
      jbpmContext.setActorId(user);
      GraphSession graphSession = jbpmContext.getGraphSession();
      Map<String, Object> hm = new HashMap<String, Object>();
      hm.put(Config.WORKFLOW_PROCESS_INSTANCE_VARIABLE_UUID, uuid);

      for (FormElement fe : variables) {
        hm.put(fe.getName(), fe);
      }

      org.jbpm.graph.def.ProcessDefinition pd =
          graphSession.getProcessDefinition(processDefinitionId);
      org.jbpm.graph.exe.ProcessInstance pi = pd.createProcessInstance(hm);

      if (pi != null) {
        org.jbpm.taskmgmt.exe.TaskMgmtInstance tmi = pi.getTaskMgmtInstance();

        // http://community.jboss.org/thread/115182
        if (tmi.getTaskMgmtDefinition().getStartTask() != null) {
          org.jbpm.taskmgmt.exe.TaskInstance ti = tmi.createStartTaskInstance();

          if (Config.WORKFLOW_START_TASK_AUTO_RUN) {
            ti.start();
            ti.end();
          }
        } else {
          pi.getRootToken().signal();
        }

        jbpmContext.save(pi);
        vo = WorkflowUtils.copy(pi);
      }
    } catch (JbpmException e) {
      throw new WorkflowException(e.getMessage(), e);
    } finally {
      jbpmContext.close();
    }

    log.debug("runProcessDefinition: {}", vo);
    return vo;
  }
Пример #11
0
  /** Delete Process Instance */
  public static void deleteProcessInstance(long processInstanceId) throws WorkflowException {
    log.debug("deleteProcessInstance({})", processInstanceId);
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();

    try {
      GraphSession graphSession = jbpmContext.getGraphSession();
      graphSession.deleteProcessInstance(processInstanceId);
      jbpmContext.getSession().flush();
    } catch (JbpmException e) {
      throw new WorkflowException(e.getMessage(), e);
    } finally {
      jbpmContext.close();
    }
  }
Пример #12
0
  public void updateProcessDefinition(
      String xmlProcessDefinition, WorkflowProcessDef wfProcessDefEntity)
      throws OperationException {
    Long l = Long.parseLong(wfProcessDefEntity.getProcessDefEngineKey());
    GraphSession graphSession = jbpmContext.getGraphSession();
    ProcessDefinition processDefinition = graphSession.getProcessDefinition(l);
    if (processDefinition != null) {
      ProcessDefinition newPD = processDefinition.parseXmlString(xmlProcessDefinition);
      processDefinition.setProcessDefinition(newPD);

      jbpmContext.getSession().merge(processDefinition);
    } else {
      throw new OperationException("Could not find process definition with (engine) key ID: " + l);
    }
  }
Пример #13
0
  public ActionForward insertPayment(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws AppException {
    String forwardPage = "";
    Inform inf = new Inform();

    Workflow workflow = (Workflow) form;

    JbpmContext jbpmContext = JbpmUtil.getJbpmContext();
    try {
      String issueperson = "user1";
      // 设置当前用户为user1
      jbpmContext.setActorId(issueperson);

      ProcessDefinition pd = jbpmContext.getGraphSession().findLatestProcessDefinition("payment");

      ProcessInstance processInstance = pd.createProcessInstance();
      ContextInstance contextInstance = processInstance.getContextInstance();

      //
      contextInstance.setVariable("issueperson", issueperson);

      // 创建开始节点的TaskInstance
      TaskInstance taskInstance = processInstance.getTaskMgmtInstance().createStartTaskInstance();

      // 向任务实例当中写入相关变量
      taskInstance.setVariable("title", workflow.getTitle());
      taskInstance.setVariable("moneyCount", workflow.getMoneyCount());
      taskInstance.setVariable("remark", workflow.getRemark());

      // 结束任务实例,token进入部门经理审批
      taskInstance.end();

      inf.setMessage("报销申请提交成功");
    } catch (Exception e) {
      e.printStackTrace();
      inf.setMessage("异常信息:" + e.getMessage());
    } finally {
      jbpmContext.close();
    }
    return forwardInformPage(inf, mapping, request);
  }
Пример #14
0
  /** Get Process Instance */
  public static ProcessInstance getProcessInstance(long processInstanceId)
      throws WorkflowException {
    log.debug("getProcessInstance({})", processInstanceId);
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();
    ProcessInstance vo = new ProcessInstance();

    try {
      GraphSession graphSession = jbpmContext.getGraphSession();
      org.jbpm.graph.exe.ProcessInstance pi = graphSession.getProcessInstance(processInstanceId);
      vo = WorkflowUtils.copy(pi);
    } catch (JbpmException e) {
      throw new WorkflowException(e.getMessage(), e);
    } finally {
      jbpmContext.close();
    }

    log.debug("getProcessInstance: {}", vo);
    return vo;
  }
Пример #15
0
  /** Delete Process Definition */
  public static void deleteProcessDefinition(long processDefinitionId) throws WorkflowException {
    log.debug("deleteProcessDefinition({})", processDefinitionId);
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();

    if (Config.SYSTEM_READONLY) {
      throw new WorkflowException("System is in read-only mode");
    }

    try {
      GraphSession graphSession = jbpmContext.getGraphSession();
      graphSession.deleteProcessDefinition(processDefinitionId);
      jbpmContext.getSession().flush();
    } catch (JbpmException e) {
      throw new WorkflowException(e.getMessage(), e);
    } finally {
      jbpmContext.close();
    }

    log.debug("deleteProcessDefinition: void");
  }
  /** Start OpenKM and possible repository and database initialization */
  public static synchronized void start() throws ServletException {
    SystemAuthentication systemAuth = new SystemAuthentication();

    if (running) {
      throw new IllegalStateException("OpenKM already started");
    }

    try {
      log.info("*** Repository initializing... ***");

      if (Config.REPOSITORY_NATIVE) {
        systemAuth.enable();
        DbRepositoryModule.initialize();
        systemAuth.disable();
      } else {
        JcrRepositoryModule.initialize();
      }

      log.info("*** Repository initialized ***");
    } catch (Exception e) {
      throw new ServletException(e.getMessage(), e);
    }

    if (Config.USER_ITEM_CACHE) {
      // Deserialize
      try {
        log.info("*** Cache deserialization ***");
        UserItemsManager.deserialize();
        UserNodeKeywordsManager.deserialize();
      } catch (DatabaseException e) {
        log.warn(e.getMessage(), e);
      }
    }

    log.info("*** User database initialized ***");

    if (!Config.REPOSITORY_NATIVE) {
      // Test for datastore
      SessionImpl si = (SessionImpl) JcrRepositoryModule.getSystemSession();

      if (((RepositoryImpl) si.getRepository()).getDataStore() == null) {
        hasConfiguredDataStore = false;
      } else {
        hasConfiguredDataStore = true;
      }
    }

    // Create timers
    uiTimer = new Timer("Update Info");
    wdTimer = new Timer("Session Watchdog");
    cronTimer = new Timer("Crontab Manager");
    uinTimer = new Timer("User Interface Notification");
    riTimer = new Timer("Repository Info", true);
    umiTimer = new Timer("User Mail Importer");
    dsgcTimer = new Timer("Datastore Garbage Collector");
    tewTimer = new Timer("Text Extractor Worker", true);

    // Workflow
    log.info("*** Initializing workflow engine... ***");
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();
    jbpmContext.setSessionFactory(HibernateUtil.getSessionFactory());
    jbpmContext.getGraphSession();
    jbpmContext.getJbpmConfiguration().getJobExecutor().start(); // startJobExecutor();
    jbpmContext.close();

    // Mime types
    log.info("*** Initializing MIME types... ***");
    MimeTypeConfig.loadMimeTypes();

    if (Config.UPDATE_INFO) {
      log.info("*** Activating update info ***");
      ui = new UpdateInfo();
      uiTimer.schedule(ui, 1000, 24 * 60 * 60 * 1000); // First in 1 seg, next each 24 hours
    }

    log.info("*** Activating watchdog ***");
    wd = new Watchdog();
    wdTimer.schedule(wd, 60 * 1000, 5 * 60 * 1000); // First in 1 min, next each 5 mins

    log.info("*** Activating cron ***");
    cron = new Cron();
    Calendar calCron = Calendar.getInstance();
    calCron.add(Calendar.MINUTE, 1);
    calCron.set(Calendar.SECOND, 0);
    calCron.set(Calendar.MILLISECOND, 0);

    // Round begin to next minute, 0 seconds, 0 miliseconds
    cronTimer.scheduleAtFixedRate(
        cron, calCron.getTime(), 60 * 1000); // First in 1 min, next each 1 min

    log.info("*** Activating UI Notification ***");
    uin = new UINotification();

    // First in 1 second next in x minutes
    uinTimer.scheduleAtFixedRate(
        uin, 1000, TimeUnit.MINUTES.toMillis(Config.SCHEDULE_UI_NOTIFICATION));

    log.info("*** Activating repository info ***");
    ri = new RepositoryInfo();

    // First in 1 min, next each X minutes
    riTimer.schedule(ri, 60 * 1000, TimeUnit.MINUTES.toMillis(Config.SCHEDULE_REPOSITORY_INFO));

    if (Config.MANAGED_TEXT_EXTRACTION_SCHEDULE > 0) {
      log.info("*** Activating text extractor worker ***");
      tew = new TextExtractorWorker();

      // First in 1 min, next each x minutes
      tewTimer.schedule(
          tew, 60 * 1000, TimeUnit.MINUTES.toMillis(Config.MANAGED_TEXT_EXTRACTION_SCHEDULE));
    }

    if (Config.SCHEDULE_MAIL_IMPORTER > 0) {
      log.info("*** Activating user mail importer ***");
      umi = new UserMailImporter();

      // First in 5 mins, next each x minutes
      umiTimer.schedule(
          umi, 5 * 60 * 1000, TimeUnit.MINUTES.toMillis(Config.SCHEDULE_MAIL_IMPORTER));
    } else {
      log.info("*** User mail importer disabled ***");
    }

    // Datastore garbage collection
    if (!Config.REPOSITORY_NATIVE && hasConfiguredDataStore) {
      log.info("*** Activating datastore garbage collection ***");
      dsgc = new DataStoreGarbageCollector();
      Calendar calGc = Calendar.getInstance();
      calGc.add(Calendar.DAY_OF_YEAR, 1);
      calGc.set(Calendar.HOUR_OF_DAY, 0);
      calGc.set(Calendar.MINUTE, 0);
      calGc.set(Calendar.SECOND, 0);
      calGc.set(Calendar.MILLISECOND, 0);
      dsgcTimer.scheduleAtFixedRate(
          dsgc, calGc.getTime(), 24 * 60 * 60 * 1000); // First tomorrow at 00:00, next
      // each 24 hours
    }

    try {
      log.info("*** Activating thesaurus repository ***");
      RDFREpository.getInstance();
    } catch (Exception e) {
      log.warn(e.getMessage(), e);
    }

    try {
      if (!Config.SYSTEM_OPENOFFICE_PATH.equals("")) {
        log.info("*** Start OpenOffice manager ***");
        DocConverter.getInstance().start();
      } else {
        log.warn("*** No OpenOffice manager configured ***");
      }
    } catch (Throwable e) {
      log.warn(e.getMessage(), e);
    }

    // Initialize plugin framework
    ExtensionManager.getInstance();

    try {
      log.info("*** Ejecute start script ***");
      File script = new File(Config.HOME_DIR + File.separatorChar + Config.START_SCRIPT);
      ExecutionUtils.runScript(script);
      File jar = new File(Config.HOME_DIR + File.separatorChar + Config.START_JAR);
      ExecutionUtils.getInstance().runJar(jar);
    } catch (Throwable e) {
      log.warn(e.getMessage(), e);
    }

    // OpenKM is started
    running = true;
  }
Пример #17
0
  /** Get Process Definition Image */
  public static byte[] getProcessDefinitionImage(long processDefinitionId, String node)
      throws WorkflowException {
    log.debug("getProcessDefinitionImage({}, {})", new Object[] {processDefinitionId, node});
    JbpmContext jbpmContext = JBPMUtils.getConfig().createJbpmContext();
    byte[] image = null;

    try {
      GraphSession graphSession = jbpmContext.getGraphSession();
      org.jbpm.graph.def.ProcessDefinition pd =
          graphSession.getProcessDefinition(processDefinitionId);
      FileDefinition fileDef = pd.getFileDefinition();

      WorkflowUtils.DiagramInfo dInfo =
          WorkflowUtils.getDiagramInfo(fileDef.getInputStream("gpd.xml"));
      WorkflowUtils.DiagramNodeInfo dNodeInfo = dInfo.getNodeMap().get(node);
      BufferedImage img = ImageIO.read(fileDef.getInputStream("processimage.jpg"));

      // Obtain all nodes Y and X
      List<Integer> ordenadas = new ArrayList<Integer>();
      List<Integer> abcisas = new ArrayList<Integer>();

      for (WorkflowUtils.DiagramNodeInfo nodeInfo : dInfo.getNodeMap().values()) {
        ordenadas.add(nodeInfo.getY());
        abcisas.add(nodeInfo.getX());
      }

      // Calculate minimal Y
      Collections.sort(ordenadas);
      int fixOrd = ordenadas.get(0) < 0 ? ordenadas.get(0) : 0;

      // Calculate minimal X
      Collections.sort(abcisas);
      int fixAbs = abcisas.get(0) < 0 ? abcisas.get(0) : 0;

      if (dNodeInfo != null) {
        // Select node
        log.debug("DiagramNodeInfo: {}", dNodeInfo);
        Graphics g = img.getGraphics();
        Graphics2D g2d = (Graphics2D) g;
        g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.25F));
        g2d.setColor(Color.blue);
        g2d.fillRect(
            dNodeInfo.getX() - fixAbs,
            dNodeInfo.getY() - fixOrd,
            dNodeInfo.getWidth(),
            dNodeInfo.getHeight());
        g.dispose();
      }

      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      ImageIO.write(img, "jpg", baos);
      image = baos.toByteArray();
      baos.flush();
      baos.close();
    } catch (JbpmException e) {
      throw new WorkflowException(e.getMessage(), e);
    } catch (IOException e) {
      throw new WorkflowException(e.getMessage(), e);
    } finally {
      jbpmContext.close();
    }

    log.debug("getProcessDefinitionImage: {}", image);
    return image;
  }