org.activiti.engine.repository.Model Java Examples

The following examples show how to use org.activiti.engine.repository.Model. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ModelQueryEscapeClauseTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
  Model model = repositoryService.newModel();
  model.setTenantId("mytenant%");
  model.setName("my model%");
  model.setKey("someKey1");
  model.setCategory("test%");
  repositoryService.saveModel(model);
  modelOneId = model.getId();
  
  model = repositoryService.newModel();
  model.setTenantId("mytenant_");
  model.setName("my model_");
  model.setKey("someKey2");
  model.setCategory("test_");
  repositoryService.saveModel(model);
  modelTwoId = model.getId();
  
  repositoryService.addModelEditorSource(modelOneId, "bytes".getBytes("utf-8"));
  repositoryService.addModelEditorSource(modelTwoId, "bytes".getBytes("utf-8"));
  
  super.setUp();
}
 
Example #2
Source File: FlowableModelManagerController.java    From hsweb-framework with Apache License 2.0 6 votes vote down vote up
@PostMapping
@ResponseStatus(value = HttpStatus.CREATED)
@ApiOperation("创建模型")
public ResponseMessage<Model> createModel(@RequestBody ModelCreateRequest model) throws Exception {
    JSONObject stencilset = new JSONObject();
    stencilset.put("namespace", "http://b3mn.org/stencilset/bpmn2.0#");
    JSONObject editorNode = new JSONObject();
    editorNode.put("id", "canvas");
    editorNode.put("resourceId", "canvas");
    editorNode.put("stencilset", stencilset);
    JSONObject modelObjectNode = new JSONObject();
    modelObjectNode.put(MODEL_REVISION, 1);
    modelObjectNode.put(MODEL_DESCRIPTION, model.getDescription());
    modelObjectNode.put(MODEL_KEY, model.getKey());
    modelObjectNode.put(MODEL_NAME, model.getName());

    Model modelData = repositoryService.newModel();
    modelData.setMetaInfo(modelObjectNode.toJSONString());
    modelData.setName(model.getName());
    modelData.setKey(model.getKey());
    repositoryService.saveModel(modelData);
    repositoryService.addModelEditorSource(modelData.getId(), editorNode.toString().getBytes("utf-8"));
    return ResponseMessage.ok(modelData).status(201);
}
 
Example #3
Source File: ModelController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 导出model的xml文件
 */
@RequestMapping(value = "export/{modelId}")
public void export(@PathVariable("modelId") String modelId, HttpServletResponse response) {
    try {
        Model modelData = repositoryService.getModel(modelId);
        BpmnJsonConverter jsonConverter = new BpmnJsonConverter();
        JsonNode editorNode = new ObjectMapper().readTree(repositoryService.getModelEditorSource(modelData.getId()));
        BpmnModel bpmnModel = jsonConverter.convertToBpmnModel(editorNode);
        BpmnXMLConverter xmlConverter = new BpmnXMLConverter();
        byte[] bpmnBytes = xmlConverter.convertToXML(bpmnModel);

        ByteArrayInputStream in = new ByteArrayInputStream(bpmnBytes);
        IOUtils.copy(in, response.getOutputStream());
        String filename = bpmnModel.getMainProcess().getId() + ".bpmn20.xml";
        response.setHeader("Content-Disposition", "attachment; filename=" + filename);
        response.flushBuffer();
    } catch (Exception e) {
        logger.error("导出model的xml文件失败:modelId={}", modelId, e);
    }
}
 
Example #4
Source File: ModelUtils.java    From openwebflow with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static Deployment deployModel(RepositoryService repositoryService, String modelId) throws IOException
{
	Model modelData = repositoryService.getModel(modelId);
	//EditorSource就是XML格式的
	byte[] bpmnBytes = repositoryService.getModelEditorSource(modelId);

	String processName = modelData.getName() + ".bpmn20.xml";
	Deployment deployment = repositoryService.createDeployment().name(modelData.getName())
			.addString(processName, new String(bpmnBytes, "utf-8")).deploy();

	//设置部署ID
	modelData.setDeploymentId(deployment.getId());
	repositoryService.saveModel(modelData);

	return deployment;
}
 
Example #5
Source File: ModelQueryEscapeClauseTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testQueryByTenantIdLike() throws Exception {
  ModelQuery query = repositoryService.createModelQuery().modelTenantIdLike("%\\%%");
  Model model = query.singleResult();
  assertNotNull(model);
  assertEquals("someKey1", model.getKey());
  assertEquals("bytes", new String(repositoryService.getModelEditorSource(model.getId()), "utf-8"));
  assertEquals(1, query.list().size());
  assertEquals(1, query.count());
  
  query = repositoryService.createModelQuery().modelTenantIdLike("%\\_%");
  model = query.singleResult();
  assertNotNull(model);
  assertEquals("someKey2", model.getKey());
  assertEquals("bytes", new String(repositoryService.getModelEditorSource(model.getId()), "utf-8"));
  assertEquals(1, query.list().size());
  assertEquals(1, query.count());
}
 
Example #6
Source File: RepositoryServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testNewModelWithSource() throws Exception {
  Model model = repositoryService.newModel();
  model.setName("Test model");
  byte[] testSource = "modelsource".getBytes("utf-8");
  repositoryService.saveModel(model);
  
  assertNotNull(model.getId());
  repositoryService.addModelEditorSource(model.getId(), testSource);
  
  model = repositoryService.getModel(model.getId());
  assertNotNull(model);
  assertEquals("Test model", model.getName());
  
  byte[] editorSourceBytes = repositoryService.getModelEditorSource(model.getId());
  assertEquals("modelsource", new String(editorSourceBytes, "utf-8"));
  
  repositoryService.deleteModel(model.getId());
}
 
Example #7
Source File: ModelResourceSourceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testSetModelEditorSource() throws Exception {

    Model model = null;
    try {

      model = repositoryService.newModel();
      model.setName("Model name");
      repositoryService.saveModel(model);

      HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_SOURCE, model.getId()));
      httpPut.setEntity(HttpMultipartHelper.getMultiPartEntity("sourcefile", "application/octet-stream", new ByteArrayInputStream("This is the new editor source".getBytes()), null));
      closeResponse(executeBinaryRequest(httpPut, HttpStatus.SC_NO_CONTENT));

      assertEquals("This is the new editor source", new String(repositoryService.getModelEditorSource(model.getId())));

    } finally {
      try {
        repositoryService.deleteModel(model.getId());
      } catch (Throwable ignore) {
        // Ignore, model might not be created
      }
    }
  }
 
Example #8
Source File: RepositoryServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testNewModelPersistence() {
  Model model = repositoryService.newModel();
  assertNotNull(model);
  
  model.setName("Test model");
  model.setCategory("test");
  model.setMetaInfo("meta");
  repositoryService.saveModel(model);
  
  assertNotNull(model.getId());
  model = repositoryService.getModel(model.getId());
  assertNotNull(model);
  assertEquals("Test model", model.getName());
  assertEquals("test", model.getCategory());
  assertEquals("meta", model.getMetaInfo());
  assertNotNull(model.getCreateTime());
  assertEquals(Integer.valueOf(1), model.getVersion());
  
  repositoryService.deleteModel(model.getId());
}
 
Example #9
Source File: ModelResourceSourceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testSetModelEditorSourceExtra() throws Exception {

    Model model = null;
    try {

      model = repositoryService.newModel();
      model.setName("Model name");
      repositoryService.saveModel(model);

      HttpPut httpPut = new HttpPut(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_SOURCE_EXTRA, model.getId()));
      httpPut.setEntity(HttpMultipartHelper.getMultiPartEntity("sourcefile", "application/octet-stream", new ByteArrayInputStream("This is the new extra editor source".getBytes()), null));
      closeResponse(executeBinaryRequest(httpPut, HttpStatus.SC_NO_CONTENT));

      assertEquals("This is the new extra editor source", new String(repositoryService.getModelEditorSourceExtra(model.getId())));

    } finally {
      try {
        repositoryService.deleteModel(model.getId());
      } catch (Throwable ignore) {
        // Ignore, model might not be created
      }
    }
  }
 
Example #10
Source File: ModelResourceSourceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testGetModelEditorSourceExtraNoSource() throws Exception {
  Model model = null;
  try {

    model = repositoryService.newModel();
    model.setName("Model name");
    repositoryService.saveModel(model);

    HttpGet httpGet = new HttpGet(SERVER_URL_PREFIX + RestUrls.createRelativeResourceUrl(RestUrls.URL_MODEL_SOURCE_EXTRA, model.getId()));
    closeResponse(executeRequest(httpGet, HttpStatus.SC_NOT_FOUND));

  } finally {
    try {
      repositoryService.deleteModel(model.getId());
    } catch (Throwable ignore) {
      // Ignore, model might not be created
    }
  }
}
 
Example #11
Source File: RepositoryServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testNewModelPersistence() {
  Model model = repositoryService.newModel();
  assertNotNull(model);

  model.setName("Test model");
  model.setCategory("test");
  model.setMetaInfo("meta");
  repositoryService.saveModel(model);

  assertNotNull(model.getId());
  model = repositoryService.getModel(model.getId());
  assertNotNull(model);
  assertEquals("Test model", model.getName());
  assertEquals("test", model.getCategory());
  assertEquals("meta", model.getMetaInfo());
  assertNotNull(model.getCreateTime());
  assertEquals(Integer.valueOf(1), model.getVersion());

  repositoryService.deleteModel(model.getId());
}
 
Example #12
Source File: RepositoryServiceTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testNewModelWithSource() throws Exception {
  Model model = repositoryService.newModel();
  model.setName("Test model");
  byte[] testSource = "modelsource".getBytes("utf-8");
  repositoryService.saveModel(model);

  assertNotNull(model.getId());
  repositoryService.addModelEditorSource(model.getId(), testSource);

  model = repositoryService.getModel(model.getId());
  assertNotNull(model);
  assertEquals("Test model", model.getName());

  byte[] editorSourceBytes = repositoryService.getModelEditorSource(model.getId());
  assertEquals("modelsource", new String(editorSourceBytes, "utf-8"));

  repositoryService.deleteModel(model.getId());
}
 
Example #13
Source File: FlowableModelManagerController.java    From hsweb-framework with Apache License 2.0 6 votes vote down vote up
@PostMapping("/{modelId}/deploy")
@ApiOperation("发布模型")
@Authorize(action = "deploy")
public ResponseMessage<Deployment> deployModel(@PathVariable String modelId) throws Exception {
    Model modelData = repositoryService.getModel(modelId);
    if (modelData == null) {
        throw new NotFoundException("模型不存在!");
    }
    ObjectNode modelNode = (ObjectNode) new ObjectMapper().readTree(repositoryService.getModelEditorSource(modelData.getId()));
    BpmnModel model = new BpmnJsonConverter().convertToBpmnModel(modelNode);
    byte[] bpmnBytes = new BpmnXMLConverter().convertToXML(model);
    String processName = modelData.getName() + ".bpmn20.xml";
    Deployment deployment = repositoryService.createDeployment()
            .name(modelData.getName())
            .addString(processName, new String(bpmnBytes, "utf8"))
            .deploy();
    return ResponseMessage.ok(deployment).include(Deployment.class, "id", "name", "new");
}
 
Example #14
Source File: ModelerController.java    From lemon with Apache License 2.0 6 votes vote down vote up
@RequestMapping("modeler-open")
public String open(@RequestParam(value = "id", required = false) String id)
        throws Exception {
    RepositoryService repositoryService = processEngine
            .getRepositoryService();
    Model model = null;

    if (!StringUtils.isEmpty(id)) {
        model = repositoryService.getModel(id);
    }

    if (model == null) {
        model = repositoryService.newModel();
        repositoryService.saveModel(model);
        id = model.getId();
    }

    // return "redirect:/cdn/modeler/editor.html?id=" + id;
    return "redirect:/cdn/public/modeler/5.18.0/modeler.html?modelId=" + id;
}
 
Example #15
Source File: ModelCollectionResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
@ApiOperation(value = "Create a model", tags = {"Models"}, notes = "All request values are optional. For example, you can only include the name attribute in the request body JSON-object, only setting the name of the model, leaving all other fields null.")
@ApiResponses(value = {
    @ApiResponse(code = 200, message = "Indicates the model was created.")
})
@RequestMapping(value = "/repository/models", method = RequestMethod.POST, produces = "application/json")
public ModelResponse createModel(@RequestBody ModelRequest modelRequest, HttpServletRequest request, HttpServletResponse response) {
  Model model = repositoryService.newModel();
  model.setCategory(modelRequest.getCategory());
  model.setDeploymentId(modelRequest.getDeploymentId());
  model.setKey(modelRequest.getKey());
  model.setMetaInfo(modelRequest.getMetaInfo());
  model.setName(modelRequest.getName());
  model.setVersion(modelRequest.getVersion());
  model.setTenantId(modelRequest.getTenantId());

  repositoryService.saveModel(model);
  response.setStatus(HttpStatus.CREATED.value());
  return restResponseFactory.createModelResponse(model);
}
 
Example #16
Source File: ModelerController.java    From lemon with Apache License 2.0 6 votes vote down vote up
@RequestMapping("model/{modelId}/save")
@ResponseBody
public String modelSave(@PathVariable("modelId") String modelId,
        @RequestParam("description") String description,
        @RequestParam("json_xml") String jsonXml,
        @RequestParam("name") String name,
        @RequestParam("svg_xml") String svgXml) throws Exception {
    RepositoryService repositoryService = processEngine
            .getRepositoryService();
    Model model = repositoryService.getModel(modelId);
    model.setName(name);
    // model.setMetaInfo(root.toString());
    logger.info("jsonXml : {}", jsonXml);
    repositoryService.saveModel(model);
    repositoryService.addModelEditorSource(model.getId(),
            jsonXml.getBytes("utf-8"));

    return "{}";
}
 
Example #17
Source File: ModelQueryTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testByLatestVersion() {
  ModelQuery query = repositoryService.createModelQuery().latestVersion().modelKey("someKey");
  Model model = query.singleResult();
  assertNotNull(model);

  // Add a new version of the model
  Model newVersion = repositoryService.newModel();
  newVersion.setName("my model");
  newVersion.setKey("someKey");
  newVersion.setCategory("test");
  newVersion.setVersion(model.getVersion() + 1);
  repositoryService.saveModel(newVersion);

  // Verify query
  model = query.singleResult();
  assertNotNull(model);
  assertTrue(model.getVersion() == 2);

  // Cleanup
  repositoryService.deleteModel(model.getId());
}
 
Example #18
Source File: ModelQueryEscapeClauseTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testQueryByTenantIdLike() throws Exception {
  ModelQuery query = repositoryService.createModelQuery().modelTenantIdLike("%\\%%");
  Model model = query.singleResult();
  assertNotNull(model);
  assertEquals("someKey1", model.getKey());
  assertEquals("bytes", new String(repositoryService.getModelEditorSource(model.getId()), "utf-8"));
  assertEquals(1, query.list().size());
  assertEquals(1, query.count());
  
  query = repositoryService.createModelQuery().modelTenantIdLike("%\\_%");
  model = query.singleResult();
  assertNotNull(model);
  assertEquals("someKey2", model.getKey());
  assertEquals("bytes", new String(repositoryService.getModelEditorSource(model.getId()), "utf-8"));
  assertEquals(1, query.list().size());
  assertEquals(1, query.count());
}
 
Example #19
Source File: ModelQueryEscapeClauseTest.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public void testQueryByCategoryLike() throws Exception {
  ModelQuery query = repositoryService.createModelQuery().modelCategoryLike("%\\%%");
  Model model = query.singleResult();
  assertNotNull(model);
  assertEquals("someKey1", model.getKey());
  assertEquals("bytes", new String(repositoryService.getModelEditorSource(model.getId()), "utf-8"));
  assertEquals(1, query.list().size());
  assertEquals(1, query.count());
  
  query = repositoryService.createModelQuery().modelCategoryLike("%\\_%");
  model = query.singleResult();
  assertNotNull(model);
  assertEquals("someKey2", model.getKey());
  assertEquals("bytes", new String(repositoryService.getModelEditorSource(model.getId()), "utf-8"));
  assertEquals(1, query.list().size());
  assertEquals(1, query.count());
}
 
Example #20
Source File: ModelController.java    From activiti-in-action-codes with Apache License 2.0 6 votes vote down vote up
/**
 * 根据Model部署流程
 */
@RequestMapping(value = "deploy/{modelId}")
public String deploy(@PathVariable("modelId") String modelId, RedirectAttributes redirectAttributes) {
    try {
        Model modelData = repositoryService.getModel(modelId);
        ObjectNode modelNode = (ObjectNode) new ObjectMapper().readTree(repositoryService.getModelEditorSource(modelData.getId()));
        byte[] bpmnBytes = null;

        BpmnModel model = new BpmnJsonConverter().convertToBpmnModel(modelNode);
        bpmnBytes = new BpmnXMLConverter().convertToXML(model);

        String processName = modelData.getName() + ".bpmn20.xml";
        Deployment deployment = repositoryService.createDeployment().name(modelData.getName()).addString(processName, new String(bpmnBytes)).deploy();
        redirectAttributes.addFlashAttribute("message", "部署成功,部署ID=" + deployment.getId());
    } catch (Exception e) {
        logger.error("根据模型部署流程失败:modelId={}", modelId, e);
    }
    return "redirect:/chapter20/model/list";
}
 
Example #21
Source File: ModelQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@Override
protected void setUp() throws Exception {
  Model model = repositoryService.newModel();
  model.setName("my model");
  model.setKey("someKey");
  model.setCategory("test");
  repositoryService.saveModel(model);
  modelOneId = model.getId();
  
  repositoryService.addModelEditorSource(modelOneId, "bytes".getBytes("utf-8"));
  
  super.setUp();
}
 
Example #22
Source File: RestResponseFactory.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public List<ModelResponse> createModelResponseList(List<Model> models) {
  RestUrlBuilder urlBuilder = createUrlBuilder();
  List<ModelResponse> responseList = new ArrayList<ModelResponse>();
  for (Model instance : models) {
    responseList.add(createModelResponse(instance, urlBuilder));
  }
  return responseList;
}
 
Example #23
Source File: RepositoryServiceTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testUpdateModelPersistence() throws Exception {
  Model model = repositoryService.newModel();
  assertNotNull(model);
  
  model.setName("Test model");
  model.setCategory("test");
  model.setMetaInfo("meta");
  repositoryService.saveModel(model);
  
  assertNotNull(model.getId());
  model = repositoryService.getModel(model.getId());
  assertNotNull(model);
  
  model.setName("New name");
  model.setCategory("New category");
  model.setMetaInfo("test");
  model.setVersion(2);
  repositoryService.saveModel(model);
  
  assertNotNull(model.getId());
  repositoryService.addModelEditorSource(model.getId(), "new".getBytes("utf-8"));
  repositoryService.addModelEditorSourceExtra(model.getId(), "new".getBytes("utf-8"));
  
  model = repositoryService.getModel(model.getId());
  
  assertEquals("New name", model.getName());
  assertEquals("New category", model.getCategory());
  assertEquals("test", model.getMetaInfo());
  assertNotNull(model.getCreateTime());
  assertEquals(Integer.valueOf(2), model.getVersion());
  assertEquals("new", new String(repositoryService.getModelEditorSource(model.getId()), "utf-8"));
  assertEquals("new", new String(repositoryService.getModelEditorSourceExtra(model.getId()), "utf-8"));
  
  repositoryService.deleteModel(model.getId());
}
 
Example #24
Source File: ModelQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testQueryByKey() {
  ModelQuery query = repositoryService.createModelQuery().modelName("my model").modelKey("someKey");
  Model model = query.singleResult();
  assertNotNull(model);
  assertEquals(1, query.list().size());
  assertEquals(1, query.count());
}
 
Example #25
Source File: ModelQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testQueryByNameAndKey() {
  ModelQuery query = repositoryService.createModelQuery().modelKey("someKey");
  Model model = query.singleResult();
  assertNotNull(model);
  assertEquals(1, query.list().size());
  assertEquals(1, query.count());
}
 
Example #26
Source File: ModelSourceExtraResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "Set the extra editor source for a model", tags = {"Models"}, consumes = "multipart/form-data",
    notes = "Response body contains the model’s raw editor source. The response’s content-type is set to application/octet-stream, regardless of the content of the source.")
@ApiResponses(value = {
    @ApiResponse(code = 200, message = "Indicates the model was found and the extra source has been updated."),
    @ApiResponse(code = 404, message = "Indicates the requested model was not found.")
})
@RequestMapping(value = "/repository/models/{modelId}/source-extra", method = RequestMethod.PUT)
protected void setModelSource(@ApiParam(name = "modelId", value="The id of the model.") @PathVariable String modelId, HttpServletRequest request, HttpServletResponse response) {
  Model model = getModelFromRequest(modelId);
  if (model != null) {
    try {

      if (request instanceof MultipartHttpServletRequest == false) {
        throw new ActivitiIllegalArgumentException("Multipart request is required");
      }

      MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;

      if (multipartRequest.getFileMap().size() == 0) {
        throw new ActivitiIllegalArgumentException("Multipart request with file content is required");
      }

      MultipartFile file = multipartRequest.getFileMap().values().iterator().next();

      repositoryService.addModelEditorSourceExtra(model.getId(), file.getBytes());
      response.setStatus(HttpStatus.NO_CONTENT.value());

    } catch (Exception e) {
      throw new ActivitiException("Error adding model editor source extra", e);
    }
  }
}
 
Example #27
Source File: DeploymentController.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
/**
 * 转换流程定义为模型
 * @param processDefinitionId
 * @return
 * @throws UnsupportedEncodingException
 * @throws XMLStreamException
 */
@RequestMapping(value = "/process/convert-to-model/{processDefinitionId}")
public String convertToModel(@PathVariable("processDefinitionId") String processDefinitionId)
        throws UnsupportedEncodingException, XMLStreamException {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
            .processDefinitionId(processDefinitionId).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);
    Model modelData = repositoryService.newModel();
    modelData.setKey(processDefinition.getKey());
    modelData.setName(processDefinition.getResourceName());
    modelData.setCategory(processDefinition.getDeploymentId());

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

    repositoryService.saveModel(modelData);

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

    return "redirect:/chapter20/model/list";
}
 
Example #28
Source File: ModelQueryTest.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public void testNativeQuery() {
  assertEquals("ACT_RE_MODEL", managementService.getTableName(Model.class));
  assertEquals("ACT_RE_MODEL", managementService.getTableName(ModelEntity.class));
  String tableName = managementService.getTableName(Model.class);
  String baseQuerySql = "SELECT * FROM " + tableName;

  assertEquals(1, repositoryService.createNativeModelQuery().sql(baseQuerySql).list().size());

  assertEquals(1, repositoryService.createNativeProcessDefinitionQuery().sql(baseQuerySql + " where NAME_ = #{name}")
      .parameter("name", "my model").list().size());

  // paging
  assertEquals(1, repositoryService.createNativeProcessDefinitionQuery().sql(baseQuerySql).listPage(0, 1).size());
  assertEquals(0, repositoryService.createNativeProcessDefinitionQuery().sql(baseQuerySql).listPage(1, 5).size());
}
 
Example #29
Source File: FlowableModelManagerController.java    From hsweb-framework with Apache License 2.0 5 votes vote down vote up
@PutMapping(value = "/{modelId}")
@ResponseStatus(value = HttpStatus.OK)
@Authorize(action = Permission.ACTION_UPDATE)
public void saveModel(@PathVariable String modelId,
                      @RequestParam Map<String, String> values) throws TranscoderException, IOException {
    Model model = repositoryService.getModel(modelId);
    JSONObject modelJson = JSON.parseObject(model.getMetaInfo());

    modelJson.put(MODEL_NAME, values.get("name"));
    modelJson.put(MODEL_DESCRIPTION, values.get("description"));

    model.setMetaInfo(modelJson.toString());
    model.setName(values.get("name"));

    repositoryService.saveModel(model);

    repositoryService.addModelEditorSource(model.getId(), values.get("json_xml").getBytes("utf-8"));

    InputStream svgStream = new ByteArrayInputStream(values.get("svg_xml").getBytes("utf-8"));
    TranscoderInput input = new TranscoderInput(svgStream);

    PNGTranscoder transcoder = new PNGTranscoder();
    // Setup output
    ByteArrayOutputStream outStream = new ByteArrayOutputStream();
    TranscoderOutput output = new TranscoderOutput(outStream);

    // Do the transformation
    transcoder.transcode(input, output);
    final byte[] result = outStream.toByteArray();
    repositoryService.addModelEditorSourceExtra(model.getId(), result);
    outStream.close();
}
 
Example #30
Source File: ModelResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@ApiOperation(value = "Update a model", tags = {"Models"},
    notes ="All request values are optional. "
        + "For example, you can only include the name attribute in the request body JSON-object, only updating the name of the model, leaving all other fields unaffected. "
        + "When an attribute is explicitly included and is set to null, the model-value will be updated to null. "
        + "Example: ```JSON \n{\"metaInfo\" : null}``` will clear the metaInfo of the model).")
@ApiResponses(value = {
    @ApiResponse(code = 200, message = "Indicates the model was found and updated."),
    @ApiResponse(code = 404, message = "Indicates the requested model was not found.")
})
@RequestMapping(value = "/repository/models/{modelId}", method = RequestMethod.PUT, produces = "application/json")
public ModelResponse updateModel(@ApiParam(name = "modelId") @PathVariable String modelId, @RequestBody ModelRequest modelRequest, HttpServletRequest request) {
  Model model = getModelFromRequest(modelId);

  if (modelRequest.isCategoryChanged()) {
    model.setCategory(modelRequest.getCategory());
  }
  if (modelRequest.isDeploymentChanged()) {
    model.setDeploymentId(modelRequest.getDeploymentId());
  }
  if (modelRequest.isKeyChanged()) {
    model.setKey(modelRequest.getKey());
  }
  if (modelRequest.isMetaInfoChanged()) {
    model.setMetaInfo(modelRequest.getMetaInfo());
  }
  if (modelRequest.isNameChanged()) {
    model.setName(modelRequest.getName());
  }
  if (modelRequest.isVersionChanged()) {
    model.setVersion(modelRequest.getVersion());
  }
  if (modelRequest.isTenantIdChanged()) {
    model.setTenantId(modelRequest.getTenantId());
  }

  repositoryService.saveModel(model);
  return restResponseFactory.createModelResponse(model);
}