-
Notifications
You must be signed in to change notification settings - Fork 232
[app-builder] add new feature variable-updater-node #452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
CodeCasterX
merged 1 commit into
ModelEngine-Group:main
from
desAweis:app-builder-variable-update-node
Sep 29, 2025
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <parent> | ||
| <groupId>modelengine.fit.jade</groupId> | ||
| <artifactId>app-builder-plugin-parent</artifactId> | ||
| <version>1.0.0-SNAPSHOT</version> | ||
| </parent> | ||
|
|
||
| <groupId>modelengine.fit.jade.plugin</groupId> | ||
| <artifactId>aipp-variable-updater</artifactId> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>modelengine.fit.jade.waterflow</groupId> | ||
| <artifactId>waterflow-runtime-service</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>modelengine.fit.jade</groupId> | ||
| <artifactId>aipp-genericable</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>modelengine.fit.jober</groupId> | ||
| <artifactId>jober-genericable</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>modelengine.fit.jade</groupId> | ||
| <artifactId>aipp-service</artifactId> | ||
| </dependency> | ||
|
|
||
| <!-- Test --> | ||
| <dependency> | ||
| <groupId>org.junit.jupiter</groupId> | ||
| <artifactId>junit-jupiter</artifactId> | ||
| </dependency> | ||
| </dependencies> | ||
|
|
||
| <build> | ||
| <plugins> | ||
| <plugin> | ||
| <groupId>org.fitframework</groupId> | ||
| <artifactId>fit-build-maven-plugin</artifactId> | ||
| <version>${fit.version}</version> | ||
| <configuration> | ||
| <category>user</category> | ||
| <level>5</level> | ||
| </configuration> | ||
| <executions> | ||
| <execution> | ||
| <id>build-plugin</id> | ||
| <goals> | ||
| <goal>build-plugin</goal> | ||
| </goals> | ||
| </execution> | ||
| <execution> | ||
| <id>package-plugin</id> | ||
| <goals> | ||
| <goal>package-plugin</goal> | ||
| </goals> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| <plugin> | ||
| <groupId>org.apache.maven.plugins</groupId> | ||
| <artifactId>maven-antrun-plugin</artifactId> | ||
| <version>${maven.antrun.version}</version> | ||
| <executions> | ||
| <execution> | ||
| <phase>install</phase> | ||
| <configuration> | ||
| <target> | ||
| <copy file="${project.build.directory}/${project.build.finalName}.jar" | ||
| todir="../../../build/plugins"/> | ||
| </target> | ||
| </configuration> | ||
| <goals> | ||
| <goal>run</goal> | ||
| </goals> | ||
| </execution> | ||
| </executions> | ||
| </plugin> | ||
| </plugins> | ||
| </build> | ||
| </project> |
79 changes: 79 additions & 0 deletions
79
...updater/src/main/java/modelengine/fit/jade/aipp/variable/updater/AippVariableUpdater.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. | ||
| * This file is a part of the ModelEngine Project. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| package modelengine.fit.jade.aipp.variable.updater; | ||
|
|
||
| import modelengine.fit.jober.aipp.common.exception.AippErrCode; | ||
| import modelengine.fit.jober.aipp.common.exception.AippParamException; | ||
| import modelengine.fit.jober.aipp.constants.AippConst; | ||
| import modelengine.fit.jober.common.ErrorCodes; | ||
| import modelengine.fit.jober.common.exceptions.JobberException; | ||
| import modelengine.fit.waterflow.spi.FlowableService; | ||
| import modelengine.fitframework.annotation.Component; | ||
| import modelengine.fitframework.annotation.Fitable; | ||
| import modelengine.fitframework.util.ObjectUtils; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * 变量更新算子服务。 | ||
| * | ||
| * @author 鲁为 | ||
| * @since 2025-09-26 | ||
| */ | ||
| @Component | ||
| public class AippVariableUpdater implements FlowableService { | ||
| private static final String UPDATE_VARIABLES = "updateVariables"; | ||
| private static final String INTERNAL = "_internal"; | ||
| private static final String OUTPUT_SCOPE = "outputScope"; | ||
| private static final String KEY = "key"; | ||
| private static final String VALUE = "value"; | ||
|
|
||
| @Override | ||
| @Fitable("modelengine.fit.jade.aipp.variable.updater") | ||
| public List<Map<String, Object>> handleTask(List<Map<String, Object>> flowData) { | ||
| Map<String, Object> businessData = this.getBusinessData(flowData); | ||
| List<Map<String, Object>> updateVariables = ObjectUtils.cast(businessData.get(UPDATE_VARIABLES)); | ||
| Map<String, Object> internal = ObjectUtils.cast(businessData.get(INTERNAL)); | ||
| Map<String, Object> outputScope = ObjectUtils.cast(internal.get(OUTPUT_SCOPE)); | ||
| for (Map<String, Object> variable : updateVariables) { | ||
| List<String> path = ObjectUtils.cast(variable.get(KEY)); | ||
| Object newValue = variable.get(VALUE); | ||
| this.updateNestedMapByPath(outputScope, path, newValue); | ||
| } | ||
| return flowData; | ||
| } | ||
|
|
||
| private Map<String, Object> getBusinessData(List<Map<String, Object>> flowData) { | ||
| if (flowData.isEmpty() || !flowData.get(0).containsKey(AippConst.BS_DATA_KEY)) { | ||
| throw new JobberException(ErrorCodes.INPUT_PARAM_IS_EMPTY, AippConst.BS_DATA_KEY); | ||
| } | ||
| return ObjectUtils.cast(flowData.get(0).get(AippConst.BS_DATA_KEY)); | ||
| } | ||
|
|
||
| private void updateNestedMapByPath(Map<String, Object> businessData, List<String> path, Object newValue) { | ||
| if (businessData == null || path == null || path.isEmpty()) { | ||
| return; | ||
| } | ||
|
|
||
| Map<String, Object> currentMap = businessData; | ||
|
|
||
| for (int i = 0; i < path.size() - 1; i++) { | ||
| String key = path.get(i); | ||
| Object value = currentMap.get(key); | ||
|
|
||
| if (value instanceof Map) { | ||
| currentMap = ObjectUtils.cast(value); | ||
| } else { | ||
| throw new AippParamException(AippErrCode.DATA_TYPE_IS_NOT_SUPPORTED); | ||
| } | ||
| } | ||
|
|
||
| String finalKey = path.get(path.size() - 1); | ||
| currentMap.put(finalKey, newValue); | ||
| } | ||
| } | ||
4 changes: 4 additions & 0 deletions
4
app-builder/plugins/aipp-variable-updater/src/main/resources/application.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| fit: | ||
| beans: | ||
| packages: | ||
| - 'modelengine.fit.jade.aipp.variable.updater' |
103 changes: 103 additions & 0 deletions
103
...ter/src/test/java/modelengine/fit/jade/aipp/variable/updater/AippVariableUpdaterTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. | ||
| * This file is a part of the ModelEngine Project. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| package modelengine.fit.jade.aipp.variable.updater; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
|
||
| import modelengine.fit.jober.aipp.common.exception.AippParamException; | ||
| import modelengine.fitframework.util.MapBuilder; | ||
| import modelengine.fitframework.util.ObjectUtils; | ||
|
|
||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * {@link AippVariableUpdater}的测试方法。 | ||
| * | ||
| * @author 鲁为 | ||
| * @since 2025-09-28 | ||
| */ | ||
| @DisplayName("变量更新节点测试。") | ||
| public class AippVariableUpdaterTest { | ||
desAweis marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| private static final String UPDATE_VARIABLES = "updateVariables"; | ||
| private static final String INTERNAL = "_internal"; | ||
| private static final String OUTPUT_SCOPE = "outputScope"; | ||
| private static final String KEY = "key"; | ||
| private static final String VALUE = "value"; | ||
|
|
||
| private final AippVariableUpdater aippVariableUpdater = new AippVariableUpdater(); | ||
|
|
||
| @Test | ||
| @DisplayName("修改 businessData 中指定路径的值。") | ||
| void shouldModifySpecificPathValue() { | ||
| Map<String, Object> flowDataInner = | ||
| this.getFlowData(this.getContextData(List.of("trace1"), "contextId"), this.buildBusinessData()); | ||
| List<Map<String, Object>> flowData = List.of(flowDataInner); | ||
| this.aippVariableUpdater.handleTask(flowData); | ||
| assertEquals(ObjectUtils.<String>cast(ObjectUtils.<Map<String, Object>>cast(ObjectUtils.<Map<String, Object>>cast( | ||
| ObjectUtils.<Map<String, Object>>cast(ObjectUtils.<Map<String, Object>>cast(ObjectUtils.<Map<String, Object>>cast( | ||
| flowData.get(0).get("businessData")).get(INTERNAL)).get(OUTPUT_SCOPE)).get( | ||
| "jade8xvdq4")) | ||
| .get("output")).get("a")), "after"); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("当 path 不存在时,抛出异常。") | ||
| void shouldThrowExceptionWhenPathDoesNotExist() { | ||
| Map<String, Object> flowDataInner = | ||
| this.getFlowData(this.getContextData(List.of("trace1"), "contextId"), this.buildInvalidBusinessData()); | ||
| List<Map<String, Object>> flowData = List.of(flowDataInner); | ||
| assertThrows(AippParamException.class, () -> this.aippVariableUpdater.handleTask(flowData)); | ||
| } | ||
|
|
||
| private Map<String, Object> getFlowData(Map<String, Object> contextData, Map<String, Object> businessData) { | ||
| return MapBuilder.get(() -> new HashMap<String, Object>()) | ||
| .put("contextData", contextData) | ||
| .put("businessData", businessData) | ||
| .build(); | ||
| } | ||
|
|
||
| private Map<String, Object> getContextData(List<String> traceIds, String contextId) { | ||
| return MapBuilder.get(() -> new HashMap<String, Object>()) | ||
| .put("flowTraceIds", traceIds) | ||
| .put("contextId", contextId) | ||
| .build(); | ||
| } | ||
|
|
||
| private Map<String, Object> buildBusinessData() { | ||
| Map<Object, Object> output = MapBuilder.get().put("a", "before").build(); | ||
| Map<Object, Object> node = MapBuilder.get().put("output", output).build(); | ||
| Map<Object, Object> outputScope = MapBuilder.get().put("jade8xvdq4", node).build(); | ||
| return MapBuilder.<String, Object>get() | ||
| .put(UPDATE_VARIABLES, | ||
| List.of(MapBuilder.get() | ||
| .put(KEY, List.of("jade8xvdq4", "output", "a")) | ||
| .put(VALUE, "after") | ||
| .build())) | ||
| .put(INTERNAL, MapBuilder.get().put(OUTPUT_SCOPE, outputScope).build()) | ||
| .build(); | ||
| } | ||
|
|
||
| private Map<String, Object> buildInvalidBusinessData() { | ||
| List<Object> output = List.of("a", "before"); | ||
| Map<Object, Object> node = MapBuilder.get().put("output", output).build(); | ||
| Map<Object, Object> outputScope = MapBuilder.get().put("jade8xvdq4", node).build(); | ||
| return MapBuilder.<String, Object>get() | ||
| .put(UPDATE_VARIABLES, | ||
| List.of(MapBuilder.get() | ||
| .put(KEY, List.of("jade8xvdq4", "output", "a")) | ||
| .put(VALUE, "after") | ||
| .build())) | ||
| .put(INTERNAL, MapBuilder.get().put(OUTPUT_SCOPE, outputScope).build()) | ||
| .build(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.