Skip to content

Commit

Permalink
fix: default template query api may lose prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
mmagi committed Jun 8, 2023
1 parent 779dc79 commit 925d123
Showing 1 changed file with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@
import org.cloud.sonic.controller.services.impl.base.SonicServiceImpl;
import org.cloud.sonic.controller.tools.robot.Message;
import org.cloud.sonic.controller.tools.robot.RobotFactory;
import org.cloud.sonic.controller.tools.robot.RobotMessenger;
import org.cloud.sonic.controller.tools.robot.message.DeviceMessage;
import org.cloud.sonic.controller.tools.robot.message.ProjectSummaryMessage;
import org.cloud.sonic.controller.tools.robot.message.TestSuiteMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.expression.Expression;
import org.springframework.expression.spel.standard.SpelExpression;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

Expand Down Expand Up @@ -118,11 +121,18 @@ private void send(List<AlertRobots> robots, Message message) {
@Override
public String getDefaultNoticeTemplate(int type, String scene) {
var messenger = robotFactory.getRobotMessenger(type);
return switch (scene) {
case SCENE_AGENT -> messenger.getDefaultDeviceMessageTemplate().getExpressionString();
case SCENE_SUMMARY -> messenger.getDefaultProjectSummaryTemplate().getExpressionString();
case SCENE_TESTSUITE -> messenger.getDefaultTestSuiteTemplate().getExpressionString();
default -> "";
var template = switch (scene) {
case SCENE_AGENT -> messenger.getDefaultDeviceMessageTemplate();
case SCENE_SUMMARY -> messenger.getDefaultProjectSummaryTemplate();
case SCENE_TESTSUITE -> messenger.getDefaultTestSuiteTemplate();
default -> null;
};
if (null == template) {
return "";
} else if (template instanceof SpelExpression) {
return RobotMessenger.templateParserContext.getExpressionPrefix() + template.getExpressionString() + RobotMessenger.templateParserContext.getExpressionSuffix();
} else {
return template.getExpressionString();
}
}
}

0 comments on commit 925d123

Please sign in to comment.