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

The following examples show how to use org.activiti.engine.RepositoryService#newModel() . 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: 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 3
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 4
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 5
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";
}