From d9e5864f48d261c06de1f1d34000ff6156155569 Mon Sep 17 00:00:00 2001 From: Christof Rabensteiner Date: Mon, 15 Jul 2019 12:04:26 +0200 Subject: Save Response To File Sink: Add Path to Configuration + Fix - Fix in ConfigUtil: SaveResponseToFile boolean would override LogResponse configuration (Copy Paste Error). --- .../at/gv/egiz/moazs/preprocess/ConfigUtil.java | 44 +++++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) (limited to 'src/main/java/at/gv/egiz/moazs/preprocess') diff --git a/src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java b/src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java index 9cdc07a..b69b828 100644 --- a/src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java +++ b/src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java @@ -12,6 +12,7 @@ import static at.gv.zustellung.app2mzs.xsd.ConfigType.configTypeBuilder; import static at.gv.zustellung.app2mzs.xsd.KeyStoreType.keyStoreTypeBuilder; import static at.gv.zustellung.app2mzs.xsd.MsgResponseSinksType.msgResponseSinksTypeBuilder; import static at.gv.zustellung.app2mzs.xsd.SSLType.SSLTypeBuilder; +import static at.gv.zustellung.app2mzs.xsd.SaveResponseToFileType.saveResponseToFileTypeBuilder; import static java.util.stream.Collectors.toMap; @Component @@ -34,11 +35,14 @@ public class ConfigUtil { public static final String MSG_RESPONSE_SINKS_KEY = "msg-response-sinks"; public static final String LOG_RESPONSE_KEY = "log-response"; public static final String SAVE_RESPONSE_TO_FILE_KEY = "save-response-to-file"; + public static final String SAVE_RESPONSE_TO_FILE_ACTIVE_KEY = "active"; + public static final String SAVE_RESPONSE_TO_FILE_PATH_KEY = "path"; + /** * Convert a map into a Config object. * - * @param map with well-defined indexes and values + * @param values: Map with well-defined indexes and values * @return Config */ public ConfigType convert(Map values) { @@ -131,11 +135,24 @@ public class ConfigUtil { private MsgResponseSinksType buildMsgResponseSinks(Map params) { var logResponse = booleanOrNull(params.get(LOG_RESPONSE_KEY)); - var saveResponse = booleanOrNull(params.get(SAVE_RESPONSE_TO_FILE_KEY)); + + var saveResponseParams = filterMapByPrefix(params, SAVE_RESPONSE_TO_FILE_KEY); + var saveResponse = buildSaveResponse(saveResponseParams); return msgResponseSinksTypeBuilder() .withLogResponse(logResponse) - .withLogResponse(saveResponse) + .withSaveResponseToFile(saveResponse) + .build(); + } + + private SaveResponseToFileType buildSaveResponse(Map params) { + + var isActive = booleanOrNull(params.get(SAVE_RESPONSE_TO_FILE_ACTIVE_KEY)); + var path = params.get(SAVE_RESPONSE_TO_FILE_PATH_KEY); + + return saveResponseToFileTypeBuilder() + .withActive(isActive) + .withPath(path) .build(); } @@ -248,12 +265,29 @@ public class ConfigUtil { builder.withLogResponse(primary.isLogResponse()); } - if (primary.isSafeResponseToFile() != null) { - builder.withLogResponse(primary.isSafeResponseToFile()); + if (primary.getSaveResponseToFile() != null) { + builder.withSaveResponseToFile(merge(primary.getSaveResponseToFile(), fallback.getSaveResponseToFile())); } return builder.build(); } + private SaveResponseToFileType merge(SaveResponseToFileType primary, SaveResponseToFileType fallback) { + + if (fallback == null) return primary; + + var builder = saveResponseToFileTypeBuilder(fallback); + + if (primary.isActive() != null) { + builder.withActive(primary.isActive()); + } + + if (primary.getPath() != null) { + builder.withPath(primary.getPath()); + } + + return builder.build(); + + } } -- cgit v1.2.3