本文主要是介绍activtiy 在线编辑器,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
目录
maven 依赖
下载activiti-webapp
Activiti configsurtion
contrller
ServiceImpl
entity
调整
maven 依赖
<dependency><groupId>org.activiti</groupId><artifactId>activiti-spring-boot-starter</artifactId><version>7.0.0.SR1</version></dependency><dependency><groupId>org.activiti</groupId><artifactId>activiti-modeler</artifactId><version>5.23.0</version></dependency><dependency><groupId>org.activiti</groupId><artifactId>activiti-diagram-rest</artifactId><version>5.23.0</version></dependency>
下载activiti-webapp
去搜索 activiti-webapp 或者是去这里 百度网盘 请输入提取码百度网盘为您提供文件的网络备份、同步和分享服务。空间大、速度快、安全稳固,支持教育网加速,支持手机端。注册使用百度网盘即可享受免费存储空间https://pan.baidu.com/s/16OQv_h8SxPn2VEw7HRp_tQ提取码为链接:https://pan.baidu.com/s/16OQv_h8SxPn2VEw7HRp_tQ
提取码:awc4
赋值到你的web目录下
Activiti configsurtion
@Configuration
public class ActivityBen extends AbstractProcessEngineAutoConfiguration {@AutowiredDataSource dataSource;@Beanpublic SpringProcessEngineConfiguration springProcessEngineConfiguration(PlatformTransactionManager platformTransactionManager){SpringProcessEngineConfiguration spec = new SpringProcessEngineConfiguration();spec.setDataSource(dataSource);spec.setTransactionManager(platformTransactionManager);spec.setDatabaseSchemaUpdate("true");Resource[] resources = null;// 启动自动部署流程try {resources = new PathMatchingResourcePatternResolver().getResources("classpath*:processes/*.bpmn");} catch (IOException e) {e.printStackTrace();}spec.setDeploymentResources(resources);return spec;}@Beanpublic ProcessEngineFactoryBean processEngine(SpringProcessEngineConfiguration engineConfiguration){ProcessEngineFactoryBean processEngineFactoryBean = new ProcessEngineFactoryBean();processEngineFactoryBean.setProcessEngineConfiguration(engineConfiguration);return processEngineFactoryBean;}@Beanpublic RepositoryService repositoryService(ProcessEngineFactoryBean engineFactoryBean) throws Exception{return engineFactoryBean.getObject().getRepositoryService();}@Beanpublic RuntimeService runtimeService(ProcessEngineFactoryBean engineFactoryBean) throws Exception{return engineFactoryBean.getObject().getRuntimeService();}@Beanpublic TaskService taskService(ProcessEngineFactoryBean engineFactoryBean) throws Exception{return engineFactoryBean.getObject().getTaskService();}@Beanpublic HistoryService historyService(ProcessEngineFactoryBean engineFactoryBean) throws Exception{return engineFactoryBean.getObject().getHistoryService();}
contrller
ntroller
public class ActivityContrllerCreate {//2. 声明一个Logger,这个是static的方式,我比较习惯这么写。private final static Logger logger = LoggerFactory.getLogger(ActivityCreateSerivce.class);@AutowiredActivityCreateSerivce activityCreateSerivce;@RequestMapping("modeler/Create")public void CreateModel(HttpServletRequest request, HttpServletResponse response){
// String s = activityCreateSerivce.CreatModel();try {response.sendRedirect(request.getContextPath() + "/modeler.html?modelId=2501");}catch(Exception e){logger.debug(e.getMessage());}}@RequestMapping(value = "modeler/service/model/{modelId}/json",method= RequestMethod.GET,produces = "application/json")@ResponseBodypublic ObjectNode getEditorJson(@PathVariable String modelId){return activityCreateSerivce.BySelectId(modelId);}@RequestMapping(value="modeler/service/editor/stencilset", method = RequestMethod.GET, produces = "application/json;charset=utf-8")public @ResponseBody String getStencilset() {InputStream stencilsetStream = this.getClass().getClassLoader().getResourceAsStream("static/stencilset.json");try {return IOUtils.toString(stencilsetStream, "utf-8");} catch (Exception e) {throw new ActivitiException("Error while loading stencil set", e);}}@RequestMapping(value="modeler/service/model/{modelId}/save", method = RequestMethod.PUT)public void saveModel(@PathVariable String modelId, @RequestParam("name") String name,@RequestParam("json_xml") String json_xml, @RequestParam("svg_xml") String svg_xml,@RequestParam("description") String description,HttpServletResponse response) {ActivitiEnitiy activitiEnitiy=new ActivitiEnitiy();activitiEnitiy.setModeid(modelId);activitiEnitiy.setName(name);activitiEnitiy.setDescription(description);activitiEnitiy.setJson_xml(json_xml);activitiEnitiy.setSvg_xml(svg_xml);if(activityCreateSerivce.ModelSave(activitiEnitiy)){ResponseUtil.out(response, Result.successWithData("模型已经保存!"));}else{ResponseUtil.out(response,Result.failed("模型保存失败!"));}}@RequestMapping(value="modeler/service/deploy",method = RequestMethod.GET)public void Deploy(@PathVariable String modelId, HttpServletResponse response )throws IOException {if(activityCreateSerivce.deploy(modelId)){ResponseUtil.out(response,Result.successWithData("已部署模型"));}else{ResponseUtil.out(response,Result.failed("模型数据为空或者数据模型不符要求!"));}}@RequestMapping(value="modeler/service/model/list")@ResponseBodypublic List<Model> Selectlist(){return activityCreateSerivce.selectList();}}
@Controller
public class RunTimeContrller {@AutowiredTaskServiceImpl service;@RequestMapping(value="modeler/service/run")public void run(@PathVariable String keyName, HttpServletResponse response){if(service.run(keyName)){ResponseUtil.out(response, Result.successWithData("已执行该操作!"));}else{ResponseUtil.out(response,Result.failed("操作失败!"));}}
}
@Controller
public class TaskContrller {@AutowiredRuntimeServiceImpl runtimeService;@RequestMapping(value="modeler/service/process")@ResponseBodypublic ProcessInstance SelectProcess(@PathVariable String process){ProcessInstance processInstance = runtimeService.startProcess(process);return processInstance;}
}
ServiceImpl
@Service
public class ActivityCreateSerivce {@Qualifier("repositoryService")@AutowiredRepositoryService service;@AutowiredObjectMapper mapper;//2. 声明一个Logger,这个是static的方式,我比较习惯这么写。private final static Logger logger = LoggerFactory.getLogger(ActivityCreateSerivce.class);public String CreatModel(){ObjectNode editorNode = mapper.createObjectNode();editorNode.put("id", "canvas");editorNode.put("resourceId", "canvas");ObjectNode stencilSetNode = mapper.createObjectNode();stencilSetNode.put("namespace", "http://b3mn.org/stencilset/bpmn2.0#");editorNode.put("stencilset", stencilSetNode);Model modelData = service.newModel();ObjectNode modelObjectNode = mapper.createObjectNode();modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, "hello1111");modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);String description = "hello1111";modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, description);modelData.setMetaInfo(modelObjectNode.toString());modelData.setName("hello1111");modelData.setKey("12313123");try {//保存模型service.saveModel(modelData);service.addModelEditorSource(modelData.getId(), editorNode.toString().getBytes("utf-8"));return modelData.getId();}catch (Exception e){logger.error(e.getMessage());}return null;}public ObjectNode BySelectId(String modelId) {ObjectNode modelNode=null;try {Model model = service.getModel(modelId);if (model != null) {if (StringUtils.isNotEmpty(model.getMetaInfo())) {modelNode = (ObjectNode) mapper.readTree(model.getMetaInfo());} else {modelNode = mapper.createObjectNode();modelNode.put("MODEL_NAME", model.getName());}modelNode.put("MODEL_ID", model.getId());ObjectNode editorJsonNode = (ObjectNode)mapper.readTree(new String(service.getModelEditorSource(model.getId()), "utf-8"));modelNode.put("model", editorJsonNode);}}catch (Exception e){logger.error(e.getMessage());throw new ActivitiException("Error creating model JSON", e);}return modelNode;}public boolean ModelSave(ActivitiEnitiy activitiEnitiy){ try {Model model = service.getModel(activitiEnitiy.getModeid());ObjectNode modelJson = (ObjectNode) mapper.readTree(model.getMetaInfo());modelJson.put("MODEL_NAME", activitiEnitiy.getName());modelJson.put("MODEL_DESCRIPTION", activitiEnitiy.getDescription());model.setMetaInfo(modelJson.toString());model.setName(activitiEnitiy.getName());service.saveModel(model);service.addModelEditorSource(model.getId(), activitiEnitiy.getJson_xml().getBytes("utf-8"));InputStream svgStream = new ByteArrayInputStream(activitiEnitiy.getSvg_xml().getBytes("utf-8"));TranscoderInput input = new TranscoderInput(svgStream);PNGTranscoder transcoder = new PNGTranscoder();// Setup outputByteArrayOutputStream outStream = new ByteArrayOutputStream();TranscoderOutput output = new TranscoderOutput(outStream);// Do the transformationtranscoder.transcode(input, output);final byte[] result = outStream.toByteArray();service.addModelEditorSourceExtra(model.getId(), result);outStream.close();return true;} catch (Exception e) {logger.error("Error saving model", e);throw new ActivitiException("Error saving model", e);}finally {return false;}}public List<Model> selectList(){return service.createModelQuery().list();}public Boolean deploy(String modelID) throws IOException {Model model = service.getModel(modelID);byte[] modelEditorSource = service.getModelEditorSource(model.getId());if(modelEditorSource==null){return false;}try {JsonNode modelNode = new ObjectMapper().readTree(modelEditorSource);BpmnModel modelBmpn = new BpmnJsonConverter().convertToBpmnModel(modelNode);if (modelBmpn.getProcesses().size() == 0) {return false;}byte[] bpmnBytes = new BpmnXMLConverter().convertToXML(modelBmpn);String processName = model.getName() + ".bpmn20.xml";Deployment deploy = service.createDeployment().name(model.getName()).addString(processName, new String(bpmnBytes, "UTF-8")).deploy();model.setDeploymentId(deploy.getId());service.saveModel(model);return true;}catch (Exception e){logger.error(e.getMessage());return false;}}
}
@Service
public class RuntimeServiceImpl {@AutowiredRuntimeServiceImpl runtimeService;public ProcessInstance startProcess(String keyName){ProcessInstance processInstance = runtimeService.startProcess(keyName);return processInstance;}}
@Service
public class TaskServiceImpl {@Qualifier("taskService")@AutowiredTaskService taskService;public boolean run(String processId){Task task = taskService.createTaskQuery().processDefinitionId(processId).singleResult();if(task== null){return false;}taskService.complete(task.getId());return true;}
}
entity
@Data
@Accessors(chain = true)
public class ActivitiEnitiy {private String modeid;private String name;private String json_xml;private String svg_xml;private String description;
}
调整
在activiti-webapp 里有几个地方需要改一下
在editor-app里app-cfg.js
*/
'use strict';var ACTIVITI = ACTIVITI || {};ACTIVITI.CONFIG = {'contextRoot' : 'modeler/service',
};
在editor-app 里的configuration 里的 url-config.js
var KISBPM = KISBPM || {};var modelId1=null;
KISBPM.URL = {getModel: function(modelId) {modelId1=modelIdreturn ACTIVITI.CONFIG.contextRoot + '/model/' + modelId + '/json';},getStencilSet: function() {return ACTIVITI.CONFIG.contextRoot + '/editor/stencilset?version=' + Date.now();},putModel: function(modelId) {return ACTIVITI.CONFIG.contextRoot + '/model/' + modelId1+ '/save';}
};
效果是这样的
这篇关于activtiy 在线编辑器的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!