From f3bca728b1a3fe22be73a2cc65f1c750afd79392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gst=C3=B6hl?= Date: Tue, 29 Mar 2022 10:20:13 +0200 Subject: [PATCH] convert foreign rule field names to lowercase --- .../verifier/sync/syncer/DgcForeignRulesSyncer.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ch-covidcertificate-backend-verifier/ch-covidcertificate-backend-verifier-sync/src/main/java/ch/admin/bag/covidcertificate/backend/verifier/sync/syncer/DgcForeignRulesSyncer.java b/ch-covidcertificate-backend-verifier/ch-covidcertificate-backend-verifier-sync/src/main/java/ch/admin/bag/covidcertificate/backend/verifier/sync/syncer/DgcForeignRulesSyncer.java index 05e255d2..91f8e288 100644 --- a/ch-covidcertificate-backend-verifier/ch-covidcertificate-backend-verifier-sync/src/main/java/ch/admin/bag/covidcertificate/backend/verifier/sync/syncer/DgcForeignRulesSyncer.java +++ b/ch-covidcertificate-backend-verifier/ch-covidcertificate-backend-verifier-sync/src/main/java/ch/admin/bag/covidcertificate/backend/verifier/sync/syncer/DgcForeignRulesSyncer.java @@ -14,6 +14,7 @@ import ch.admin.bag.covidcertificate.backend.verifier.model.ForeignRule; import ch.admin.bag.covidcertificate.backend.verifier.sync.utils.CmsUtil; import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ObjectNode; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -35,6 +36,7 @@ public class DgcForeignRulesSyncer { private static final Logger logger = LoggerFactory.getLogger(DgcForeignRulesSyncer.class); private final ForeignRulesDataService foreignRulesDataService; private final DgcRulesClient dgcRulesClient; + private final ObjectMapper mapper = new ObjectMapper(); public DgcForeignRulesSyncer( DgcRulesClient dgcRulesClient, ForeignRulesDataService foreignRulesDataService) { @@ -87,7 +89,11 @@ private ForeignRule decodeRule(ObjectNode rule, String country, String id) throws CertificateException, IOException, OperatorCreationException, CMSException { var foreignRule = new ForeignRule(); String content = new String((byte[]) CmsUtil.decodeCms(rule.get("cms").asText()), StandardCharsets.UTF_8); - foreignRule.setContent(content); + ObjectNode convertedNode = mapper.createObjectNode(); + mapper.readTree(content).fields().forEachRemaining(field -> { + convertedNode.set(field.getKey().toLowerCase(), field.getValue()); + }); + foreignRule.setContent(convertedNode.toString()); var validUntil = LocalDateTime.parse(rule.get("validTo").asText(), DateTimeFormatter.ISO_OFFSET_DATE_TIME); foreignRule.setValidUntil(validUntil); var validFrom = LocalDateTime.parse(rule.get("validTo").asText(), DateTimeFormatter.ISO_OFFSET_DATE_TIME); @@ -95,6 +101,7 @@ private ForeignRule decodeRule(ObjectNode rule, String country, String id) foreignRule.setVersion(rule.get("version").asText()); foreignRule.setCountry(country); foreignRule.setId(id); + return foreignRule; } }