BpmExtendJarController.java
5.43 KB
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
113
114
115
116
117
118
119
120
121
122
123
124
125
package com.hotent.runtime.controller;
import com.hotent.base.controller.BaseController;
import com.hotent.base.exception.MessagePassingException;
import com.hotent.base.groovy.IScript;
import com.hotent.base.groovy.IUserScript;
import com.hotent.base.model.CommonResult;
import com.hotent.base.util.BeanUtils;
import com.hotent.base.util.ExtendClassLoader;
import com.hotent.base.util.FileUtil;
import com.hotent.runtime.manager.BpmExtendJarManager;
import com.hotent.runtime.model.BpmExtendClass;
import com.hotent.runtime.model.BpmExtendJar;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import java.io.IOException;
import java.util.*;
import java.util.Map.Entry;
/**
* 扩展jar包管理模块 前端控制器
*
* @company 广州宏天软件股份有限公司
* @author 超级管理员
* @since 2021-01-19
*/
@RestController
@RequestMapping("/bpmExtendJar/v1/")
public class BpmExtendJarController extends BaseController<BpmExtendJarManager, BpmExtendJar> {
@RequestMapping(value = "resolutionJar", method = RequestMethod.POST, produces = { "application/json; charset=utf-8" })
@ApiOperation(value = "解析上传的jar包", httpMethod = "POST", notes = "解析上传的jar包")
public CommonResult<BpmExtendJar> resolutionJar(MultipartHttpServletRequest request,
@ApiParam(name="type",value="jar扩展包类型") @RequestParam(required = false) Integer type) throws Exception {
Map<String, MultipartFile> fileMaps = request.getFileMap();
Iterator<MultipartFile> it = fileMaps.values().iterator();
Integer jarType = 2;
if(request.getParameter("type") != null){
jarType = Integer.parseInt(request.getParameter("type"));
}
BpmExtendJar jarManage = new BpmExtendJar();
while (it.hasNext()) {
MultipartFile f = it.next();
String oriFileName = f.getOriginalFilename();
jarManage.setJarBytes(FileUtil.readByte(f.getInputStream()));
jarManage.setSize(Integer.valueOf((int) Math.round((double) f.getSize() / 1024)));
jarManage.setName(oriFileName);
jarManage.setType(jarType);
setJarClassList(jarManage);
}
return new CommonResult<BpmExtendJar>(true, "上传成功", jarManage);
}
@SuppressWarnings("rawtypes")
private void setJarClassList(BpmExtendJar jarManage) throws IOException {
Map<String, Class> resolutionJarClass = null;
try {
resolutionJarClass = ExtendClassLoader.resolutionJarClass(jarManage.getJarBytes(), jarManage.getType());
}catch (NullPointerException e){
throw new MessagePassingException("文件不合法");
}
if (BeanUtils.isNotEmpty(resolutionJarClass)) {
Set<String> simpleNmaes = new HashSet<>();
List<BpmExtendClass> addClassList = new ArrayList<>();
for (Iterator<Entry<String, Class>> iterator = resolutionJarClass.entrySet().iterator(); iterator.hasNext();) {
Entry<String, Class> next = iterator.next();
Class cls = next.getValue();
BpmExtendClass extendClass = new BpmExtendClass();
extendClass.setPath(cls.getName());
extendClass.setSimpleName(ExtendClassLoader.getSimpleName(cls.getName()));
simpleNmaes.add(extendClass.getSimpleName());
extendClass.setMd5(next.getKey());
if (IUserScript.class.isAssignableFrom(cls)) {
extendClass.setType("2");
} else if (IScript.class.isAssignableFrom(cls)) {
extendClass.setType("1");
}
addClassList.add(extendClass);
}
jarManage.setClassList(addClassList);
}
}
@RequestMapping(value = "saveJar", method = RequestMethod.POST, produces = { "application/json; charset=utf-8" })
@ApiOperation(value = "附件上传操作", httpMethod = "POST", notes = "附件上传操作")
public CommonResult<String> saveJar(@ApiParam(name = "jar", value = "jar包管理对象") @RequestBody BpmExtendJar jar)throws Exception {
return baseService.saveJar(jar);
}
@DeleteMapping("deleteById")
@ApiOperation("根据id删除")
public CommonResult<String> deleteById(@ApiParam(name = "id", value = "实体id") @RequestParam String id) {
baseService.remove(id);
return new CommonResult<>();
}
@GetMapping("getJarById")
@ApiOperation("根据id删除")
public BpmExtendJar getJarById(@ApiParam(name = "id", value = "实体id") @RequestParam String id) throws IOException {
BpmExtendJar byId = baseService.getById(id);
setJarClassList(byId);
return byId;
}
@RequestMapping(value = "publishJar", method = RequestMethod.GET, produces = { "application/json; charset=utf-8" })
@ApiOperation(value = "发布jar包将其中的脚本类注册到服务中", httpMethod = "GET", notes = "发布jar包将其中的脚本类注册到服务中")
public CommonResult<String> publishJar(@ApiParam(name = "jarId", value = "jar包Id") @RequestParam String jarId,
@ApiParam(name = "iscover", value = "是否覆盖同名class") @RequestParam Optional<Boolean> iscover)throws Exception {
return baseService.publishJar(jarId, iscover.orElse(false));
}
/**
* 根据类型查找对应的jar
* @param type 类型
* @return jar信息列表
*/
@RequestMapping(value = "getJarByType", method = RequestMethod.GET, produces = { "application/json; charset=utf-8" })
public List<BpmExtendJar> getJarByType(@ApiParam(name = "type", value = "jar包类型") @RequestParam(value="type") Integer type) {
return baseService.getJarByType(type);
}
}