@SuppressWarnings("serial")
  private PopupView createProcessDefinitionPopup(final ProcessDefinition processDefinition) {
    final VerticalLayout layout = new VerticalLayout();
    final PopupView popup = new PopupView(processDefinition.getName(), layout);

    layout.setSizeUndefined();
    layout.setMargin(true);
    layout.setSpacing(true);
    Label header =
        new Label(
            String.format(
                "What would you like to do with <b>%s</b>?", processDefinition.getName()));
    header.setContentMode(Label.CONTENT_XHTML);
    layout.addComponent(header);

    Button startNewInstanceButton = new Button("Start a new instance");
    startNewInstanceButton.addStyleName(Reindeer.BUTTON_SMALL);
    startNewInstanceButton.addListener(
        new Button.ClickListener() {

          @Override
          public void buttonClick(ClickEvent event) {
            getPresenter().startNewInstance(processDefinition);
            popup.setPopupVisible(false);
          }
        });
    layout.addComponent(startNewInstanceButton);

    return popup;
  }
 protected String getProcessDisplayName(ProcessDefinition processDefinition) {
   if (processDefinition.getName() != null) {
     return processDefinition.getName();
   } else {
     return processDefinition.getKey();
   }
 }
 protected String getProcessDisplayName(
     ProcessDefinition processDefinition, ProcessInstance processInstance) {
   if (processDefinition.getName() != null) {
     return processDefinition.getName() + " (" + processInstance.getId() + ")";
   } else {
     return processDefinition.getKey() + " (" + processInstance.getId() + ")";
   }
 }
  @Test
  public void testDeployIdenticalProcessDefinitions() {
    List<String> deploymentIds = new ArrayList<String>();
    deploymentIds.add(
        deployProcessString(
            ("<definitions "
                + NAMESPACE
                + " "
                + TARGET_NAMESPACE
                + ">"
                + "  <process id='IDR' name='Insurance Damage Report' />"
                + "</definitions>")));
    deploymentIds.add(
        deployProcessString(
            ("<definitions "
                + NAMESPACE
                + " "
                + TARGET_NAMESPACE
                + ">"
                + "  <process id='IDR' name='Insurance Damage Report' />"
                + "</definitions>")));

    RepositoryService repositoryService = activitiRule.getRepositoryService();
    List<ProcessDefinition> processDefinitions =
        repositoryService
            .createProcessDefinitionQuery()
            .orderByProcessDefinitionKey()
            .asc()
            .orderByProcessDefinitionVersion()
            .desc()
            .list();

    assertNotNull(processDefinitions);
    assertEquals(2, processDefinitions.size());

    ProcessDefinition processDefinition = processDefinitions.get(0);
    assertEquals("IDR", processDefinition.getKey());
    assertEquals("Insurance Damage Report", processDefinition.getName());
    assertTrue(processDefinition.getId().startsWith("IDR:2"));
    assertEquals(2, processDefinition.getVersion());

    processDefinition = processDefinitions.get(1);
    assertEquals("IDR", processDefinition.getKey());
    assertEquals("Insurance Damage Report", processDefinition.getName());
    assertTrue(processDefinition.getId().startsWith("IDR:1"));
    assertEquals(1, processDefinition.getVersion());

    deleteDeployments(deploymentIds);
  }
 @Override
 public void showProcessStartSuccess(ProcessDefinition process) {
   getViewLayout()
       .getWindow()
       .showNotification(
           String.format("%s started successfully", process.getName()),
           Notification.TYPE_HUMANIZED_MESSAGE);
 }
 @Override
 public void showProcessStartFailure(ProcessDefinition process) {
   getViewLayout()
       .getWindow()
       .showNotification(
           String.format(
               "Could not start %s. Please check the logs for more information.",
               process.getName()),
           Notification.TYPE_ERROR_MESSAGE);
 }
 private void updateComponent() {
   removeAllComponents();
   if (processDefinitions != null) {
     for (ProcessDefinition pd : processDefinitions) {
       final Component processComponent =
           createProcessDefinitionComponent(pd.getName(), pd.getKey());
       addComponent(processComponent);
     }
   }
 }
  protected void initWindow() {
    windowLayout.setSpacing(true);
    addStyleName(Reindeer.WINDOW_LIGHT);
    setModal(true);
    center();

    String name = processDefinition.getName();
    if (StringUtils.isEmpty(name)) {
      name = processDefinition.getKey();
    }
    setCaption(i18nManager.getMessage(Messages.PROCESS_CONVERT_POPUP_CAPTION, name));
  }
 protected void setTenantAndName(ActivityExecution execution) {
   Map beans = Context.getProcessEngineConfiguration().getBeans();
   ProcessEngine pe = (ProcessEngine) beans.get("processEngine");
   String processDefinitionId = ((ExecutionEntity) execution).getProcessDefinitionId();
   RepositoryService repositoryService = pe.getRepositoryService();
   ProcessDefinition processDefinition =
       repositoryService
           .createProcessDefinitionQuery()
           .processDefinitionId(processDefinitionId)
           .singleResult();
   m_tenant = processDefinition.getTenantId();
   m_processDefinitionKey = processDefinition.getKey();
   info("ID:" + processDefinition.getId());
   info("Name:" + processDefinition.getName());
   info("Key:" + processDefinition.getKey());
 }
  @Deployment(resources = {"org/activiti/engine/test/api/oneTaskProcess.bpmn20.xml"})
  public void testFindProcessDefinitionById() {
    List<ProcessDefinition> definitions = repositoryService.createProcessDefinitionQuery().list();
    assertEquals(1, definitions.size());

    ProcessDefinition processDefinition =
        repositoryService
            .createProcessDefinitionQuery()
            .processDefinitionId(definitions.get(0).getId())
            .singleResult();
    runtimeService.startProcessInstanceByKey("oneTaskProcess");
    assertNotNull(processDefinition);
    assertEquals("oneTaskProcess", processDefinition.getKey());
    assertEquals("The One Task Process", processDefinition.getName());

    processDefinition = repositoryService.getProcessDefinition(definitions.get(0).getId());
    assertEquals("This is a process for testing purposes", processDefinition.getDescription());
  }
Пример #11
0
  /**
   * 将部署的流程转换为模型
   *
   * @param procDefId
   * @throws UnsupportedEncodingException
   * @throws XMLStreamException
   */
  @Transactional(readOnly = false)
  public org.activiti.engine.repository.Model convertToModel(String procDefId)
      throws UnsupportedEncodingException, XMLStreamException {

    ProcessDefinition processDefinition =
        repositoryService
            .createProcessDefinitionQuery()
            .processDefinitionId(procDefId)
            .singleResult();
    InputStream bpmnStream =
        repositoryService.getResourceAsStream(
            processDefinition.getDeploymentId(), processDefinition.getResourceName());
    XMLInputFactory xif = XMLInputFactory.newInstance();
    InputStreamReader in = new InputStreamReader(bpmnStream, "UTF-8");
    XMLStreamReader xtr = xif.createXMLStreamReader(in);
    BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);

    BpmnJsonConverter converter = new BpmnJsonConverter();
    ObjectNode modelNode = converter.convertToJson(bpmnModel);
    org.activiti.engine.repository.Model modelData = repositoryService.newModel();
    modelData.setKey(processDefinition.getKey());
    modelData.setName(processDefinition.getResourceName());
    modelData.setCategory(processDefinition.getCategory()); // .getDeploymentId());
    modelData.setDeploymentId(processDefinition.getDeploymentId());
    modelData.setVersion(
        Integer.parseInt(
            String.valueOf(
                repositoryService.createModelQuery().modelKey(modelData.getKey()).count() + 1)));

    ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
    modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, processDefinition.getName());
    modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, modelData.getVersion());
    modelObjectNode.put(
        ModelDataJsonConstants.MODEL_DESCRIPTION, processDefinition.getDescription());
    modelData.setMetaInfo(modelObjectNode.toString());

    repositoryService.saveModel(modelData);

    repositoryService.addModelEditorSource(
        modelData.getId(), modelNode.toString().getBytes("utf-8"));

    return modelData;
  }
Пример #12
0
  /**
   * easyui AJAX请求数据
   *
   * @param request
   * @param response
   * @param dataGrid
   */
  @RequestMapping(params = "datagrid")
  public void datagrid(
      HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {

    ProcessDefinitionQuery query = repositoryService.createProcessDefinitionQuery();
    List<ProcessDefinition> list = query.list();

    StringBuffer rows = new StringBuffer();
    int i = 0;
    for (ProcessDefinition pi : list) {
      Deployment deployment =
          repositoryService
              .createDeploymentQuery()
              .deploymentId(pi.getDeploymentId())
              .singleResult();
      i++;
      rows.append(
          "{'id':"
              + i
              + ",'processDefinitionId':'"
              + pi.getId()
              + "','deploymentDate':'"
              + new SimpleDateFormat("yyyy-MM-dd").format(deployment.getDeploymentTime())
              + "','resourceName':'"
              + pi.getResourceName()
              + "','deploymentId':'"
              + pi.getDeploymentId()
              + "','key':'"
              + pi.getKey()
              + "','name':'"
              + pi.getName()
              + "','version':'"
              + pi.getVersion()
              + "','isSuspended':'"
              + pi.isSuspended()
              + "'},");
    }
    String rowStr = StringUtils.substringBeforeLast(rows.toString(), ",");

    JSONObject jObject =
        JSONObject.fromObject("{'total':" + query.count() + ",'rows':[" + rowStr + "]}");
    responseDatagrid(response, jObject);
  }
  public List<KickstartWorkflowInfo> convertToWorkflowInfoList(
      List<ProcessDefinition> processDefinitions) {
    List<KickstartWorkflowInfo> infoList = new ArrayList<KickstartWorkflowInfo>();
    for (ProcessDefinition processDefinition : processDefinitions) {
      KickstartWorkflowInfo workflowInfo = new KickstartWorkflowInfo();
      workflowInfo.setId(processDefinition.getId());
      workflowInfo.setKey(processDefinition.getKey());
      workflowInfo.setName(processDefinition.getName());
      workflowInfo.setVersion(processDefinition.getVersion());
      workflowInfo.setDeploymentId(processDefinition.getDeploymentId());

      Date deploymentTime =
          repositoryService
              .createDeploymentQuery()
              .deploymentId(processDefinition.getDeploymentId())
              .singleResult()
              .getDeploymentTime();
      workflowInfo.setCreateTime(deploymentTime);

      workflowInfo.setNrOfRuntimeInstances(
          historyService
              .createHistoricProcessInstanceQuery()
              .processDefinitionId(processDefinition.getId())
              .unfinished()
              .count());
      workflowInfo.setNrOfHistoricInstances(
          historyService
              .createHistoricProcessInstanceQuery()
              .processDefinitionId(processDefinition.getId())
              .finished()
              .count());

      infoList.add(workflowInfo);
    }
    return infoList;
  }
Пример #14
0
  /**
   * @Title: myWorkTaskData @Description: TODO
   *
   * @param request
   * @param response
   * @param dataGrid void
   * @throws
   * @exception
   * @author fly
   * @date 2015年6月23日 上午10:20:42
   */
  @RequestMapping(params = "myWorkTaskData")
  public void myWorkTaskData(
      HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {

    String userId = ResourceUtil.getSessionUserName().getId();
    // involvedUser 当前用户相关的
    HistoricProcessInstanceQuery query =
        historyService.createHistoricProcessInstanceQuery().involvedUser(userId);

    List<HistoricProcessInstance> historicTasks =
        query
            .orderByProcessInstanceStartTime()
            .desc()
            .listPage(dataGrid.getStart(), dataGrid.getEnd());
    long total = query.count();
    System.out.println(dataGrid.getStart() + " end: " + dataGrid.getEnd());
    StringBuffer rows = new StringBuffer();
    for (HistoricProcessInstance t : historicTasks) {
      ProcessDefinition processDefinition =
          repositoryService.getProcessDefinition(t.getProcessDefinitionId());

      rows.append(
          "{'id':'"
              + t.getId()
              + "','key':'"
              + processDefinition.getName()
              + "-"
              + DateUtils.date_sdf.format(t.getStartTime())
              + "','taskId':'"
              + t.getId()
              + "'");
      // 流程详细查看
      WorkFlowSetEntity workFlowSet =
          systemService.findUniqueByProperty(
              WorkFlowSetEntity.class, "deploymentId", processDefinition.getDeploymentId());
      if (workFlowSet != null) {
        rows.append(",'action':'" + workFlowSet.getDetailUrl() + "'");
      }
      // 流程用户处理
      if (t.getStartUserId() != null) {
        TSUser user = systemService.get(TSUser.class, t.getStartUserId());
        rows.append(",'username':'******'");
      }

      // 流程开始结束时间处理
      if (t.getStartTime() == null) {
        rows.append(",'beginDate':'无'");
      } else {
        rows.append(",'beginDate':'" + DateUtils.datetimeFormat.format(t.getStartTime()) + "'");
      }
      if (t.getEndTime() == null) {
        rows.append(",'endDate':'无','stateType':'办理中'");

      } else {
        rows.append(
            ",'endDate':'"
                + DateUtils.datetimeFormat.format(t.getEndTime())
                + "','stateType':'已完成'");
      }
      rows.append("},");
    }
    String rowStr = StringUtils.substringBeforeLast(rows.toString(), ",");

    JSONObject jObject = JSONObject.fromObject("{'total':" + total + ",'rows':[" + rowStr + "]}");
    responseDatagrid(response, jObject);
  }