From 14d8a84f5f1f052b9a9e5a43bc1678ce72844735 Mon Sep 17 00:00:00 2001 From: Hilmar Falkenberg Date: Mon, 10 Oct 2022 15:28:50 +0200 Subject: [PATCH] merge pandamic radar from main into Release 2.28 (#1930) * Update maven.config (#1922) preparation for release 2.29 * auto close json-schema InputStream (#1923) * Bump test-containers.version from 1.17.4 to 1.17.5 (#1925) Bumps `test-containers.version` from 1.17.4 to 1.17.5. Updates `testcontainers` from 1.17.4 to 1.17.5 - [Release notes](https://github.com/testcontainers/testcontainers-java/releases) - [Changelog](https://github.com/testcontainers/testcontainers-java/blob/main/CHANGELOG.md) - [Commits](https://github.com/testcontainers/testcontainers-java/compare/1.17.4...1.17.5) Updates `junit-jupiter` from 1.17.4 to 1.17.5 - [Release notes](https://github.com/testcontainers/testcontainers-java/releases) - [Changelog](https://github.com/testcontainers/testcontainers-java/blob/main/CHANGELOG.md) - [Commits](https://github.com/testcontainers/testcontainers-java/compare/1.17.4...1.17.5) Updates `postgresql` from 1.17.4 to 1.17.5 - [Release notes](https://github.com/testcontainers/testcontainers-java/releases) - [Changelog](https://github.com/testcontainers/testcontainers-java/blob/main/CHANGELOG.md) - [Commits](https://github.com/testcontainers/testcontainers-java/compare/1.17.4...1.17.5) --- updated-dependencies: - dependency-name: org.testcontainers:testcontainers dependency-type: direct:development update-type: version-update:semver-patch - dependency-name: org.testcontainers:junit-jupiter dependency-type: direct:development update-type: version-update:semver-patch - dependency-name: org.testcontainers:postgresql dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump tomcat.version from 9.0.67 to 9.0.68 (#1929) Bumps `tomcat.version` from 9.0.67 to 9.0.68. Updates `tomcat-embed-core` from 9.0.67 to 9.0.68 Updates `tomcat-embed-el` from 9.0.67 to 9.0.68 Updates `tomcat-annotations-api` from 9.0.67 to 9.0.68 --- updated-dependencies: - dependency-name: org.apache.tomcat.embed:tomcat-embed-core dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.apache.tomcat.embed:tomcat-embed-el dependency-type: direct:production update-type: version-update:semver-patch - dependency-name: org.apache.tomcat:tomcat-annotations-api dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * split also the retention policy by profile (#1927) (#1928) * Protocol Buffer update for release 2.28.x at Wed Oct 5 12:10:37 UTC 2022 (#1926) * Update from https://github.com/corona-warn-app/cwa-protocol-buffers/commit/f5a31a861483cb9d2410c81aca0bc3f8617445a2 * proposal/draft STATISTICS_PANDEMIC_RADAR_URL * corrected param name * LinkCard setHeader * dummy LinkCardFactory for new enum: PANDEMIC_RADAR_CARD * tests for pandemic radar card * move up * refactoring Co-authored-by: Hilmar Falkenberg Co-authored-by: SAP * Protocol Buffer update for release 2.28.x at Wed Oct 5 12:10:37 UTC 2022 (#1926) * Update from https://github.com/corona-warn-app/cwa-protocol-buffers/commit/f5a31a861483cb9d2410c81aca0bc3f8617445a2 * proposal/draft STATISTICS_PANDEMIC_RADAR_URL * corrected param name * LinkCard setHeader * dummy LinkCardFactory for new enum: PANDEMIC_RADAR_CARD * tests for pandemic radar card * move up * refactoring Co-authored-by: Hilmar Falkenberg Co-authored-by: SAP Signed-off-by: dependabot[bot] Co-authored-by: mfromme <42937780+mfromme@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: CWA Technical User <67319337+Corona-Warn-App-Technical-User@users.noreply.github.com> Co-authored-by: SAP --- .../protocols/internal/stats/link_card.proto | 12 +++++++ .../protocols/internal/stats/statistics.proto | 3 ++ pom.xml | 4 +-- .../config/DistributionServiceConfig.java | 10 ++++++ .../StatisticsToProtobufMapping.java | 9 +++++ .../statistics/keyfigurecard/Cards.java | 5 ++- .../factory/EmptyCardFactory.java | 17 ---------- .../factory/HeaderCardFactory.java | 11 ++++-- .../factory/LinkCardFactory.java | 11 ++++++ .../src/main/resources/application.yaml | 3 +- .../statistics/KeyFigureCardFactoryTest.java | 34 +++++++++++++++++++ .../src/test/resources/application.yaml | 1 + 12 files changed, 96 insertions(+), 24 deletions(-) create mode 100644 common/protocols/src/main/proto/app/coronawarn/server/common/protocols/internal/stats/link_card.proto create mode 100644 services/distribution/src/main/java/app/coronawarn/server/services/distribution/statistics/keyfigurecard/factory/LinkCardFactory.java diff --git a/common/protocols/src/main/proto/app/coronawarn/server/common/protocols/internal/stats/link_card.proto b/common/protocols/src/main/proto/app/coronawarn/server/common/protocols/internal/stats/link_card.proto new file mode 100644 index 0000000000..1307d5a986 --- /dev/null +++ b/common/protocols/src/main/proto/app/coronawarn/server/common/protocols/internal/stats/link_card.proto @@ -0,0 +1,12 @@ +// This file is auto-generated, DO NOT make any changes here +syntax = "proto3"; +package app.coronawarn.server.common.protocols.internal.stats; +option java_multiple_files = true; +import "app/coronawarn/server/common/protocols/internal/stats/card_header.proto"; + +message LinkCard { + + CardHeader header = 1; + + string url = 2; +} \ No newline at end of file diff --git a/common/protocols/src/main/proto/app/coronawarn/server/common/protocols/internal/stats/statistics.proto b/common/protocols/src/main/proto/app/coronawarn/server/common/protocols/internal/stats/statistics.proto index 37fc54c318..6eb6726caf 100644 --- a/common/protocols/src/main/proto/app/coronawarn/server/common/protocols/internal/stats/statistics.proto +++ b/common/protocols/src/main/proto/app/coronawarn/server/common/protocols/internal/stats/statistics.proto @@ -3,6 +3,7 @@ syntax = "proto3"; package app.coronawarn.server.common.protocols.internal.stats; option java_multiple_files = true; import "app/coronawarn/server/common/protocols/internal/stats/key_figure_card.proto"; +import "app/coronawarn/server/common/protocols/internal/stats/link_card.proto"; message Statistics { @@ -11,4 +12,6 @@ message Statistics { repeated int32 cardIdSequence = 1; repeated KeyFigureCard keyFigureCards = 2; + + repeated LinkCard linkCards = 3; } \ No newline at end of file diff --git a/pom.xml b/pom.xml index 2d1bdac9ff..ad02141371 100644 --- a/pom.xml +++ b/pom.xml @@ -68,12 +68,12 @@ 4.1.82.Final 31.1-jre 2.13.4 - 1.17.4 + 1.17.5 42.5.0 2.34.0 4.5.13 4.13.2 - 9.0.67 + 9.0.68 0.2.6 10.3.4 3.1.0 diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/config/DistributionServiceConfig.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/config/DistributionServiceConfig.java index be8868b0a4..b3b1b05ce5 100644 --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/config/DistributionServiceConfig.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/config/DistributionServiceConfig.java @@ -338,6 +338,16 @@ public static class StatisticsConfig { private String bucket; + private String pandemicRadarUrl; + + public String getPandemicRadarUrl() { + return pandemicRadarUrl; + } + + public void setPandemicRadarUrl(String pandemicRadarUrl) { + this.pandemicRadarUrl = pandemicRadarUrl; + } + public String getLocalStatisticPath() { return localStatisticPath; } diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/statistics/StatisticsToProtobufMapping.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/statistics/StatisticsToProtobufMapping.java index c60389716a..1f60434150 100644 --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/statistics/StatisticsToProtobufMapping.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/statistics/StatisticsToProtobufMapping.java @@ -15,7 +15,9 @@ import static app.coronawarn.server.services.distribution.statistics.keyfigurecard.Cards.getNameFor; import app.coronawarn.server.common.persistence.service.StatisticsDownloadService; +import app.coronawarn.server.common.protocols.internal.stats.CardHeader; import app.coronawarn.server.common.protocols.internal.stats.KeyFigureCard; +import app.coronawarn.server.common.protocols.internal.stats.LinkCard; import app.coronawarn.server.common.protocols.internal.stats.Statistics; import app.coronawarn.server.common.shared.util.SerializationUtils; import app.coronawarn.server.common.shared.util.TimeUtils; @@ -116,6 +118,7 @@ public Statistics constructProtobufStatistics() { return Statistics.newBuilder() .addAllCardIdSequence(getAllCardIdSequence()) .addAllKeyFigureCards(buildAllKeyFigureCards(jsonStringObjects)) + .addAllLinkCards(buildAllLinkCards()) .build(); } } catch (BucketNotFoundException | ConnectionException | FilePathNotFoundException | IOException ex) { @@ -124,6 +127,12 @@ public Statistics constructProtobufStatistics() { } } + private Iterable buildAllLinkCards() { + return Collections.singleton( + LinkCard.newBuilder().setHeader(CardHeader.newBuilder().setCardId(Cards.PANDEMIC_RADAR_CARD.ordinal()).build()) + .setUrl(distributionServiceConfig.getStatistics().getPandemicRadarUrl()).build()); + } + private List getAllCardIdSequence() { String[] idSequenceArray = distributionServiceConfig.getCardIdSequence() .replace("[", "").replace("]", "") diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/statistics/keyfigurecard/Cards.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/statistics/keyfigurecard/Cards.java index beceb471d8..fc57dca2aa 100644 --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/statistics/keyfigurecard/Cards.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/statistics/keyfigurecard/Cards.java @@ -12,6 +12,7 @@ import app.coronawarn.server.services.distribution.statistics.keyfigurecard.factory.IntensiveCareCardFactory; import app.coronawarn.server.services.distribution.statistics.keyfigurecard.factory.JoinedIncidenceCardFactory; import app.coronawarn.server.services.distribution.statistics.keyfigurecard.factory.KeySubmissionCardFactory; +import app.coronawarn.server.services.distribution.statistics.keyfigurecard.factory.LinkCardFactory; import app.coronawarn.server.services.distribution.statistics.keyfigurecard.factory.ReproductionNumberCardFactory; import app.coronawarn.server.services.distribution.statistics.keyfigurecard.factory.VaccinationDosesCardFactory; @@ -64,7 +65,9 @@ public enum Cards { /** * Third Dose Card. */ - BOOSTER_VACCINATED_CARD(new BoosterVaccinatedCardFactory(), "Booster Vaccinated Card"); + BOOSTER_VACCINATED_CARD(new BoosterVaccinatedCardFactory(), "Booster Vaccinated Card"), + + PANDEMIC_RADAR_CARD(new LinkCardFactory(), "Link Card"); /** * Get card factory by ID. diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/statistics/keyfigurecard/factory/EmptyCardFactory.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/statistics/keyfigurecard/factory/EmptyCardFactory.java index c71de0db54..35c5bc77ae 100644 --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/statistics/keyfigurecard/factory/EmptyCardFactory.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/statistics/keyfigurecard/factory/EmptyCardFactory.java @@ -2,27 +2,10 @@ import static app.coronawarn.server.services.distribution.statistics.keyfigurecard.Cards.EMPTY_CARD; -import app.coronawarn.server.common.protocols.internal.stats.KeyFigureCard; -import app.coronawarn.server.common.protocols.internal.stats.KeyFigureCard.Builder; -import app.coronawarn.server.services.distribution.statistics.StatisticsJsonStringObject; -import java.util.Collections; -import java.util.List; -import java.util.Optional; - public class EmptyCardFactory extends HeaderCardFactory { @Override protected int getCardId() { return EMPTY_CARD.ordinal(); } - - @Override - protected KeyFigureCard buildKeyFigureCard(StatisticsJsonStringObject stats, Builder keyFigureBuilder) { - return keyFigureBuilder.build(); - } - - @Override - protected List> getRequiredFieldValues(StatisticsJsonStringObject stats) { - return Collections.emptyList(); - } } diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/statistics/keyfigurecard/factory/HeaderCardFactory.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/statistics/keyfigurecard/factory/HeaderCardFactory.java index 11b2ae2b31..1635d04755 100644 --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/statistics/keyfigurecard/factory/HeaderCardFactory.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/statistics/keyfigurecard/factory/HeaderCardFactory.java @@ -5,10 +5,12 @@ import app.coronawarn.server.common.protocols.internal.stats.CardHeader; import app.coronawarn.server.common.protocols.internal.stats.KeyFigureCard; +import app.coronawarn.server.common.protocols.internal.stats.KeyFigureCard.Builder; import app.coronawarn.server.services.distribution.config.DistributionServiceConfig; import app.coronawarn.server.services.distribution.statistics.StatisticsJsonStringObject; import java.time.LocalDate; import java.time.format.DateTimeFormatter; +import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; @@ -57,8 +59,9 @@ private void throwIfNullFieldsFound(StatisticsJsonStringObject stats) { protected abstract int getCardId(); - protected abstract KeyFigureCard buildKeyFigureCard(StatisticsJsonStringObject stats, - KeyFigureCard.Builder keyFigureBuilder); + protected KeyFigureCard buildKeyFigureCard(StatisticsJsonStringObject stats, Builder keyFigureBuilder) { + return keyFigureBuilder == null ? null : keyFigureBuilder.build(); + } /** * Return the list of required fields to create this card. Implemented by factories. If any of the fields returned by @@ -68,7 +71,9 @@ protected abstract KeyFigureCard buildKeyFigureCard(StatisticsJsonStringObject s * @param stats JSON string object. * @return List of objects to be checked if are null. */ - protected abstract List> getRequiredFieldValues(StatisticsJsonStringObject stats); + protected List> getRequiredFieldValues(StatisticsJsonStringObject stats) { + return Collections.emptyList(); + } public void setConfig(final DistributionServiceConfig config) { this.config = config; diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/statistics/keyfigurecard/factory/LinkCardFactory.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/statistics/keyfigurecard/factory/LinkCardFactory.java new file mode 100644 index 0000000000..d44b25e9a7 --- /dev/null +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/statistics/keyfigurecard/factory/LinkCardFactory.java @@ -0,0 +1,11 @@ +package app.coronawarn.server.services.distribution.statistics.keyfigurecard.factory; + +import static app.coronawarn.server.services.distribution.statistics.keyfigurecard.Cards.PANDEMIC_RADAR_CARD; + +public class LinkCardFactory extends HeaderCardFactory { + + @Override + public int getCardId() { + return PANDEMIC_RADAR_CARD.ordinal(); + } +} diff --git a/services/distribution/src/main/resources/application.yaml b/services/distribution/src/main/resources/application.yaml index 1071dec043..07eb7d9b24 100644 --- a/services/distribution/src/main/resources/application.yaml +++ b/services/distribution/src/main/resources/application.yaml @@ -38,7 +38,7 @@ services: eu-package-name: EUR # Indicates whether the shifting and expiry policies are applied to all supported countries during distribution. apply-policies-for-all-countries: false - card-id-sequence: ${STATS_CARD_ID_SEQUENCE:[10,2,8,9,1,3,4,5,6,11,7]} + card-id-sequence: ${STATS_CARD_ID_SEQUENCE:[12,999,10,2,8,9,1,3,4,5,6,11,7]} # Local paths, that are used during the export creation. connection-pool-size: 200 default-archive-name: export.bin @@ -117,6 +117,7 @@ services: secret-key: ${STATISTICS_FILE_SECRET_ACCESS_KEY:} endpoint: ${STATISTICS_FILE_S3_ENDPOINT:} bucket: ${STATISTICS_FILE_S3_BUCKET:obs-cwa-public-dev} + pandemic-radar-url: ${STATISTICS_PANDEMIC_RADAR_URL:https://www.rki.de/DE/Content/InfAZ/N/Neuartiges_Coronavirus/Situationsberichte/COVID-19-Trends/COVID-19-Trends.html?__blob=publicationFile#/home} app-features: - label: unencrypted-checkins-enabled diff --git a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/statistics/KeyFigureCardFactoryTest.java b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/statistics/KeyFigureCardFactoryTest.java index 8d9802f6bd..9ad50042e3 100644 --- a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/statistics/KeyFigureCardFactoryTest.java +++ b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/statistics/KeyFigureCardFactoryTest.java @@ -8,19 +8,25 @@ import static app.coronawarn.server.services.distribution.statistics.keyfigurecard.Cards.INFECTIONS_CARD; import static app.coronawarn.server.services.distribution.statistics.keyfigurecard.Cards.INTENSIVE_CARE_CARD; import static app.coronawarn.server.services.distribution.statistics.keyfigurecard.Cards.KEY_SUBMISSION_CARD; +import static app.coronawarn.server.services.distribution.statistics.keyfigurecard.Cards.PANDEMIC_RADAR_CARD; import static app.coronawarn.server.services.distribution.statistics.keyfigurecard.Cards.REPRODUCTION_NUMBER_CARD; import static app.coronawarn.server.services.distribution.statistics.keyfigurecard.Cards.VACCINATION_DOSES_CARD; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertEquals; +import app.coronawarn.server.common.protocols.internal.stats.CardHeader; import app.coronawarn.server.common.protocols.internal.stats.KeyFigure; import app.coronawarn.server.common.protocols.internal.stats.KeyFigure.Rank; import app.coronawarn.server.common.protocols.internal.stats.KeyFigure.Trend; import app.coronawarn.server.common.protocols.internal.stats.KeyFigure.TrendSemantic; +import app.coronawarn.server.common.protocols.internal.stats.KeyFigureCard; +import app.coronawarn.server.common.protocols.internal.stats.LinkCard; import app.coronawarn.server.services.distribution.config.DistributionServiceConfig; +import app.coronawarn.server.services.distribution.statistics.keyfigurecard.Cards; import app.coronawarn.server.services.distribution.statistics.keyfigurecard.KeyFigureCardFactory; import app.coronawarn.server.services.distribution.statistics.keyfigurecard.factory.MissingPropertyException; +import org.junit.Assert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; @@ -486,6 +492,34 @@ void testCardHasCorrectKeyFigures() { } } + @Nested + @EnableConfigurationProperties(value = DistributionServiceConfig.class) + @ContextConfiguration(classes = { + KeyFigureCardFactory.class}, initializers = ConfigDataApplicationContextInitializer.class) + class PandemicRadarCardTest { + + @Autowired + DistributionServiceConfig distributionServiceConfig; + + @Test + void pandemicRadarCardCreeationShouldReturnNull() { + KeyFigureCard keyFigureCard = figureCardFactory.createKeyFigureCard(statisticsJsonStringObject, PANDEMIC_RADAR_CARD.ordinal()); + Assert.assertNotNull(keyFigureCard); + Assert.assertEquals(0, keyFigureCard.getKeyFiguresCount()); + } + + @Test + void pandemicRadarCardAttributeTest() { + LinkCard card = LinkCard.newBuilder() + .setHeader(CardHeader.newBuilder().setCardId(PANDEMIC_RADAR_CARD.ordinal()).build()) + .setUrl(distributionServiceConfig.getStatistics().getPandemicRadarUrl()).build(); + CardHeader header = card.getHeader(); + Assert.assertEquals(0L, header.getUpdatedAt()); + Assert.assertEquals(12, header.getCardId()); + Assert.assertEquals("https://www.rki.de/DE/Content/InfAZ/N/Neuartiges_Coronavirus/Situationsberichte/COVID-19-Trends/COVID-19-Trends.html?__blob=publicationFile#/home", card.getUrl()); + } + } + private void assertKeyFigure(KeyFigure result, double value, Rank rank, Trend trend, TrendSemantic trendSemantic, Integer decimals) { assertThat(result).extracting(KeyFigure::getValue, KeyFigure::getRank, KeyFigure::getTrend, diff --git a/services/distribution/src/test/resources/application.yaml b/services/distribution/src/test/resources/application.yaml index 938e9d0f66..f6155042e5 100644 --- a/services/distribution/src/test/resources/application.yaml +++ b/services/distribution/src/test/resources/application.yaml @@ -75,6 +75,7 @@ services: secret-key: secretKey endpoint: https://localhost bucket: ${STATS_S3_BUCKET:obs-cwa-public-dev} + pandemic-radar-url: ${STATISTICS_PANDEMIC_RADAR_URL:https://www.rki.de/DE/Content/InfAZ/N/Neuartiges_Coronavirus/Situationsberichte/COVID-19-Trends/COVID-19-Trends.html?__blob=publicationFile#/home} app-features: - label: unencrypted-checkins-enabled