|
|
|
@ -261,43 +261,24 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
|
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
if (checkDescriptionLength(description)) { |
|
|
|
|
putMsg(result, Status.DESCRIPTION_TOO_LONG_ERROR); |
|
|
|
|
return result; |
|
|
|
|
throw new ServiceException(Status.DESCRIPTION_TOO_LONG_ERROR); |
|
|
|
|
} |
|
|
|
|
// check whether the new process define name exist
|
|
|
|
|
ProcessDefinition definition = processDefinitionMapper.verifyByDefineName(project.getCode(), name); |
|
|
|
|
if (definition != null) { |
|
|
|
|
putMsg(result, Status.PROCESS_DEFINITION_NAME_EXIST, name); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
List<TaskDefinitionLog> taskDefinitionLogs = JSONUtils.toList(taskDefinitionJson, TaskDefinitionLog.class); |
|
|
|
|
Map<String, Object> checkTaskDefinitions = checkTaskDefinitionList(taskDefinitionLogs, taskDefinitionJson); |
|
|
|
|
if (checkTaskDefinitions.get(Constants.STATUS) != Status.SUCCESS) { |
|
|
|
|
return checkTaskDefinitions; |
|
|
|
|
} |
|
|
|
|
List<ProcessTaskRelationLog> taskRelationList = |
|
|
|
|
JSONUtils.toList(taskRelationJson, ProcessTaskRelationLog.class); |
|
|
|
|
Map<String, Object> checkRelationJson = |
|
|
|
|
checkTaskRelationList(taskRelationList, taskRelationJson, taskDefinitionLogs); |
|
|
|
|
if (checkRelationJson.get(Constants.STATUS) != Status.SUCCESS) { |
|
|
|
|
return checkRelationJson; |
|
|
|
|
throw new ServiceException(Status.PROCESS_DEFINITION_NAME_EXIST, name); |
|
|
|
|
} |
|
|
|
|
List<TaskDefinitionLog> taskDefinitionLogs = generateTaskDefinitionList(taskDefinitionJson); |
|
|
|
|
List<ProcessTaskRelationLog> taskRelationList = generateTaskRelationList(taskRelationJson, taskDefinitionLogs); |
|
|
|
|
int tenantId = -1; |
|
|
|
|
if (!Constants.DEFAULT.equals(tenantCode)) { |
|
|
|
|
Tenant tenant = tenantMapper.queryByTenantCode(tenantCode); |
|
|
|
|
if (tenant == null) { |
|
|
|
|
putMsg(result, Status.TENANT_NOT_EXIST); |
|
|
|
|
return result; |
|
|
|
|
throw new ServiceException(Status.TENANT_NOT_EXIST); |
|
|
|
|
} |
|
|
|
|
tenantId = tenant.getId(); |
|
|
|
|
} |
|
|
|
|
long processDefinitionCode; |
|
|
|
|
try { |
|
|
|
|
processDefinitionCode = CodeGenerateUtils.getInstance().genCode(); |
|
|
|
|
} catch (CodeGenerateException e) { |
|
|
|
|
putMsg(result, Status.INTERNAL_SERVER_ERROR_ARGS); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
long processDefinitionCode = CodeGenerateUtils.getInstance().genCode(); |
|
|
|
|
ProcessDefinition processDefinition = |
|
|
|
|
new ProcessDefinition(projectCode, name, processDefinitionCode, description, |
|
|
|
|
globalParams, locations, timeout, loginUser.getId(), tenantId); |
|
|
|
@ -317,66 +298,63 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
|
|
|
|
|
logger.info("The task has not changed, so skip"); |
|
|
|
|
} |
|
|
|
|
if (saveTaskResult == Constants.DEFINITION_FAILURE) { |
|
|
|
|
putMsg(result, Status.CREATE_TASK_DEFINITION_ERROR); |
|
|
|
|
throw new ServiceException(Status.CREATE_TASK_DEFINITION_ERROR); |
|
|
|
|
} |
|
|
|
|
int insertVersion = processService.saveProcessDefine(loginUser, processDefinition, Boolean.TRUE, Boolean.TRUE); |
|
|
|
|
if (insertVersion == 0) { |
|
|
|
|
putMsg(result, Status.CREATE_PROCESS_DEFINITION_ERROR); |
|
|
|
|
throw new ServiceException(Status.CREATE_PROCESS_DEFINITION_ERROR); |
|
|
|
|
} |
|
|
|
|
int insertResult = processService.saveTaskRelation(loginUser, processDefinition.getProjectCode(), |
|
|
|
|
processDefinition.getCode(), |
|
|
|
|
insertVersion, taskRelationList, taskDefinitionLogs, Boolean.TRUE); |
|
|
|
|
if (insertResult == Constants.EXIT_CODE_SUCCESS) { |
|
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
|
result.put(Constants.DATA_LIST, processDefinition); |
|
|
|
|
} else { |
|
|
|
|
putMsg(result, Status.CREATE_PROCESS_TASK_RELATION_ERROR); |
|
|
|
|
if (insertResult != Constants.EXIT_CODE_SUCCESS) { |
|
|
|
|
throw new ServiceException(Status.CREATE_PROCESS_TASK_RELATION_ERROR); |
|
|
|
|
} |
|
|
|
|
saveOtherRelation(loginUser, processDefinition, result, otherParamsJson); |
|
|
|
|
|
|
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
|
result.put(Constants.DATA_LIST, processDefinition); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Map<String, Object> checkTaskDefinitionList(List<TaskDefinitionLog> taskDefinitionLogs, |
|
|
|
|
String taskDefinitionJson) { |
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
private List<TaskDefinitionLog> generateTaskDefinitionList(String taskDefinitionJson) { |
|
|
|
|
try { |
|
|
|
|
if (taskDefinitionLogs.isEmpty()) { |
|
|
|
|
logger.error("taskDefinitionJson invalid: {}", taskDefinitionJson); |
|
|
|
|
putMsg(result, Status.DATA_IS_NOT_VALID, taskDefinitionJson); |
|
|
|
|
return result; |
|
|
|
|
List<TaskDefinitionLog> taskDefinitionLogs = JSONUtils.toList(taskDefinitionJson, TaskDefinitionLog.class); |
|
|
|
|
if (CollectionUtils.isEmpty(taskDefinitionLogs)) { |
|
|
|
|
logger.error("Generate task definition list failed, the given taskDefinitionJson is invalided: {}", |
|
|
|
|
taskDefinitionJson); |
|
|
|
|
throw new ServiceException(Status.DATA_IS_NOT_VALID, taskDefinitionJson); |
|
|
|
|
} |
|
|
|
|
for (TaskDefinitionLog taskDefinitionLog : taskDefinitionLogs) { |
|
|
|
|
|
|
|
|
|
if (!taskPluginManager.checkTaskParameters(ParametersNode.builder() |
|
|
|
|
.taskType(taskDefinitionLog.getTaskType()) |
|
|
|
|
.taskParams(taskDefinitionLog.getTaskParams()) |
|
|
|
|
.dependence(taskDefinitionLog.getDependence()) |
|
|
|
|
.build())) { |
|
|
|
|
logger.error("task definition {} parameter invalid", taskDefinitionLog.getName()); |
|
|
|
|
putMsg(result, Status.PROCESS_NODE_S_PARAMETER_INVALID, taskDefinitionLog.getName()); |
|
|
|
|
return result; |
|
|
|
|
logger.error( |
|
|
|
|
"Generate task definition list failed, the given task definition parameter is invalided, taskName: {}, taskDefinition: {}", |
|
|
|
|
taskDefinitionLog.getName(), taskDefinitionLog); |
|
|
|
|
throw new ServiceException(Status.PROCESS_NODE_S_PARAMETER_INVALID, taskDefinitionLog.getName()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
|
return taskDefinitionLogs; |
|
|
|
|
} catch (ServiceException ex) { |
|
|
|
|
throw ex; |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
result.put(Constants.STATUS, Status.REQUEST_PARAMS_NOT_VALID_ERROR); |
|
|
|
|
result.put(Constants.MSG, e.getMessage()); |
|
|
|
|
logger.error("Generate task definition list failed, meet an unknown exception", e); |
|
|
|
|
throw new ServiceException(Status.REQUEST_PARAMS_NOT_VALID_ERROR); |
|
|
|
|
} |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private Map<String, Object> checkTaskRelationList(List<ProcessTaskRelationLog> taskRelationList, |
|
|
|
|
String taskRelationJson, |
|
|
|
|
private List<ProcessTaskRelationLog> generateTaskRelationList(String taskRelationJson, |
|
|
|
|
List<TaskDefinitionLog> taskDefinitionLogs) { |
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
|
try { |
|
|
|
|
if (taskRelationList == null || taskRelationList.isEmpty()) { |
|
|
|
|
logger.error("task relation list is null"); |
|
|
|
|
putMsg(result, Status.DATA_IS_NOT_VALID, taskRelationJson); |
|
|
|
|
return result; |
|
|
|
|
List<ProcessTaskRelationLog> taskRelationList = |
|
|
|
|
JSONUtils.toList(taskRelationJson, ProcessTaskRelationLog.class); |
|
|
|
|
if (CollectionUtils.isEmpty(taskRelationList)) { |
|
|
|
|
logger.error("Generate task relation list failed the taskRelation list is empty, taskRelationJson: {}", |
|
|
|
|
taskRelationJson); |
|
|
|
|
throw new ServiceException(Status.DATA_IS_NOT_VALID); |
|
|
|
|
} |
|
|
|
|
List<ProcessTaskRelation> processTaskRelations = taskRelationList.stream() |
|
|
|
|
.map(processTaskRelationLog -> JSONUtils.parseObject(JSONUtils.toJsonString(processTaskRelationLog), |
|
|
|
@ -390,31 +368,29 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
|
|
|
|
|
Collection<Long> codes = CollectionUtils.subtract(postTaskCodes, taskNodeCodes); |
|
|
|
|
if (CollectionUtils.isNotEmpty(codes)) { |
|
|
|
|
logger.error("the task code is not exist"); |
|
|
|
|
putMsg(result, Status.TASK_DEFINE_NOT_EXIST, |
|
|
|
|
StringUtils.join(codes, Constants.COMMA)); |
|
|
|
|
return result; |
|
|
|
|
throw new ServiceException(Status.TASK_DEFINE_NOT_EXIST, StringUtils.join(codes, Constants.COMMA)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if (graphHasCycle(taskNodeList)) { |
|
|
|
|
logger.error("process DAG has cycle"); |
|
|
|
|
putMsg(result, Status.PROCESS_NODE_HAS_CYCLE); |
|
|
|
|
return result; |
|
|
|
|
throw new ServiceException(Status.PROCESS_NODE_HAS_CYCLE); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// check whether the task relation json is normal
|
|
|
|
|
for (ProcessTaskRelationLog processTaskRelationLog : taskRelationList) { |
|
|
|
|
if (processTaskRelationLog.getPostTaskCode() == 0) { |
|
|
|
|
logger.error("the post_task_code or post_task_version can't be zero"); |
|
|
|
|
putMsg(result, Status.CHECK_PROCESS_TASK_RELATION_ERROR); |
|
|
|
|
return result; |
|
|
|
|
throw new ServiceException(Status.CHECK_PROCESS_TASK_RELATION_ERROR); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
putMsg(result, Status.SUCCESS); |
|
|
|
|
return taskRelationList; |
|
|
|
|
} catch (ServiceException ex) { |
|
|
|
|
throw ex; |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
result.put(Constants.STATUS, Status.REQUEST_PARAMS_NOT_VALID_ERROR); |
|
|
|
|
result.put(Constants.MSG, e.getMessage()); |
|
|
|
|
logger.error("Check task relation list error, meet an unknown exception, given taskRelationJson: {}", |
|
|
|
|
taskRelationJson, e); |
|
|
|
|
throw new ServiceException(Status.REQUEST_PARAMS_NOT_VALID_ERROR); |
|
|
|
|
} |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -620,18 +596,8 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro
|
|
|
|
|
putMsg(result, Status.DESCRIPTION_TOO_LONG_ERROR); |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
List<TaskDefinitionLog> taskDefinitionLogs = JSONUtils.toList(taskDefinitionJson, TaskDefinitionLog.class); |
|
|
|
|
Map<String, Object> checkTaskDefinitions = checkTaskDefinitionList(taskDefinitionLogs, taskDefinitionJson); |
|
|
|
|
if (checkTaskDefinitions.get(Constants.STATUS) != Status.SUCCESS) { |
|
|
|
|
return checkTaskDefinitions; |
|
|
|
|
} |
|
|
|
|
List<ProcessTaskRelationLog> taskRelationList = |
|
|
|
|
JSONUtils.toList(taskRelationJson, ProcessTaskRelationLog.class); |
|
|
|
|
Map<String, Object> checkRelationJson = |
|
|
|
|
checkTaskRelationList(taskRelationList, taskRelationJson, taskDefinitionLogs); |
|
|
|
|
if (checkRelationJson.get(Constants.STATUS) != Status.SUCCESS) { |
|
|
|
|
return checkRelationJson; |
|
|
|
|
} |
|
|
|
|
List<TaskDefinitionLog> taskDefinitionLogs = generateTaskDefinitionList(taskDefinitionJson); |
|
|
|
|
List<ProcessTaskRelationLog> taskRelationList = generateTaskRelationList(taskRelationJson, taskDefinitionLogs); |
|
|
|
|
|
|
|
|
|
int tenantId = -1; |
|
|
|
|
if (!Constants.DEFAULT.equals(tenantCode)) { |
|
|
|
|