Java Code Examples for org.activiti.engine.RepositoryService#saveModel()

The following examples show how to use org.activiti.engine.RepositoryService#saveModel() . 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: ModelUtils.java    From openwebflow with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static Model createNewModel(RepositoryService repositoryService, String name, String description)
		throws IOException
{
	ObjectMapper objectMapper = new ObjectMapper();
	Model modelData = repositoryService.newModel();

	ObjectNode modelObjectNode = objectMapper.createObjectNode();
	modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, name);
	modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);

	modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, description);
	modelData.setMetaInfo(modelObjectNode.toString());
	modelData.setName(name);

	repositoryService.saveModel(modelData);
	repositoryService.addModelEditorSource(modelData.getId(), EMPTY_MODEL_XML.getBytes("utf-8"));
	return modelData;
}
 
Example 2
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 3
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 4
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 5
Source File: ModelTest.java    From opscenter with Apache License 2.0 5 votes vote down vote up
@RequestMapping("create")
public void createModel(HttpServletRequest request, HttpServletResponse response){
    try{
        String modelName = "modelName";
        String modelKey = "modelKey";
        String description = "description";

        ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();

        RepositoryService repositoryService = processEngine.getRepositoryService();

        ObjectMapper objectMapper = new ObjectMapper();
        ObjectNode editorNode = objectMapper.createObjectNode();
        editorNode.put("id", "canvas");
        editorNode.put("resourceId", "canvas");
        ObjectNode stencilSetNode = objectMapper.createObjectNode();
        stencilSetNode.put("namespace", "http://b3mn.org/stencilset/bpmn2.0#");
        editorNode.put("stencilset", stencilSetNode);
        Model modelData = repositoryService.newModel();

        ObjectNode modelObjectNode = objectMapper.createObjectNode();
        modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, modelName);
        modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);
        modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, description);
        modelData.setMetaInfo(modelObjectNode.toString());
        modelData.setName(modelName);
        modelData.setKey(modelKey);

        //保存模型
        repositoryService.saveModel(modelData);
        repositoryService.addModelEditorSource(modelData.getId(), editorNode.toString().getBytes("utf-8"));
        response.sendRedirect(request.getContextPath() + "/modeler.html?modelId=" + modelData.getId());
    }catch (Exception e){
    }
}
 
Example 6
Source File: ModelUtils.java    From openwebflow with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void importModel(RepositoryService repositoryService, File modelFile) throws IOException,
		XMLStreamException
{
	InputStreamReader reader = new InputStreamReader(new FileInputStream(modelFile), "utf-8");
	String fileContent = IOUtils.readStringAndClose(reader, (int) modelFile.length());

	BpmnModel bpmnModel = new BpmnXMLConverter().convertToBpmnModel(new StringStreamSourceEx(fileContent), false,
		false);

	String processName = bpmnModel.getMainProcess().getName();
	if (processName == null || processName.isEmpty())
	{
		processName = bpmnModel.getMainProcess().getId();
	}

	Model modelData = repositoryService.newModel();
	ObjectNode modelObjectNode = new ObjectMapper().createObjectNode();
	modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, processName);
	modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);
	modelData.setMetaInfo(modelObjectNode.toString());
	modelData.setName(processName);
	modelData.setKey(modelFile.getName());

	repositoryService.saveModel(modelData);

	repositoryService.addModelEditorSource(modelData.getId(), fileContent.getBytes("utf-8"));
	Logger.getLogger(ModelUtils.class)
			.info(String.format("importing model file: %s", modelFile.getCanonicalPath()));
}
 
Example 7
Source File: ModelerController.java    From lemon with Apache License 2.0 5 votes vote down vote up
@RequestMapping("xml2json")
public String xml2json(
        @RequestParam("processDefinitionId") String processDefinitionId)
        throws Exception {
    RepositoryService repositoryService = processEngine
            .getRepositoryService();

    ProcessDefinition processDefinition = repositoryService
            .getProcessDefinition(processDefinitionId);

    Model model = repositoryService.newModel();
    model.setName(processDefinition.getName());
    model.setDeploymentId(processDefinition.getDeploymentId());
    repositoryService.saveModel(model);

    BpmnModel bpmnModel = repositoryService
            .getBpmnModel(processDefinitionId);
    ObjectNode objectNode = new BpmnJsonConverter()
            .convertToJson(bpmnModel);

    String json = objectNode.toString();

    repositoryService.addModelEditorSource(model.getId(),
            json.getBytes("utf-8"));

    return "redirect:/modeler/modeler-list.do";
}
 
Example 8
Source File: ModelerController.java    From lemon with Apache License 2.0 4 votes vote down vote up
@RequestMapping("modeler-deploy")
public String deploy(@RequestParam("id") String id,
        org.springframework.ui.Model theModel) throws Exception {
    String tenantId = tenantHolder.getTenantId();
    RepositoryService repositoryService = processEngine
            .getRepositoryService();
    Model modelData = repositoryService.getModel(id);
    byte[] bytes = repositoryService
            .getModelEditorSource(modelData.getId());

    if (bytes == null) {
        theModel.addAttribute("message", "模型数据为空,请先设计流程并成功保存,再进行发布。");

        return "modeler/failure";
    }

    JsonNode modelNode = (JsonNode) new ObjectMapper().readTree(bytes);
    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, "UTF-8"))
            .tenantId(tenantId).deploy();
    modelData.setDeploymentId(deployment.getId());
    repositoryService.saveModel(modelData);

    List<ProcessDefinition> processDefinitions = repositoryService
            .createProcessDefinitionQuery()
            .deploymentId(deployment.getId()).list();

    for (ProcessDefinition processDefinition : processDefinitions) {
        processEngine.getManagementService().executeCommand(
                new SyncProcessCmd(processDefinition.getId()));
    }

    return "redirect:/modeler/modeler-list.do";
}