@Test
 public void testAct() throws Exception {
   String path = ProcessDefManagerTest.class.getClassLoader().getResource("act.json").getPath();
   String value = FileUtils.readFileToString(new File(path));
   BpmnJsonConverter jsonConverter = new BpmnJsonConverter();
   JsonNode jsonNode = new ObjectMapper().readTree(value);
   BpmnModel model = jsonConverter.convertToBpmnModel(jsonNode);
   Map<String, List<ExtensionAttribute>> map = model.getProcesses().get(0).getAttributes();
   int i = 0;
 }
  @Test
  public void testJSON() throws Exception {
    String path = ProcessDefManagerTest.class.getClassLoader().getResource("act.json").getPath();
    String value = FileUtils.readFileToString(new File(path));
    BpmnJsonConverter jsonConverter = new BpmnJsonConverter();
    JsonNode jsonNode = new ObjectMapper().readTree(value);
    BpmnModel bpmnModel = jsonConverter.convertToBpmnModel(jsonNode);
    BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter();
    byte[] data = bpmnXMLConverter.convertToXML(bpmnModel, "UTF-8");
    String xml = new String(data);
    System.out.println(xml);

    int i = 0;
  }
Exemplo n.º 3
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;
  }