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

Commit

Permalink
Merge branch 'rel/0.5.8' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-kirschnick committed Jun 4, 2020
2 parents ad1cd64 + 2dce81c commit 85c5d35
Show file tree
Hide file tree
Showing 10 changed files with 105 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .mvn/maven.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-Drevision=0.5.7
-Drevision=0.5.8
-Dlicense.projectName=Corona-Warn-App
-Dlicense.inceptionYear=2020
-Dlicense.licenseName=apache_v2
2 changes: 1 addition & 1 deletion common/persistence/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
<version>2.0.0</version>
<configuration>
<includes>**/*.java</includes>
<copyrightOwners>${organization.name} and all other contributors</copyrightOwners>
<copyrightOwners>${project.organization.name} and all other contributors</copyrightOwners>
<processStartTag>---license-start</processStartTag>
<processEndTag>---license-end</processEndTag>
<sectionDelimiter>---</sectionDelimiter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ option java_multiple_files = true;
message AttenuationDuration {
Thresholds thresholds = 1;
Weights weights = 2;
int32 defaultBucketOffset = 3;
int32 riskScoreNormalizationDivisor = 4;
}

message Thresholds {
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<version>2.0.0</version>
<configuration>
<includes>**/*.java</includes>
<copyrightOwners>${organization.name} and all other contributors</copyrightOwners>
<copyrightOwners>${project.organization.name} and all other contributors</copyrightOwners>
<processStartTag>---license-start</processStartTag>
<processEndTag>---license-end</processEndTag>
<sectionDelimiter>---</sectionDelimiter>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
import static app.coronawarn.server.services.distribution.assembly.appconfig.validation.ParameterSpec.ATTENUATION_DURATION_THRESHOLD_MIN;
import static app.coronawarn.server.services.distribution.assembly.appconfig.validation.ParameterSpec.ATTENUATION_DURATION_WEIGHT_MAX;
import static app.coronawarn.server.services.distribution.assembly.appconfig.validation.ParameterSpec.ATTENUATION_DURATION_WEIGHT_MIN;
import static app.coronawarn.server.services.distribution.assembly.appconfig.validation.ParameterSpec.DEFAULT_BUCKET_OFFSET_MAX;
import static app.coronawarn.server.services.distribution.assembly.appconfig.validation.ParameterSpec.DEFAULT_BUCKET_OFFSET_MIN;
import static app.coronawarn.server.services.distribution.assembly.appconfig.validation.ParameterSpec.RISK_SCORE_NORMALIZATION_DIVISOR_MAX;
import static app.coronawarn.server.services.distribution.assembly.appconfig.validation.ParameterSpec.RISK_SCORE_NORMALIZATION_DIVISOR_MIN;
import static app.coronawarn.server.services.distribution.assembly.appconfig.validation.WeightValidationError.ErrorType.OUT_OF_RANGE;
import static app.coronawarn.server.services.distribution.assembly.appconfig.validation.WeightValidationError.ErrorType.TOO_MANY_DECIMAL_PLACES;

Expand All @@ -49,6 +53,8 @@ public ValidationResult validate() {

validateThresholds();
validateWeights();
validateDefaultBucketOffset();
validateRiskScoreNormalizationDivisor();

return errors;
}
Expand All @@ -57,8 +63,8 @@ private void validateThresholds() {
int lower = attenuationDuration.getThresholds().getLower();
int upper = attenuationDuration.getThresholds().getUpper();

checkThresholdBound("lower", lower);
checkThresholdBound("upper", upper);
checkValueRange("thresholds.lower", lower, ATTENUATION_DURATION_THRESHOLD_MIN, ATTENUATION_DURATION_THRESHOLD_MAX);
checkValueRange("thresholds.upper", upper, ATTENUATION_DURATION_THRESHOLD_MIN, ATTENUATION_DURATION_THRESHOLD_MAX);

if (lower > upper) {
String parameters = "attenuation-duration.thresholds.lower, attenuation-duration.thresholds.upper";
Expand All @@ -67,10 +73,10 @@ private void validateThresholds() {
}
}

private void checkThresholdBound(String thresholdLabel, int thresholdValue) {
if (thresholdValue < ATTENUATION_DURATION_THRESHOLD_MIN || thresholdValue > ATTENUATION_DURATION_THRESHOLD_MAX) {
private void checkValueRange(String parameterLabel, int value, int min, int max) {
if (value < min || value > max) {
this.errors.add(new GeneralValidationError(
"attenuation-duration.thresholds." + thresholdLabel, thresholdValue, VALUE_OUT_OF_BOUNDS));
"attenuation-duration." + parameterLabel, value, VALUE_OUT_OF_BOUNDS));
}
}

Expand All @@ -91,4 +97,15 @@ private void checkWeight(String weightLabel, double weightValue) {
"attenuation-duration.weights." + weightLabel, weightValue, TOO_MANY_DECIMAL_PLACES));
}
}

private void validateDefaultBucketOffset() {
int bucketOffset = attenuationDuration.getDefaultBucketOffset();
checkValueRange("default-bucket-offset", bucketOffset, DEFAULT_BUCKET_OFFSET_MIN, DEFAULT_BUCKET_OFFSET_MAX);
}

private void validateRiskScoreNormalizationDivisor() {
int riskScoreNormalizationDivisor = attenuationDuration.getRiskScoreNormalizationDivisor();
checkValueRange("risk-score-normalization-divisor", riskScoreNormalizationDivisor,
RISK_SCORE_NORMALIZATION_DIVISOR_MIN, RISK_SCORE_NORMALIZATION_DIVISOR_MAX);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,25 @@ private ParameterSpec() {
* Maximum number of allowed decimals for an attenuation weight.
*/
public static final int ATTENUATION_DURATION_WEIGHT_MAX_DECIMALS = 3;


/**
* The allowed minimum value for a default bucket offset.
*/
public static final int DEFAULT_BUCKET_OFFSET_MIN = 0;

/**
* The allowed maximum value for a default bucket offset.
*/
public static final int DEFAULT_BUCKET_OFFSET_MAX = 1;

/**
* The allowed minimum value for a risk score normalization divisor.
*/
public static final int RISK_SCORE_NORMALIZATION_DIVISOR_MIN = 0;

/**
* The allowed maximum value for a risk score normalization divisor.
*/
public static final int RISK_SCORE_NORMALIZATION_DIVISOR_MAX = 1000;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
# Each of the aforementioned partitions has a weight in the range of [0, 1]
# assigned to it. The number of decimal places is restricted to 3.
#
# default-bucket-offset value range: {0, 1}
# risk-score-normalization-divisor value range: [1, 1000]
#
# Change this file with caution!

thresholds:
Expand All @@ -13,3 +16,5 @@ weights:
low: 1.0
mid: 0.5
high: 0.0
default-bucket-offset: 0
risk-score-normalization-divisor: 25
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
import static app.coronawarn.server.services.distribution.assembly.appconfig.validation.ParameterSpec.ATTENUATION_DURATION_THRESHOLD_MIN;
import static app.coronawarn.server.services.distribution.assembly.appconfig.validation.ParameterSpec.ATTENUATION_DURATION_WEIGHT_MAX;
import static app.coronawarn.server.services.distribution.assembly.appconfig.validation.ParameterSpec.ATTENUATION_DURATION_WEIGHT_MIN;
import static app.coronawarn.server.services.distribution.assembly.appconfig.validation.ParameterSpec.DEFAULT_BUCKET_OFFSET_MAX;
import static app.coronawarn.server.services.distribution.assembly.appconfig.validation.ParameterSpec.DEFAULT_BUCKET_OFFSET_MIN;
import static app.coronawarn.server.services.distribution.assembly.appconfig.validation.ParameterSpec.RISK_SCORE_NORMALIZATION_DIVISOR_MAX;
import static app.coronawarn.server.services.distribution.assembly.appconfig.validation.ParameterSpec.RISK_SCORE_NORMALIZATION_DIVISOR_MIN;
import static app.coronawarn.server.services.distribution.assembly.appconfig.validation.RiskScoreClassificationValidatorTest.buildError;
import static app.coronawarn.server.services.distribution.assembly.appconfig.validation.RiskScoreClassificationValidatorTest.buildExpectedResult;
import static app.coronawarn.server.services.distribution.assembly.appconfig.validation.WeightValidationError.ErrorType.OUT_OF_RANGE;
Expand All @@ -44,12 +48,14 @@ public class AttenuationDurationValidatorTest {
buildThresholds(ATTENUATION_DURATION_THRESHOLD_MIN, ATTENUATION_DURATION_THRESHOLD_MAX);
private static final Weights VALID_WEIGHTS =
buildWeights(ATTENUATION_DURATION_WEIGHT_MAX, ATTENUATION_DURATION_WEIGHT_MAX, ATTENUATION_DURATION_WEIGHT_MAX);
private static final int VALID_BUCKET_OFFSET = DEFAULT_BUCKET_OFFSET_MAX;
private static final int VALID_NORMALIZATION_DIVISOR = RISK_SCORE_NORMALIZATION_DIVISOR_MIN;

@ParameterizedTest
@ValueSource(ints = {ATTENUATION_DURATION_THRESHOLD_MIN - 1, ATTENUATION_DURATION_THRESHOLD_MAX + 1})
void failsIfAttenuationDurationThresholdOutOfBounds(int invalidThresholdValue) {
AttenuationDurationValidator validator = buildValidator(
buildThresholds(invalidThresholdValue, invalidThresholdValue), VALID_WEIGHTS);
buildThresholds(invalidThresholdValue, invalidThresholdValue));

ValidationResult expectedResult = buildExpectedResult(
buildError("attenuation-duration.thresholds.lower", invalidThresholdValue, VALUE_OUT_OF_BOUNDS),
Expand All @@ -58,10 +64,35 @@ void failsIfAttenuationDurationThresholdOutOfBounds(int invalidThresholdValue) {
assertThat(validator.validate()).isEqualTo(expectedResult);
}

@ParameterizedTest
@ValueSource(ints = {DEFAULT_BUCKET_OFFSET_MIN - 1, DEFAULT_BUCKET_OFFSET_MAX + 1})
void failsIfBucketOffsetOutOfBounds(int invalidDefaultBucketOffsetValue) {
AttenuationDurationValidator validator = buildValidator(VALID_THRESHOLDS, VALID_WEIGHTS,
invalidDefaultBucketOffsetValue, VALID_NORMALIZATION_DIVISOR);

ValidationResult expectedResult = buildExpectedResult(
buildError("attenuation-duration.default-bucket-offset", invalidDefaultBucketOffsetValue, VALUE_OUT_OF_BOUNDS));

assertThat(validator.validate()).isEqualTo(expectedResult);
}

@ParameterizedTest
@ValueSource(ints = {RISK_SCORE_NORMALIZATION_DIVISOR_MIN - 1, RISK_SCORE_NORMALIZATION_DIVISOR_MAX + 1})
void failsIfRiskScoreNormalizationDivisorOutOfBounds(int invalidRiskScoreNormalizationDivisorValue) {
AttenuationDurationValidator validator = buildValidator(VALID_THRESHOLDS, VALID_WEIGHTS, VALID_BUCKET_OFFSET,
invalidRiskScoreNormalizationDivisorValue);

ValidationResult expectedResult = buildExpectedResult(
buildError("attenuation-duration.risk-score-normalization-divisor", invalidRiskScoreNormalizationDivisorValue,
VALUE_OUT_OF_BOUNDS));

assertThat(validator.validate()).isEqualTo(expectedResult);
}

@Test
void failsIfUpperAttenuationDurationThresholdLesserThanLower() {
AttenuationDurationValidator validator = buildValidator(
buildThresholds(ATTENUATION_DURATION_THRESHOLD_MAX, ATTENUATION_DURATION_THRESHOLD_MIN), VALID_WEIGHTS);
buildThresholds(ATTENUATION_DURATION_THRESHOLD_MAX, ATTENUATION_DURATION_THRESHOLD_MIN));

ValidationResult expectedResult = buildExpectedResult(
new GeneralValidationError("attenuation-duration.thresholds.lower, attenuation-duration.thresholds.upper",
Expand All @@ -73,7 +104,7 @@ void failsIfUpperAttenuationDurationThresholdLesserThanLower() {
@ParameterizedTest
@ValueSource(doubles = {ATTENUATION_DURATION_WEIGHT_MIN - .1, ATTENUATION_DURATION_WEIGHT_MAX + .1})
void failsIfWeightsOutOfBounds(double invalidWeightValue) {
AttenuationDurationValidator validator = buildValidator(VALID_THRESHOLDS,
AttenuationDurationValidator validator = buildValidator(
buildWeights(invalidWeightValue, invalidWeightValue, invalidWeightValue));

ValidationResult expectedResult = buildExpectedResult(
Expand All @@ -87,7 +118,7 @@ void failsIfWeightsOutOfBounds(double invalidWeightValue) {
@Test
void failsIfWeightsHaveTooManyDecimalPlaces() {
double invalidWeightValue = ATTENUATION_DURATION_WEIGHT_MAX - 0.0000001;
AttenuationDurationValidator validator = buildValidator(VALID_THRESHOLDS,
AttenuationDurationValidator validator = buildValidator(
buildWeights(invalidWeightValue, invalidWeightValue, invalidWeightValue));

ValidationResult expectedResult = buildExpectedResult(
Expand All @@ -98,10 +129,22 @@ void failsIfWeightsHaveTooManyDecimalPlaces() {
assertThat(validator.validate()).isEqualTo(expectedResult);
}

private static AttenuationDurationValidator buildValidator(Thresholds thresholds, Weights weights) {
private static AttenuationDurationValidator buildValidator(Thresholds thresholds) {
return buildValidator(thresholds, VALID_WEIGHTS, VALID_BUCKET_OFFSET, VALID_NORMALIZATION_DIVISOR);
}

private static AttenuationDurationValidator buildValidator(Weights weights) {
return buildValidator(VALID_THRESHOLDS, weights, VALID_BUCKET_OFFSET, VALID_NORMALIZATION_DIVISOR);
}

private static AttenuationDurationValidator buildValidator(
Thresholds thresholds, Weights weights, int defaultBucketOffset, int riskScoreNormalizationDivisor) {
return new AttenuationDurationValidator(AttenuationDuration.newBuilder()
.setThresholds(thresholds)
.setWeights(weights).build());
.setWeights(weights)
.setDefaultBucketOffset(defaultBucketOffset)
.setRiskScoreNormalizationDivisor(riskScoreNormalizationDivisor)
.build());
}

private static Thresholds buildThresholds(int lower, int upper) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ weights:
low: 1.0
mid: 0.5
high: 0.0
default-bucket-offset: 0
risk-score-normalization-divisor: 25
2 changes: 1 addition & 1 deletion services/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
<version>2.0.0</version>
<configuration>
<includes>**/*.java</includes>
<copyrightOwners>${organization.name} and all other contributors</copyrightOwners>
<copyrightOwners>${project.organization.name} and all other contributors</copyrightOwners>
<processStartTag>---license-start</processStartTag>
<processEndTag>---license-end</processEndTag>
<sectionDelimiter>---</sectionDelimiter>
Expand Down

0 comments on commit 85c5d35

Please sign in to comment.