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

Commit

Permalink
STATISTICS_PANDEMIC_RADAR_BMG
Browse files Browse the repository at this point in the history
  • Loading branch information
hilmarf committed Dec 7, 2022
1 parent 9218b2d commit 705480e
Show file tree
Hide file tree
Showing 20 changed files with 1,731 additions and 1,578 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,12 @@ public Statistics constructProtobufStatistics() {
}

private Iterable<? extends LinkCard> buildAllLinkCards() {
return Collections.singleton(
return List.of(
LinkCard.newBuilder().setHeader(CardHeader.newBuilder().setCardId(Cards.PANDEMIC_RADAR_CARD.ordinal()).build())
.setUrl(distributionServiceConfig.getStatistics().getPandemicRadarUrl()).build());
.setUrl(distributionServiceConfig.getStatistics().getPandemicRadarUrl()).build(),
LinkCard.newBuilder()
.setHeader(CardHeader.newBuilder().setCardId(Cards.PANDEMIC_RADAR_BMG_CARD.ordinal()).build())
.setUrl(distributionServiceConfig.getStatistics().getPandemicRadarBmgUrl()).build());
}

private List<Integer> getAllCardIdSequence() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,67 +21,98 @@ public enum Cards {
/**
* Empty card.
*/
EMPTY_CARD(new EmptyCardFactory(), "EMPTY CARD"),
EMPTY_CARD("EMPTY CARD"),
/**
* Infections Card.
*/
INFECTIONS_CARD(new InfectionsCardFactory(), "Infections Card"),
INFECTIONS_CARD("Infections Card"),
/**
* Incidence Card.
*/
INCIDENCE_CARD(new IncidenceCardFactory(), "Incidence Card"),
INCIDENCE_CARD("Incidence Card"),
/**
* Key Submission Card.
*/
KEY_SUBMISSION_CARD(new KeySubmissionCardFactory(), "Key Submission Card"),
KEY_SUBMISSION_CARD("Key Submission Card"),
/**
* Reproduction Number Card.
*/
REPRODUCTION_NUMBER_CARD(new ReproductionNumberCardFactory(), "Reproduction Number Card"),
REPRODUCTION_NUMBER_CARD("Reproduction Number Card"),
/**
* First Vaccination Card.
*/
FIRST_VACCINATION_CARD(new FirstVaccinationCardFactory(), "First Vaccination Card"),
FIRST_VACCINATION_CARD("First Vaccination Card"),
/**
* Fully Vaccincated Card.
*/
FULLY_VACCINATED_CARD(new FullyVaccinatedCardFactory(), "Fully Vaccincated Card"),
FULLY_VACCINATED_CARD("Fully Vaccincated Card"),
/**
* Vaccination Doses Card.
*/
VACCINATION_DOSES_CARD(new VaccinationDosesCardFactory(), "Vaccination Doses Card"),
VACCINATION_DOSES_CARD("Vaccination Doses Card"),
/**
* Hospitalization Incidence Card.
*/
HOSPITALIZATION_INCIDENCE_CARD(new HospitalizationIncidenceCardFactory(), "Hospitalization Incidence Card"),
HOSPITALIZATION_INCIDENCE_CARD("Hospitalization Incidence Card"),
/**
* Intensive Care Card.
*/
INTENSIVE_CARE_CARD(new IntensiveCareCardFactory(), "Intensive Care Card"),
INTENSIVE_CARE_CARD("Intensive Care Card"),
/**
* Joined Incidence Card.
*/
JOINED_INCIDENCE_CARD(new JoinedIncidenceCardFactory(), "Joined incidence Card"),
JOINED_INCIDENCE_CARD("Joined incidence Card"),
/**
* Third Dose Card.
*/
BOOSTER_VACCINATED_CARD(new BoosterVaccinatedCardFactory(), "Booster Vaccinated Card"),

PANDEMIC_RADAR_CARD(new LinkCardFactory(), "Link Card");
BOOSTER_VACCINATED_CARD("Booster Vaccinated Card"),
/**
* Outdated pandemic radar URL card.
*/
PANDEMIC_RADAR_CARD("Link Card"),
/**
* New pandemic radar (BMG) URL card.
*/
PANDEMIC_RADAR_BMG_CARD("Pandemic Radar Card (BMG)"),
;

/**
* Get card factory by ID.
*
* @param id {@link #ordinal()}
* @param card {@link #ordinal()}
* @param config The distribution configuration used to get the infection threshold parameter.
* @return {@link #getFactory()}
*/
public static HeaderCardFactory getFactoryFor(final int id, final DistributionServiceConfig config) {
try {
values()[id].getFactory().setConfig(config);
return values()[id].getFactory();
} catch (final ArrayIndexOutOfBoundsException e) {
return EMPTY_CARD.getFactory();
public static HeaderCardFactory getFactoryFor(final Cards card, final DistributionServiceConfig config) {
switch (card) {
case INFECTIONS_CARD:
return new InfectionsCardFactory(config);
case INCIDENCE_CARD:
return new IncidenceCardFactory(config);
case KEY_SUBMISSION_CARD:
return new KeySubmissionCardFactory(config);
case REPRODUCTION_NUMBER_CARD:
return new ReproductionNumberCardFactory(config);
case FIRST_VACCINATION_CARD:
return new FirstVaccinationCardFactory(config);
case FULLY_VACCINATED_CARD:
return new FullyVaccinatedCardFactory(config);
case VACCINATION_DOSES_CARD:
return new VaccinationDosesCardFactory(config);
case HOSPITALIZATION_INCIDENCE_CARD:
return new HospitalizationIncidenceCardFactory(config);
case INTENSIVE_CARE_CARD:
return new IntensiveCareCardFactory(config);
case JOINED_INCIDENCE_CARD:
return new JoinedIncidenceCardFactory(config);
case BOOSTER_VACCINATED_CARD:
return new BoosterVaccinatedCardFactory(config);
case PANDEMIC_RADAR_CARD:
return new LinkCardFactory(config, PANDEMIC_RADAR_CARD);
case PANDEMIC_RADAR_BMG_CARD:
return new LinkCardFactory(config, PANDEMIC_RADAR_BMG_CARD);
default:
return new EmptyCardFactory(config);
}
}

Expand All @@ -99,19 +130,12 @@ public static String getNameFor(final int id) {
}
}

final HeaderCardFactory factory;

final String name;

Cards(final HeaderCardFactory factory, final String name) {
this.factory = factory;
Cards(final String name) {
this.name = name;
}

HeaderCardFactory getFactory() {
return factory;
}

String getName() {
return name;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
package app.coronawarn.server.services.distribution.statistics.keyfigurecard;

import static app.coronawarn.server.services.distribution.statistics.keyfigurecard.Cards.getFactoryFor;
import static app.coronawarn.server.services.distribution.statistics.keyfigurecard.Cards.values;

import app.coronawarn.server.common.protocols.internal.stats.KeyFigureCard;
import app.coronawarn.server.services.distribution.config.DistributionServiceConfig;
import app.coronawarn.server.services.distribution.statistics.StatisticsJsonStringObject;
import app.coronawarn.server.services.distribution.statistics.keyfigurecard.factory.EmptyCardFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class KeyFigureCardFactory {

private static final Logger logger = LoggerFactory.getLogger(KeyFigureCardFactory.class);

@Autowired
DistributionServiceConfig distributionServiceConfig;

public KeyFigureCard createKeyFigureCard(StatisticsJsonStringObject stats, int cardId) {
return getFactoryFor(cardId, this.distributionServiceConfig).makeKeyFigureCard(stats);
/**
* Creates a new statistics card, based upon the given ordinal.
*
* @param stats data for the card.
* @param cardId ordinal number of {@link Cards}.
* @return a new {@link KeyFigureCard}.
*/
public KeyFigureCard createKeyFigureCard(final StatisticsJsonStringObject stats, final int cardId) {
try {
return getFactoryFor(values()[cardId], distributionServiceConfig).makeKeyFigureCard(stats);
} catch (final IndexOutOfBoundsException e) {
logger.error(Cards.class + " doesn't contain value for: " + cardId, e);
return new EmptyCardFactory(distributionServiceConfig).makeKeyFigureCard(stats);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@
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.KeyFigureCard.Builder;
import app.coronawarn.server.services.distribution.config.DistributionServiceConfig;
import app.coronawarn.server.services.distribution.statistics.StatisticsJsonStringObject;
import java.util.List;
import java.util.Optional;

public class BoosterVaccinatedCardFactory extends HeaderCardFactory {

public BoosterVaccinatedCardFactory(final DistributionServiceConfig config) {
super(config);
}

@Override
protected int getCardId() {
return BOOSTER_VACCINATED_CARD.ordinal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

import static app.coronawarn.server.services.distribution.statistics.keyfigurecard.Cards.EMPTY_CARD;

import app.coronawarn.server.services.distribution.config.DistributionServiceConfig;

public class EmptyCardFactory extends HeaderCardFactory {

public EmptyCardFactory(final DistributionServiceConfig config) {
super(config);
}

@Override
protected int getCardId() {
return EMPTY_CARD.ordinal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@
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.KeyFigureCard.Builder;
import app.coronawarn.server.services.distribution.config.DistributionServiceConfig;
import app.coronawarn.server.services.distribution.statistics.StatisticsJsonStringObject;
import java.util.List;
import java.util.Optional;

public class FirstVaccinationCardFactory extends HeaderCardFactory {

public FirstVaccinationCardFactory(final DistributionServiceConfig config) {
super(config);
}

@Override
protected int getCardId() {
return FIRST_VACCINATION_CARD.ordinal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@
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.KeyFigureCard.Builder;
import app.coronawarn.server.services.distribution.config.DistributionServiceConfig;
import app.coronawarn.server.services.distribution.statistics.StatisticsJsonStringObject;
import java.util.List;
import java.util.Optional;

public class FullyVaccinatedCardFactory extends HeaderCardFactory {

public FullyVaccinatedCardFactory(final DistributionServiceConfig config) {
super(config);
}

@Override
protected int getCardId() {
return FULLY_VACCINATED_CARD.ordinal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public abstract class HeaderCardFactory {

protected DistributionServiceConfig config;

public HeaderCardFactory(final DistributionServiceConfig config) {
this.config = config;
}

/**
* Create KeyFigureCard object. Calls the children method `buildKeyFigureCard` for card specific properties. This
* method adds the generic CardHeader that all KeyFigureCards must have.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
import app.coronawarn.server.common.protocols.internal.stats.KeyFigure.Rank;
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 app.coronawarn.server.services.distribution.statistics.keyfigurecard.ValueTrendCalculator;
import java.util.List;
import java.util.Optional;

public class HospitalizationIncidenceCardFactory extends HeaderCardFactory {

public HospitalizationIncidenceCardFactory(final DistributionServiceConfig config) {
super(config);
}

@Override
protected int getCardId() {
return HOSPITALIZATION_INCIDENCE_CARD.ordinal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
import app.coronawarn.server.common.protocols.internal.stats.KeyFigure.Rank;
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 app.coronawarn.server.services.distribution.statistics.keyfigurecard.ValueTrendCalculator;
import java.util.List;
import java.util.Optional;

public class IncidenceCardFactory extends HeaderCardFactory {

public IncidenceCardFactory(final DistributionServiceConfig config) {
super(config);
}

@Override
protected int getCardId() {
return INCIDENCE_CARD.ordinal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import app.coronawarn.server.common.protocols.internal.stats.KeyFigure;
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 app.coronawarn.server.services.distribution.statistics.keyfigurecard.ValueTrendCalculator;
import java.util.List;
Expand All @@ -19,6 +20,10 @@

public class InfectionsCardFactory extends HeaderCardFactory {

public InfectionsCardFactory(final DistributionServiceConfig config) {
super(config);
}

private static final Logger logger = LoggerFactory.getLogger(InfectionsCardFactory.class);

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@
import app.coronawarn.server.common.protocols.internal.stats.KeyFigure.Rank;
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 app.coronawarn.server.services.distribution.statistics.keyfigurecard.ValueTrendCalculator;
import java.util.List;
import java.util.Optional;

public class IntensiveCareCardFactory extends HeaderCardFactory {

public IntensiveCareCardFactory(final DistributionServiceConfig config) {
super(config);
}

@Override
protected int getCardId() {
return INTENSIVE_CARE_CARD.ordinal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import app.coronawarn.server.common.protocols.internal.stats.KeyFigure.Rank;
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 app.coronawarn.server.services.distribution.statistics.keyfigurecard.ValueTrendCalculator;
import java.time.LocalDate;
Expand All @@ -15,6 +16,10 @@

public class JoinedIncidenceCardFactory extends HeaderCardFactory {

public JoinedIncidenceCardFactory(final DistributionServiceConfig config) {
super(config);
}

@Override
protected int getCardId() {
return JOINED_INCIDENCE_CARD.ordinal();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
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.KeyFigureCard.Builder;
import app.coronawarn.server.services.distribution.config.DistributionServiceConfig;
import app.coronawarn.server.services.distribution.statistics.StatisticsJsonStringObject;
import app.coronawarn.server.services.distribution.statistics.keyfigurecard.ValueTrendCalculator;
import java.util.List;
import java.util.Optional;


public class KeySubmissionCardFactory extends HeaderCardFactory {

public KeySubmissionCardFactory(final DistributionServiceConfig config) {
super(config);
}

@Override
protected int getCardId() {
return KEY_SUBMISSION_CARD.ordinal();
Expand Down
Loading

0 comments on commit 705480e

Please sign in to comment.