前言
本博客是將modeler單獨(dú)出來(lái)和業(yè)務(wù)系統(tǒng)整合的方案,希望對(duì)使用activiti的童鞋有所幫助
文件整合
在src/main/resource中添加modeler配置文件
editor.html,plugins.xml,stencilset.json,ui.properties,ui.properties.alfresco
在src/main/webapp中添加modeler文件夾
文件夾中包括modeler中的api,diagram-viewer,,editor,,explorer,,libs文件夾
修改web.xml
<servlet >
<servlet-name> ExplorerRestletServlet</servlet-name >
<servlet-class> org.restlet.ext.servlet.ServerServlet</servlet-class >
<init-param>
<!-- Application class name -->
<param-name> org.restlet.application</param-name >
<param-value> com.isprint.ssf.controller.ExplorerRestApplication</param-value >
</init-param>
</servlet >
<servlet >
<servlet-name> RestletServlet</servlet-name >
<servlet-class> org.restlet.ext.servlet.ServerServlet</servlet-class >
<init-param>
<!-- Application class name -->
<param-name> org.restlet.application</param-name >
<param-value> org.activiti.rest.service.application.ActivitiRestServicesApplication </param-value>
</init-param>
</servlet >
<!-- Catch all service requests -->
<servlet-mapping>
<servlet-name> RestletServlet</servlet-name >
<url-pattern> /rest/*</ url-pattern>
</servlet-mapping >
<servlet-mapping>
<servlet-name> ExplorerRestletServlet</servlet-name >
<url-pattern> /modeler/service/*</url-pattern >
</servlet-mapping>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
封裝API
1,、添加ExplorerRestApplication 類
public class ExplorerRestApplication extends ActivitiRestApplication {
public ExplorerRestApplication() {
super();
}
/**
* Creates a root Restlet that will receive all incoming calls.
*/
@Override
public synchronized Restlet createInboundRoot() {
Router router = new Router(getContext());
router.attachDefault(DefaultResource.class);
ModelerServicesInit.attachResources(router);
JsonpFilter jsonpFilter = new JsonpFilter(getContext());
jsonpFilter.setNext(router);
return jsonpFilter;
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
2,、添加ModelController類,,完成流程創(chuàng)建,、部署、編輯,、導(dǎo)出,、刪除操作。
/**
* 流程模型控制器
*
* @author
*/
@Controller
@RequestMapping(value = "/model")
public class ModelController {
protected Logger logger = LoggerFactory.getLogger(getClass());
@Autowired
RepositoryService repositoryService;
@Autowired
ModelService modelService;
@RequestMapping(value = "list")
@ResponseBody
public Map<String, Object> modelList(ModelDto modelDto, HttpServletRequest request) {
return modelService.queryModel(modelDto);
}
/**
* 創(chuàng)建模型
*/
@RequestMapping("create")
public void create(ModelDto modelDto, HttpServletRequest request, HttpServletResponse response) {
try {
ObjectMapper objectMapper = new ObjectMapper();
ObjectNode editorNode = objectMapper.createObjectNode();
editorNode.put("id", "canvas");
editorNode.put("resourceId", "canvas");
ObjectNode stencilSetNode = objectMapper.createObjectNode();
stencilSetNode.put("namespace", "http:///stencilset/bpmn2.0#");
editorNode.put("stencilset", stencilSetNode);
Model modelData = repositoryService.newModel();
ObjectNode modelObjectNode = objectMapper.createObjectNode();
modelObjectNode.put(ModelDataJsonConstants.MODEL_NAME, modelDto.getName());
modelObjectNode.put(ModelDataJsonConstants.MODEL_REVISION, 1);
String description = StringUtils.defaultString(modelDto.getDescription());
modelObjectNode.put(ModelDataJsonConstants.MODEL_DESCRIPTION, description);
modelData.setMetaInfo(modelObjectNode.toString());
modelData.setName(modelDto.getName());
modelData.setKey(StringUtils.defaultString(modelDto.getKey()));
//保存模型
repositoryService.saveModel(modelData);
repositoryService.addModelEditorSource(modelData.getId(), editorNode.toString().getBytes("utf-8"));
response.sendRedirect(request.getContextPath() + "/modeler/service/editor?id=" + modelData.getId());
} catch (Exception e) {
logger.error("創(chuàng)建模型失?。?, e);
}
}
/**
* 根據(jù)Model部署流程
*/
@RequestMapping(value = "deploy/{modelId}")
@ResponseBody
public String deploy(@PathVariable("modelId") String modelId, RedirectAttributes redirectAttributes) {
try {
Model modelData = repositoryService.getModel(modelId);
ObjectNode modelNode = (ObjectNode) new ObjectMapper().readTree(repositoryService.getModelEditorSource(modelData.getId()));
byte[] bpmnBytes = null;
BpmnModel model = new BpmnJsonConverter().convertToBpmnModel(modelNode);
bpmnBytes = new BpmnXMLConverter().convertToXML(model);
String processName = modelData.getName() + ".bpmn20.xml";
repositoryService.createDeployment().name(modelData.getName()).addString(processName, new String(bpmnBytes,"UTF-8")).deploy();
//redirectAttributes.addFlashAttribute("message", "部署成功,,部署ID=" + deployment.getId());
} catch (Exception e) {
logger.error("根據(jù)模型部署流程失敗:modelId={}", modelId, e);
}
return "deployesuccess";
}
/**
* 導(dǎo)出model的xml文件
*/
@RequestMapping(value = "export/{modelId}")
public void export(@PathVariable("modelId") String modelId, HttpServletResponse response) {
try {
Model modelData = repositoryService.getModel(modelId);
BpmnJsonConverter jsonConverter = new BpmnJsonConverter();
JsonNode editorNode = new ObjectMapper().readTree(repositoryService.getModelEditorSource(modelData.getId()));
BpmnModel bpmnModel = jsonConverter.convertToBpmnModel(editorNode);
BpmnXMLConverter xmlConverter = new BpmnXMLConverter();
byte[] bpmnBytes = xmlConverter.convertToXML(bpmnModel);
ByteArrayInputStream in = new ByteArrayInputStream(bpmnBytes);
IOUtils.copy(in, response.getOutputStream());
String filename = bpmnModel.getMainProcess().getId() + ".bpmn20.xml";
response.setHeader("Content-Disposition", "attachment; filename=" + filename);
response.flushBuffer();
} catch (Exception e) {
logger.error("導(dǎo)出model的xml文件失?。簃odelId={}", modelId, e);
}
}
@RequestMapping(value = "delete/{modelId}")
@ResponseBody
public String delete(@PathVariable("modelId") String modelId) {
repositoryService.deleteModel(modelId);
return "deletesuccess";
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
3,、添加Service、Dao類
ModelService接口
public interface ModelService {
public Map<String,Object> queryModel(ModelDto modelDto);
}
Service實(shí)現(xiàn)
@Service
@Transactional
public class ModelServiceImpl implements ModelService {
public static final Logger logger = Logger
.getLogger(ModelServiceImpl.class);
@Autowired
private IModelDao modelDao;
public Map<String,Object> queryModel(ModelDto modelDto){
Map<String,Object> map = new HashMap<String,Object>();
Map<String,String> paramMap=new HashMap<String,String>();
if(StringUtils.isNotBlank(modelDto.getId())){
paramMap.put("id", modelDto.getId());
}
if(StringUtils.isNotBlank(modelDto.getKey())){
paramMap.put("key", modelDto.getKey());
}
if(StringUtils.isNotBlank(modelDto.getName())){
paramMap.put("name", modelDto.getName());
}
List<ModelDto> modelDtoList=modelDao.getModelByQuery(paramMap, modelDto.getPage(), modelDto.getRows());
map.put("total", modelDao.getModelCountByQuery(paramMap));
map.put("rows", modelDtoList);
return map;
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
Dao接口
import java.util.List;
import java.util.Map;
public interface IModelDao {
public List<ModelDto> getModelByQuery(Map<String,String> paramMap, int page, int rows);
public int getModelCountByQuery(Map<String,String> paramMap);
}
Dao實(shí)現(xiàn)
@Autowired
DirectlyDBService db;
public static final Logger log = Logger.getLogger(ModelDaoImpl.class);
@Override
public List<ModelDto> getModelByQuery(Map<String, String> paramMap,
int page, int rows) {
int firstRow;
int maxRow;
if (page > 1) {
firstRow = (page - 1) * rows + 1;
maxRow = page * rows;
} else {
firstRow = 1;
maxRow = firstRow * rows;
}
StringBuilder sb = new StringBuilder();
sb.append("select * from ( ");
sb.append(" select t.*,ROWNUM rn from (");
sb.append(" select * from ACT_RE_MODEL where 1=1 ");
if (paramMap.containsKey("id")) {
sb.append(" and id_ ='" + paramMap.get("id") + "'");
}
if (paramMap.containsKey("name")) {
sb.append(" and name_ like '%" + paramMap.get("name") + "%'");
}
if (paramMap.containsKey("key")) {
sb.append(" and key_ like '%" + paramMap.get("key") + "%'");
}
sb.append(" ORDER BY create_time_ DESC) t)");
sb.append(" where rn >=" + firstRow + " and rn<=" + maxRow);
List<ModelDto> modelDtoList = new ArrayList<ModelDto>();
try {
List<Map<String, Object>> list = db.listBySql(sb.toString());
for (Map<String, Object> dbMap : list) {
ModelDto modelDto = new ModelDto();
modelDto.setId(dbMap.get("ID_").toString());
modelDto.setName(dbMap.get("NAME_") == null ? "" : dbMap.get(
"NAME_").toString());
modelDto.setRev(dbMap.get("REV_") == null ? 0 : Integer
.parseInt(dbMap.get("REV_").toString()));
modelDto.setKey(dbMap.get("KEY_") == null ? "" : dbMap.get(
"KEY_").toString());
modelDto.setCategory(dbMap.get("CATEGORY_") == null ? ""
: dbMap.get("CATEGORY_").toString());
modelDto.setVersion(dbMap.get("VERSION_") == null ? 0 : Integer
.parseInt(dbMap.get("VERSION_").toString()));
modelDto.setMetaInfo(dbMap.get("META_INFO_") == null ? ""
: dbMap.get("META_INFO_").toString());
modelDto.setDeploymentId(dbMap.get("DEPLOYMENT_ID_") == null ? ""
: dbMap.get("DEPLOYMENT_ID_").toString());
modelDto.setEditorSourceValueId(dbMap
.get("EDITOR_SOURCE_VALUE_ID_") == null ? "" : dbMap
.get("EDITOR_SOURCE_VALUE_ID_").toString());
modelDto.setEditorSourceExtraValueId(dbMap
.get("EDITOR_SOURCE_EXTRA_VALUE_ID_") == null ? ""
: dbMap.get("EDITOR_SOURCE_EXTRA_VALUE_ID_").toString());
modelDto.setTenantId(dbMap.get("TENANT_ID_") == null ? ""
: dbMap.get("TENANT_ID_").toString());
modelDto.setCreateTime(dbMap.get("CREATE_TIME_") == null ? ""
: dbMap.get("CREATE_TIME_").toString());
modelDto.setLastUpdateTime(dbMap.get("LAST_UPDATE_TIME_") == null ? ""
:dbMap.get("LAST_UPDATE_TIME_").toString());
modelDtoList.add(modelDto);
}
} catch (Exception e) {
log.error("ModelDao-getModelByQuery", e);
}
return modelDtoList;
}
@Override
public int getModelCountByQuery(Map<String, String> paramMap) {
StringBuilder sb = new StringBuilder();
sb.append("select count(*) as MODELCOUNT from ( ");
sb.append(" select t.* from (");
sb.append(" select * from ACT_RE_MODEL where 1=1 ");
if (paramMap.containsKey("id")) {
sb.append(" and id_ ='" + paramMap.get("id") + "'");
}
if (paramMap.containsKey("name")) {
sb.append(" and name_ like '%" + paramMap.get("name") + "%'");
}
if (paramMap.containsKey("key")) {
sb.append(" and key_ like '%" + paramMap.get("key") + "%'");
}
sb.append(" ORDER BY id_ DESC) t)");
System.out.println(sb);
List<Map<String, Object>> list = db.listBySql(sb.toString());
if (list != null && !list.isEmpty()) {
Map<String, Object> listMap = list.get(0);
return Integer.valueOf(listMap.get("MODELCOUNT").toString())
.intValue();
} else {
return 0;
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
總結(jié)
通過上面的操作之后,,就已經(jīng)準(zhǔn)備好Modeler使用的環(huán)境了,,如果業(yè)務(wù)系統(tǒng)想集成此流程設(shè)計(jì)器的話,就需要調(diào)用提供的方法即可,。
|