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 01590880..0e484d2d 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 @@ -23,7 +23,6 @@ import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; -import java.util.Locale; import org.bouncycastle.cms.CMSException; import org.bouncycastle.operator.OperatorCreationException; import org.slf4j.Logger; @@ -48,28 +47,24 @@ public int sync() { List countries = dgcRulesClient.getCountries(); countries.remove("CH"); int successful = 0; - for(var country: countries){ + for (var country : countries) { var rules = new ArrayList(); var downloaded = dgcRulesClient.download(country); - downloaded.forEach( (id, ruleVersions) -> { - ruleVersions.forEach( version ->{ - try { - rules.add( - decodeRule( - (ObjectNode) version, country, id)); - } catch (Exception e) { - logger.error( - "Failed to decode rule {}", - id, - e); - } - } - ); - }); + downloaded.forEach( + (id, ruleVersions) -> { + ruleVersions.forEach( + version -> { + try { + rules.add(decodeRule((ObjectNode) version, country, id)); + } catch (Exception e) { + logger.error("Failed to decode rule {}", id, e); + } + }); + }); - if(rules.isEmpty()){ + if (rules.isEmpty()) { logger.error("No rules were downloaded or decoded for {}", country); - }else{ + } else { foreignRulesDataService.removeRuleSet(country); rules.forEach(foreignRulesDataService::insertRule); successful += rules.size(); @@ -77,7 +72,8 @@ public int sync() { } var end = Instant.now(); logger.info( - "Successfully downloaded {} foreign rules {} ms", successful, + "Successfully downloaded {} foreign rules {} ms", + successful, end.toEpochMilli() - start.toEpochMilli()); return successful; } @@ -85,16 +81,30 @@ public int sync() { 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); + String content = + new String( + (byte[]) CmsUtil.decodeCms(rule.get("cms").asText()), + StandardCharsets.UTF_8); ObjectNode convertedNode = mapper.createObjectNode(); - mapper.readTree(content).fields().forEachRemaining(field -> { - String fieldName = field.getKey().substring(0,1).toLowerCase().concat(field.getKey().substring(1)); - convertedNode.set(fieldName, field.getValue()); - }); + mapper.readTree(content) + .fields() + .forEachRemaining( + field -> { + String fieldName = + field.getKey() + .substring(0, 1) + .toLowerCase() + .concat(field.getKey().substring(1)); + convertedNode.set(fieldName, field.getValue()); + }); foreignRule.setContent(convertedNode.toString()); - var validUntil = LocalDateTime.parse(rule.get("validTo").asText(), DateTimeFormatter.ISO_OFFSET_DATE_TIME); + 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); + 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); diff --git a/ch-covidcertificate-backend-verifier/ch-covidcertificate-backend-verifier-sync/src/test/java/ch/admin/bag/covidcertificate/backend/verifier/sync/syncer/ForeignRulesSyncTest.java b/ch-covidcertificate-backend-verifier/ch-covidcertificate-backend-verifier-sync/src/test/java/ch/admin/bag/covidcertificate/backend/verifier/sync/syncer/ForeignRulesSyncTest.java index c378b58f..b8cdab74 100644 --- a/ch-covidcertificate-backend-verifier/ch-covidcertificate-backend-verifier-sync/src/test/java/ch/admin/bag/covidcertificate/backend/verifier/sync/syncer/ForeignRulesSyncTest.java +++ b/ch-covidcertificate-backend-verifier/ch-covidcertificate-backend-verifier-sync/src/test/java/ch/admin/bag/covidcertificate/backend/verifier/sync/syncer/ForeignRulesSyncTest.java @@ -11,13 +11,10 @@ package ch.admin.bag.covidcertificate.backend.verifier.sync.syncer; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.springframework.test.web.client.match.MockRestRequestMatchers.method; import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; -import ch.admin.bag.covidcertificate.backend.verifier.model.sync.CertificateType; import java.net.URI; import java.nio.file.Files; import java.nio.file.Path; diff --git a/ch-covidcertificate-backend-verifier/ch-covidcertificate-backend-verifier-ws/src/main/java/ch/admin/bag/covidcertificate/backend/verifier/ws/controller/ForeignRulesControllerV2.java b/ch-covidcertificate-backend-verifier/ch-covidcertificate-backend-verifier-ws/src/main/java/ch/admin/bag/covidcertificate/backend/verifier/ws/controller/ForeignRulesControllerV2.java index 069c13b8..97828ae7 100644 --- a/ch-covidcertificate-backend-verifier/ch-covidcertificate-backend-verifier-ws/src/main/java/ch/admin/bag/covidcertificate/backend/verifier/ws/controller/ForeignRulesControllerV2.java +++ b/ch-covidcertificate-backend-verifier/ch-covidcertificate-backend-verifier-ws/src/main/java/ch/admin/bag/covidcertificate/backend/verifier/ws/controller/ForeignRulesControllerV2.java @@ -18,16 +18,13 @@ import com.fasterxml.jackson.databind.ObjectMapper; import java.security.NoSuchAlgorithmException; import java.time.Instant; -import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Objects; import java.util.stream.Collectors; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.boot.actuate.autoconfigure.metrics.MetricsProperties.Web; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; diff --git a/ch-covidcertificate-backend-verifier/ch-covidcertificate-backend-verifier-ws/src/test/java/ch/admin/bag/covidcertificate/backend/verifier/ws/controller/ForeignRulesControllerV2Test.java b/ch-covidcertificate-backend-verifier/ch-covidcertificate-backend-verifier-ws/src/test/java/ch/admin/bag/covidcertificate/backend/verifier/ws/controller/ForeignRulesControllerV2Test.java index bcd4bdf1..db385a5f 100644 --- a/ch-covidcertificate-backend-verifier/ch-covidcertificate-backend-verifier-ws/src/test/java/ch/admin/bag/covidcertificate/backend/verifier/ws/controller/ForeignRulesControllerV2Test.java +++ b/ch-covidcertificate-backend-verifier/ch-covidcertificate-backend-verifier-ws/src/test/java/ch/admin/bag/covidcertificate/backend/verifier/ws/controller/ForeignRulesControllerV2Test.java @@ -16,11 +16,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import ch.admin.bag.covidcertificate.backend.verifier.ws.util.TestHelper; -import ch.admin.bag.covidcertificate.backend.verifier.ws.utils.EtagUtil; -import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.ObjectNode; import java.util.Map; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; diff --git a/ch-covidcertificate-backend-verifier/ch-covidcertificate-backend-verifier-ws/src/test/java/ch/admin/bag/covidcertificate/backend/verifier/ws/util/MockForeignRuleDataService.java b/ch-covidcertificate-backend-verifier/ch-covidcertificate-backend-verifier-ws/src/test/java/ch/admin/bag/covidcertificate/backend/verifier/ws/util/MockForeignRuleDataService.java index 5a8850a6..8bfcb04f 100644 --- a/ch-covidcertificate-backend-verifier/ch-covidcertificate-backend-verifier-ws/src/test/java/ch/admin/bag/covidcertificate/backend/verifier/ws/util/MockForeignRuleDataService.java +++ b/ch-covidcertificate-backend-verifier/ch-covidcertificate-backend-verifier-ws/src/test/java/ch/admin/bag/covidcertificate/backend/verifier/ws/util/MockForeignRuleDataService.java @@ -15,7 +15,7 @@ public class MockForeignRuleDataService implements ForeignRulesDataService { private final ForeignRule at1 = new ForeignRule(); private final ForeignRule at2 = new ForeignRule(); - public MockForeignRuleDataService(){ + public MockForeignRuleDataService() { at1.setId("GR-AT-0039"); at1.setVersion("0.0.1"); at1.setCountry("AT"); @@ -38,22 +38,18 @@ public List getCountries() { @Override public List getRulesForCountry(String country) { - if(country.equals("AT")){ + if (country.equals("AT")) { return Arrays.asList(at1, at2); - }else if(country.equals("DE")){ + } else if (country.equals("DE")) { return new ArrayList<>(); - }else{ + } else { return new ArrayList<>(); } } @Override - public void insertRule(ForeignRule rule) { - - } + public void insertRule(ForeignRule rule) {} @Override - public void removeRuleSet(String country) { - - } + public void removeRuleSet(String country) {} }