Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Commit

Permalink
convert foreign rule field names to lowercase
Browse files Browse the repository at this point in the history
  • Loading branch information
gstoehld committed Mar 29, 2022
1 parent 312ccac commit f3bca72
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -87,14 +89,19 @@ 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);
foreignRule.setValidFrom(validFrom);
foreignRule.setVersion(rule.get("version").asText());
foreignRule.setCountry(country);
foreignRule.setId(id);

return foreignRule;
}
}

0 comments on commit f3bca72

Please sign in to comment.