本文整理汇总了Java中org.activiti.engine.repository.ProcessDefinition.getDiagramResourceName方法的典型用法代码示例。如果您正苦于以下问题:Java ProcessDefinition.getDiagramResourceName方法的具体用法?Java ProcessDefinition.getDiagramResourceName怎么用?Java ProcessDefinition.getDiagramResourceName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.activiti.engine.repository.ProcessDefinition
的用法示例。
在下文中一共展示了ProcessDefinition.getDiagramResourceName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadByDeployment
import org.activiti.engine.repository.ProcessDefinition; //导入方法依赖的package包/类
/**
* 读取资源,通过部署ID
*
* @param processDefinitionId 流程定义
* @param resourceType 资源类型(xml|image)
* @throws Exception
*/
@RequestMapping(value = "/resource/read")
public void loadByDeployment(@RequestParam("processDefinitionId") String processDefinitionId,
@RequestParam("resourceType") String resourceType,
HttpServletResponse response) throws Exception {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult();
String resourceName = "";
if (resourceType.equals("image")) {
resourceName = processDefinition.getDiagramResourceName();
} else if (resourceType.equals("xml")) {
resourceName = processDefinition.getResourceName();
}
InputStream resourceAsStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), resourceName);
byte[] b = new byte[1024];
int len = -1;
while ((len = resourceAsStream.read(b, 0, 1024)) != -1) {
response.getOutputStream().write(b, 0, len);
}
}
示例2: loadByProcessInstance
import org.activiti.engine.repository.ProcessDefinition; //导入方法依赖的package包/类
/**
* 读取资源,通过流程ID
*
* @param resourceType 资源类型(xml|image)
* @param processInstanceId 流程实例ID
* @param response
* @throws Exception
*/
@RequestMapping(value = "/resource/process-instance")
public void loadByProcessInstance(@RequestParam("type") String resourceType, @RequestParam("pid") String processInstanceId, HttpServletResponse response)
throws Exception {
InputStream resourceAsStream = null;
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(processInstance.getProcessDefinitionId())
.singleResult();
String resourceName = "";
if (resourceType.equals("image")) {
resourceName = processDefinition.getDiagramResourceName();
} else if (resourceType.equals("xml")) {
resourceName = processDefinition.getResourceName();
}
resourceAsStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), resourceName);
byte[] b = new byte[1024];
int len = -1;
while ((len = resourceAsStream.read(b, 0, 1024)) != -1) {
response.getOutputStream().write(b, 0, len);
}
}
示例3: getImage
import org.activiti.engine.repository.ProcessDefinition; //导入方法依赖的package包/类
@Test
public void getImage() throws IOException {
ProcessEngine processEngine = ProcessEngineConfiguration.createProcessEngineConfigurationFromResource("activiti.cfg.xml").buildProcessEngine();
logger.info("### ============= 创建Activiti流程引擎实例, {}", processEngine);
RepositoryService repositoryService = processEngine.getRepositoryService();
//通过流程ID(XML上写的)找到流程
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
.processDefinitionId("请假流程:2:10004")
.singleResult();
String diagramResourceName = processDefinition.getDiagramResourceName();
logger.info(diagramResourceName);
InputStream imageStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), diagramResourceName);
FileUtils.writeByteArrayToFile(new File("F:\\123456.png"),IOUtils.toByteArray(imageStream));
imageStream.close();
processEngine.close();
}
示例4: resourceRead
import org.activiti.engine.repository.ProcessDefinition; //导入方法依赖的package包/类
/**
* 读取资源,通过部署ID
* @param processDefinitionId 流程定义ID
* @param processInstanceId 流程实例ID
* @param resourceType 资源类型(xml|image)
*/
public InputStream resourceRead(String procDefId, String proInsId, String resType) throws Exception {
if (StringUtils.isBlank(procDefId)){
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(proInsId).singleResult();
procDefId = processInstance.getProcessDefinitionId();
}
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(procDefId).singleResult();
String resourceName = "";
if (resType.equals("image")) {
resourceName = processDefinition.getDiagramResourceName();
} else if (resType.equals("xml")) {
resourceName = processDefinition.getResourceName();
}
InputStream resourceAsStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), resourceName);
return resourceAsStream;
}
示例5: downloadFlow
import org.activiti.engine.repository.ProcessDefinition; //导入方法依赖的package包/类
@RequestMapping(value = "/processdef/export/{type}/{id}", method = RequestMethod.GET)
public void downloadFlow(@PathVariable("type") String type, @PathVariable("id") String id, HttpServletResponse response) {
try {
ProcessDefinition processDefinition = repositoryService.getProcessDefinition(id);
String resourceName = "";
if (type.equals("image")) {
resourceName = processDefinition.getDiagramResourceName();
} else if (type.equals("xml")) {
resourceName = processDefinition.getResourceName();
}
InputStream resourceAsStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), resourceName);
IOUtils.copy(resourceAsStream, response.getOutputStream());
response.setHeader("Content-Disposition", "attachment; filename=" + resourceName);
response.flushBuffer();
} catch (Exception e) {
LOGGER.error("导出流程定义的" + type + "文件失败:processDefId={}", id, e);
}
}
示例6: testProcessDiagramResource
import org.activiti.engine.repository.ProcessDefinition; //导入方法依赖的package包/类
@Deployment(resources={
"org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.bpmn20.xml",
"org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.jpg"
})
public void testProcessDiagramResource() {
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
assertEquals("org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.bpmn20.xml", processDefinition.getResourceName());
assertTrue(processDefinition.hasStartFormKey());
String diagramResourceName = processDefinition.getDiagramResourceName();
assertEquals("org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.jpg", diagramResourceName);
InputStream diagramStream = repositoryService.getResourceAsStream(deploymentId, "org/activiti/engine/test/bpmn/deployment/BpmnDeploymentTest.testProcessDiagramResource.jpg");
byte[] diagramBytes = IoUtil.readInputStream(diagramStream, "diagram stream");
assertEquals(33343, diagramBytes.length);
}
示例7: exportDiagramToFile
import org.activiti.engine.repository.ProcessDefinition; //导入方法依赖的package包/类
/**
* 导出图片文件到硬盘
*
* @return 文件的全路径
*/
public static String exportDiagramToFile(RepositoryService repositoryService, ProcessDefinition processDefinition, String exportDir) throws IOException {
String diagramResourceName = processDefinition.getDiagramResourceName();
String key = processDefinition.getKey();
int version = processDefinition.getVersion();
String diagramPath = "";
InputStream resourceAsStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), diagramResourceName);
byte[] b = new byte[resourceAsStream.available()];
@SuppressWarnings("unused")
int len = -1;
resourceAsStream.read(b, 0, b.length);
// create file if not exist
String diagramDir = exportDir + "/" + key + "/" + version;
File diagramDirFile = new File(diagramDir);
if (!diagramDirFile.exists()) {
diagramDirFile.mkdirs();
}
diagramPath = diagramDir + "/" + diagramResourceName;
File file = new File(diagramPath);
// 文件存在退出
if (file.exists()) {
// 文件大小相同时直接返回否则重新创建文件(可能损坏)
logger.debug("diagram exist, ignore... : {}", diagramPath);
return diagramPath;
} else {
file.createNewFile();
}
logger.debug("export diagram to : {}", diagramPath);
// wirte bytes to file
FileUtils.writeByteArrayToFile(file, b, true);
return diagramPath;
}
示例8: processDefinitionQueryTest
import org.activiti.engine.repository.ProcessDefinition; //导入方法依赖的package包/类
@Test
public void processDefinitionQueryTest() {
List<ProcessDefinition> processDefinitionList = repositoryService.createProcessDefinitionQuery()
.list();
for (ProcessDefinition processDefinition : processDefinitionList) {
String tmp = "\r\n" +
"#=======================================================================================================================#\r\n" +
"# Spring MVC Context 容器初始化完成之后的处理:\r\n" +
"#\t getId " + processDefinition.getId() + "\r\n" +
"#\t getCategory " + processDefinition.getCategory() + "\r\n" +
"#\t getName " + processDefinition.getName() + "\r\n" +
"#\t getKey " + processDefinition.getKey() + "\r\n" +
"#\t getDescription " + processDefinition.getDescription() + "\r\n" +
"#\t getVersion " + processDefinition.getVersion() + "\r\n" +
"#\t getResourceName " + processDefinition.getResourceName() + "\r\n" +
"#\t getDeploymentId " + processDefinition.getDeploymentId() + "\r\n" +
"#\t getDiagramResourceName " + processDefinition.getDiagramResourceName() + "\r\n" +
"#\t hasStartFormKey " + processDefinition.hasStartFormKey() + "\r\n" +
"#\t hasGraphicalNotation " + processDefinition.hasGraphicalNotation() + "\r\n" +
"#\t isSuspended " + processDefinition.isSuspended() + "\r\n" +
"#\t getTenantId " + processDefinition.getTenantId() + "\r\n" +
"#=======================================================================================================================#\r\n";
logger.info(tmp);
}
// org.activiti.rest.service.application.ActivitiRestServicesApplication
// org.activiti.rest.service.api.RestActionRequest
}
示例9: BpmModelVo
import org.activiti.engine.repository.ProcessDefinition; //导入方法依赖的package包/类
public BpmModelVo(ProcessDefinition o) {
this.id = o.getId();
this.category = o.getCategory();
this.name = o.getName();
this.key = o.getKey();
this.description = o.getDescription();
this.version = o.getVersion();
this.deploymentId = o.getDeploymentId();
this.resourceName = o.getResourceName();
this.diagramResourceName = o.getDiagramResourceName();
}
示例10: ProcessDefinitionVo
import org.activiti.engine.repository.ProcessDefinition; //导入方法依赖的package包/类
public ProcessDefinitionVo(ProcessDefinition o) {
this.id = o.getId();
this.category = o.getCategory();
this.name = o.getName();
this.key = o.getKey();
this.description = o.getDescription();
this.version = o.getVersion();
this.resourceName = o.getResourceName();
this.deploymentId = o.getDeploymentId();
this.diagramResourceName = o.getDiagramResourceName();
this.hasStartFormKey = o.hasStartFormKey();
this.hasGraphicalNotation = o.hasGraphicalNotation();
this.suspended = o.isSuspended();
this.tenantId = o.getTenantId();
}
示例11: generateResource
import org.activiti.engine.repository.ProcessDefinition; //导入方法依赖的package包/类
/**
* 生成资源文件,并返回文件路径 给开发者看的
*/
@RequestMapping(value = "/processdef/generate/{type}/{pdId}", method = RequestMethod.POST)
@ResponseBody
public Result generateResource(@PathVariable("type") String type, @PathVariable("pdId") String pdId, HttpServletRequest request) {
try {
String dirPath = request.getRealPath("/");
ProcessDefinition processDefinition = repositoryService.getProcessDefinition(pdId);
String resourceName = "";
if (type.equals("image")) {
resourceName = processDefinition.getDiagramResourceName();
} else if (type.equals("xml")) {
resourceName = processDefinition.getResourceName();
}
InputStream resourceAsStream = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), resourceName);
String realPath = dirPath + File.separator + DIR_PATH + File.separator + resourceName;
realPath=realPath.replaceAll("\\\\", "/");
File file = new File(realPath);
if (file.exists()) {
file.delete();
}
FileUtil.copyInputStreamToFile(resourceAsStream, file);
String realName = (DIR_PATH + File.separator + resourceName).replaceAll("\\\\", "/");
return new Result(true, realName, "成功生成png");
} catch (Exception e) {
LOGGER.error("生成资源文件异常,pdId={}", pdId, e);
return new Result(false);
}
}
示例12: findProcessPic
import org.activiti.engine.repository.ProcessDefinition; //导入方法依赖的package包/类
@Override
public InputStream findProcessPic(String procDefId) {
ProcessDefinition definition = getProcessDefinitionById(procDefId);
String source = definition.getDiagramResourceName();
return repositoryService.getResourceAsStream(definition.getDeploymentId(),source);
}
示例13: exportDiagrams
import org.activiti.engine.repository.ProcessDefinition; //导入方法依赖的package包/类
/**
* 导出图片文件到硬盘
*/
public List<String> exportDiagrams(String exportDir) throws IOException {
List<String> files = new ArrayList<String>();
List<ProcessDefinition> list = repositoryService.createProcessDefinitionQuery().list();
for (ProcessDefinition processDefinition : list) {
String diagramResourceName = processDefinition.getDiagramResourceName();
String key = processDefinition.getKey();
int version = processDefinition.getVersion();
String diagramPath = "";
InputStream resourceAsStream = repositoryService.getResourceAsStream(
processDefinition.getDeploymentId(), diagramResourceName);
byte[] b = new byte[resourceAsStream.available()];
@SuppressWarnings("unused")
int len = -1;
resourceAsStream.read(b, 0, b.length);
// create file if not exist
String diagramDir = exportDir + "/" + key + "/" + version;
File diagramDirFile = new File(diagramDir);
if (!diagramDirFile.exists()) {
diagramDirFile.mkdirs();
}
diagramPath = diagramDir + "/" + diagramResourceName;
File file = new File(diagramPath);
// 文件存在退出
if (file.exists()) {
// 文件大小相同时直接返回否则重新创建文件(可能损坏)
logger.debug("diagram exist, ignore... : {}", diagramPath);
files.add(diagramPath);
} else {
file.createNewFile();
logger.debug("export diagram to : {}", diagramPath);
// wirte bytes to file
FileUtils.writeByteArrayToFile(file, b, true);
files.add(diagramPath);
}
}
return files;
}
示例14: generateImage
import org.activiti.engine.repository.ProcessDefinition; //导入方法依赖的package包/类
/**
* 生成流程实例的流程图片,并重点高亮当前节点,高亮已经执行的链路
*
* @param instanceId 流程实例
* @param request
* @return 第二个参数为生成的图片路径
*/
@RequestMapping(value = "/processinstance/generate/{instanceId}", method = RequestMethod.POST)
@ResponseBody
public Result generateImage(@PathVariable("instanceId") String instanceId, HttpServletRequest request) {
try {
String dirPath = request.getRealPath("/");
ProcessInstance processInstance=runtimeService.createProcessInstanceQuery().processInstanceId(instanceId)
.singleResult();
BpmnModel bpmnModel;
List<String> activeActivityIds=new ArrayList<>();
String processDefinitionId;
//存在活动节点,流程正在进行中
if(processInstance!=null) {
processDefinitionId=processInstance.getProcessDefinitionId();
//task = taskService.createTaskQuery().processInstanceId(instanceId).singleResult();
//流程定义
//正在活动的节点
activeActivityIds = runtimeService.getActiveActivityIds(instanceId);//(task.getExecutionId());
}else {
//流程已经结束
HistoricProcessInstance instance=historyService.createHistoricProcessInstanceQuery()
.processInstanceId(instanceId).singleResult();
processDefinitionId=instance.getProcessDefinitionId();
}
bpmnModel = repositoryService.getBpmnModel(processDefinitionId);
ProcessDiagramGenerator pdg = processEngine.getProcessEngineConfiguration().getProcessDiagramGenerator();
//-------------------------------executedActivityIdList已经执行的节点------------------------------------
List<HistoricActivityInstance> historicActivityInstanceList = historyService
.createHistoricActivityInstanceQuery()
.processInstanceId(instanceId).orderByHistoricActivityInstanceStartTime().asc().list();
// 已执行的节点ID集合
List<String> executedActivityIdList = new ArrayList<>();
for (HistoricActivityInstance activityInstance : historicActivityInstanceList) {
executedActivityIdList.add(activityInstance.getActivityId());
}
ProcessDefinition processDefinition = repositoryService.getProcessDefinition(processDefinitionId);
String resourceName = instanceId + "_" + processDefinition.getDiagramResourceName();
List<String> highLightedFlows = getHighLightedFlows((ProcessDefinitionEntity) processDefinition,
historicActivityInstanceList);
//生成流图片 所有走过的节点高亮 第三个参数 activeActivityIds=当前活动节点点高亮;executedActivityIdList=已经执行过的节点高亮
InputStream inputStream = pdg.generateDiagram(bpmnModel, "PNG", activeActivityIds, highLightedFlows,
processEngine.getProcessEngineConfiguration().getActivityFontName(),
processEngine.getProcessEngineConfiguration().getLabelFontName(),
processEngine.getProcessEngineConfiguration().getActivityFontName(),
processEngine.getProcessEngineConfiguration().getProcessEngineConfiguration().getClassLoader(), 1);
resourceName=DateUtil.format(new Date(),"yyyyMMddHHmmss")+"_"+resourceName;
//生成本地图片
String realPath = dirPath + File.separator + DIR_PATH + File.separator + resourceName;
realPath=realPath.replaceAll("\\\\", "/");
File file = new File(realPath);
if (file.exists()) {
file.delete();
}
FileUtil.copyInputStreamToFile(inputStream, file);
String realName = (DIR_PATH + File.separator + resourceName).replaceAll("\\\\", "/");
inputStream.close();
return new Result(true, realName, "成功生成png");
} catch (Exception e) {
LOGGER.error("生成图像文件异常,instanceId={}", instanceId, e);
return new Result(false);
}
}
示例15: testClasspathDeployment
import org.activiti.engine.repository.ProcessDefinition; //导入方法依赖的package包/类
@Test
public void testClasspathDeployment() throws Exception {
// 定义classpath
String bpmnClasspath = "chapter5/candidateUserInUserTask.bpmn";
String pngClasspath = "chapter5/candidateUserInUserTask.png";
// 创建部署构建器
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
// 添加资源
deploymentBuilder.addClasspathResource(bpmnClasspath);
deploymentBuilder.addClasspathResource(pngClasspath);
// 执行部署
deploymentBuilder.deploy();
// 验证流程定义是否部署成功
ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();
long count = processDefinitionQuery.processDefinitionKey("candidateUserInUserTask").count();
assertEquals(1, count);
// 读取图片文件
ProcessDefinition processDefinition = processDefinitionQuery.singleResult();
String diagramResourceName = processDefinition.getDiagramResourceName();
assertEquals(pngClasspath, diagramResourceName);
Map<String, Object> vars = new HashMap<String, Object>();
ArrayList<Date> objs = new ArrayList<Date>();
objs.add(new Date());
vars.put("list", objs);
// vars.put("aaa", "333");
runtimeService.startProcessInstanceByKey("candidateUserInUserTask", vars);
List<Task> list = taskService.createTaskQuery().includeProcessVariables().list();
System.out.println(list);
Task task = taskService.createTaskQuery().taskId(list.get(0).getId())
.includeProcessVariables().includeTaskLocalVariables().singleResult();
CommandContext commandContext = Context.getCommandContext();
System.out.println(task);
System.out.println(commandContext);
// ProcessEngineImpl defaultProcessEngine = (ProcessEngineImpl) ProcessEngines.getDefaultProcessEngine();
// Context.setProcessEngineConfiguration(defaultProcessEngine.getProcessEngineConfiguration());
// Context.setCommandContext(defaultProcessEngine.getProcessEngineConfiguration().getCommandContextFactory().createCommandContext(null));
System.out.println(Context.getCommandContext());
System.out.println(task.getProcessVariables());
}