Search in sources :

Example 56 with Model

use of org.activiti.engine.repository.Model in project Activiti by Activiti.

the class ModelQueryTest method testVerifyModelProperties.

public void testVerifyModelProperties() {
    List<Model> models = repositoryService.createModelQuery().orderByModelName().asc().list();
    Model modelOne = models.get(0);
    assertThat(modelOne.getName()).isEqualTo("my model");
    assertThat(modelOne.getId()).isEqualTo(modelOneId);
    models = repositoryService.createModelQuery().modelNameLike("%model%").orderByModelName().asc().list();
    assertThat(models.get(0).getName()).isEqualTo("my model");
    assertThat(models).hasSize(1);
    assertThat(repositoryService.createModelQuery().orderByModelId().asc().list()).hasSize(1);
}
Also used : Model(org.activiti.engine.repository.Model)

Example 57 with Model

use of org.activiti.engine.repository.Model in project Activiti by Activiti.

the class ModelQueryTest method testQueryByNameAndKey.

public void testQueryByNameAndKey() {
    ModelQuery query = repositoryService.createModelQuery().modelKey("someKey");
    Model model = query.singleResult();
    assertThat(model).isNotNull();
    assertThat(query.list()).hasSize(1);
    assertThat(query.count()).isEqualTo(1);
}
Also used : Model(org.activiti.engine.repository.Model) ModelQuery(org.activiti.engine.repository.ModelQuery)

Example 58 with Model

use of org.activiti.engine.repository.Model in project Activiti by Activiti.

the class RepositoryServiceTest method testUpdateModelPersistence.

public void testUpdateModelPersistence() throws Exception {
    Model model = repositoryService.newModel();
    assertThat(model).isNotNull();
    model.setName("Test model");
    model.setCategory("test");
    model.setMetaInfo("meta");
    repositoryService.saveModel(model);
    assertThat(model.getId()).isNotNull();
    model = repositoryService.getModel(model.getId());
    assertThat(model).isNotNull();
    model.setName("New name");
    model.setCategory("New category");
    model.setMetaInfo("test");
    model.setVersion(2);
    repositoryService.saveModel(model);
    assertThat(model.getId()).isNotNull();
    repositoryService.addModelEditorSource(model.getId(), "new".getBytes("utf-8"));
    repositoryService.addModelEditorSourceExtra(model.getId(), "new".getBytes("utf-8"));
    model = repositoryService.getModel(model.getId());
    assertThat(model.getName()).isEqualTo("New name");
    assertThat(model.getCategory()).isEqualTo("New category");
    assertThat(model.getMetaInfo()).isEqualTo("test");
    assertThat(model.getCreateTime()).isNotNull();
    assertThat(model.getVersion()).isEqualTo(Integer.valueOf(2));
    assertThat(new String(repositoryService.getModelEditorSource(model.getId()), "utf-8")).isEqualTo("new");
    assertThat(new String(repositoryService.getModelEditorSourceExtra(model.getId()), "utf-8")).isEqualTo("new");
    repositoryService.deleteModel(model.getId());
}
Also used : Model(org.activiti.engine.repository.Model) BpmnModel(org.activiti.bpmn.model.BpmnModel)

Example 59 with Model

use of org.activiti.engine.repository.Model in project Activiti by Activiti.

the class ModelQueryEscapeClauseTest method testQueryByNameLike.

public void testQueryByNameLike() throws Exception {
    ModelQuery query = repositoryService.createModelQuery().modelNameLike("%\\%%");
    Model model = query.singleResult();
    assertThat(model).isNotNull();
    assertThat(model.getKey()).isEqualTo("someKey1");
    assertThat(new String(repositoryService.getModelEditorSource(model.getId()), "utf-8")).isEqualTo("bytes");
    assertThat(query.list()).hasSize(1);
    assertThat(query.count()).isEqualTo(1);
    query = repositoryService.createModelQuery().modelNameLike("%\\_%");
    model = query.singleResult();
    assertThat(model).isNotNull();
    assertThat(model.getKey()).isEqualTo("someKey2");
    assertThat(new String(repositoryService.getModelEditorSource(model.getId()), "utf-8")).isEqualTo("bytes");
    assertThat(query.list()).hasSize(1);
    assertThat(query.count()).isEqualTo(1);
}
Also used : Model(org.activiti.engine.repository.Model) ModelQuery(org.activiti.engine.repository.ModelQuery)

Example 60 with Model

use of org.activiti.engine.repository.Model in project my_curd by qinyou.

the class ProcessModelController method modelDeploy.

// 模型部署
@Before(IdRequired.class)
public void modelDeploy() throws IOException {
    String modelId = get("id");
    Model model = ActivitiUtils.getRepositoryService().getModel(modelId);
    if (model == null) {
        renderFail("参数错误");
        return;
    }
    ObjectNode modelNode = (ObjectNode) new ObjectMapper().readTree(ActivitiUtils.getRepositoryService().getModelEditorSource(model.getId()));
    BpmnModel bpmnModel = new BpmnJsonConverter().convertToBpmnModel(modelNode);
    // 这样是为了 流程定义转换为 模型是 ,模型能有 名称和 描述
    if (StringUtils.isEmpty(bpmnModel.getMainProcess().getDocumentation())) {
        bpmnModel.getMainProcess().setDocumentation((String) JSON.parseObject(model.getMetaInfo()).get("description"));
    }
    if (StringUtils.isEmpty(bpmnModel.getMainProcess().getName())) {
        bpmnModel.getMainProcess().setName(model.getName());
    }
    byte[] bpmnBytes = new BpmnXMLConverter().convertToXML(bpmnModel);
    Deployment deployment = ActivitiUtils.getRepositoryService().createDeployment().name("通过model部署,modelId: " + model.getId()).addString(bpmnModel.getMainProcess().getId() + ".bpmn", new String(bpmnBytes, ActConst.DEFAULT_CHARSET)).deploy();
    renderSuccess("部署成功,部署ID=" + deployment.getId());
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Model(org.activiti.engine.repository.Model) BpmnModel(org.activiti.bpmn.model.BpmnModel) Deployment(org.activiti.engine.repository.Deployment) BpmnJsonConverter(org.activiti.editor.language.json.converter.BpmnJsonConverter) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BpmnModel(org.activiti.bpmn.model.BpmnModel) BpmnXMLConverter(org.activiti.bpmn.converter.BpmnXMLConverter) Before(com.jfinal.aop.Before)

Aggregations

Model (org.activiti.engine.repository.Model)60 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)20 BpmnModel (org.activiti.bpmn.model.BpmnModel)13 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)12 ModelQuery (org.activiti.engine.repository.ModelQuery)9 InputStream (java.io.InputStream)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 ActivitiException (org.activiti.engine.ActivitiException)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 Calendar (java.util.Calendar)6 Deployment (org.activiti.engine.test.Deployment)6 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)6 BpmnXMLConverter (org.activiti.bpmn.converter.BpmnXMLConverter)5 BpmnJsonConverter (org.activiti.editor.language.json.converter.BpmnJsonConverter)5 HttpGet (org.apache.http.client.methods.HttpGet)5 Before (com.jfinal.aop.Before)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 HttpPut (org.apache.http.client.methods.HttpPut)4 StringEntity (org.apache.http.entity.StringEntity)4