* [Improvement] Improvement the error message when batch delete workflow Co-authored-by: HomminLee <hommin84255@163.com>
This commit is contained in:
parent
36764b02e8
commit
e68395fa01
|
|
@ -638,29 +638,7 @@ public class ProcessDefinitionController extends BaseController {
|
|||
public Result batchDeleteProcessDefinitionByCodes(@ApiIgnore @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
|
||||
@ApiParam(name = "projectCode", value = "PROJECT_CODE", required = true) @PathVariable long projectCode,
|
||||
@RequestParam("codes") String codes) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
Set<String> deleteFailedCodeSet = new HashSet<>();
|
||||
if (!StringUtils.isEmpty(codes)) {
|
||||
String[] processDefinitionCodeArray = codes.split(",");
|
||||
for (String strProcessDefinitionCode : processDefinitionCodeArray) {
|
||||
long code = Long.parseLong(strProcessDefinitionCode);
|
||||
try {
|
||||
Map<String, Object> deleteResult = processDefinitionService.deleteProcessDefinitionByCode(loginUser, projectCode, code);
|
||||
if (!Status.SUCCESS.equals(deleteResult.get(Constants.STATUS))) {
|
||||
deleteFailedCodeSet.add((String) deleteResult.get(Constants.MSG));
|
||||
logger.error((String) deleteResult.get(Constants.MSG));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
deleteFailedCodeSet.add(MessageFormat.format(Status.DELETE_PROCESS_DEFINE_BY_CODES_ERROR.getMsg(), strProcessDefinitionCode));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!deleteFailedCodeSet.isEmpty()) {
|
||||
putMsg(result, BATCH_DELETE_PROCESS_DEFINE_BY_CODES_ERROR, String.join("\n", deleteFailedCodeSet));
|
||||
} else {
|
||||
putMsg(result, Status.SUCCESS);
|
||||
}
|
||||
Map<String, Object> result = processDefinitionService.batchDeleteProcessDefinitionByCodes(loginUser, projectCode, codes);
|
||||
return returnDataList(result);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -271,9 +271,12 @@ public enum Status {
|
|||
SCHEDULE_CRON_STATE_ONLINE(50023, "the status of schedule {0} is already online", "调度配置[{0}]已上线"),
|
||||
DELETE_SCHEDULE_CRON_BY_ID_ERROR(50024, "delete schedule by id error", "删除调度配置错误"),
|
||||
BATCH_DELETE_PROCESS_DEFINE_ERROR(50025, "batch delete process definition error", "批量删除工作流定义错误"),
|
||||
BATCH_DELETE_PROCESS_DEFINE_BY_CODES_ERROR(50026, "batch delete process definition by codes {0} error", "批量删除工作流定义[{0}]错误"),
|
||||
DELETE_PROCESS_DEFINE_BY_CODES_ERROR(50026, "delete process definition by codes {0} error", "删除工作流定义[{0}]错误"),
|
||||
TENANT_NOT_SUITABLE(50027, "there is not any tenant suitable, please choose a tenant available.", "没有合适的租户,请选择可用的租户"),
|
||||
BATCH_DELETE_PROCESS_DEFINE_BY_CODES_ERROR(50026, "batch delete process definition by codes error: {0}",
|
||||
"批量删除工作流定义错误: {0}"),
|
||||
DELETE_PROCESS_DEFINE_BY_CODES_ERROR(50026, "delete process definition by codes error: {0}",
|
||||
"删除工作流定义错误: {0}"),
|
||||
TENANT_NOT_SUITABLE(50027, "there is not any tenant suitable, please choose a tenant available.",
|
||||
"没有合适的租户,请选择可用的租户"),
|
||||
EXPORT_PROCESS_DEFINE_BY_ID_ERROR(50028, "export process definition by id error", "导出工作流定义错误"),
|
||||
BATCH_EXPORT_PROCESS_DEFINE_BY_IDS_ERROR(50028, "batch export process definition by ids error", "批量导出工作流定义错误"),
|
||||
IMPORT_PROCESS_DEFINE_ERROR(50029, "import process definition error", "导入工作流定义错误"),
|
||||
|
|
@ -304,6 +307,9 @@ public enum Status {
|
|||
DELETE_EDGE_ERROR(50055, "delete edge error", "删除工作流任务连接线错误"),
|
||||
NOT_SUPPORT_UPDATE_TASK_DEFINITION(50056, "task state does not support modification", "当前任务不支持修改"),
|
||||
NOT_SUPPORT_COPY_TASK_TYPE(50057, "task type [{0}] does not support copy", "不支持复制的任务类型[{0}]"),
|
||||
BATCH_EXECUTE_PROCESS_INSTANCE_ERROR(50058, "change process instance status error: {0}", "修改工作实例状态错误: {0}"),
|
||||
START_TASK_INSTANCE_ERROR(50059, "start task instance error", "运行任务流实例错误"),
|
||||
DELETE_PROCESS_DEFINE_ERROR(50060, "delete process definition [{0}] error: {1}", "删除工作流定义[{0}]错误: {1}"),
|
||||
HDFS_NOT_STARTUP(60001, "hdfs not startup", "hdfs未启用"),
|
||||
STORAGE_NOT_STARTUP(60002, "storage not startup", "存储未启用"),
|
||||
S3_CANNOT_RENAME(60003, "directory cannot be renamed", "S3无法重命名文件夹"),
|
||||
|
|
|
|||
|
|
@ -195,6 +195,18 @@ public interface ProcessDefinitionService {
|
|||
String name,
|
||||
long processDefinitionCode);
|
||||
|
||||
/**
|
||||
* batch delete process definition by code
|
||||
*
|
||||
* @param loginUser login user
|
||||
* @param projectCode project code
|
||||
* @param codes process definition codes
|
||||
* @return delete result code
|
||||
*/
|
||||
Map<String, Object> batchDeleteProcessDefinitionByCodes(User loginUser,
|
||||
long projectCode,
|
||||
String codes);
|
||||
|
||||
/**
|
||||
* delete process definition by code
|
||||
*
|
||||
|
|
|
|||
|
|
@ -720,6 +720,45 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
|
|||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Map<String, Object> batchDeleteProcessDefinitionByCodes(User loginUser, long projectCode, String codes) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
if (StringUtils.isEmpty(codes)) {
|
||||
logger.error("Parameter processDefinitionCodes is empty, projectCode is {}.", projectCode);
|
||||
putMsg(result, Status.PROCESS_DEFINITION_CODES_IS_EMPTY);
|
||||
return result;
|
||||
}
|
||||
|
||||
Set<Long> definitionCodes = Lists.newArrayList(codes.split(Constants.COMMA)).stream().map(Long::parseLong)
|
||||
.collect(Collectors.toSet());
|
||||
List<ProcessDefinition> processDefinitionList = processDefinitionMapper.queryByCodes(definitionCodes);
|
||||
Set<Long> queryCodes =
|
||||
processDefinitionList.stream().map(ProcessDefinition::getCode).collect(Collectors.toSet());
|
||||
// definitionCodes - queryCodes
|
||||
Set<Long> diffCode =
|
||||
definitionCodes.stream().filter(code -> !queryCodes.contains(code)).collect(Collectors.toSet());
|
||||
|
||||
if (!diffCode.isEmpty()) {
|
||||
logger.error("Process definition does not exist, processCodes:{}.",
|
||||
diffCode.stream().map(String::valueOf).collect(Collectors.joining(Constants.COMMA)));
|
||||
throw new ServiceException(Status.BATCH_DELETE_PROCESS_DEFINE_BY_CODES_ERROR,
|
||||
diffCode.stream().map(code -> code + "[process definition not exist]")
|
||||
.collect(Collectors.joining(Constants.COMMA))
|
||||
);
|
||||
}
|
||||
|
||||
for (ProcessDefinition process : processDefinitionList) {
|
||||
try {
|
||||
this.deleteProcessDefinitionByCode(loginUser, process.getCode());
|
||||
} catch (Exception e) {
|
||||
throw new ServiceException(Status.DELETE_PROCESS_DEFINE_ERROR, process.getName(), e.getMessage());
|
||||
}
|
||||
}
|
||||
putMsg(result, Status.SUCCESS);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Process definition want to delete whether used in other task, should throw exception when have be used.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -444,7 +444,6 @@ public class ProcessDefinitionServiceTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testReleaseProcessDefinition() {
|
||||
long projectCode = 1L;
|
||||
Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode));
|
||||
|
|
|
|||
Loading…
Reference in New Issue