wolfboys commented on code in PR #1866:
URL:
https://github.com/apache/incubator-streampark/pull/1866#discussion_r1001917086
##########
streampark-console/streampark-console-service/src/main/java/org/apache/streampark/console/core/service/impl/VariableServiceImpl.java:
##########
@@ -79,4 +110,74 @@ public Variable findByVariableCode(Long teamId, String
variableCode) {
public List<Variable> findByTeamId(Long teamId) {
return baseMapper.selectByTeamId(teamId);
}
+
+ /**
+ * Replace placeholders with defined variable codes.
+ * @param teamId
+ * @param paramWithPlaceholders Parameters with placeholders, e.g.
"--cluster ${kafka.cluster}"
+ * @return
+ */
+ @Override
+ public String parseVariable(Long teamId, String paramWithPlaceholders) {
Review Comment:
> @1996fanrui @wolfboys is this okay?
>
> ```
> /**
> * Replace variable with defined variable codes.
> * @param teamId
> * @param mixed Text with placeholders, e.g. "--cluster
${kafka.cluster}"
> * @return
> */
> @Override
> public String replaceVariable(Long teamId, String mixed) {
> if (StringUtils.isEmpty(mixed)) {
> return mixed;
> }
> List<Variable> variables = findByTeamId(teamId);
> if (CollectionUtils.isEmpty(variables)) {
> return mixed;
> }
> Map<String, String> variableMap =
variables.stream().collect(Collectors.toMap(Variable::getVariableCode,
Variable::getVariableValue));
> String restore = mixed;
> Matcher matcher = placeholderPattern.matcher(restore);
> while (matcher.find()) {
> String placeholder = matcher.group();
> String variableCode = getCodeFromPlaceholder(placeholder);
> String variableVaule = variableMap.get(variableCode);
> if (StringUtils.isNotEmpty(variableVaule)) {
> restore = restore.replace(placeholder, variableVaule);
> }
> }
> return restore;
> }
> ```
LGTM
--
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]