aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java')
-rw-r--r--src/main/java/at/gv/egiz/moazs/preprocess/ConfigUtil.java44
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();
+
+ }
}