当前位置:   article > 正文

springboot集成activity6.0.0_activiti-app中复制用户任务怎么节点id是一样的

activiti-app中复制用户任务怎么节点id是一样的

个人博客地址:www.wzbjsz.cn

在线浏览地址:activiti.wzbjsz.cn

什么是工作流?

工作流(Workflow),就是通过计算机对业务流程自动化执行管理。它主要解决的是“使在多个参与者之间按照某种预定义的规则自动进行传递文档、信息或任务的过程,从而实现某个预期的业务目标,或者促使此目标的实现”。

什么是Activiti?

Alfresco软件在2010年5月17日宣布Activiti业务流程管理(BPM)开源项目的正式启动,其首席架构师由业务流程管理BPM的专家 Tom Baeyens担任,Tom Baeyens就是原来jbpm的架构师,而jbpm是一个非常有名的工作流引擎,当然activiti也是一个工作流引擎。

Activiti是一个工作流引擎, activiti可以将业务系统中复杂的业务流程抽取出来,使用专门的建模语言(BPMN2.0)进行定义,业务系统按照预先定义的流程进行执行,实现了业务系统的业务流程由activiti进行管理,减少业务系统由于流程变更进行系统升级改造的工作量,从而提高系统的健壮性,同时也减少了系统开发维护成本。

什么是BPMN?

BPMN(Business Process Model And Notation)- 业务流程模型和符号 是由BPMI(Business Process Management Initiative)开发的一套标准的业务流程建模符号,使用BPMN提供的符号可以创建业务流程。 2004年5月发布了BPMN1.0规范.BPMI于2005年9月并入OMG(The Object Management Group对象管理组织)组织。OMG于2011年1月发布BPMN2.0的最终版本。

 

具体发展历史如下:


BPMN 是目前被各 BPM 厂商广泛接受的 BPM 标准。Activiti 就是使用 BPMN 2.0 进行流程建模、流程执行管理,它包括很多的建模符号,比如:

Event 用一个圆圈表示,它是流程中运行过程中发生的事情。


活动用圆角矩形表示,一个流程由一个活动或多个活动组成

 

一个bpmn图形的例子:

Bpmn图形其实是通过xml表示业务流程,上边的.bpmn文件使用文本编辑器打开:

一:在项目pom.xml文件中添加activity依赖。

  1. <dependency>
  2. <groupId>org.activiti</groupId>
  3. <artifactId>activiti-spring-boot-starter-basic</artifactId>
  4. <version>6.0.0</version>
  5. </dependency>

二:修改启动类。

@SpringBootApplication(exclude={org.activiti.spring.boot.SecurityAutoConfiguration.class})

三:流程文件。
在src/main/java/resources目录下新建processes目录,并在该目录下新增一个业务流程文件(默认以.bpmn20.xml或.bpmn为后缀名)(activity默认校验resources下的processes文件夹里的流程文件,如果没有processes目录并且目录下没有流程文件会报错class path resource [processes/] cannot be resolved to URL because it does not exist),
可以在配置文件中配置spring.activiti.check-process-definitions=false,设置为不校验,这样就不会报错。
四:修改activity默认的id生成策略。
1.activiti默认的ID生成策略在高并发场景下会出现ID重复的情况,因此在高并发场景下建议采用UUID的策略。
2.传统的spring在配置文件中添加idGenerator属性:

  1. <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
  2. <!-- UUID作为主键生成策略 -->
  3. <property name="idGenerator" ref="idGenerator" />
  4. </bean>

3.springboot中在配置类中修改idGenerator。
需要写一个类实现IdGenerator,并重写getNextId()方法;
activity也内置了一个实现类org.activiti.engine.impl.persistence.StrongUuidGenerator,生成的uuid是带'-'的

  1. package com.mycompany.myapp.config;
  2. import org.activiti.spring.SpringProcessEngineConfiguration;
  3. import org.activiti.spring.boot.ProcessEngineConfigurationConfigurer;
  4. import org.springframework.context.annotation.Configuration;
  5. import com.mycompany.myapp.utils.idGenerator;
  6. /**
  7. * @author www.wzbjsz.cn
  8. * @date 2019-01-09 10:26:47
  9. */
  10. @Configuration
  11. public class ActivitiConfig implements ProcessEngineConfigurationConfigurer {
  12. @Override
  13. public void configure(SpringProcessEngineConfiguration springProcessEngineConfiguration) {
  14. springProcessEngineConfiguration.setIdGenerator(new idGenerator());
  15. }
  16. }
  1. package com.mycompany.myapp.utils;
  2. import java.util.UUID;
  3. import org.activiti.engine.impl.cfg.IdGenerator;
  4. /**
  5. * @author www.wzbjsz.cn
  6. * @date 2019-01-09 10:47:59
  7. */
  8. public class idGenerator implements IdGenerator{
  9. /**
  10. * 封装JDK自带的UUID, 通过Random数字生成, 中间无-分割.
  11. */
  12. public static String uuid() {
  13. return UUID.randomUUID().toString().replaceAll("-", "");
  14. }
  15. /**
  16. * Activiti ID 生成
  17. */
  18. @Override
  19. public String getNextId() {
  20. return IdGen.uuid();
  21. }
  22. }

五:配置文件属性:
1.spring.activiti.database-schema-update

spring.activiti.database-schema-update=true

databaseSchemaUpdate配置项可以设置流程引擎启动和关闭时数据库执行的策略。 databaseSchemaUpdate有以下四个值:

  1. falsefalse为默认值,设置为该值后,Activiti在启动时,会对比数据库表中保存的版本,如果版本不匹配时,将在启动时抛出异常。
  2. true:设置为该值后,Activiti会对数据库中所有的表进行更新,如果表不存在,则Activiti会自动创建。
  3. create-drop:Activiti启动时,会执行数据库表的创建操作,在Activiti关闭时,执行数据库表的删除操作。
  4. drop-create:Activiti启动时,执行数据库表的删除操作在Activiti关闭时,会执行数据库表的创建操作。

设置为true后启动应用,会在数据库里创建28张表,表创建好之后停止应用,设置为false,每次应用启动不检查Activiti数据表是否存在及版本号是否匹配,以提升应用启动速度。
2.spring.activiti.history-level

  1. #保存历史数据级别设置为full最高级别,便于历史数据的追溯
  2. spring.activiti.history-level=full

对于历史数据,保存到何种粒度,Activiti提供了history-level属性对其进行配置。history-level属性有点像log4j的日志输出级别,该属性有以下四个值:

  1. none:不保存任何的历史数据,因此,在流程执行过程中,这是最高效的。
  2. activity:级别高于none,保存流程实例与流程行为,其他数据不保存。
  3. audit:除activity级别会保存的数据外,还会保存全部的流程任务及其属性。audit为history的默认值。
  4. full:保存历史数据的最高级别,除了会保存audit级别的数据外,还会保存其他全部流程相关的细节数据,包括一些流程参数等。

3.spring.activiti.check-process-definitions

  1. #关闭activiti自动部署(使用流程设计器部署,不使用具体文件访问方式)
  2. spring.activiti.check-process-definitions=false

六:集成在线流程设计器Activiti Modeler。
1.pom文件添加activiti-modeler依赖。

  1. <!-- https://mvnrepository.com/artifact/org.activiti/activiti-modeler -->
  2. <dependency>
  3. <groupId>org.activiti</groupId>
  4. <artifactId>activiti-modeler</artifactId>
  5. <version>5.22.0</version>
  6. <exclusions>
  7. <exclusion>
  8. <groupId>org.activiti</groupId>
  9. <artifactId>activiti-bpmn-model</artifactId>
  10. </exclusion>
  11. </exclusions>
  12. </dependency>

2.下载activiti5.22.0源码https://github.com/Activiti/Activiti/tree/activiti-5.22.0
3.复制Activiti 5.22.0中Activiti\modules\activiti-webapp-explorer2\src\main\webapp中的diagram-viewer、editor-app两个文件夹和modeler.html文件到Spring Boot项目resources目录下的static文件夹下。

image.png

 

image.png


4.修改resource/static/editor-app/app-cfg.js。

image.png


改为:

 

  1. var ACTIVITI = ACTIVITI || {};
  2. ACTIVITI.CONFIG = {
  3. 'contextRoot' : '/service',
  4. };

5.复制Activiti\modules\activiti-webapp-explorer2\src\main\resources中的stencilset.json文件到Spring Boot项目中的resources目录下,activiti自带是英文的。
6.将Activiti 5.22.0源码中activiti-modeler中的下列3个java文件复制到自己的项目中,并在三个java类上添加注解@RequestMapping("/service")。(/service与上面app-cfg.js中保持一致)

 

image.png

 

image.png

 

7.修改ModelSaveRestResource.java文件:

  1. /* Licensed under the Apache License, Version 2.0 (the "License");
  2. * you may not use this file except in compliance with the License.
  3. * You may obtain a copy of the License at
  4. *
  5. * http://www.apache.org/licenses/LICENSE-2.0
  6. *
  7. * Unless required by applicable law or agreed to in writing, software
  8. * distributed under the License is distributed on an "AS IS" BASIS,
  9. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. * See the License for the specific language governing permissions and
  11. * limitations under the License.
  12. */
  13. package com.mycompany.myapp.modeler.editor.model;
  14. import java.io.ByteArrayInputStream;
  15. import java.io.ByteArrayOutputStream;
  16. import java.io.InputStream;
  17. import org.activiti.editor.constants.ModelDataJsonConstants;
  18. import org.activiti.engine.ActivitiException;
  19. import org.activiti.engine.RepositoryService;
  20. import org.activiti.engine.repository.Model;
  21. import org.apache.batik.transcoder.TranscoderInput;
  22. import org.apache.batik.transcoder.TranscoderOutput;
  23. import org.apache.batik.transcoder.image.PNGTranscoder;
  24. import org.slf4j.Logger;
  25. import org.slf4j.LoggerFactory;
  26. import org.springframework.beans.factory.annotation.Autowired;
  27. import org.springframework.http.HttpStatus;
  28. import org.springframework.web.bind.annotation.PathVariable;
  29. import org.springframework.web.bind.annotation.RequestMapping;
  30. import org.springframework.web.bind.annotation.RequestMethod;
  31. import org.springframework.web.bind.annotation.ResponseStatus;
  32. import org.springframework.web.bind.annotation.RestController;
  33. import com.fasterxml.jackson.databind.ObjectMapper;
  34. import com.fasterxml.jackson.databind.node.ObjectNode;
  35. /**
  36. * @author Tijs Rademakers
  37. */
  38. @RestController
  39. @RequestMapping("/service")
  40. public class ModelSaveRestResource implements ModelDataJsonConstants {
  41. protected static final Logger LOGGER = LoggerFactory.getLogger(ModelSaveRestResource.class);
  42. @Autowired
  43. private RepositoryService repositoryService;
  44. @Autowired
  45. private ObjectMapper objectMapper;
  46. @RequestMapping(value="/model/{modelId}/save", method = RequestMethod.PUT)
  47. @ResponseStatus(value = HttpStatus.OK)
  48. public void saveModel(@PathVariable String modelId
  49. , String name, String description
  50. , String json_xml, String svg_xml) {
  51. try {
  52. Model model = repositoryService.getModel(modelId);
  53. ObjectNode modelJson = (ObjectNode) objectMapper.readTree(model.getMetaInfo());
  54. modelJson.put(MODEL_NAME, name);
  55. modelJson.put(MODEL_DESCRIPTION, description);
  56. model.setMetaInfo(modelJson.toString());
  57. model.setName(name);
  58. repositoryService.saveModel(model);
  59. repositoryService.addModelEditorSource(model.getId(), json_xml.getBytes("utf-8"));
  60. InputStream svgStream = new ByteArrayInputStream(svg_xml.getBytes("utf-8"));
  61. TranscoderInput input = new TranscoderInput(svgStream);
  62. PNGTranscoder transcoder = new PNGTranscoder();
  63. // Setup output
  64. ByteArrayOutputStream outStream = new ByteArrayOutputStream();
  65. TranscoderOutput output = new TranscoderOutput(outStream);
  66. // Do the transformation
  67. transcoder.transcode(input, output);
  68. final byte[] result = outStream.toByteArray();
  69. repositoryService.addModelEditorSourceExtra(model.getId(), result);
  70. outStream.close();
  71. } catch (Exception e) {
  72. LOGGER.error("Error saving model", e);
  73. throw new ActivitiException("Error saving model", e);
  74. }
  75. }
  76. }

8.测试创建模型。

  1. /**
  2. * 新建一个空模型
  3. * @return
  4. * @throws UnsupportedEncodingException
  5. */
  6. @GetMapping("/create")
  7. public void newModel(HttpServletRequest request,HttpServletResponse response) throws Exception {
  8. //初始化一个空模型
  9. Model model = repositoryService.newModel();
  10. //设置一些默认信息
  11. String name = "new-process";
  12. String description = "";
  13. int revision = 1;
  14. String key = "process";
  15. ObjectNode modelNode = objectMapper.createObjectNode();
  16. modelNode.put(ModelDataJsonConstants.MODEL_NAME, name);
  17. modelNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, description);
  18. modelNode.put(ModelDataJsonConstants.MODEL_REVISION, revision);
  19. model.setName(name);
  20. model.setKey(key);
  21. model.setMetaInfo(modelNode.toString());
  22. repositoryService.saveModel(model);
  23. String id = model.getId();
  24. //完善ModelEditorSource
  25. ObjectNode editorNode = objectMapper.createObjectNode();
  26. editorNode.put("id", "canvas");
  27. editorNode.put("resourceId", "canvas");
  28. ObjectNode stencilSetNode = objectMapper.createObjectNode();
  29. stencilSetNode.put("namespace",
  30. "http://b3mn.org/stencilset/bpmn2.0#");
  31. editorNode.set("stencilset", stencilSetNode);
  32. repositoryService.addModelEditorSource(id,editorNode.toString().getBytes("utf-8"));
  33. response.sendRedirect("/modeler.html?modelId="+id);
  34. }

9.请求创建模型接口后,显示如下页面表示成功:

image.png


10.去掉Activiti Afresco的logo标题栏,并且把样式上的空白栏去掉。
1)修改modeler.html中的以下内容,注意不要把该文本删除,建议加style=”display:none”,删除后其会造成底层下的一些内容有40个像数的东西显示不出来,也可以直接删除掉。

 

  1. <div style="display:none" class="navbar navbar-fixed-top navbar-inverse" role="navigation" id="main-header">
  2. <div class="navbar-header">
  3. <a href="" ng-click="backToLanding()" class="navbar-brand"
  4. title="{{'GENERAL.MAIN-TITLE' | translate}}"><span
  5. class="sr-only">{{'GENERAL.MAIN-TITLE' | translate}}</span></a>
  6. </div>
  7. </div>

2)在editor-app/css/style-common.css中,把以下样式的padding-top部分改为0px;

  1. .wrapper.full {
  2. padding: 0px 0px 0px 0px;
  3. overflow: hidden;
  4. max-width: 100%;
  5. min-width: 100%;
  6. }

11.保存模型如果报错获取不到参数。(http://www.wzbjsz.cn),添加过滤器:

  1. package com.mycompany.myapp.config;
  2. import javax.servlet.annotation.WebFilter;
  3. import org.springframework.core.annotation.Order;
  4. import org.springframework.stereotype.Component;
  5. import org.springframework.web.filter.HttpPutFormContentFilter;
  6. /**
  7. * @author www.wzbjsz.cn
  8. * @date 2019-01-20 15:47:39
  9. */
  10. @Component
  11. @WebFilter(urlPatterns = "/*", filterName = "putFilter")
  12. @Order(Integer.MIN_VALUE)
  13. public class PutFilter extends HttpPutFormContentFilter {
  14. }

七.modeler相关方法的封装。

  1. package com.lhtc.jv.vo;
  2. import java.io.Serializable;
  3. import javax.validation.constraints.NotNull;
  4. import lombok.Data;
  5. /**
  6. * @author www.wzbjsz.cn
  7. * @date 2019-01-21 14:38:54
  8. */
  9. @Data
  10. public class ActModelVO implements Serializable{
  11. /**
  12. *
  13. */
  14. private static final long serialVersionUID = 1L;
  15. private String id;//模型id
  16. @NotNull
  17. private String name;//模型名称
  18. @NotNull
  19. private String key;//模型标识
  20. private String description;//模型描述
  21. private String category;//模型分类
  22. }
  1. package com.lhtc.jv.service;
  2. import java.io.ByteArrayInputStream;
  3. import java.io.IOException;
  4. import java.io.UnsupportedEncodingException;
  5. import java.util.List;
  6. import javax.servlet.http.HttpServletResponse;
  7. import org.activiti.bpmn.converter.BpmnXMLConverter;
  8. import org.activiti.bpmn.model.BpmnModel;
  9. import org.activiti.editor.constants.ModelDataJsonConstants;
  10. import org.activiti.editor.language.json.converter.BpmnJsonConverter;
  11. import org.activiti.engine.RepositoryService;
  12. import org.activiti.engine.repository.Deployment;
  13. import org.activiti.engine.repository.Model;
  14. import org.activiti.engine.repository.ModelQuery;
  15. import org.activiti.engine.repository.ProcessDefinition;
  16. import org.apache.commons.io.IOUtils;
  17. import org.springframework.beans.factory.annotation.Autowired;
  18. import org.springframework.data.domain.Page;
  19. import org.springframework.data.domain.PageImpl;
  20. import org.springframework.data.domain.Pageable;
  21. import org.springframework.stereotype.Service;
  22. import org.springframework.transaction.annotation.Transactional;
  23. import com.fasterxml.jackson.databind.ObjectMapper;
  24. import com.fasterxml.jackson.databind.node.ObjectNode;
  25. import com.lhtc.jv.vo.ActModelVO;
  26. /**
  27. * 流程模型service
  28. * @author www.wzbjsz.cn
  29. * @date 2019-01-21 11:28:38
  30. */
  31. @Service
  32. @Transactional(readOnly = true)
  33. public class ActModelService {
  34. @Autowired
  35. private RepositoryService repositoryService;
  36. @Autowired
  37. private ObjectMapper objectMapper;
  38. /**
  39. * 创建模型
  40. * @param actModelVO
  41. * @return
  42. * @throws UnsupportedEncodingException
  43. */
  44. @Transactional(readOnly = false)
  45. public Model createModel(ActModelVO actModelVO) throws UnsupportedEncodingException{
  46. //初始化一个空模型
  47. Model model = repositoryService.newModel();
  48. model.setKey(actModelVO.getKey());
  49. model.setName(actModelVO.getName());
  50. model.setCategory(actModelVO.getCategory());
  51. model.setVersion(Integer.parseInt(String.valueOf(repositoryService.createModelQuery().modelKey(model.getKey()).count()+1)));
  52. ObjectNode modelNode = objectMapper.createObjectNode();
  53. modelNode.put(ModelDataJsonConstants.MODEL_NAME, model.getName());
  54. modelNode.put(ModelDataJsonConstants.MODEL_REVISION, model.getVersion());
  55. modelNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, actModelVO.getDescription());
  56. model.setMetaInfo(modelNode.toString());
  57. repositoryService.saveModel(model);
  58. //完善ModelEditorSource
  59. ObjectNode editorNode = objectMapper.createObjectNode();
  60. editorNode.put("id", "canvas");
  61. editorNode.put("resourceId", "canvas");
  62. ObjectNode stencilSetNode = objectMapper.createObjectNode();
  63. stencilSetNode.put("namespace","http://b3mn.org/stencilset/bpmn2.0#");
  64. editorNode.set("stencilset", stencilSetNode);
  65. repositoryService.addModelEditorSource(model.getId(),editorNode.toString().getBytes("utf-8"));
  66. return model;
  67. }
  68. /**
  69. * 根据模型id查询
  70. * @param modelId 模型id
  71. * @return
  72. */
  73. public Model getModelById(String modelId){
  74. return repositoryService.getModel(modelId);
  75. }
  76. /**
  77. * 查询模型列表
  78. * @param pageable
  79. * @return
  80. */
  81. public Page<Model> getAllModels(Pageable pageable){
  82. ModelQuery modelQuery = repositoryService.createModelQuery().latestVersion().orderByLastUpdateTime().desc();
  83. return new PageImpl<>(modelQuery.listPage(pageable.getPageNumber()*pageable.getPageSize(), pageable.getPageSize()), pageable, modelQuery.count());
  84. }
  85. /**
  86. * 部署模型
  87. * @param modelId 模型id
  88. * @return
  89. * @throws IOException
  90. */
  91. @Transactional(readOnly = false)
  92. public List<ProcessDefinition> deployModel(String modelId) throws IOException{
  93. Model modelData = repositoryService.getModel(modelId);
  94. BpmnJsonConverter jsonConverter = new BpmnJsonConverter();
  95. ObjectNode editorNode = (ObjectNode) new ObjectMapper().readTree(repositoryService.getModelEditorSource(modelData.getId()));
  96. BpmnModel bpmnModel = jsonConverter.convertToBpmnModel(editorNode);
  97. BpmnXMLConverter xmlConverter = new BpmnXMLConverter();
  98. byte[] bpmnBytes = xmlConverter.convertToXML(bpmnModel);
  99. ByteArrayInputStream in = new ByteArrayInputStream(bpmnBytes);
  100. Deployment deployment = repositoryService.createDeployment().name(modelData.getName())
  101. .addInputStream(modelData.getKey()+".bpmn20.xml", in).enableDuplicateFiltering().deploy();
  102. return repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).list();
  103. }
  104. /**
  105. * 删除模型
  106. * @param modelId 模型id
  107. */
  108. @Transactional(readOnly = false)
  109. public void deleteModel(String modelId){
  110. repositoryService.deleteModel(modelId);
  111. }
  112. /**
  113. * 导出模型xml文件
  114. * @param modelId 模型id
  115. * @param response HttpServletResponse
  116. * @throws IOException
  117. */
  118. public void exportModel(String modelId, HttpServletResponse response) throws IOException{
  119. Model modelData = repositoryService.getModel(modelId);
  120. BpmnJsonConverter jsonConverter = new BpmnJsonConverter();
  121. ObjectNode editorNode = (ObjectNode) new ObjectMapper().readTree(repositoryService.getModelEditorSource(modelData.getId()));
  122. BpmnModel bpmnModel = jsonConverter.convertToBpmnModel(editorNode);
  123. BpmnXMLConverter xmlConverter = new BpmnXMLConverter();
  124. byte[] bpmnBytes = xmlConverter.convertToXML(bpmnModel);
  125. ByteArrayInputStream in = new ByteArrayInputStream(bpmnBytes);
  126. IOUtils.copy(in, response.getOutputStream());
  127. String filename = bpmnModel.getMainProcess().getId() + ".bpmn20.xml";
  128. response.setHeader("Content-Disposition", "attachment; filename=" + java.net.URLEncoder.encode(filename, "UTF-8"));
  129. response.flushBuffer();
  130. }
  131. }
  1. package com.lhtc.jv.web.rest.activiti;
  2. import java.io.IOException;
  3. import java.io.UnsupportedEncodingException;
  4. import java.net.URI;
  5. import java.net.URISyntaxException;
  6. import java.util.List;
  7. import java.util.Optional;
  8. import javax.servlet.http.HttpServletResponse;
  9. import javax.validation.Valid;
  10. import org.activiti.engine.repository.Model;
  11. import org.activiti.engine.repository.ProcessDefinition;
  12. import org.slf4j.Logger;
  13. import org.slf4j.LoggerFactory;
  14. import org.springframework.beans.factory.annotation.Autowired;
  15. import org.springframework.data.domain.Page;
  16. import org.springframework.data.domain.Pageable;
  17. import org.springframework.http.HttpHeaders;
  18. import org.springframework.http.HttpStatus;
  19. import org.springframework.http.ResponseEntity;
  20. import org.springframework.util.CollectionUtils;
  21. import org.springframework.web.bind.annotation.DeleteMapping;
  22. import org.springframework.web.bind.annotation.GetMapping;
  23. import org.springframework.web.bind.annotation.PathVariable;
  24. import org.springframework.web.bind.annotation.PostMapping;
  25. import org.springframework.web.bind.annotation.PutMapping;
  26. import org.springframework.web.bind.annotation.RequestBody;
  27. import org.springframework.web.bind.annotation.RequestMapping;
  28. import org.springframework.web.bind.annotation.RequestParam;
  29. import org.springframework.web.bind.annotation.RestController;
  30. import com.lhtc.jv.service.ActModelService;
  31. import com.lhtc.jv.vo.ActModelVO;
  32. import com.lhtc.jv.web.rest.util.HeaderUtil;
  33. import com.lhtc.jv.web.rest.util.PaginationUtil;
  34. import io.github.jhipster.web.util.ResponseUtil;
  35. /**
  36. * 流程模型controller
  37. * @author www.wzbjsz.cn
  38. * @date 2019-01-21 13:39:47
  39. */
  40. @RestController
  41. @RequestMapping("/api")
  42. public class ActModelResource {
  43. private final Logger log = LoggerFactory.getLogger(ActModelResource.class);
  44. private static final String ENTITY_NAME = "model";
  45. @Autowired
  46. private ActModelService actModelService;
  47. /**
  48. * 创建模型
  49. * @param actModelVO
  50. * @return the ResponseEntity with status 201 (Created) and with body the new model
  51. * @throws UnsupportedEncodingException
  52. * @throws URISyntaxException if the Location URI syntax is incorrect
  53. */
  54. @PostMapping("/models")
  55. public ResponseEntity<Model> createModel(@Valid @RequestBody ActModelVO actModelVO) throws UnsupportedEncodingException, URISyntaxException{
  56. log.debug("REST request to save Model : {}", actModelVO);
  57. Model result = actModelService.createModel(actModelVO);
  58. return ResponseEntity.created(new URI("/act/models/" + result.getId()))
  59. .headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString()))
  60. .body(result);
  61. }
  62. /**
  63. * 根据模型id查询
  64. * @param modelId 模型id
  65. * @return
  66. */
  67. @GetMapping("/models/{modelId}")
  68. public ResponseEntity<Model> getModel(@PathVariable String modelId){
  69. log.debug("REST request to get Model : {}", modelId);
  70. return ResponseUtil.wrapOrNotFound(Optional.ofNullable(actModelService.getModelById(modelId)));
  71. }
  72. /**
  73. * 查询模型列表
  74. * @param pageable the pagination information
  75. * @return the ResponseEntity with status 200 (OK) and with body all models
  76. */
  77. @GetMapping("/models")
  78. public ResponseEntity<List<Model>> getAllModels(Pageable pageable) {
  79. final Page<Model> page = actModelService.getAllModels(pageable);
  80. HttpHeaders headers = PaginationUtil.generatePaginationHttpHeaders(page, "/act/models");
  81. return new ResponseEntity<>(page.getContent(), headers, HttpStatus.OK);
  82. }
  83. /**
  84. * 部署模型
  85. * @param modelId 模型id
  86. * @return
  87. */
  88. @PutMapping("/models/deploy")
  89. public ResponseEntity<Void> deployModel(@RequestBody ActModelVO actModelVO){
  90. String modelId = actModelVO.getId();
  91. log.debug("REST request to deploy Model : {}", modelId);
  92. try {
  93. List<ProcessDefinition> processDefinitions = actModelService.deployModel(modelId);
  94. if(!CollectionUtils.isEmpty(processDefinitions)){
  95. return ResponseEntity.ok().headers(HeaderUtil.createAlert("A " + ENTITY_NAME + " is deployed with identifier " + modelId, modelId)).build();
  96. }
  97. } catch (Exception e) {
  98. e.printStackTrace();
  99. }
  100. return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).headers(HeaderUtil.createFailureAlert(ENTITY_NAME, modelId,"A " + ENTITY_NAME + " failed to deploy with identifier " + modelId)).build();
  101. }
  102. /**
  103. * 删除模型
  104. * @param modelId 模型id
  105. * @return
  106. */
  107. @DeleteMapping("/models/{modelId}")
  108. public ResponseEntity<Void> deleteModel(@PathVariable String modelId) {
  109. log.debug("REST request to delete Model: {}", modelId);
  110. actModelService.deleteModel(modelId);
  111. return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(ENTITY_NAME, modelId)).build();
  112. }
  113. /**
  114. * 导出模型xml文件
  115. * @param modelId 模型id
  116. * @param response HttpServletResponse
  117. * @throws IOException
  118. */
  119. @GetMapping("/models/export")
  120. public void exportModel(@RequestParam("modelId")String modelId, HttpServletResponse response) throws IOException{
  121. actModelService.exportModel(modelId, response);
  122. }
  123. }


 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/703890
推荐阅读
相关标签
  

闽ICP备14008679号