ruanwenjun commented on code in PR #17961:
URL: 
https://github.com/apache/dolphinscheduler/pull/17961#discussion_r2774620830


##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java:
##########
@@ -291,6 +292,15 @@ public Map<String, Object> createWorkflowDefinition(User 
loginUser,
                     definition.getName(), definition.getCode());
             throw new ServiceException(Status.WORKFLOW_DEFINITION_NAME_EXIST, 
name);
         }
+
+        try {
+            validateGlobalParams(globalParams);
+        } catch (ServiceException ex) {
+            log.warn("Invalid globalParams: {}", ex.getMessage());
+            putMsg(result, Status.REQUEST_PARAMS_NOT_VALID_ERROR, 
ex.getMessage());
+            return result;
+        }

Review Comment:
   ```suggestion
               validateGlobalParams(globalParams);
   ```
   Directly throw `ServiceException` at `validateGlobalParams`, please don't 
use a lot of try catch here.



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java:
##########
@@ -847,6 +866,42 @@ public Map<String, Object> updateWorkflowDefinition(User 
loginUser,
         return result;
     }
 
+    /**
+     * Validates global parameters: non-empty keys, no duplicates, and 
required values for IN-type params.
+     */
+    private void validateGlobalParams(String globalParams) {

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



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java:
##########
@@ -847,6 +866,42 @@ public Map<String, Object> updateWorkflowDefinition(User 
loginUser,
         return result;
     }
 
+    /**
+     * Validates global parameters: non-empty keys, no duplicates, and 
required values for IN-type params.
+     */
+    private void validateGlobalParams(String globalParams) {
+        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);
+            }
+
+            if (Direct.IN.equals(p.getDirect()) && 
StringUtils.isEmpty(p.getValue())) {
+                throw new ServiceException("IN param value required for key: " 
+ key);
+            }

Review Comment:
   We should support the value to be null.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to