Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ public Map<String, Object> createWorkflowDefinition(User loginUser,
definition.getName(), definition.getCode());
throw new ServiceException(Status.WORKFLOW_DEFINITION_NAME_EXIST, name);
}

validateGlobalParams(globalParams);

List<TaskDefinitionLog> taskDefinitionLogs = generateTaskDefinitionList(taskDefinitionJson);
List<WorkflowTaskRelationLog> taskRelationList = generateTaskRelationList(taskRelationJson, taskDefinitionLogs);

Expand Down Expand Up @@ -784,6 +787,9 @@ public Map<String, Object> updateWorkflowDefinition(User loginUser,
putMsg(result, Status.DESCRIPTION_TOO_LONG_ERROR);
return result;
}

validateGlobalParams(globalParams);

List<TaskDefinitionLog> taskDefinitionLogs = generateTaskDefinitionList(taskDefinitionJson);
List<WorkflowTaskRelationLog> taskRelationList = generateTaskRelationList(taskRelationJson, taskDefinitionLogs);

Expand Down Expand Up @@ -820,6 +826,38 @@ public Map<String, Object> updateWorkflowDefinition(User loginUser,
return result;
}

/**
* Validates global parameters: non-empty keys, no duplicates
*/
private void validateGlobalParams(String globalParams) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't be writing this kind of glue code everywhere. Why not use a GlobalParamValidator to handle this task?

if (StringUtils.isBlank(globalParams)) {
return;
}

List<Property> params;
try {
params = JSONUtils.toList(globalParams, Property.class);
} catch (Exception e) {
throw new ServiceException("Invalid globalParams");
}

if (params == null || params.isEmpty()) {
return;
}

Set<String> keys = new HashSet<>();
for (Property p : params) {
if (StringUtils.isEmpty(p.getProp())) {
throw new ServiceException("Global param key cannot be empty");
}

String key = p.getProp().trim();
if (!keys.add(key)) {
throw new ServiceException("Duplicate global param key: " + key);
}
}
}

/**
* Task want to delete whether used in other task, should throw exception when have be used.
* <p>
Expand Down