diff options
author | Christof Rabensteiner <christof.rabensteiner@iaik.tugraz.at> | 2019-07-15 12:04:26 +0200 |
---|---|---|
committer | Christof Rabensteiner <christof.rabensteiner@iaik.tugraz.at> | 2019-07-15 12:09:28 +0200 |
commit | d9e5864f48d261c06de1f1d34000ff6156155569 (patch) | |
tree | d66524e395f403d57f27d25cfdcab5dcd25511e4 /src/main/java/at/gv/egiz/moazs/preprocess | |
parent | 25d68c8900c2cc791f03ea3db173955ca237fd55 (diff) | |
download | moa-zs-d9e5864f48d261c06de1f1d34000ff6156155569.tar.gz moa-zs-d9e5864f48d261c06de1f1d34000ff6156155569.tar.bz2 moa-zs-d9e5864f48d261c06de1f1d34000ff6156155569.zip |
Save Response To File Sink: Add Path to Configuration + Fix
- Fix in ConfigUtil: SaveResponseToFile boolean would override
LogResponse configuration (Copy Paste Error).
Diffstat (limited to 'src/main/java/at/gv/egiz/moazs/preprocess')
-rw-r--r-- | src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java | 44 |
1 files changed, 39 insertions, 5 deletions
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<String, String> values) { @@ -131,11 +135,24 @@ public class ConfigUtil { private MsgResponseSinksType buildMsgResponseSinks(Map<String, String> 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<String, String> 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(); + + } } |