Skip to content

Commit

Permalink
Added: Enable minus in variables of email context
Browse files Browse the repository at this point in the history
  • Loading branch information
djuarezgf committed Dec 2, 2024
1 parent 2420deb commit 8170f6a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,4 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Fetch human readable bridgehead for emails
- Email context project bridgeheads variable
- Decode Base64 values of email context
- Enable minus in variables of email context
1 change: 1 addition & 0 deletions src/main/java/de/samply/app/ProjectManagerConst.java
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ public class ProjectManagerConst {
public final static String CUSTOM_PROJECT_CONFIGURATION = "CUSTOM";
public final static String EMAIL_SERVICE = "EMAIL_SERVICE";
public final static String HYPHEN = "minus";
public final static String BASE_64 = "b64";
public final static String HTTP_PROTOCOL_SCHEMA = "http";
public final static String HTTPS_PROTOCOL_SCHEMA = "https";

Expand Down
19 changes: 16 additions & 3 deletions src/main/java/de/samply/email/EmailContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

@Slf4j
@Component
Expand All @@ -20,16 +21,28 @@ public class EmailContext {
private Map<String, String> context = new HashMap<>();


// Keys may contain the "-" character, which is represented as "MINUS" in environment variables.
// If a key is Base64-encoded, it should start with the prefix "B64" to indicate its encoding.
@PostConstruct
public void init() {
log.info("Email Context initialized:");
Map<String, String> tempContext = Map.copyOf(context);
Map<String, String> tempContext = new HashMap<>(context);
context.entrySet().stream().forEach(keyValue -> {
log.info("\t-\t{}: {}", keyValue.getKey(), keyValue.getValue());
Base64Utils.decodeIfNecessary(keyValue.getValue()).ifPresent(value -> tempContext.put(keyValue.getKey(), value));
String key = replaceHyphen(keyValue.getKey());
AtomicReference<String> value = new AtomicReference<>(keyValue.getValue());
if (key.startsWith(ProjectManagerConst.BASE_64)) {
key = key.replaceFirst(ProjectManagerConst.BASE_64, "");
Base64Utils.decodeIfNecessary(keyValue.getValue()).ifPresent(value::set);
}
log.info("\t-\t{}: {}", key, value.get());
tempContext.put(key, value.get());
});
context = tempContext;
}

private String replaceHyphen(String var) {
return var.replace(ProjectManagerConst.HYPHEN, "-");
}


}

0 comments on commit 8170f6a

Please sign in to comment.