Skip to content

Commit

Permalink
Bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
djuarezgf committed Dec 4, 2024
1 parent 7cc52b4 commit e959157
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
17 changes: 11 additions & 6 deletions src/main/java/de/samply/email/EmailKeyValues.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ private void addProjectBridgeheadOrProject(EmailRecipient emailRecipient) {
AtomicReference<Optional<Project>> projectOptional = new AtomicReference<>(Optional.empty());
emailRecipient.getProjectCode().ifPresent(projectCode ->
projectRepository.findByCode(projectCode).ifPresent(project ->
emailRecipient.getBridgehead().ifPresent(bridgehead ->
projectBridgeheadRepository.findFirstByBridgeheadAndProject(bridgehead, project).ifPresentOrElse(projectBridgehead ->
projectBridgeheadOptional.set(Optional.of(projectBridgehead)),
() -> projectOptional.set(Optional.of(project))))));
emailRecipient.getBridgehead().ifPresentOrElse(bridgehead ->
projectBridgeheadRepository.findFirstByBridgeheadAndProject(bridgehead, project).ifPresentOrElse(projectBridgehead ->
projectBridgeheadOptional.set(Optional.of(projectBridgehead)),
() -> projectOptional.set(Optional.of(project))),
() -> projectOptional.set(Optional.of(project)))));
if (projectBridgeheadOptional.get().isPresent()) {
add(projectBridgeheadOptional.get().get());
} else if (projectOptional.get().isPresent()) {
Expand Down Expand Up @@ -154,7 +155,7 @@ private void addBridgeheads(Project project) {
addKeyValue(ProjectManagerConst.EMAIL_CONTEXT_PROJECT_BRIDGEHEADS,
projectBridgeheadRepository.findByProject(project).stream()
.map(projectBridgehead -> fetchHumanReadableBridgehead(projectBridgehead.getBridgehead()))
.collect(Collectors.joining(",")));
.collect(Collectors.joining(", ")));
}

private void addLastDocument(Project project) {
Expand Down Expand Up @@ -207,10 +208,14 @@ private void addEmailData(String email, @NotNull String emailKey, @NotNull Strin
}

public String replaceHtmlVariables(String htmlText) {
return replaceHtmlVariables(htmlText, keyValues);
}

public static String replaceHtmlVariables(String htmlText, Map<String,String> keyValues) {
if (htmlText != null) {
// Regular expression to match the variable pattern
// e.g. <variable1/> It is like a HTML tag
String regex = "<\\s*(\\w+)\\s*/>";
String regex = "<\\s*([a-zA-Z0-9_-]+)\\s*/>";

// Use StringBuilder to build the result efficiently
StringBuilder result = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected void doProcess(ITemplateContext context, IProcessableElementTag tag, I
String variableName = tagName.contains(":")
? tagName.substring(tagName.indexOf(':') + 1)
: tagName;
if (supportedTagNames.contains(variableName)) {
if (supportedTagNames.contains(variableName) || context.getVariable(variableName) != null) {
// Retrieve the desired variable from the context
Object variableValue = context.getVariable(variableName);

Expand Down

0 comments on commit e959157

Please sign in to comment.