Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ fit start -Dfit.profiles.active=prod

> 这里直接使用了 `fit` 命令,该命令请参考 `fit-framework` 项目的[指导手册](https://github.com/ModelEngine-Group/fit-framework/blob/main/docs/framework/fit/java/quick-start-guide/03.%20%E4%BD%BF%E7%94%A8%E6%8F%92%E4%BB%B6%E7%9A%84%E7%83%AD%E6%8F%92%E6%8B%94%E8%83%BD%E5%8A%9B.md)。
>
> 当前,`app-platform` 使用了 `fit` 的 3.5.1 版本,因此,如果采用手动编译,需要在 `fit-framework` 仓库中切换到 `v3.5.1` 标签处进行编译构建操作。
> 当前,`app-platform` 使用了 `fit` 的 3.5.3 版本,因此,如果采用手动编译,需要在 `fit-framework` 仓库中切换到 `v3.5.3` 标签处进行编译构建操作。

---------

Expand Down
2 changes: 1 addition & 1 deletion app-builder/plugins/aipp-classify-question/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
<dependency>
<groupId>org.fitframework.plugin</groupId>
<artifactId>fit-message-serializer-json-jackson</artifactId>
<version>3.5.1</version>
<version>3.5.3</version>
Comment thread
reeeborn33 marked this conversation as resolved.
Outdated
<scope>test</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion app-builder/plugins/aipp-extractor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<dependency>
<groupId>org.fitframework.plugin</groupId>
<artifactId>fit-message-serializer-json-jackson</artifactId>
<version>3.5.1</version>
<version>3.5.3</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion app-builder/plugins/aipp-http-call/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<dependency>
<groupId>org.fitframework.plugin</groupId>
<artifactId>fit-message-serializer-json-jackson</artifactId>
<version>3.5.1</version>
<version>3.5.3</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion app-builder/plugins/aipp-loop-tool/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
<plugin>
<groupId>org.fitframework.fel</groupId>
<artifactId>tool-maven-plugin</artifactId>
<version>3.5.1</version>
<version>3.5.3</version>
<executions>
<execution>
<id>build-tool</id>
Expand Down
2 changes: 1 addition & 1 deletion app-builder/plugins/aipp-parallel-tool/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
<plugin>
<groupId>org.fitframework.fel</groupId>
<artifactId>tool-maven-plugin</artifactId>
<version>3.5.1</version>
<version>3.5.3</version>
<executions>
<execution>
<id>build-tool</id>
Expand Down
4 changes: 2 additions & 2 deletions app-builder/plugins/aipp-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
<dependency>
<groupId>org.fitframework.plugin</groupId>
<artifactId>fit-message-serializer-json-jackson</artifactId>
<version>3.5.1</version>
<version>3.5.3</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -315,7 +315,7 @@
<plugin>
<groupId>org.fitframework.fel</groupId>
<artifactId>tool-maven-plugin</artifactId>
<version>3.5.1</version>
<version>3.5.3</version>
<executions>
<execution>
<id>build-tool</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ tool:
FILEEXTRACTNODESTATE: fileExtractionNodeState
LOOPNODESTATE: loopNodeState
PARALLELNODESTATE: parallelNodeState
TEXTCONCATENATENODESTATE: textConcatenateNodeState
export-meta:
version: 1.0.1
sensitive:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,10 @@
"type": "parallelNodeState",
"name": "Parallel",
"uniqueName": ""
},
{
"type": "textConcatenateNodeState",
"name": "Text Joiner",
"uniqueName": ""
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,10 @@
"type": "parallelNodeState",
"name": "并行",
"uniqueName": ""
},
{
"type": "textConcatenateNodeState",
"name": "文本拼接",
"uniqueName": ""
}
]
2 changes: 1 addition & 1 deletion app-builder/plugins/aipp-rewriter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
<dependency>
<groupId>org.fitframework.plugin</groupId>
<artifactId>fit-message-serializer-json-jackson</artifactId>
<version>3.5.1</version>
<version>3.5.3</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
89 changes: 89 additions & 0 deletions app-builder/plugins/aipp-template-render/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?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-template-render</artifactId>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<!-- Services -->
<dependency>
<groupId>modelengine.jade.service</groupId>
<artifactId>aipp-template-render-service</artifactId>
</dependency>

<!-- Test -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
<dependency>
<groupId>modelengine.fit.jade</groupId>
<artifactId>aipp-service</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.fitframework</groupId>
<artifactId>fit-build-maven-plugin</artifactId>
<version>${fit.version}</version>
<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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*---------------------------------------------------------------------------------------------
* 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.template.render;

import static modelengine.fitframework.util.ObjectUtils.nullIf;

import modelengine.fitframework.annotation.Component;
import modelengine.fitframework.parameterization.ParameterizationMode;
import modelengine.fitframework.parameterization.ParameterizedString;
import modelengine.fitframework.parameterization.ParameterizedStringResolver;

import java.util.Collections;
import java.util.Map;

/**
* {@link TemplateService} 的实现类。
*
* @author 孙怡菲
* @since 2025-08-29
*/
@Component
public class TemplateServiceImpl implements TemplateService {
Comment thread
CodeCasterX marked this conversation as resolved.
Comment thread
reeeborn33 marked this conversation as resolved.
@Override
public String renderTemplate(String template, Map<String, Object> args) {
if (template == null) {
return null;
}
if (args == null) {
args = Map.of();
}
Map<String, Object> params = nullIf(args, Collections.emptyMap());
ParameterizedStringResolver resolver =
ParameterizedStringResolver.create("{{", "}}", '/', ParameterizationMode.LENIENT_EMPTY);
ParameterizedString parameterizedString = resolver.resolve(template);
return parameterizedString.format(params, null);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
fit:
beans:
packages:
- 'modelengine.fit.jade.aipp.template.render'
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
/*---------------------------------------------------------------------------------------------
* 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.template.render;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;

/**
* {@link TemplateServiceImpl} 的测试类。
*
* @author 孙怡菲
* @since 2025-08-28
*/
class TemplateServiceImplTest {
private TemplateServiceImpl textTool;

@BeforeEach
void setUp() {
this.textTool = new TemplateServiceImpl();
}

@Test
@DisplayName("基础模板变量替换成功")
void shouldReplaceBasicVariables() {
String template = "Hello {{name}}, your score is {{score}}.";
Map<String, Object> args = new HashMap<>();
args.put("name", "Tom");
args.put("score", 95);

String result = this.textTool.renderTemplate(template, args);
assertEquals("Hello Tom, your score is 95.", result);
}

@Test
@DisplayName("缺失变量时置为空字符串")
void shouldReplaceMissingVariableWithEmpty() {
String template = "Hello {{name}}, your score is {{score}}.";
Map<String, Object> args = new HashMap<>();
args.put("name", "Tom");

String result = this.textTool.renderTemplate(template, args);
assertEquals("Hello Tom, your score is .", result);
}

@Test
@DisplayName("空参数Map时模板变量置为空")
void shouldHandleEmptyArgsMap() {
String template = "Hello {{name}}!";
Map<String, Object> args = new HashMap<>();

String result = this.textTool.renderTemplate(template, args);
assertEquals("Hello !", result);
}

@Test
@DisplayName("参数为null时模板变量置为空")
void shouldHandleNullArgs() {
String template = "Hello {{name}}!";

String result = this.textTool.renderTemplate(template, null);
assertEquals("Hello !", result);
}

@Test
@DisplayName("模板无占位符时内容保持不变")
void shouldHandleTemplateWithoutPlaceholders() {
String template = "Hello world!";

String result = this.textTool.renderTemplate(template, Map.of("name", "Tom"));
assertEquals("Hello world!", result);
}

@Test
@DisplayName("变量中包含占位符内容保持不变")
void shouldHandleVariableWithPlaceholders() {
String template = "Hello {{name}}!";

String result = this.textTool.renderTemplate(template, Map.of("name", "{{Tom}}"));
assertEquals("Hello {{Tom}}!", result);
}

@Test
@DisplayName("变量为 List 时正常替换")
void shouldReplaceListVariableCorrectly() {
String template = "Items: {{items}}";
Map<String, Object> args = new HashMap<>();
args.put("items", Arrays.asList("apple", "banana", "cherry"));

String result = this.textTool.renderTemplate(template, args);
assertEquals("Items: [apple, banana, cherry]", result);
}

@Test
@DisplayName("变量为 Map 时正常替换")
void shouldReplaceMapVariableCorrectly() {
String template = "Map data: {{data}}";
Map<String, Object> args = new HashMap<>();
Map<String, Object> mapValue = new LinkedHashMap<>();
mapValue.put("a", 1);
mapValue.put("b", 2);
args.put("data", mapValue);

String result = this.textTool.renderTemplate(template, args);
assertEquals("Map data: {a=1, b=2}", result);
}
}
Loading