repo
stringclasses
1 value
pull_number
int64
45
1.97k
instance_id
stringlengths
30
32
issue_numbers
sequence
base_commit
stringlengths
40
40
patch
stringlengths
750
219k
test_patch
stringlengths
527
181k
problem_statement
stringlengths
127
5.13k
hints_text
stringclasses
20 values
created_at
timestamp[us]
corona-warn-app/cwa-server
45
corona-warn-app__cwa-server-45
[ "34" ]
e8ca246da1ab3620b6340383d4a59fe2041af562
diff --git a/common/persistence/src/main/java/app/coronawarn/server/services/common/persistence/service/DiagnosisKeyService.java b/common/persistence/src/main/java/app/coronawarn/server/services/common/persistence/service/DiagnosisKeyService.java --- a/common/persistence/src/main/java/app/coronawarn/server/services/common/persistence/service/DiagnosisKeyService.java +++ b/common/persistence/src/main/java/app/coronawarn/server/services/common/persistence/service/DiagnosisKeyService.java @@ -13,16 +13,12 @@ public class DiagnosisKeyService { private DiagnosisKeyRepository keyRepository; /** - * Persists the specified collection of {@link DiagnosisKey} instances. Use the returned - * collection for further operations as the saveDiagnosisKeys operation might have changed the - * {@link DiagnosisKey} instances completely. + * Persists the specified collection of {@link DiagnosisKey} instances. * * @param diagnosisKeys must not contain {@literal null}. - * @return a collection of the saved keys; will never contain {@literal null}. * @throws IllegalArgumentException in case the given collection contains {@literal null}. */ - public Collection<DiagnosisKey> saveDiagnosisKeys( - Collection<DiagnosisKey> diagnosisKeys) { - return keyRepository.saveAll(diagnosisKeys); + public void saveDiagnosisKeys(Collection<DiagnosisKey> diagnosisKeys) { + keyRepository.saveAll(diagnosisKeys); } } diff --git a/services/submission/src/main/java/app/coronawarn/server/services/submission/controller/SubmissionController.java b/services/submission/src/main/java/app/coronawarn/server/services/submission/controller/SubmissionController.java --- a/services/submission/src/main/java/app/coronawarn/server/services/submission/controller/SubmissionController.java +++ b/services/submission/src/main/java/app/coronawarn/server/services/submission/controller/SubmissionController.java @@ -1,23 +1,22 @@ package app.coronawarn.server.services.submission.controller; -import java.util.Collection; -import java.util.Collections; -import java.util.stream.Collectors; import app.coronawarn.server.common.protocols.generated.ExposureKeys.TemporaryExposureKey; import app.coronawarn.server.services.common.persistence.domain.DiagnosisKey; import app.coronawarn.server.services.common.persistence.service.DiagnosisKeyService; import app.coronawarn.server.services.submission.verification.TanVerifier; +import java.util.Collection; +import java.util.Collections; +import java.util.stream.Collectors; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; -// TODO Implement Unit Tests @RestController @RequestMapping("/version/v1") public class SubmissionController { @@ -34,9 +33,8 @@ public ResponseEntity<String> hello() { } // TODO update protoSpec and endpoint to Collection<TemporaryExposureKey> - @PostMapping(value = "/diagnosis-keys/country/{country}") - public ResponseEntity<String> submitDiagnosisKey( - @PathVariable String country, + @PostMapping(value = "/diagnosis-keys") + public ResponseEntity<Void> submitDiagnosisKey( @RequestBody TemporaryExposureKey exposureKeys, @RequestHeader(value = "cwa-fake") Integer fake, @RequestHeader(value = "cwa-authorization") String tan) { @@ -56,15 +54,14 @@ public ResponseEntity<String> submitDiagnosisKey( /** * @return A response that indicates that an invalid TAN was specified in the request. */ - private ResponseEntity<String> buildTanInvalidResponseEntity() { - // TODO implement - return null; + private ResponseEntity<Void> buildTanInvalidResponseEntity() { + return ResponseEntity.status(HttpStatus.FORBIDDEN).build(); } /** * @return A response that indicates successful request processing. */ - private ResponseEntity<String> buildSuccessResponseEntity() { + private ResponseEntity<Void> buildSuccessResponseEntity() { return ResponseEntity.ok().build(); } diff --git a/services/submission/src/main/resources/application.properties b/services/submission/src/main/resources/application.properties --- a/services/submission/src/main/resources/application.properties +++ b/services/submission/src/main/resources/application.properties @@ -1,3 +1,3 @@ logging.level.org.springframework.web=DEBUG -spring.jpa.hibernate.ddl-auto = create +spring.jpa.hibernate.ddl-auto=create spring.flyway.enabled=false
diff --git a/services/distribution/src/test/resources/application.properties b/services/distribution/src/test/resources/application.properties --- a/services/distribution/src/test/resources/application.properties +++ b/services/distribution/src/test/resources/application.properties @@ -1,5 +1,4 @@ -spring.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver -spring.datasource.url=jdbc:hsqldb:mem:testdb;DB_CLOSE_DELAY=-1 -spring.datasource.username=cwa -spring.datasource.password=cwa -spring.jpa.hibernate.ddl-auto=create \ No newline at end of file +spring.jpa.hibernate.ddl-auto=create +logging.level.org.springframework=off +logging.level.root=warn +spring.main.banner-mode=off diff --git a/services/distribution/src/test/resources/logback-test.xml b/services/distribution/src/test/resources/logback-test.xml new file mode 100644 --- /dev/null +++ b/services/distribution/src/test/resources/logback-test.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8"?> +<configuration> + <include resource="org/springframework/boot/logging/logback/base.xml" /> + <logger name="org.springframework" level="off"/> +</configuration> diff --git a/services/submission/src/test/java/app/coronawarn/server/services/submission/ServerApplicationTests.java b/services/submission/src/test/java/app/coronawarn/server/services/submission/ServerApplicationTests.java --- a/services/submission/src/test/java/app/coronawarn/server/services/submission/ServerApplicationTests.java +++ b/services/submission/src/test/java/app/coronawarn/server/services/submission/ServerApplicationTests.java @@ -1,13 +1,20 @@ package app.coronawarn.server.services.submission; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import app.coronawarn.server.services.submission.controller.SubmissionController; import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @SpringBootTest class ServerApplicationTests { - @Test - void contextLoads() { - } + @Autowired + private SubmissionController controller; + @Test + public void contextLoads() { + assertNotNull(this.controller); + } } diff --git a/services/submission/src/test/java/app/coronawarn/server/services/submission/controller/SubmissionControllerTest.java b/services/submission/src/test/java/app/coronawarn/server/services/submission/controller/SubmissionControllerTest.java new file mode 100644 --- /dev/null +++ b/services/submission/src/test/java/app/coronawarn/server/services/submission/controller/SubmissionControllerTest.java @@ -0,0 +1,159 @@ +package app.coronawarn.server.services.submission.controller; + + +import static app.coronawarn.server.common.protocols.generated.ExposureKeys.TemporaryExposureKey; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.any; +import static org.mockito.Mockito.anyCollection; +import static org.mockito.Mockito.anyString; +import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import app.coronawarn.server.services.common.persistence.service.DiagnosisKeyService; +import app.coronawarn.server.services.submission.verification.TanVerifier; +import com.google.protobuf.ByteString; +import java.net.URI; +import java.util.HashSet; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.RequestEntity; +import org.springframework.http.ResponseEntity; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +public class SubmissionControllerTest { + + private static final URI SUBMISSION_URL = URI.create("/version/v1/diagnosis-keys"); + + @MockBean + private DiagnosisKeyService diagnosisKeyService; + + @MockBean + private TanVerifier tanVerifier; + + @Autowired + private TestRestTemplate testRestTemplate; + + @BeforeEach + public void setUpMocks() { + when(tanVerifier.verifyTan(anyString())).thenReturn(true); + } + + @Test + public void checkResponseStatusForValidParameters() { + ResponseEntity<Void> actResponse = + executeRequest(buildTemporaryExposureKey(), buildOkHeaders()); + + assertEquals(HttpStatus.OK, actResponse.getStatusCode()); + } + + @Test + public void checkSaveOperationCallForValidParameters() { + executeRequest(buildTemporaryExposureKey(), buildOkHeaders()); + + verify(diagnosisKeyService, atLeastOnce()).saveDiagnosisKeys(anyCollection()); + } + + @ParameterizedTest + @MethodSource("createIncompleteHeaders") + public void badRequestIfCwaHeadersMissing(HttpHeaders headers) { + ResponseEntity<Void> actResponse = executeRequest(buildTemporaryExposureKey(), headers); + + verify(diagnosisKeyService, never()).saveDiagnosisKeys(any()); + assertEquals(HttpStatus.BAD_REQUEST, actResponse.getStatusCode()); + } + + private static Stream<Arguments> createIncompleteHeaders() { + return Stream.of( + Arguments.of(setContentTypeProtoBufHeader(new HttpHeaders())), + Arguments.of(setContentTypeProtoBufHeader(setCwaFakeHeader(new HttpHeaders(), "0"))), + Arguments.of(setContentTypeProtoBufHeader(setCwaAuthHeader(new HttpHeaders())))); + } + + @Test + public void checkAcceptedHttpMethods() { + Set<HttpMethod> expAllowedMethods = + Stream.of(HttpMethod.POST, HttpMethod.OPTIONS) + .collect(Collectors.toCollection(HashSet::new)); + + Set<HttpMethod> actAllowedMethods = testRestTemplate.optionsForAllow(SUBMISSION_URL.toString()); + + assertEquals(expAllowedMethods, actAllowedMethods); + } + + @Test + public void invalidTanHandling() { + when(tanVerifier.verifyTan(anyString())).thenReturn(false); + + ResponseEntity<Void> actResponse = + executeRequest(buildTemporaryExposureKey(), buildOkHeaders()); + + verify(diagnosisKeyService, never()).saveDiagnosisKeys(any()); + assertEquals(HttpStatus.FORBIDDEN, actResponse.getStatusCode()); + } + + @Test + public void fakeRequestHandling() { + HttpHeaders headers = buildOkHeaders(); + setCwaFakeHeader(headers, "1"); + + ResponseEntity<Void> actResponse = executeRequest(buildTemporaryExposureKey(), headers); + + verify(diagnosisKeyService, never()).saveDiagnosisKeys(any()); + assertEquals(HttpStatus.OK, actResponse.getStatusCode()); + } + + private static HttpHeaders buildOkHeaders() { + HttpHeaders headers = setCwaAuthHeader(setContentTypeProtoBufHeader(new HttpHeaders())); + + return setCwaFakeHeader(headers, "0"); + } + + private static HttpHeaders setContentTypeProtoBufHeader(HttpHeaders headers) { + headers.setContentType(MediaType.valueOf("application/x-protobuf")); + return headers; + } + + private static HttpHeaders setCwaAuthHeader(HttpHeaders headers) { + headers.set("cwa-authorization", "okTan"); + return headers; + } + + private static HttpHeaders setCwaFakeHeader(HttpHeaders headers, String value) { + headers.set("cwa-fake", value); + return headers; + } + + private static TemporaryExposureKey buildTemporaryExposureKey() { + return buildTemporaryExposureKey("testKey123456789", 3L, 2); + } + + private static TemporaryExposureKey buildTemporaryExposureKey( + String keyData, long rollingStartNumber, int riskLevelValue) { + return TemporaryExposureKey.newBuilder() + .setKeyData(ByteString.copyFromUtf8(keyData)) + .setRollingStartNumber(rollingStartNumber) + .setRiskLevelValue(riskLevelValue).build(); + } + + private ResponseEntity<Void> executeRequest(TemporaryExposureKey body, HttpHeaders headers) { + RequestEntity<TemporaryExposureKey> request = + new RequestEntity<>(body, headers, HttpMethod.POST, SUBMISSION_URL); + return testRestTemplate.postForEntity(SUBMISSION_URL, request, Void.class); + } +} diff --git a/services/submission/src/test/resources/application.properties b/services/submission/src/test/resources/application.properties --- a/services/submission/src/test/resources/application.properties +++ b/services/submission/src/test/resources/application.properties @@ -1,5 +1,4 @@ -spring.datasource.driver-class-name=org.hsqldb.jdbc.JDBCDriver -spring.datasource.url=jdbc:hsqldb:mem:testdb;DB_CLOSE_DELAY=-1 -spring.datasource.username=cwa -spring.datasource.password=cwa -spring.jpa.hibernate.ddl-auto=create \ No newline at end of file +spring.jpa.hibernate.ddl-auto=create +logging.level.org.springframework=off +logging.level.root=warn +spring.main.banner-mode=off diff --git a/services/submission/src/test/resources/logback-test.xml b/services/submission/src/test/resources/logback-test.xml new file mode 100644 --- /dev/null +++ b/services/submission/src/test/resources/logback-test.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="UTF-8"?> +<configuration> + <include resource="org/springframework/boot/logging/logback/base.xml" /> + <logger name="org.springframework" level="off"/> +</configuration>
Diagnosis key submission unit tests Implement unit tests for the diagnosis key submission service according to best practices.
2020-05-08T09:00:07
corona-warn-app/cwa-server
106
corona-warn-app__cwa-server-106
[ "5" ]
23b492fe7b9f0821f2a8c34516cb858efcfaa55b
diff --git a/common/persistence/src/main/java/app/coronawarn/server/common/persistence/repository/DiagnosisKeyRepository.java b/common/persistence/src/main/java/app/coronawarn/server/common/persistence/repository/DiagnosisKeyRepository.java --- a/common/persistence/src/main/java/app/coronawarn/server/common/persistence/repository/DiagnosisKeyRepository.java +++ b/common/persistence/src/main/java/app/coronawarn/server/common/persistence/repository/DiagnosisKeyRepository.java @@ -1,9 +1,18 @@ package app.coronawarn.server.common.persistence.repository; import app.coronawarn.server.common.persistence.domain.DiagnosisKey; +import javax.transaction.Transactional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @Repository public interface DiagnosisKeyRepository extends JpaRepository<DiagnosisKey, Long> { + + /** + * Deletes all entries that have a submission timestamp lesser or equal to the specified one. + * + * @param submissionTimestamp the submission timestamp up to which entries will be deleted. + */ + @Transactional + public void deleteBySubmissionTimestampIsLessThanEqual(long submissionTimestamp); } diff --git a/common/persistence/src/main/java/app/coronawarn/server/common/persistence/service/DiagnosisKeyService.java b/common/persistence/src/main/java/app/coronawarn/server/common/persistence/service/DiagnosisKeyService.java --- a/common/persistence/src/main/java/app/coronawarn/server/common/persistence/service/DiagnosisKeyService.java +++ b/common/persistence/src/main/java/app/coronawarn/server/common/persistence/service/DiagnosisKeyService.java @@ -1,7 +1,11 @@ package app.coronawarn.server.common.persistence.service; +import static java.time.ZoneOffset.UTC; + import app.coronawarn.server.common.persistence.domain.DiagnosisKey; import app.coronawarn.server.common.persistence.repository.DiagnosisKeyRepository; +import java.time.Instant; +import java.time.LocalDateTime; import java.util.Collection; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; @@ -30,4 +34,18 @@ public void saveDiagnosisKeys(Collection<DiagnosisKey> diagnosisKeys) { public List<DiagnosisKey> getDiagnosisKeys() { return keyRepository.findAll(Sort.by(Sort.Direction.ASC, "submissionTimestamp")); } + + /** + * Deletes all diagnosis key entries which have a submission timestamp that is older than the + * specified number of days. + * + * @param daysToRetain the number of days until which diagnosis keys will be retained. + */ + public void applyRetentionPolicy(int daysToRetain) { + long threshold = LocalDateTime + .ofInstant(Instant.now(), UTC) + .minusDays(daysToRetain) + .toEpochSecond(UTC) / 3600L; + keyRepository.deleteBySubmissionTimestampIsLessThanEqual(threshold); + } } diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/DiagnosisKeyDistributionRunner.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/DiagnosisKeyDistributionRunner.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/DiagnosisKeyDistributionRunner.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/DiagnosisKeyDistributionRunner.java @@ -24,7 +24,7 @@ import org.springframework.stereotype.Component; @Component -@Order(2) +@Order(3) /** * This runner retrieves stored diagnosis keys, the generates and persists the respective diagnosis * key bundles. diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/ExposureConfigurationDistributionRunner.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/ExposureConfigurationDistributionRunner.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/ExposureConfigurationDistributionRunner.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/ExposureConfigurationDistributionRunner.java @@ -23,7 +23,7 @@ import org.springframework.stereotype.Component; @Component -@Order(1) +@Order(2) /** * Reads the exposure configuration parameters from the respective file in the class path, then * generates and persists the respective exposure configuration bundle. diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/RetentionPolicyRunner.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/RetentionPolicyRunner.java new file mode 100644 --- /dev/null +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/RetentionPolicyRunner.java @@ -0,0 +1,37 @@ +package app.coronawarn.server.services.distribution.runner; + +import app.coronawarn.server.common.persistence.service.DiagnosisKeyService; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +/** + * This runner removes any diagnosis keys from the database that were submitted before a configured + * threshold of days. + */ +@Component +@Order(1) +public class RetentionPolicyRunner implements ApplicationRunner { + + private static final Logger logger = LoggerFactory + .getLogger(RetentionPolicyRunner.class); + + @Autowired + private DiagnosisKeyService diagnosisKeyService; + + @Value("${app.coronawarn.server.services.distribution.retention_days}") + private Integer rententionDays; + + @Override + public void run(ApplicationArguments args) { + diagnosisKeyService.applyRetentionPolicy(rententionDays); + + logger.debug("Retention policy applied successfully. Deleted all entries older that {} days.", + rententionDays); + } +} diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/S3DistributionRunner.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/S3DistributionRunner.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/S3DistributionRunner.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/S3DistributionRunner.java @@ -16,7 +16,7 @@ * This runner will sync the base working directory to the S3. */ @Component -@Order(3) +@Order(4) public class S3DistributionRunner implements ApplicationRunner { private Logger logger = LoggerFactory.getLogger(this.getClass()); diff --git a/services/distribution/src/main/resources/application.properties b/services/distribution/src/main/resources/application.properties --- a/services/distribution/src/main/resources/application.properties +++ b/services/distribution/src/main/resources/application.properties @@ -2,6 +2,7 @@ logging.level.org.springframework.web=INFO logging.level.app.coronawarn=INFO spring.main.web-application-type=NONE +app.coronawarn.server.services.distribution.retention_days=14 app.coronawarn.server.services.distribution.version=v1 app.coronawarn.server.services.distribution.paths.output=out app.coronawarn.server.services.distribution.paths.privatekey=classpath:certificates/client/private.pem
diff --git a/common/persistence/src/test/java/app/coronawarn/server/common/persistence/TestApplication.java b/common/persistence/src/test/java/app/coronawarn/server/common/persistence/TestApplication.java new file mode 100644 --- /dev/null +++ b/common/persistence/src/test/java/app/coronawarn/server/common/persistence/TestApplication.java @@ -0,0 +1,15 @@ +package app.coronawarn.server.common.persistence; + +import app.coronawarn.server.common.persistence.service.DiagnosisKeyService; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@SpringBootApplication +@Configuration +public class TestApplication { + @Bean + DiagnosisKeyService createDiagnosisKeyService() { + return new DiagnosisKeyService(); + } +} diff --git a/common/persistence/src/test/java/app/coronawarn/server/common/persistence/service/DiagnosisKeyServiceTest.java b/common/persistence/src/test/java/app/coronawarn/server/common/persistence/service/DiagnosisKeyServiceTest.java new file mode 100644 --- /dev/null +++ b/common/persistence/src/test/java/app/coronawarn/server/common/persistence/service/DiagnosisKeyServiceTest.java @@ -0,0 +1,125 @@ +package app.coronawarn.server.common.persistence.service; + +import static java.time.ZoneOffset.UTC; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import app.coronawarn.server.common.persistence.domain.DiagnosisKey; +import app.coronawarn.server.common.persistence.repository.DiagnosisKeyRepository; +import java.time.OffsetDateTime; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import org.assertj.core.util.Lists; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; + +@DataJpaTest +public class DiagnosisKeyServiceTest { + + @Autowired + private DiagnosisKeyService diagnosisKeyService; + + @Autowired + private DiagnosisKeyRepository diagnosisKeyRepository; + + @AfterEach + public void tearDown() { + diagnosisKeyRepository.deleteAll(); + } + + @Test + void testRetrievalForEmptyDB() { + var actKeys = diagnosisKeyService.getDiagnosisKeys(); + assertDiagnosisKeysEqual(Lists.emptyList(), actKeys); + } + + @Test + void testSaveAndRetrieve() { + var expKeys = List.of(buildDiagnosisKeyForSubmissionTimestamp(0L)); + + diagnosisKeyService.saveDiagnosisKeys(expKeys); + var actKeys = diagnosisKeyService.getDiagnosisKeys(); + + assertDiagnosisKeysEqual(expKeys, actKeys); + } + + @Test + void testSortedRetrievalResult() { + var expKeys = new ArrayList<>(List.of( + buildDiagnosisKeyForSubmissionTimestamp(1L), + buildDiagnosisKeyForSubmissionTimestamp(0L))); + + diagnosisKeyService.saveDiagnosisKeys(expKeys); + + // reverse to match expected sort order + Collections.reverse(expKeys); + var actKeys = diagnosisKeyService.getDiagnosisKeys(); + + assertDiagnosisKeysEqual(expKeys, actKeys); + } + + @Test + void testApplyRetentionPolicyForEmptyDb() { + diagnosisKeyService.applyRetentionPolicy(1); + var actKeys = diagnosisKeyService.getDiagnosisKeys(); + assertDiagnosisKeysEqual(Lists.emptyList(), actKeys); + } + + @Test + void testApplyRetentionPolicyForOneNotApplicableEntry() { + var expKeys = List.of(buildDiagnosisKeyForDateTime(OffsetDateTime.now(UTC).minusHours(23))); + + diagnosisKeyService.saveDiagnosisKeys(expKeys); + diagnosisKeyService.applyRetentionPolicy(1); + var actKeys = diagnosisKeyService.getDiagnosisKeys(); + + assertDiagnosisKeysEqual(expKeys, actKeys); + } + + @Test + void testApplyRetentionPolicyForOneApplicableEntry() { + var keys = List.of(buildDiagnosisKeyForDateTime(OffsetDateTime.now(UTC).minusDays(1L))); + + diagnosisKeyService.saveDiagnosisKeys(keys); + diagnosisKeyService.applyRetentionPolicy(1); + var actKeys = diagnosisKeyService.getDiagnosisKeys(); + + assertDiagnosisKeysEqual(Lists.emptyList(), actKeys); + } + + private void assertDiagnosisKeysEqual(List<DiagnosisKey> expDiagKeys, + List<DiagnosisKey> actDiagKeys) { + assertEquals(expDiagKeys.size(), actDiagKeys.size(), "Cardinality mismatch"); + + for (int i = 0; i < expDiagKeys.size(); i++) { + var expDiagKey = expDiagKeys.get(i); + var actDiagKey = actDiagKeys.get(i); + + assertEquals( + expDiagKey.getKeyData(), actDiagKey.getKeyData(), "keyData mismatch"); + assertEquals(expDiagKey.getRollingStartNumber(), actDiagKey.getRollingStartNumber(), + "rollingStartNumber mismatch"); + assertEquals(expDiagKey.getRollingPeriod(), actDiagKey.getRollingPeriod(), + "rollingPeriod mismatch"); + assertEquals(expDiagKey.getTransmissionRiskLevel(), actDiagKey.getTransmissionRiskLevel(), + "transmissionRiskLevel mismatch"); + assertEquals(expDiagKey.getSubmissionTimestamp(), actDiagKey.getSubmissionTimestamp(), + "submissionTimestamp mismatch"); + } + } + + public static DiagnosisKey buildDiagnosisKeyForSubmissionTimestamp(long submissionTimeStamp) { + return DiagnosisKey.builder() + .withKeyData(new byte[16]) + .withRollingStartNumber(0L) + .withRollingPeriod(1L) + .withTransmissionRiskLevel(2) + .withSubmissionTimestamp(submissionTimeStamp).build(); + } + + public static DiagnosisKey buildDiagnosisKeyForDateTime(OffsetDateTime dateTime) { + return buildDiagnosisKeyForSubmissionTimestamp(dateTime.toEpochSecond() / 3600); + } +} diff --git a/common/persistence/src/test/resources/application.properties b/common/persistence/src/test/resources/application.properties new file mode 100644 --- /dev/null +++ b/common/persistence/src/test/resources/application.properties @@ -0,0 +1,6 @@ +spring.flyway.enabled=false +spring.jpa.hibernate.ddl-auto=create +spring.jpa.properties.hibernate.show_sql=false +spring.main.banner-mode=off +logging.level.org.springframework=off +logging.level.root=off \ No newline at end of file diff --git a/common/persistence/src/test/resources/logback-test.xml b/common/persistence/src/test/resources/logback-test.xml new file mode 100644 --- /dev/null +++ b/common/persistence/src/test/resources/logback-test.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="UTF-8"?> +<configuration> + <include resource="org/springframework/boot/logging/logback/base.xml" /> + <logger name="org.springframework" level="off"/> + <logger name="root" level="ERROR"/> +</configuration> diff --git a/services/distribution/src/test/resources/application.properties b/services/distribution/src/test/resources/application.properties --- a/services/distribution/src/test/resources/application.properties +++ b/services/distribution/src/test/resources/application.properties @@ -3,6 +3,7 @@ logging.level.org.springframework=off logging.level.root=off spring.main.banner-mode=off +app.coronawarn.server.services.distribution.retention_days=14 app.coronawarn.server.services.distribution.version=v1 app.coronawarn.server.services.distribution.paths.output=out app.coronawarn.server.services.distribution.paths.privatekey=classpath:certificates/client/private.pem
Set Retention Days to 14 Any key data that is associated to a point in time older than 14 days shall be removed from the database and will also be removed from the CDN and therefore the index file.
2020-05-14T23:08:17
corona-warn-app/cwa-server
113
corona-warn-app__cwa-server-113
[ "112" ]
ac44b28ad79130bd39e2d002cddf3a67799a80fb
diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/crypto/CryptoProvider.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/component/CryptoProvider.java similarity index 89% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/crypto/CryptoProvider.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/component/CryptoProvider.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/crypto/CryptoProvider.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/component/CryptoProvider.java @@ -1,4 +1,4 @@ -package app.coronawarn.server.services.distribution.crypto; +package app.coronawarn.server.services.distribution.assembly.component; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -22,7 +22,7 @@ import org.springframework.stereotype.Component; /** - * Wrapper class for a {@link CryptoProvider#getPrivateKey() private key} and a {@link + * Wrapper component for a {@link CryptoProvider#getPrivateKey() private key} and a {@link * CryptoProvider#getCertificate()} certificate} from the application properties. */ @Component @@ -30,10 +30,10 @@ public class CryptoProvider { private static final Logger logger = LoggerFactory.getLogger(CryptoProvider.class); - @Value("${app.coronawarn.server.services.distribution.paths.privatekey}") + @Value("${services.distribution.paths.privatekey}") private String privateKeyPath; - @Value("${app.coronawarn.server.services.distribution.paths.certificate}") + @Value("${services.distribution.paths.certificate}") private String certificatePath; @Autowired @@ -72,10 +72,10 @@ private static Certificate getCertificateFromBytes(final byte[] bytes) * Reads and returns the {@link PrivateKey} configured in the application properties. */ public PrivateKey getPrivateKey() { - if (this.privateKey == null) { + if (privateKey == null) { Resource privateKeyResource = resourceLoader.getResource(privateKeyPath); try (InputStream privateKeyStream = privateKeyResource.getInputStream()) { - this.privateKey = getPrivateKeyFromStream(privateKeyStream); + privateKey = getPrivateKeyFromStream(privateKeyStream); } catch (IOException e) { logger.error("Failed to load private key from {}", privateKeyPath, e); throw new RuntimeException(e); diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/component/CwaApiStructureProvider.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/component/CwaApiStructureProvider.java new file mode 100644 --- /dev/null +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/component/CwaApiStructureProvider.java @@ -0,0 +1,35 @@ +package app.coronawarn.server.services.distribution.assembly.component; + +import app.coronawarn.server.services.distribution.assembly.structure.directory.Directory; +import app.coronawarn.server.services.distribution.assembly.structure.directory.IndexDirectory; +import app.coronawarn.server.services.distribution.assembly.structure.directory.IndexDirectoryImpl; +import app.coronawarn.server.services.distribution.assembly.structure.directory.decorator.IndexingDecorator; +import java.util.Set; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * Assembles the content underneath the {@code /version} path of the CWA API. + */ +@Component +public class CwaApiStructureProvider { + + private final String VERSION_DIRECTORY = "version"; + private final String VERSION_V1 = "v1"; + + @Autowired + private ExposureConfigurationStructureProvider exposureConfigurationStructureProvider; + + @Autowired + private DiagnosisKeysStructureProvider diagnosisKeysStructureProvider; + + public Directory getDirectory() { + IndexDirectory<?> versionDirectory = + new IndexDirectoryImpl<>(VERSION_DIRECTORY, __ -> Set.of(VERSION_V1), Object::toString); + + versionDirectory.addDirectoryToAll(__ -> exposureConfigurationStructureProvider.getExposureConfiguration()); + versionDirectory.addDirectoryToAll(__ -> diagnosisKeysStructureProvider.getDiagnosisKeys()); + + return new IndexingDecorator<>(versionDirectory); + } +} diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/component/DiagnosisKeysStructureProvider.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/component/DiagnosisKeysStructureProvider.java new file mode 100644 --- /dev/null +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/component/DiagnosisKeysStructureProvider.java @@ -0,0 +1,37 @@ +package app.coronawarn.server.services.distribution.assembly.component; + +import app.coronawarn.server.common.persistence.domain.DiagnosisKey; +import app.coronawarn.server.common.persistence.service.DiagnosisKeyService; +import app.coronawarn.server.services.distribution.assembly.diagnosiskeys.structure.directory.DiagnosisKeysDirectoryImpl; +import app.coronawarn.server.services.distribution.assembly.structure.directory.Directory; +import java.util.Collection; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * Retrieves stored diagnosis keys and builds a {@link DiagnosisKeysDirectoryImpl} with them. + */ +@Component +public class DiagnosisKeysStructureProvider { + + private static final Logger logger = LoggerFactory.getLogger(DiagnosisKeysStructureProvider.class); + + @Autowired + private DiagnosisKeyService diagnosisKeyService; + + @Autowired + private CryptoProvider cryptoProvider; + + public Directory getDiagnosisKeys() { + Collection<DiagnosisKey> diagnosisKeys = readDiagnosisKeys(); + return new DiagnosisKeysDirectoryImpl(diagnosisKeys, cryptoProvider); + } + + private Collection<DiagnosisKey> readDiagnosisKeys() { + logger.debug("Querying diagnosis keys from the database..."); + return diagnosisKeyService.getDiagnosisKeys(); + } + +} diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/component/ExposureConfigurationStructureProvider.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/component/ExposureConfigurationStructureProvider.java new file mode 100644 --- /dev/null +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/component/ExposureConfigurationStructureProvider.java @@ -0,0 +1,40 @@ +package app.coronawarn.server.services.distribution.assembly.component; + +import app.coronawarn.server.common.protocols.internal.RiskScoreParameters; +import app.coronawarn.server.services.distribution.assembly.exposureconfig.ExposureConfigurationProvider; +import app.coronawarn.server.services.distribution.assembly.exposureconfig.UnableToLoadFileException; +import app.coronawarn.server.services.distribution.assembly.exposureconfig.structure.directory.ExposureConfigurationDirectoryImpl; +import app.coronawarn.server.services.distribution.assembly.structure.directory.Directory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * Reads the exposure configuration parameters from the respective file in the class path and builds + * a {@link ExposureConfigurationDirectoryImpl} with them. + */ +@Component +public class ExposureConfigurationStructureProvider { + + private static final Logger logger = LoggerFactory + .getLogger(ExposureConfigurationStructureProvider.class); + + @Autowired + private CryptoProvider cryptoProvider; + + public Directory getExposureConfiguration() { + var riskScoreParameters = readExposureConfiguration(); + return new ExposureConfigurationDirectoryImpl(riskScoreParameters, cryptoProvider); + } + + private RiskScoreParameters readExposureConfiguration() { + logger.debug("Reading exposure configuration..."); + try { + return ExposureConfigurationProvider.readMasterFile(); + } catch (UnableToLoadFileException e) { + logger.error("Could not load exposure configuration parameters", e); + throw new RuntimeException(e); + } + } +} diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/component/OutputDirectoryProvider.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/component/OutputDirectoryProvider.java new file mode 100644 --- /dev/null +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/component/OutputDirectoryProvider.java @@ -0,0 +1,37 @@ +package app.coronawarn.server.services.distribution.assembly.component; + +import app.coronawarn.server.services.distribution.assembly.structure.directory.Directory; +import app.coronawarn.server.services.distribution.assembly.structure.directory.DirectoryImpl; +import java.io.IOException; +import org.apache.commons.io.FileUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +/** + * Creates and clears a {@link Directory} on disk, which is defined by the application properties. + */ +@Component +public class OutputDirectoryProvider { + + private static final Logger logger = LoggerFactory.getLogger(OutputDirectoryProvider.class); + + @Value("${services.distribution.paths.output}") + private String outputPath; + + public Directory getDirectory() { + return new DirectoryImpl(getFileOnDisk()); + } + + public java.io.File getFileOnDisk() { + return new java.io.File(outputPath); + } + + public void clear() throws IOException { + logger.debug("Clearing output directory..."); + java.io.File outputDirectory = getFileOnDisk(); + FileUtils.deleteDirectory(outputDirectory); + outputDirectory.mkdirs(); + } +} diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/diagnosiskeys/structure/directory/DiagnosisKeysCountryDirectoryImpl.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/structure/directory/DiagnosisKeysCountryDirectoryImpl.java similarity index 55% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/diagnosiskeys/structure/directory/DiagnosisKeysCountryDirectoryImpl.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/structure/directory/DiagnosisKeysCountryDirectoryImpl.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/diagnosiskeys/structure/directory/DiagnosisKeysCountryDirectoryImpl.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/structure/directory/DiagnosisKeysCountryDirectoryImpl.java @@ -1,13 +1,13 @@ -package app.coronawarn.server.services.distribution.diagnosiskeys.structure.directory; +package app.coronawarn.server.services.distribution.assembly.diagnosiskeys.structure.directory; import app.coronawarn.server.common.persistence.domain.DiagnosisKey; -import app.coronawarn.server.services.distribution.crypto.CryptoProvider; -import app.coronawarn.server.services.distribution.diagnosiskeys.structure.directory.decorator.DateAggregatingDecorator; -import app.coronawarn.server.services.distribution.structure.directory.Directory; -import app.coronawarn.server.services.distribution.structure.directory.IndexDirectory; -import app.coronawarn.server.services.distribution.structure.directory.IndexDirectoryImpl; -import app.coronawarn.server.services.distribution.structure.directory.decorator.IndexingDecorator; -import app.coronawarn.server.services.distribution.structure.util.ImmutableStack; +import app.coronawarn.server.services.distribution.assembly.component.CryptoProvider; +import app.coronawarn.server.services.distribution.assembly.diagnosiskeys.structure.directory.decorator.DateAggregatingDecorator; +import app.coronawarn.server.services.distribution.assembly.structure.directory.Directory; +import app.coronawarn.server.services.distribution.assembly.structure.directory.IndexDirectory; +import app.coronawarn.server.services.distribution.assembly.structure.directory.IndexDirectoryImpl; +import app.coronawarn.server.services.distribution.assembly.structure.directory.decorator.IndexingDecorator; +import app.coronawarn.server.services.distribution.assembly.structure.util.ImmutableStack; import java.time.LocalDate; import java.util.Collection; import java.util.Set; @@ -17,8 +17,8 @@ public class DiagnosisKeysCountryDirectoryImpl extends IndexDirectoryImpl<String private static final String COUNTRY_DIRECTORY = "country"; private static final String COUNTRY = "DE"; - private Collection<DiagnosisKey> diagnosisKeys; - private CryptoProvider cryptoProvider; + private final Collection<DiagnosisKey> diagnosisKeys; + private final CryptoProvider cryptoProvider; public DiagnosisKeysCountryDirectoryImpl(Collection<DiagnosisKey> diagnosisKeys, CryptoProvider cryptoProvider) { diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/diagnosiskeys/structure/directory/DiagnosisKeysDateDirectoryImpl.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/structure/directory/DiagnosisKeysDateDirectoryImpl.java similarity index 59% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/diagnosiskeys/structure/directory/DiagnosisKeysDateDirectoryImpl.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/structure/directory/DiagnosisKeysDateDirectoryImpl.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/diagnosiskeys/structure/directory/DiagnosisKeysDateDirectoryImpl.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/structure/directory/DiagnosisKeysDateDirectoryImpl.java @@ -1,13 +1,13 @@ -package app.coronawarn.server.services.distribution.diagnosiskeys.structure.directory; +package app.coronawarn.server.services.distribution.assembly.diagnosiskeys.structure.directory; import app.coronawarn.server.common.persistence.domain.DiagnosisKey; -import app.coronawarn.server.services.distribution.crypto.CryptoProvider; -import app.coronawarn.server.services.distribution.diagnosiskeys.util.DateTime; -import app.coronawarn.server.services.distribution.structure.directory.Directory; -import app.coronawarn.server.services.distribution.structure.directory.IndexDirectory; -import app.coronawarn.server.services.distribution.structure.directory.IndexDirectoryImpl; -import app.coronawarn.server.services.distribution.structure.directory.decorator.IndexingDecorator; -import app.coronawarn.server.services.distribution.structure.util.ImmutableStack; +import app.coronawarn.server.services.distribution.assembly.component.CryptoProvider; +import app.coronawarn.server.services.distribution.assembly.diagnosiskeys.util.DateTime; +import app.coronawarn.server.services.distribution.assembly.structure.directory.Directory; +import app.coronawarn.server.services.distribution.assembly.structure.directory.IndexDirectory; +import app.coronawarn.server.services.distribution.assembly.structure.directory.IndexDirectoryImpl; +import app.coronawarn.server.services.distribution.assembly.structure.directory.decorator.IndexingDecorator; +import app.coronawarn.server.services.distribution.assembly.structure.util.ImmutableStack; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; @@ -18,14 +18,14 @@ public class DiagnosisKeysDateDirectoryImpl extends IndexDirectoryImpl<LocalDate private static final String DATE_DIRECTORY = "date"; private static final DateTimeFormatter ISO8601 = DateTimeFormatter.ofPattern("yyyy-MM-dd"); - private Collection<DiagnosisKey> diagnosisKeys; - private CryptoProvider cryptoProvider; + private final Collection<DiagnosisKey> diagnosisKeys; + private final CryptoProvider cryptoProvider; public DiagnosisKeysDateDirectoryImpl(Collection<DiagnosisKey> diagnosisKeys, CryptoProvider cryptoProvider) { super(DATE_DIRECTORY, __ -> DateTime.getDates(diagnosisKeys), ISO8601::format); - this.diagnosisKeys = diagnosisKeys; this.cryptoProvider = cryptoProvider; + this.diagnosisKeys = diagnosisKeys; } @Override diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/diagnosiskeys/structure/directory/DiagnosisKeysDirectoryImpl.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/structure/directory/DiagnosisKeysDirectoryImpl.java similarity index 69% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/diagnosiskeys/structure/directory/DiagnosisKeysDirectoryImpl.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/structure/directory/DiagnosisKeysDirectoryImpl.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/diagnosiskeys/structure/directory/DiagnosisKeysDirectoryImpl.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/structure/directory/DiagnosisKeysDirectoryImpl.java @@ -1,12 +1,12 @@ -package app.coronawarn.server.services.distribution.diagnosiskeys.structure.directory; +package app.coronawarn.server.services.distribution.assembly.diagnosiskeys.structure.directory; import app.coronawarn.server.common.persistence.domain.DiagnosisKey; -import app.coronawarn.server.services.distribution.crypto.CryptoProvider; -import app.coronawarn.server.services.distribution.structure.directory.Directory; -import app.coronawarn.server.services.distribution.structure.directory.DirectoryImpl; -import app.coronawarn.server.services.distribution.structure.directory.IndexDirectory; -import app.coronawarn.server.services.distribution.structure.directory.decorator.IndexingDecorator; -import app.coronawarn.server.services.distribution.structure.util.ImmutableStack; +import app.coronawarn.server.services.distribution.assembly.component.CryptoProvider; +import app.coronawarn.server.services.distribution.assembly.structure.directory.Directory; +import app.coronawarn.server.services.distribution.assembly.structure.directory.DirectoryImpl; +import app.coronawarn.server.services.distribution.assembly.structure.directory.IndexDirectory; +import app.coronawarn.server.services.distribution.assembly.structure.directory.decorator.IndexingDecorator; +import app.coronawarn.server.services.distribution.assembly.structure.util.ImmutableStack; import java.util.Collection; /** diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/diagnosiskeys/structure/directory/DiagnosisKeysHourDirectoryImpl.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/structure/directory/DiagnosisKeysHourDirectoryImpl.java similarity index 61% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/diagnosiskeys/structure/directory/DiagnosisKeysHourDirectoryImpl.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/structure/directory/DiagnosisKeysHourDirectoryImpl.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/diagnosiskeys/structure/directory/DiagnosisKeysHourDirectoryImpl.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/structure/directory/DiagnosisKeysHourDirectoryImpl.java @@ -1,13 +1,13 @@ -package app.coronawarn.server.services.distribution.diagnosiskeys.structure.directory; +package app.coronawarn.server.services.distribution.assembly.diagnosiskeys.structure.directory; import app.coronawarn.server.common.persistence.domain.DiagnosisKey; -import app.coronawarn.server.services.distribution.crypto.CryptoProvider; -import app.coronawarn.server.services.distribution.diagnosiskeys.structure.file.HourFileImpl; -import app.coronawarn.server.services.distribution.diagnosiskeys.util.DateTime; -import app.coronawarn.server.services.distribution.structure.directory.IndexDirectoryImpl; -import app.coronawarn.server.services.distribution.structure.file.File; -import app.coronawarn.server.services.distribution.structure.file.decorator.SigningDecorator; -import app.coronawarn.server.services.distribution.structure.util.ImmutableStack; +import app.coronawarn.server.services.distribution.assembly.component.CryptoProvider; +import app.coronawarn.server.services.distribution.assembly.diagnosiskeys.structure.file.HourFileImpl; +import app.coronawarn.server.services.distribution.assembly.diagnosiskeys.util.DateTime; +import app.coronawarn.server.services.distribution.assembly.structure.directory.IndexDirectoryImpl; +import app.coronawarn.server.services.distribution.assembly.structure.file.File; +import app.coronawarn.server.services.distribution.assembly.structure.file.decorator.SigningDecorator; +import app.coronawarn.server.services.distribution.assembly.structure.util.ImmutableStack; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.Collection; @@ -16,9 +16,9 @@ public class DiagnosisKeysHourDirectoryImpl extends IndexDirectoryImpl<LocalDate private static final String HOUR_DIRECTORY = "hour"; - private Collection<DiagnosisKey> diagnosisKeys; - private LocalDate currentDate; - private CryptoProvider cryptoProvider; + private final Collection<DiagnosisKey> diagnosisKeys; + private final LocalDate currentDate; + private final CryptoProvider cryptoProvider; public DiagnosisKeysHourDirectoryImpl(Collection<DiagnosisKey> diagnosisKeys, LocalDate currentDate, CryptoProvider cryptoProvider) { diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/diagnosiskeys/structure/directory/decorator/DateAggregatingDecorator.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/structure/directory/decorator/DateAggregatingDecorator.java similarity index 77% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/diagnosiskeys/structure/directory/decorator/DateAggregatingDecorator.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/structure/directory/decorator/DateAggregatingDecorator.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/diagnosiskeys/structure/directory/decorator/DateAggregatingDecorator.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/structure/directory/decorator/DateAggregatingDecorator.java @@ -1,16 +1,16 @@ -package app.coronawarn.server.services.distribution.diagnosiskeys.structure.directory.decorator; +package app.coronawarn.server.services.distribution.assembly.diagnosiskeys.structure.directory.decorator; import app.coronawarn.server.common.protocols.internal.FileBucket; import app.coronawarn.server.common.protocols.internal.SignedPayload; -import app.coronawarn.server.services.distribution.crypto.CryptoProvider; -import app.coronawarn.server.services.distribution.structure.Writable; -import app.coronawarn.server.services.distribution.structure.directory.Directory; -import app.coronawarn.server.services.distribution.structure.directory.decorator.DirectoryDecorator; -import app.coronawarn.server.services.distribution.structure.file.File; -import app.coronawarn.server.services.distribution.structure.file.FileImpl; -import app.coronawarn.server.services.distribution.structure.file.decorator.SigningDecorator; -import app.coronawarn.server.services.distribution.structure.functional.CheckedFunction; -import app.coronawarn.server.services.distribution.structure.util.ImmutableStack; +import app.coronawarn.server.services.distribution.assembly.component.CryptoProvider; +import app.coronawarn.server.services.distribution.assembly.structure.Writable; +import app.coronawarn.server.services.distribution.assembly.structure.directory.Directory; +import app.coronawarn.server.services.distribution.assembly.structure.directory.decorator.DirectoryDecorator; +import app.coronawarn.server.services.distribution.assembly.structure.file.File; +import app.coronawarn.server.services.distribution.assembly.structure.file.FileImpl; +import app.coronawarn.server.services.distribution.assembly.structure.file.decorator.SigningDecorator; +import app.coronawarn.server.services.distribution.assembly.structure.functional.CheckedFunction; +import app.coronawarn.server.services.distribution.assembly.structure.util.ImmutableStack; import java.util.ArrayList; import java.util.Comparator; import java.util.List; diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/diagnosiskeys/structure/file/HourFileImpl.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/structure/file/HourFileImpl.java similarity index 86% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/diagnosiskeys/structure/file/HourFileImpl.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/structure/file/HourFileImpl.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/diagnosiskeys/structure/file/HourFileImpl.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/structure/file/HourFileImpl.java @@ -1,13 +1,13 @@ -package app.coronawarn.server.services.distribution.diagnosiskeys.structure.file; +package app.coronawarn.server.services.distribution.assembly.diagnosiskeys.structure.file; import app.coronawarn.server.common.persistence.domain.DiagnosisKey; import app.coronawarn.server.common.protocols.external.exposurenotification.File; import app.coronawarn.server.common.protocols.external.exposurenotification.Key; import app.coronawarn.server.common.protocols.internal.FileBucket; -import app.coronawarn.server.services.distribution.diagnosiskeys.util.Batch; -import app.coronawarn.server.services.distribution.diagnosiskeys.util.DateTime; -import app.coronawarn.server.services.distribution.structure.file.FileImpl; -import app.coronawarn.server.services.distribution.structure.util.ImmutableStack; +import app.coronawarn.server.services.distribution.assembly.diagnosiskeys.util.Batch; +import app.coronawarn.server.services.distribution.assembly.diagnosiskeys.util.DateTime; +import app.coronawarn.server.services.distribution.assembly.structure.file.FileImpl; +import app.coronawarn.server.services.distribution.assembly.structure.util.ImmutableStack; import com.google.protobuf.ByteString; import java.time.Instant; import java.time.LocalDateTime; diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/diagnosiskeys/util/Batch.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/util/Batch.java similarity index 97% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/diagnosiskeys/util/Batch.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/util/Batch.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/diagnosiskeys/util/Batch.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/util/Batch.java @@ -1,4 +1,4 @@ -package app.coronawarn.server.services.distribution.diagnosiskeys.util; +package app.coronawarn.server.services.distribution.assembly.diagnosiskeys.util; import app.coronawarn.server.common.protocols.external.exposurenotification.File; import app.coronawarn.server.common.protocols.external.exposurenotification.Header; diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/diagnosiskeys/util/DateTime.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/util/DateTime.java similarity index 95% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/diagnosiskeys/util/DateTime.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/util/DateTime.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/diagnosiskeys/util/DateTime.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/util/DateTime.java @@ -1,4 +1,4 @@ -package app.coronawarn.server.services.distribution.diagnosiskeys.util; +package app.coronawarn.server.services.distribution.assembly.diagnosiskeys.util; import app.coronawarn.server.common.persistence.domain.DiagnosisKey; import java.time.LocalDate; diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/diagnosiskeys/util/Maths.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/util/Maths.java similarity index 64% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/diagnosiskeys/util/Maths.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/util/Maths.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/diagnosiskeys/util/Maths.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/util/Maths.java @@ -1,4 +1,4 @@ -package app.coronawarn.server.services.distribution.diagnosiskeys.util; +package app.coronawarn.server.services.distribution.assembly.diagnosiskeys.util; public class Maths { diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/ExposureConfigurationProvider.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/ExposureConfigurationProvider.java similarity index 92% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/ExposureConfigurationProvider.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/ExposureConfigurationProvider.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/ExposureConfigurationProvider.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/ExposureConfigurationProvider.java @@ -1,8 +1,8 @@ -package app.coronawarn.server.services.distribution.exposureconfig; +package app.coronawarn.server.services.distribution.assembly.exposureconfig; import app.coronawarn.server.common.protocols.internal.RiskScoreParameters; import app.coronawarn.server.common.protocols.internal.RiskScoreParameters.Builder; -import app.coronawarn.server.services.distribution.exposureconfig.parsing.YamlConstructorForProtoBuf; +import app.coronawarn.server.services.distribution.assembly.exposureconfig.parsing.YamlConstructorForProtoBuf; import java.io.IOException; import java.io.InputStream; import org.springframework.core.io.ClassPathResource; diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/UnableToLoadFileException.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/UnableToLoadFileException.java similarity index 79% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/UnableToLoadFileException.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/UnableToLoadFileException.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/UnableToLoadFileException.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/UnableToLoadFileException.java @@ -1,4 +1,4 @@ -package app.coronawarn.server.services.distribution.exposureconfig; +package app.coronawarn.server.services.distribution.assembly.exposureconfig; /** * The file could not be loaded/parsed correctly. diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/parsing/YamlConstructorForProtoBuf.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/parsing/YamlConstructorForProtoBuf.java similarity index 85% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/parsing/YamlConstructorForProtoBuf.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/parsing/YamlConstructorForProtoBuf.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/parsing/YamlConstructorForProtoBuf.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/parsing/YamlConstructorForProtoBuf.java @@ -1,4 +1,4 @@ -package app.coronawarn.server.services.distribution.exposureconfig.parsing; +package app.coronawarn.server.services.distribution.assembly.exposureconfig.parsing; import java.util.Arrays; import org.yaml.snakeyaml.constructor.Constructor; @@ -20,9 +20,9 @@ public YamlConstructorForProtoBuf() { setPropertyUtils(new ProtoBufPropertyUtils()); } - private class ProtoBufPropertyUtils extends PropertyUtils { + private static class ProtoBufPropertyUtils extends PropertyUtils { - public Property getProperty(Class<? extends Object> type, String name, BeanAccess bAccess) { + public Property getProperty(Class<?> type, String name, BeanAccess bAccess) { return super.getProperty(type, transformToProtoNaming(name), bAccess); } diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/structure/ExposureConfigurationDirectoryImpl.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/structure/ExposureConfigurationDirectoryImpl.java similarity index 69% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/structure/ExposureConfigurationDirectoryImpl.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/structure/ExposureConfigurationDirectoryImpl.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/structure/ExposureConfigurationDirectoryImpl.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/structure/ExposureConfigurationDirectoryImpl.java @@ -1,12 +1,12 @@ -package app.coronawarn.server.services.distribution.exposureconfig.structure; +package app.coronawarn.server.services.distribution.assembly.exposureconfig.structure; import app.coronawarn.server.common.protocols.internal.RiskScoreParameters; -import app.coronawarn.server.services.distribution.crypto.CryptoProvider; -import app.coronawarn.server.services.distribution.structure.directory.DirectoryImpl; -import app.coronawarn.server.services.distribution.structure.directory.IndexDirectoryImpl; -import app.coronawarn.server.services.distribution.structure.directory.decorator.IndexingDecorator; -import app.coronawarn.server.services.distribution.structure.file.FileImpl; -import app.coronawarn.server.services.distribution.structure.file.decorator.SigningDecorator; +import app.coronawarn.server.services.distribution.assembly.component.CryptoProvider; +import app.coronawarn.server.services.distribution.assembly.structure.directory.DirectoryImpl; +import app.coronawarn.server.services.distribution.assembly.structure.directory.IndexDirectoryImpl; +import app.coronawarn.server.services.distribution.assembly.structure.directory.decorator.IndexingDecorator; +import app.coronawarn.server.services.distribution.assembly.structure.file.FileImpl; +import app.coronawarn.server.services.distribution.assembly.structure.file.decorator.SigningDecorator; import java.util.Set; /** diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/structure/directory/ExposureConfigurationDirectoryImpl.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/structure/directory/ExposureConfigurationDirectoryImpl.java similarity index 68% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/structure/directory/ExposureConfigurationDirectoryImpl.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/structure/directory/ExposureConfigurationDirectoryImpl.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/structure/directory/ExposureConfigurationDirectoryImpl.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/structure/directory/ExposureConfigurationDirectoryImpl.java @@ -1,12 +1,12 @@ -package app.coronawarn.server.services.distribution.exposureconfig.structure.directory; +package app.coronawarn.server.services.distribution.assembly.exposureconfig.structure.directory; import app.coronawarn.server.common.protocols.internal.RiskScoreParameters; -import app.coronawarn.server.services.distribution.crypto.CryptoProvider; -import app.coronawarn.server.services.distribution.structure.directory.DirectoryImpl; -import app.coronawarn.server.services.distribution.structure.directory.IndexDirectoryImpl; -import app.coronawarn.server.services.distribution.structure.directory.decorator.IndexingDecorator; -import app.coronawarn.server.services.distribution.structure.file.FileImpl; -import app.coronawarn.server.services.distribution.structure.file.decorator.SigningDecorator; +import app.coronawarn.server.services.distribution.assembly.component.CryptoProvider; +import app.coronawarn.server.services.distribution.assembly.structure.directory.DirectoryImpl; +import app.coronawarn.server.services.distribution.assembly.structure.directory.IndexDirectoryImpl; +import app.coronawarn.server.services.distribution.assembly.structure.directory.decorator.IndexingDecorator; +import app.coronawarn.server.services.distribution.assembly.structure.file.FileImpl; +import app.coronawarn.server.services.distribution.assembly.structure.file.decorator.SigningDecorator; import java.util.Set; /** diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/validation/ExposureConfigurationValidator.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/validation/ExposureConfigurationValidator.java similarity index 93% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/validation/ExposureConfigurationValidator.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/validation/ExposureConfigurationValidator.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/validation/ExposureConfigurationValidator.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/validation/ExposureConfigurationValidator.java @@ -1,8 +1,8 @@ -package app.coronawarn.server.services.distribution.exposureconfig.validation; +package app.coronawarn.server.services.distribution.assembly.exposureconfig.validation; import app.coronawarn.server.common.protocols.internal.RiskLevel; import app.coronawarn.server.common.protocols.internal.RiskScoreParameters; -import app.coronawarn.server.services.distribution.exposureconfig.validation.WeightValidationError.ErrorType; +import app.coronawarn.server.services.distribution.assembly.exposureconfig.validation.WeightValidationError.ErrorType; import java.beans.BeanInfo; import java.beans.IntrospectionException; import java.beans.Introspector; @@ -19,7 +19,7 @@ */ public class ExposureConfigurationValidator { - private RiskScoreParameters config; + private final RiskScoreParameters config; private ValidationResult errors; diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/validation/ParameterSpec.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/validation/ParameterSpec.java similarity index 85% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/validation/ParameterSpec.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/validation/ParameterSpec.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/validation/ParameterSpec.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/validation/ParameterSpec.java @@ -1,4 +1,4 @@ -package app.coronawarn.server.services.distribution.exposureconfig.validation; +package app.coronawarn.server.services.distribution.assembly.exposureconfig.validation; /** * Definition of the spec according to Apple/Google: diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/validation/RiskLevelValidationError.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/validation/RiskLevelValidationError.java similarity index 93% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/validation/RiskLevelValidationError.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/validation/RiskLevelValidationError.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/validation/RiskLevelValidationError.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/validation/RiskLevelValidationError.java @@ -1,4 +1,4 @@ -package app.coronawarn.server.services.distribution.exposureconfig.validation; +package app.coronawarn.server.services.distribution.assembly.exposureconfig.validation; import java.util.Objects; diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/validation/ValidationError.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/validation/ValidationError.java similarity index 67% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/validation/ValidationError.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/validation/ValidationError.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/validation/ValidationError.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/validation/ValidationError.java @@ -1,4 +1,4 @@ -package app.coronawarn.server.services.distribution.exposureconfig.validation; +package app.coronawarn.server.services.distribution.assembly.exposureconfig.validation; /** * A validation error, found during the process of validating the Exposure Configuration. Can either diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/validation/ValidationFailedException.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/validation/ValidationFailedException.java similarity index 78% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/validation/ValidationFailedException.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/validation/ValidationFailedException.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/validation/ValidationFailedException.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/validation/ValidationFailedException.java @@ -1,4 +1,4 @@ -package app.coronawarn.server.services.distribution.exposureconfig.validation; +package app.coronawarn.server.services.distribution.assembly.exposureconfig.validation; /** * The validation could not be executed. Find more information about the root cause in the cause diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/validation/ValidationResult.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/validation/ValidationResult.java similarity index 87% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/validation/ValidationResult.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/validation/ValidationResult.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/validation/ValidationResult.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/validation/ValidationResult.java @@ -1,4 +1,4 @@ -package app.coronawarn.server.services.distribution.exposureconfig.validation; +package app.coronawarn.server.services.distribution.assembly.exposureconfig.validation; import java.util.HashSet; diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/validation/WeightValidationError.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/validation/WeightValidationError.java similarity index 94% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/validation/WeightValidationError.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/validation/WeightValidationError.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/exposureconfig/validation/WeightValidationError.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/validation/WeightValidationError.java @@ -1,4 +1,4 @@ -package app.coronawarn.server.services.distribution.exposureconfig.validation; +package app.coronawarn.server.services.distribution.assembly.exposureconfig.validation; import java.util.Objects; diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/io/IO.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/io/IO.java similarity index 96% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/io/IO.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/io/IO.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/io/IO.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/io/IO.java @@ -1,4 +1,4 @@ -package app.coronawarn.server.services.distribution.io; +package app.coronawarn.server.services.distribution.assembly.io; import java.io.File; import java.io.FileOutputStream; diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/Writable.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/Writable.java similarity index 74% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/Writable.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/Writable.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/Writable.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/Writable.java @@ -1,7 +1,7 @@ -package app.coronawarn.server.services.distribution.structure; +package app.coronawarn.server.services.distribution.assembly.structure; -import app.coronawarn.server.services.distribution.structure.directory.Directory; -import app.coronawarn.server.services.distribution.structure.util.ImmutableStack; +import app.coronawarn.server.services.distribution.assembly.structure.directory.Directory; +import app.coronawarn.server.services.distribution.assembly.structure.util.ImmutableStack; /** * Something that can be written to disk. diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/WritableImpl.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/WritableImpl.java similarity index 82% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/WritableImpl.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/WritableImpl.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/WritableImpl.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/WritableImpl.java @@ -1,6 +1,6 @@ -package app.coronawarn.server.services.distribution.structure; +package app.coronawarn.server.services.distribution.assembly.structure; -import app.coronawarn.server.services.distribution.structure.directory.Directory; +import app.coronawarn.server.services.distribution.assembly.structure.directory.Directory; import java.util.Objects; public abstract class WritableImpl implements Writable { diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/directory/Directory.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/directory/Directory.java similarity index 75% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/directory/Directory.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/directory/Directory.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/directory/Directory.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/directory/Directory.java @@ -1,7 +1,7 @@ -package app.coronawarn.server.services.distribution.structure.directory; +package app.coronawarn.server.services.distribution.assembly.structure.directory; -import app.coronawarn.server.services.distribution.structure.Writable; -import app.coronawarn.server.services.distribution.structure.file.File; +import app.coronawarn.server.services.distribution.assembly.structure.Writable; +import app.coronawarn.server.services.distribution.assembly.structure.file.File; import java.util.Set; /** diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/directory/DirectoryImpl.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/directory/DirectoryImpl.java similarity index 87% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/directory/DirectoryImpl.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/directory/DirectoryImpl.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/directory/DirectoryImpl.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/directory/DirectoryImpl.java @@ -1,8 +1,8 @@ -package app.coronawarn.server.services.distribution.structure.directory; +package app.coronawarn.server.services.distribution.assembly.structure.directory; -import app.coronawarn.server.services.distribution.structure.WritableImpl; -import app.coronawarn.server.services.distribution.structure.file.File; -import app.coronawarn.server.services.distribution.structure.util.ImmutableStack; +import app.coronawarn.server.services.distribution.assembly.structure.WritableImpl; +import app.coronawarn.server.services.distribution.assembly.structure.file.File; +import app.coronawarn.server.services.distribution.assembly.structure.util.ImmutableStack; import java.util.HashSet; import java.util.Set; diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/directory/IndexDirectory.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/directory/IndexDirectory.java similarity index 77% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/directory/IndexDirectory.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/directory/IndexDirectory.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/directory/IndexDirectory.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/directory/IndexDirectory.java @@ -1,9 +1,9 @@ -package app.coronawarn.server.services.distribution.structure.directory; +package app.coronawarn.server.services.distribution.assembly.structure.directory; -import app.coronawarn.server.services.distribution.structure.functional.DirectoryFunction; -import app.coronawarn.server.services.distribution.structure.functional.FileFunction; -import app.coronawarn.server.services.distribution.structure.functional.Formatter; -import app.coronawarn.server.services.distribution.structure.util.ImmutableStack; +import app.coronawarn.server.services.distribution.assembly.structure.functional.DirectoryFunction; +import app.coronawarn.server.services.distribution.assembly.structure.functional.FileFunction; +import app.coronawarn.server.services.distribution.assembly.structure.functional.Formatter; +import app.coronawarn.server.services.distribution.assembly.structure.util.ImmutableStack; import java.util.Set; import java.util.Stack; @@ -32,7 +32,7 @@ public interface IndexDirectory<T> extends Directory { void addDirectoryToAll(DirectoryFunction directoryFunction); /** - * Calls the {@link app.coronawarn.server.services.distribution.structure.functional.IndexFunction} + * Calls the {@link app.coronawarn.server.services.distribution.assembly.structure.functional.IndexFunction} * with the {@code indices} to calculate and return the elements of the index of this {@link * IndexDirectory}. * diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/directory/IndexDirectoryImpl.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/directory/IndexDirectoryImpl.java similarity index 85% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/directory/IndexDirectoryImpl.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/directory/IndexDirectoryImpl.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/directory/IndexDirectoryImpl.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/directory/IndexDirectoryImpl.java @@ -1,11 +1,11 @@ -package app.coronawarn.server.services.distribution.structure.directory; +package app.coronawarn.server.services.distribution.assembly.structure.directory; -import app.coronawarn.server.services.distribution.structure.file.File; -import app.coronawarn.server.services.distribution.structure.functional.DirectoryFunction; -import app.coronawarn.server.services.distribution.structure.functional.FileFunction; -import app.coronawarn.server.services.distribution.structure.functional.Formatter; -import app.coronawarn.server.services.distribution.structure.functional.IndexFunction; -import app.coronawarn.server.services.distribution.structure.util.ImmutableStack; +import app.coronawarn.server.services.distribution.assembly.structure.file.File; +import app.coronawarn.server.services.distribution.assembly.structure.functional.DirectoryFunction; +import app.coronawarn.server.services.distribution.assembly.structure.functional.FileFunction; +import app.coronawarn.server.services.distribution.assembly.structure.functional.Formatter; +import app.coronawarn.server.services.distribution.assembly.structure.functional.IndexFunction; +import app.coronawarn.server.services.distribution.assembly.structure.util.ImmutableStack; import java.util.HashSet; import java.util.Set; import java.util.Stack; @@ -61,7 +61,7 @@ public void addDirectoryToAll(DirectoryFunction directoryFunction) { * Creates a new subdirectory for every element of the {@link IndexDirectory#getIndex index} and * writes {@link IndexDirectory#addFileToAll files} and {@link IndexDirectory#addDirectory * directories} to those. The respective element of the index will be pushed onto the Stack for - * subsequent {@link app.coronawarn.server.services.distribution.structure.Writable#prepare} calls + * subsequent {@link app.coronawarn.server.services.distribution.assembly.structure.Writable#prepare} calls * on those files and directories. * * @param indices A {@link Stack} of parameters from all {@link IndexDirectory IndexDirectories} diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/directory/decorator/DirectoryDecorator.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/directory/decorator/DirectoryDecorator.java similarity index 75% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/directory/decorator/DirectoryDecorator.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/directory/decorator/DirectoryDecorator.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/directory/decorator/DirectoryDecorator.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/directory/decorator/DirectoryDecorator.java @@ -1,9 +1,9 @@ -package app.coronawarn.server.services.distribution.structure.directory.decorator; +package app.coronawarn.server.services.distribution.assembly.structure.directory.decorator; -import app.coronawarn.server.services.distribution.structure.Writable; -import app.coronawarn.server.services.distribution.structure.directory.Directory; -import app.coronawarn.server.services.distribution.structure.file.File; -import app.coronawarn.server.services.distribution.structure.util.ImmutableStack; +import app.coronawarn.server.services.distribution.assembly.structure.Writable; +import app.coronawarn.server.services.distribution.assembly.structure.directory.Directory; +import app.coronawarn.server.services.distribution.assembly.structure.file.File; +import app.coronawarn.server.services.distribution.assembly.structure.util.ImmutableStack; import java.util.Set; /** diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/directory/decorator/IndexingDecorator.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/directory/decorator/IndexingDecorator.java similarity index 72% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/directory/decorator/IndexingDecorator.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/directory/decorator/IndexingDecorator.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/directory/decorator/IndexingDecorator.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/directory/decorator/IndexingDecorator.java @@ -1,9 +1,9 @@ -package app.coronawarn.server.services.distribution.structure.directory.decorator; +package app.coronawarn.server.services.distribution.assembly.structure.directory.decorator; -import app.coronawarn.server.services.distribution.structure.directory.IndexDirectory; -import app.coronawarn.server.services.distribution.structure.directory.IndexDirectoryImpl; -import app.coronawarn.server.services.distribution.structure.file.FileImpl; -import app.coronawarn.server.services.distribution.structure.util.ImmutableStack; +import app.coronawarn.server.services.distribution.assembly.structure.directory.IndexDirectory; +import app.coronawarn.server.services.distribution.assembly.structure.directory.IndexDirectoryImpl; +import app.coronawarn.server.services.distribution.assembly.structure.file.FileImpl; +import app.coronawarn.server.services.distribution.assembly.structure.util.ImmutableStack; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -14,7 +14,7 @@ /** * A {@link DirectoryDecorator} that writes a file called {@code "index"}, containing a JSON array * containing all elements returned {@link IndexDirectoryImpl#getIndex}, formatted with the {@link - * IndexDirectoryImpl#getIndexFormatter} on {@link app.coronawarn.server.services.distribution.structure.Writable#prepare}. + * IndexDirectoryImpl#getIndexFormatter} on {@link app.coronawarn.server.services.distribution.assembly.structure.Writable#prepare}. */ public class IndexingDecorator<T> extends DirectoryDecorator { diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/file/File.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/file/File.java similarity index 64% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/file/File.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/file/File.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/file/File.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/file/File.java @@ -1,6 +1,6 @@ -package app.coronawarn.server.services.distribution.structure.file; +package app.coronawarn.server.services.distribution.assembly.structure.file; -import app.coronawarn.server.services.distribution.structure.Writable; +import app.coronawarn.server.services.distribution.assembly.structure.Writable; /** * A {@link Writable} containing some bytes. diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/file/FileImpl.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/file/FileImpl.java similarity index 69% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/file/FileImpl.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/file/FileImpl.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/file/FileImpl.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/file/FileImpl.java @@ -1,9 +1,9 @@ -package app.coronawarn.server.services.distribution.structure.file; +package app.coronawarn.server.services.distribution.assembly.structure.file; -import app.coronawarn.server.services.distribution.io.IO; -import app.coronawarn.server.services.distribution.structure.Writable; -import app.coronawarn.server.services.distribution.structure.WritableImpl; -import app.coronawarn.server.services.distribution.structure.util.ImmutableStack; +import app.coronawarn.server.services.distribution.assembly.io.IO; +import app.coronawarn.server.services.distribution.assembly.structure.Writable; +import app.coronawarn.server.services.distribution.assembly.structure.WritableImpl; +import app.coronawarn.server.services.distribution.assembly.structure.util.ImmutableStack; /** * Implementation of {@link File} that interfaces with {@link java.io.File Files} on disk. diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/file/decorator/FileDecorator.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/file/decorator/FileDecorator.java similarity index 70% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/file/decorator/FileDecorator.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/file/decorator/FileDecorator.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/file/decorator/FileDecorator.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/file/decorator/FileDecorator.java @@ -1,9 +1,9 @@ -package app.coronawarn.server.services.distribution.structure.file.decorator; +package app.coronawarn.server.services.distribution.assembly.structure.file.decorator; -import app.coronawarn.server.services.distribution.structure.Writable; -import app.coronawarn.server.services.distribution.structure.directory.Directory; -import app.coronawarn.server.services.distribution.structure.file.File; -import app.coronawarn.server.services.distribution.structure.util.ImmutableStack; +import app.coronawarn.server.services.distribution.assembly.structure.Writable; +import app.coronawarn.server.services.distribution.assembly.structure.directory.Directory; +import app.coronawarn.server.services.distribution.assembly.structure.file.File; +import app.coronawarn.server.services.distribution.assembly.structure.util.ImmutableStack; /** * Decorates a {@link File} (e.g. to modify its content) on {@link Writable#prepare}. This class diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/file/decorator/SigningDecorator.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/file/decorator/SigningDecorator.java similarity index 85% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/file/decorator/SigningDecorator.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/file/decorator/SigningDecorator.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/file/decorator/SigningDecorator.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/file/decorator/SigningDecorator.java @@ -1,9 +1,9 @@ -package app.coronawarn.server.services.distribution.structure.file.decorator; +package app.coronawarn.server.services.distribution.assembly.structure.file.decorator; import app.coronawarn.server.common.protocols.internal.SignedPayload; -import app.coronawarn.server.services.distribution.crypto.CryptoProvider; -import app.coronawarn.server.services.distribution.structure.file.File; -import app.coronawarn.server.services.distribution.structure.util.ImmutableStack; +import app.coronawarn.server.services.distribution.assembly.component.CryptoProvider; +import app.coronawarn.server.services.distribution.assembly.structure.file.File; +import app.coronawarn.server.services.distribution.assembly.structure.util.ImmutableStack; import com.google.protobuf.ByteString; import java.security.GeneralSecurityException; import java.security.PrivateKey; diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/functional/CheckedFunction.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/functional/CheckedFunction.java similarity index 85% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/functional/CheckedFunction.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/functional/CheckedFunction.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/functional/CheckedFunction.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/functional/CheckedFunction.java @@ -1,4 +1,4 @@ -package app.coronawarn.server.services.distribution.structure.functional; +package app.coronawarn.server.services.distribution.assembly.structure.functional; import java.util.function.Function; diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/functional/DirectoryFunction.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/functional/DirectoryFunction.java new file mode 100644 --- /dev/null +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/functional/DirectoryFunction.java @@ -0,0 +1,14 @@ +package app.coronawarn.server.services.distribution.assembly.structure.functional; + +import app.coronawarn.server.services.distribution.assembly.structure.directory.Directory; +import app.coronawarn.server.services.distribution.assembly.structure.util.ImmutableStack; +import java.util.function.Function; + +/** + * A {@code Function<Stack<Object>, Directory>}. + */ +@FunctionalInterface +public interface DirectoryFunction extends Function<ImmutableStack<Object>, Directory> { + + Directory apply(ImmutableStack<Object> t); +} diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/functional/FileFunction.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/functional/FileFunction.java new file mode 100644 --- /dev/null +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/functional/FileFunction.java @@ -0,0 +1,14 @@ +package app.coronawarn.server.services.distribution.assembly.structure.functional; + +import app.coronawarn.server.services.distribution.assembly.structure.file.File; +import app.coronawarn.server.services.distribution.assembly.structure.util.ImmutableStack; +import java.util.function.Function; + +/** + * A {@code Function<Stack<Object>, File>}. + */ +@FunctionalInterface +public interface FileFunction extends Function<ImmutableStack<Object>, File> { + + File apply(ImmutableStack<Object> t); +} diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/functional/Formatter.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/functional/Formatter.java similarity index 74% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/functional/Formatter.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/functional/Formatter.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/functional/Formatter.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/functional/Formatter.java @@ -1,4 +1,4 @@ -package app.coronawarn.server.services.distribution.structure.functional; +package app.coronawarn.server.services.distribution.assembly.structure.functional; import java.util.function.Function; diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/functional/IndexFunction.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/functional/IndexFunction.java similarity index 64% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/functional/IndexFunction.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/functional/IndexFunction.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/functional/IndexFunction.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/functional/IndexFunction.java @@ -1,6 +1,6 @@ -package app.coronawarn.server.services.distribution.structure.functional; +package app.coronawarn.server.services.distribution.assembly.structure.functional; -import app.coronawarn.server.services.distribution.structure.util.ImmutableStack; +import app.coronawarn.server.services.distribution.assembly.structure.util.ImmutableStack; import java.util.Set; import java.util.function.Function; diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/util/ImmutableStack.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/util/ImmutableStack.java similarity index 84% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/util/ImmutableStack.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/util/ImmutableStack.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/util/ImmutableStack.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assembly/structure/util/ImmutableStack.java @@ -1,10 +1,10 @@ -package app.coronawarn.server.services.distribution.structure.util; +package app.coronawarn.server.services.distribution.assembly.structure.util; import java.util.Stack; public class ImmutableStack<T> { - private Stack<T> stack; + private final Stack<T> stack; public ImmutableStack() { this.stack = new Stack<>(); diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/objectstore/ObjectStoreAccess.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/objectstore/ObjectStoreAccess.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/objectstore/ObjectStoreAccess.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/objectstore/ObjectStoreAccess.java @@ -36,9 +36,9 @@ @Component public class ObjectStoreAccess { - private Logger logger = LoggerFactory.getLogger(this.getClass()); + private final Logger logger = LoggerFactory.getLogger(this.getClass()); - private String bucket; + private final String bucket; private S3Client client; diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/objectstore/S3Publisher.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/objectstore/S3Publisher.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/objectstore/S3Publisher.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/objectstore/S3Publisher.java @@ -16,14 +16,14 @@ @Component public class S3Publisher { - private Logger logger = LoggerFactory.getLogger(this.getClass()); + private final Logger logger = LoggerFactory.getLogger(this.getClass()); /** * prefix path on S3, enforced for all methods on this class. */ private String prefixPath = "cwa/"; - private ObjectStoreAccess objectStoreAccess; + private final ObjectStoreAccess objectStoreAccess; @Autowired public S3Publisher(ObjectStoreAccess objectStoreAccess) { diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/Assembly.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/Assembly.java new file mode 100644 --- /dev/null +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/Assembly.java @@ -0,0 +1,42 @@ +package app.coronawarn.server.services.distribution.runner; + +import app.coronawarn.server.services.distribution.assembly.component.CwaApiStructureProvider; +import app.coronawarn.server.services.distribution.assembly.component.OutputDirectoryProvider; +import app.coronawarn.server.services.distribution.assembly.structure.directory.Directory; +import app.coronawarn.server.services.distribution.assembly.structure.util.ImmutableStack; +import java.io.IOException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.ApplicationArguments; +import org.springframework.boot.ApplicationRunner; +import org.springframework.core.annotation.Order; +import org.springframework.stereotype.Component; + +/** + * This runner assembles and writes diagnosis key bundles and the parameter configuration. + */ +@Component +@Order(2) +public class Assembly implements ApplicationRunner { + + private static final Logger logger = LoggerFactory.getLogger(Assembly.class); + + @Autowired + private OutputDirectoryProvider outputDirectoryProvider; + + @Autowired + private CwaApiStructureProvider cwaApiStructureProvider; + + @Override + public void run(ApplicationArguments args) throws IOException { + Directory outputDirectory = this.outputDirectoryProvider.getDirectory(); + outputDirectory.addDirectory(cwaApiStructureProvider.getDirectory()); + this.outputDirectoryProvider.clear(); + logger.debug("Preparing files..."); + outputDirectory.prepare(new ImmutableStack<>()); + logger.debug("Writing files..."); + outputDirectory.write(); + logger.debug("Distribution run finished successfully."); + } +} diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/DiagnosisKeyDistributionRunner.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/DiagnosisKeyDistributionRunner.java deleted file mode 100644 --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/DiagnosisKeyDistributionRunner.java +++ /dev/null @@ -1,78 +0,0 @@ -package app.coronawarn.server.services.distribution.runner; - -import app.coronawarn.server.common.persistence.domain.DiagnosisKey; -import app.coronawarn.server.common.persistence.service.DiagnosisKeyService; -import app.coronawarn.server.services.distribution.crypto.CryptoProvider; -import app.coronawarn.server.services.distribution.diagnosiskeys.structure.directory.DiagnosisKeysDirectoryImpl; -import app.coronawarn.server.services.distribution.structure.directory.DirectoryImpl; -import app.coronawarn.server.services.distribution.structure.directory.IndexDirectory; -import app.coronawarn.server.services.distribution.structure.directory.IndexDirectoryImpl; -import app.coronawarn.server.services.distribution.structure.directory.decorator.IndexingDecorator; -import app.coronawarn.server.services.distribution.structure.util.ImmutableStack; -import java.io.File; -import java.io.IOException; -import java.util.Collection; -import java.util.Set; -import org.apache.commons.io.FileUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.ApplicationArguments; -import org.springframework.boot.ApplicationRunner; -import org.springframework.core.annotation.Order; -import org.springframework.stereotype.Component; - -@Component -@Order(3) -/** - * This runner retrieves stored diagnosis keys, the generates and persists the respective diagnosis - * key bundles. - */ -public class DiagnosisKeyDistributionRunner implements ApplicationRunner { - - private static final Logger logger = LoggerFactory - .getLogger(DiagnosisKeyDistributionRunner.class); - - private static final String VERSION_DIRECTORY = "version"; - - @Value("${app.coronawarn.server.services.distribution.version}") - private String version; - - @Value("${app.coronawarn.server.services.distribution.paths.output}") - private String outputPath; - - @Autowired - private CryptoProvider cryptoProvider; - - @Autowired - private DiagnosisKeyService diagnosisKeyService; - - - @Override - public void run(ApplicationArguments args) throws IOException { - Collection<DiagnosisKey> diagnosisKeys = diagnosisKeyService.getDiagnosisKeys(); - - DiagnosisKeysDirectoryImpl diagnosisKeysDirectory = - new DiagnosisKeysDirectoryImpl(diagnosisKeys, cryptoProvider); - - IndexDirectory<?> versionDirectory = - new IndexDirectoryImpl<>(VERSION_DIRECTORY, __ -> Set.of(version), Object::toString); - - versionDirectory.addDirectoryToAll(__ -> diagnosisKeysDirectory); - - java.io.File outputDirectory = new File(outputPath); - clearDirectory(outputDirectory); - DirectoryImpl root = new DirectoryImpl(outputDirectory); - root.addDirectory(new IndexingDecorator<>(versionDirectory)); - - root.prepare(new ImmutableStack<>()); - root.write(); - logger.debug("Diagnosis key distribution structure written successfully."); - } - - private static void clearDirectory(File directory) throws IOException { - FileUtils.deleteDirectory(directory); - directory.mkdirs(); - } -} diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/ExposureConfigurationDistributionRunner.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/ExposureConfigurationDistributionRunner.java deleted file mode 100644 --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/ExposureConfigurationDistributionRunner.java +++ /dev/null @@ -1,70 +0,0 @@ -package app.coronawarn.server.services.distribution.runner; - -import app.coronawarn.server.common.protocols.internal.RiskScoreParameters; -import app.coronawarn.server.services.distribution.crypto.CryptoProvider; -import app.coronawarn.server.services.distribution.exposureconfig.ExposureConfigurationProvider; -import app.coronawarn.server.services.distribution.exposureconfig.UnableToLoadFileException; -import app.coronawarn.server.services.distribution.exposureconfig.structure.directory.ExposureConfigurationDirectoryImpl; -import app.coronawarn.server.services.distribution.structure.directory.Directory; -import app.coronawarn.server.services.distribution.structure.directory.DirectoryImpl; -import app.coronawarn.server.services.distribution.structure.directory.IndexDirectory; -import app.coronawarn.server.services.distribution.structure.directory.IndexDirectoryImpl; -import app.coronawarn.server.services.distribution.structure.directory.decorator.IndexingDecorator; -import app.coronawarn.server.services.distribution.structure.util.ImmutableStack; -import java.io.File; -import java.util.Set; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.ApplicationArguments; -import org.springframework.boot.ApplicationRunner; -import org.springframework.core.annotation.Order; -import org.springframework.stereotype.Component; - -@Component -@Order(2) -/** - * Reads the exposure configuration parameters from the respective file in the class path, then - * generates and persists the respective exposure configuration bundle. - */ -public class ExposureConfigurationDistributionRunner implements ApplicationRunner { - - private static final Logger logger = - LoggerFactory.getLogger(ExposureConfigurationDistributionRunner.class); - - @Value("${app.coronawarn.server.services.distribution.version}") - private String version; - - @Value("${app.coronawarn.server.services.distribution.paths.output}") - private String outputPath; - - @Autowired - private CryptoProvider cryptoProvider; - - private static final String VERSION_DIRECTORY = "version"; - - @Override - public void run(ApplicationArguments args) { - var riskScoreParameters = readExposureConfiguration(); - IndexDirectory<?> versionDirectory = - new IndexDirectoryImpl<>(VERSION_DIRECTORY, __ -> Set.of(version), Object::toString); - ExposureConfigurationDirectoryImpl parametersDirectory = - new ExposureConfigurationDirectoryImpl(riskScoreParameters, cryptoProvider); - Directory root = new DirectoryImpl(new File(outputPath)); - versionDirectory.addDirectoryToAll(__ -> parametersDirectory); - root.addDirectory(new IndexingDecorator<>(versionDirectory)); - root.prepare(new ImmutableStack<>()); - root.write(); - logger.debug("Exposure configuration structure written successfully."); - } - - private RiskScoreParameters readExposureConfiguration() { - try { - return ExposureConfigurationProvider.readMasterFile(); - } catch (UnableToLoadFileException e) { - logger.error("Could not load exposure configuration parameters", e); - throw new RuntimeException(e); - } - } -} diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/RetentionPolicyRunner.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/RetentionPolicy.java similarity index 85% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/RetentionPolicyRunner.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/RetentionPolicy.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/RetentionPolicyRunner.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/RetentionPolicy.java @@ -16,15 +16,15 @@ */ @Component @Order(1) -public class RetentionPolicyRunner implements ApplicationRunner { +public class RetentionPolicy implements ApplicationRunner { private static final Logger logger = LoggerFactory - .getLogger(RetentionPolicyRunner.class); + .getLogger(RetentionPolicy.class); @Autowired private DiagnosisKeyService diagnosisKeyService; - @Value("${app.coronawarn.server.services.distribution.retention_days}") + @Value("${services.distribution.retention_days}") private Integer rententionDays; @Override diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/S3DistributionRunner.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/S3Distribution.java similarity index 69% rename from services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/S3DistributionRunner.java rename to services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/S3Distribution.java --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/S3DistributionRunner.java +++ b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/runner/S3Distribution.java @@ -1,12 +1,12 @@ package app.coronawarn.server.services.distribution.runner; +import app.coronawarn.server.services.distribution.assembly.component.OutputDirectoryProvider; import app.coronawarn.server.services.distribution.objectstore.S3Publisher; import java.io.IOException; import java.nio.file.Path; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.core.annotation.Order; @@ -16,13 +16,13 @@ * This runner will sync the base working directory to the S3. */ @Component -@Order(4) -public class S3DistributionRunner implements ApplicationRunner { +@Order(3) +public class S3Distribution implements ApplicationRunner { - private Logger logger = LoggerFactory.getLogger(this.getClass()); + private final Logger logger = LoggerFactory.getLogger(this.getClass()); - @Value("${app.coronawarn.server.services.distribution.paths.output}") - private String workdir; + @Autowired + private OutputDirectoryProvider outputDirectoryProvider; @Autowired private S3Publisher s3Publisher; @@ -30,8 +30,7 @@ public class S3DistributionRunner implements ApplicationRunner { @Override public void run(ApplicationArguments args) { try { - Path pathToDistribute = Path.of(workdir).toAbsolutePath(); - + Path pathToDistribute = outputDirectoryProvider.getFileOnDisk().toPath().toAbsolutePath(); s3Publisher.publishFolder(pathToDistribute); } catch (IOException | UnsupportedOperationException e) { logger.error("Distribution failed.", e); diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/functional/DirectoryFunction.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/functional/DirectoryFunction.java deleted file mode 100644 --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/functional/DirectoryFunction.java +++ /dev/null @@ -1,14 +0,0 @@ -package app.coronawarn.server.services.distribution.structure.functional; - -import app.coronawarn.server.services.distribution.structure.directory.Directory; -import app.coronawarn.server.services.distribution.structure.util.ImmutableStack; -import java.util.function.Function; - -/** - * A {@code Function<Stack<Object>, Directory>}. - */ -@FunctionalInterface -public interface DirectoryFunction extends Function<ImmutableStack<Object>, Directory> { - - Directory apply(ImmutableStack<Object> t); -} diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/functional/FileFunction.java b/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/functional/FileFunction.java deleted file mode 100644 --- a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/structure/functional/FileFunction.java +++ /dev/null @@ -1,14 +0,0 @@ -package app.coronawarn.server.services.distribution.structure.functional; - -import app.coronawarn.server.services.distribution.structure.file.File; -import app.coronawarn.server.services.distribution.structure.util.ImmutableStack; -import java.util.function.Function; - -/** - * A {@code Function<Stack<Object>, File>}. - */ -@FunctionalInterface -public interface FileFunction extends Function<ImmutableStack<Object>, File> { - - File apply(ImmutableStack<Object> t); -} diff --git a/services/distribution/src/main/resources/application.properties b/services/distribution/src/main/resources/application.properties --- a/services/distribution/src/main/resources/application.properties +++ b/services/distribution/src/main/resources/application.properties @@ -2,11 +2,10 @@ logging.level.org.springframework.web=INFO logging.level.app.coronawarn=INFO spring.main.web-application-type=NONE -app.coronawarn.server.services.distribution.retention_days=14 -app.coronawarn.server.services.distribution.version=v1 -app.coronawarn.server.services.distribution.paths.output=out -app.coronawarn.server.services.distribution.paths.privatekey=classpath:certificates/client/private.pem -app.coronawarn.server.services.distribution.paths.certificate=classpath:certificates/chain/certificate.crt +services.distribution.retention_days=14 +services.distribution.paths.output=out +services.distribution.paths.privatekey=classpath:certificates/client/private.pem +services.distribution.paths.certificate=classpath:certificates/chain/certificate.crt spring.flyway.enabled=false spring.jpa.hibernate.ddl-auto=validate
diff --git a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/ApplicationInitializationTest.java b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/ApplicationInitializationTest.java --- a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/ApplicationInitializationTest.java +++ b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/ApplicationInitializationTest.java @@ -3,7 +3,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import app.coronawarn.server.common.persistence.service.DiagnosisKeyService; -import app.coronawarn.server.services.distribution.crypto.CryptoProvider; +import app.coronawarn.server.services.distribution.assembly.component.CryptoProvider; import app.coronawarn.server.services.distribution.objectstore.S3Publisher; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; diff --git a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/crypto/CryptoProviderTest.java b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/component/CryptoProviderTest.java similarity index 92% rename from services/distribution/src/test/java/app/coronawarn/server/services/distribution/crypto/CryptoProviderTest.java rename to services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/component/CryptoProviderTest.java --- a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/crypto/CryptoProviderTest.java +++ b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/component/CryptoProviderTest.java @@ -1,4 +1,4 @@ -package app.coronawarn.server.services.distribution.crypto; +package app.coronawarn.server.services.distribution.assembly.component; import static org.junit.jupiter.api.Assertions.assertNotNull; diff --git a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/diagnosiskeys/structure/directory/DiagnosisKeysDirectoryTest.java b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/structure/directory/DiagnosisKeysStructureProviderDirectoryTest.java similarity index 93% rename from services/distribution/src/test/java/app/coronawarn/server/services/distribution/diagnosiskeys/structure/directory/DiagnosisKeysDirectoryTest.java rename to services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/structure/directory/DiagnosisKeysStructureProviderDirectoryTest.java --- a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/diagnosiskeys/structure/directory/DiagnosisKeysDirectoryTest.java +++ b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/structure/directory/DiagnosisKeysStructureProviderDirectoryTest.java @@ -1,14 +1,14 @@ -package app.coronawarn.server.services.distribution.diagnosiskeys.structure.directory; +package app.coronawarn.server.services.distribution.assembly.diagnosiskeys.structure.directory; import static app.coronawarn.server.services.distribution.common.Helpers.buildDiagnosisKeyForSubmissionTimestamp; import static java.lang.String.join; import static org.junit.jupiter.api.Assertions.assertEquals; import app.coronawarn.server.common.persistence.domain.DiagnosisKey; -import app.coronawarn.server.services.distribution.crypto.CryptoProvider; -import app.coronawarn.server.services.distribution.structure.directory.Directory; -import app.coronawarn.server.services.distribution.structure.directory.DirectoryImpl; -import app.coronawarn.server.services.distribution.structure.util.ImmutableStack; +import app.coronawarn.server.services.distribution.assembly.component.CryptoProvider; +import app.coronawarn.server.services.distribution.assembly.structure.directory.Directory; +import app.coronawarn.server.services.distribution.assembly.structure.directory.DirectoryImpl; +import app.coronawarn.server.services.distribution.assembly.structure.util.ImmutableStack; import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -31,7 +31,7 @@ @ExtendWith(SpringExtension.class) @ContextConfiguration(classes = {CryptoProvider.class}, initializers = ConfigFileApplicationContextInitializer.class) -public class DiagnosisKeysDirectoryTest { +public class DiagnosisKeysStructureProviderDirectoryTest { @Autowired CryptoProvider cryptoProvider; diff --git a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/diagnosiskeys/util/DateTimeTest.java b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/util/DateTimeTest.java similarity index 97% rename from services/distribution/src/test/java/app/coronawarn/server/services/distribution/diagnosiskeys/util/DateTimeTest.java rename to services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/util/DateTimeTest.java --- a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/diagnosiskeys/util/DateTimeTest.java +++ b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/diagnosiskeys/util/DateTimeTest.java @@ -1,4 +1,4 @@ -package app.coronawarn.server.services.distribution.diagnosiskeys.util; +package app.coronawarn.server.services.distribution.assembly.diagnosiskeys.util; import static app.coronawarn.server.services.distribution.common.Helpers.buildDiagnosisKeyForDateTime; import static java.util.Collections.emptyList; diff --git a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/exposureconfig/ExposureConfigurationMasterFileTest.java b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/ExposureConfigurationStructureProviderMasterFileTest.java similarity index 64% rename from services/distribution/src/test/java/app/coronawarn/server/services/distribution/exposureconfig/ExposureConfigurationMasterFileTest.java rename to services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/ExposureConfigurationStructureProviderMasterFileTest.java --- a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/exposureconfig/ExposureConfigurationMasterFileTest.java +++ b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/ExposureConfigurationStructureProviderMasterFileTest.java @@ -1,9 +1,9 @@ -package app.coronawarn.server.services.distribution.exposureconfig; +package app.coronawarn.server.services.distribution.assembly.exposureconfig; import static org.junit.jupiter.api.Assertions.assertEquals; -import app.coronawarn.server.services.distribution.exposureconfig.validation.ExposureConfigurationValidator; -import app.coronawarn.server.services.distribution.exposureconfig.validation.ValidationResult; +import app.coronawarn.server.services.distribution.assembly.exposureconfig.validation.ExposureConfigurationValidator; +import app.coronawarn.server.services.distribution.assembly.exposureconfig.validation.ValidationResult; import org.junit.jupiter.api.Test; /** @@ -12,7 +12,7 @@ * * There should never be any deployment when this test is failing. */ -public class ExposureConfigurationMasterFileTest { +public class ExposureConfigurationStructureProviderMasterFileTest { private static final ValidationResult SUCCESS = new ValidationResult(); diff --git a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/exposureconfig/ExposureConfigurationProviderTest.java b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/ExposureConfigurationStructureProviderProviderTest.java similarity index 87% rename from services/distribution/src/test/java/app/coronawarn/server/services/distribution/exposureconfig/ExposureConfigurationProviderTest.java rename to services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/ExposureConfigurationStructureProviderProviderTest.java --- a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/exposureconfig/ExposureConfigurationProviderTest.java +++ b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/ExposureConfigurationStructureProviderProviderTest.java @@ -1,4 +1,4 @@ -package app.coronawarn.server.services.distribution.exposureconfig; +package app.coronawarn.server.services.distribution.assembly.exposureconfig; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -6,7 +6,7 @@ import app.coronawarn.server.common.protocols.internal.RiskScoreParameters; import org.junit.jupiter.api.Test; -public class ExposureConfigurationProviderTest { +public class ExposureConfigurationStructureProviderProviderTest { @Test public void okFile() throws UnableToLoadFileException { diff --git a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/exposureconfig/validation/ExposureConfigurationValidatorTest.java b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/validation/ExposureConfigurationStructureProviderValidatorTest.java similarity index 87% rename from services/distribution/src/test/java/app/coronawarn/server/services/distribution/exposureconfig/validation/ExposureConfigurationValidatorTest.java rename to services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/validation/ExposureConfigurationStructureProviderValidatorTest.java --- a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/exposureconfig/validation/ExposureConfigurationValidatorTest.java +++ b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/validation/ExposureConfigurationStructureProviderValidatorTest.java @@ -1,18 +1,18 @@ -package app.coronawarn.server.services.distribution.exposureconfig.validation; +package app.coronawarn.server.services.distribution.assembly.exposureconfig.validation; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import app.coronawarn.server.services.distribution.exposureconfig.ExposureConfigurationProvider; -import app.coronawarn.server.services.distribution.exposureconfig.UnableToLoadFileException; -import app.coronawarn.server.services.distribution.exposureconfig.validation.WeightValidationError.ErrorType; +import app.coronawarn.server.services.distribution.assembly.exposureconfig.ExposureConfigurationProvider; +import app.coronawarn.server.services.distribution.assembly.exposureconfig.UnableToLoadFileException; +import app.coronawarn.server.services.distribution.assembly.exposureconfig.validation.WeightValidationError.ErrorType; import java.util.stream.Stream; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -public class ExposureConfigurationValidatorTest { +public class ExposureConfigurationStructureProviderValidatorTest { private static final ValidationResult SUCCESS = new ValidationResult(); diff --git a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/exposureconfig/validation/TestWithExpectedResult.java b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/validation/TestWithExpectedResult.java similarity index 83% rename from services/distribution/src/test/java/app/coronawarn/server/services/distribution/exposureconfig/validation/TestWithExpectedResult.java rename to services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/validation/TestWithExpectedResult.java --- a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/exposureconfig/validation/TestWithExpectedResult.java +++ b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/exposureconfig/validation/TestWithExpectedResult.java @@ -1,4 +1,4 @@ -package app.coronawarn.server.services.distribution.exposureconfig.validation; +package app.coronawarn.server.services.distribution.assembly.exposureconfig.validation; public class TestWithExpectedResult { diff --git a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/structure/WritableTest.java b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/structure/WritableTest.java similarity index 81% rename from services/distribution/src/test/java/app/coronawarn/server/services/distribution/structure/WritableTest.java rename to services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/structure/WritableTest.java --- a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/structure/WritableTest.java +++ b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/structure/WritableTest.java @@ -1,11 +1,11 @@ -package app.coronawarn.server.services.distribution.structure; +package app.coronawarn.server.services.distribution.assembly.structure; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import app.coronawarn.server.services.distribution.structure.directory.Directory; -import app.coronawarn.server.services.distribution.structure.directory.DirectoryImpl; -import app.coronawarn.server.services.distribution.structure.util.ImmutableStack; +import app.coronawarn.server.services.distribution.assembly.structure.directory.Directory; +import app.coronawarn.server.services.distribution.assembly.structure.directory.DirectoryImpl; +import app.coronawarn.server.services.distribution.assembly.structure.util.ImmutableStack; import java.io.File; import org.junit.jupiter.api.Test; diff --git a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/structure/directory/DirectoryTest.java b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/structure/directory/DirectoryTest.java similarity index 90% rename from services/distribution/src/test/java/app/coronawarn/server/services/distribution/structure/directory/DirectoryTest.java rename to services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/structure/directory/DirectoryTest.java --- a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/structure/directory/DirectoryTest.java +++ b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/structure/directory/DirectoryTest.java @@ -1,13 +1,13 @@ -package app.coronawarn.server.services.distribution.structure.directory; +package app.coronawarn.server.services.distribution.assembly.structure.directory; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; -import app.coronawarn.server.services.distribution.structure.file.File; -import app.coronawarn.server.services.distribution.structure.file.FileImpl; -import app.coronawarn.server.services.distribution.structure.util.ImmutableStack; +import app.coronawarn.server.services.distribution.assembly.structure.file.File; +import app.coronawarn.server.services.distribution.assembly.structure.file.FileImpl; +import app.coronawarn.server.services.distribution.assembly.structure.util.ImmutableStack; import java.io.IOException; import java.util.Set; import org.junit.Rule; diff --git a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/structure/directory/IndexDirectoryTest.java b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/structure/directory/IndexDirectoryTest.java similarity index 85% rename from services/distribution/src/test/java/app/coronawarn/server/services/distribution/structure/directory/IndexDirectoryTest.java rename to services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/structure/directory/IndexDirectoryTest.java --- a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/structure/directory/IndexDirectoryTest.java +++ b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/structure/directory/IndexDirectoryTest.java @@ -1,13 +1,13 @@ -package app.coronawarn.server.services.distribution.structure.directory; +package app.coronawarn.server.services.distribution.assembly.structure.directory; import static org.junit.jupiter.api.Assertions.assertEquals; -import app.coronawarn.server.services.distribution.structure.Writable; -import app.coronawarn.server.services.distribution.structure.file.File; -import app.coronawarn.server.services.distribution.structure.file.FileImpl; -import app.coronawarn.server.services.distribution.structure.functional.Formatter; -import app.coronawarn.server.services.distribution.structure.functional.IndexFunction; -import app.coronawarn.server.services.distribution.structure.util.ImmutableStack; +import app.coronawarn.server.services.distribution.assembly.structure.Writable; +import app.coronawarn.server.services.distribution.assembly.structure.file.File; +import app.coronawarn.server.services.distribution.assembly.structure.file.FileImpl; +import app.coronawarn.server.services.distribution.assembly.structure.functional.Formatter; +import app.coronawarn.server.services.distribution.assembly.structure.functional.IndexFunction; +import app.coronawarn.server.services.distribution.assembly.structure.util.ImmutableStack; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; diff --git a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/structure/directory/decorators/DirectoryDecoratorTest.java b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/structure/directory/decorators/DirectoryDecoratorTest.java similarity index 63% rename from services/distribution/src/test/java/app/coronawarn/server/services/distribution/structure/directory/decorators/DirectoryDecoratorTest.java rename to services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/structure/directory/decorators/DirectoryDecoratorTest.java --- a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/structure/directory/decorators/DirectoryDecoratorTest.java +++ b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/structure/directory/decorators/DirectoryDecoratorTest.java @@ -1,14 +1,14 @@ -package app.coronawarn.server.services.distribution.structure.directory.decorators; +package app.coronawarn.server.services.distribution.assembly.structure.directory.decorators; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -import app.coronawarn.server.services.distribution.structure.directory.Directory; -import app.coronawarn.server.services.distribution.structure.directory.DirectoryImpl; -import app.coronawarn.server.services.distribution.structure.directory.decorator.DirectoryDecorator; -import app.coronawarn.server.services.distribution.structure.file.File; -import app.coronawarn.server.services.distribution.structure.file.FileImpl; -import app.coronawarn.server.services.distribution.structure.util.ImmutableStack; +import app.coronawarn.server.services.distribution.assembly.structure.directory.Directory; +import app.coronawarn.server.services.distribution.assembly.structure.directory.DirectoryImpl; +import app.coronawarn.server.services.distribution.assembly.structure.directory.decorator.DirectoryDecorator; +import app.coronawarn.server.services.distribution.assembly.structure.file.File; +import app.coronawarn.server.services.distribution.assembly.structure.file.FileImpl; +import app.coronawarn.server.services.distribution.assembly.structure.util.ImmutableStack; import org.junit.jupiter.api.Test; public class DirectoryDecoratorTest { @@ -52,7 +52,7 @@ public void checkProxiesAllMethods() { verify(decoree).getFileOnDisk(); } - private class TestDirectoryDecorator extends DirectoryDecorator { + private static class TestDirectoryDecorator extends DirectoryDecorator { protected TestDirectoryDecorator(Directory directory) { super(directory); diff --git a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/structure/directory/decorators/IndexingDecoratorTest.java b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/structure/directory/decorators/IndexingDecoratorTest.java similarity index 77% rename from services/distribution/src/test/java/app/coronawarn/server/services/distribution/structure/directory/decorators/IndexingDecoratorTest.java rename to services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/structure/directory/decorators/IndexingDecoratorTest.java --- a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/structure/directory/decorators/IndexingDecoratorTest.java +++ b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/structure/directory/decorators/IndexingDecoratorTest.java @@ -1,13 +1,13 @@ -package app.coronawarn.server.services.distribution.structure.directory.decorators; +package app.coronawarn.server.services.distribution.assembly.structure.directory.decorators; import static app.coronawarn.server.services.distribution.common.Helpers.prepareAndWrite; import static org.junit.jupiter.api.Assertions.assertTrue; -import app.coronawarn.server.services.distribution.structure.directory.Directory; -import app.coronawarn.server.services.distribution.structure.directory.DirectoryImpl; -import app.coronawarn.server.services.distribution.structure.directory.IndexDirectory; -import app.coronawarn.server.services.distribution.structure.directory.IndexDirectoryImpl; -import app.coronawarn.server.services.distribution.structure.directory.decorator.IndexingDecorator; +import app.coronawarn.server.services.distribution.assembly.structure.directory.Directory; +import app.coronawarn.server.services.distribution.assembly.structure.directory.DirectoryImpl; +import app.coronawarn.server.services.distribution.assembly.structure.directory.IndexDirectory; +import app.coronawarn.server.services.distribution.assembly.structure.directory.IndexDirectoryImpl; +import app.coronawarn.server.services.distribution.assembly.structure.directory.decorator.IndexingDecorator; import java.io.File; import java.io.FileReader; import java.io.IOException; diff --git a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/structure/file/FileTest.java b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/structure/file/FileTest.java similarity index 81% rename from services/distribution/src/test/java/app/coronawarn/server/services/distribution/structure/file/FileTest.java rename to services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/structure/file/FileTest.java --- a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/structure/file/FileTest.java +++ b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/structure/file/FileTest.java @@ -1,11 +1,11 @@ -package app.coronawarn.server.services.distribution.structure.file; +package app.coronawarn.server.services.distribution.assembly.structure.file; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; -import app.coronawarn.server.services.distribution.structure.directory.Directory; -import app.coronawarn.server.services.distribution.structure.directory.DirectoryImpl; +import app.coronawarn.server.services.distribution.assembly.structure.directory.Directory; +import app.coronawarn.server.services.distribution.assembly.structure.directory.DirectoryImpl; import java.io.IOException; import java.nio.file.Files; import org.junit.Rule; @@ -15,7 +15,7 @@ public class FileTest { - private byte[] bytes = "World".getBytes(); + private final byte[] bytes = "World".getBytes(); private File file; @Rule diff --git a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/structure/file/decorators/FileDecoratorTest.java b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/structure/file/decorators/FileDecoratorTest.java similarity index 62% rename from services/distribution/src/test/java/app/coronawarn/server/services/distribution/structure/file/decorators/FileDecoratorTest.java rename to services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/structure/file/decorators/FileDecoratorTest.java --- a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/structure/file/decorators/FileDecoratorTest.java +++ b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/structure/file/decorators/FileDecoratorTest.java @@ -1,13 +1,13 @@ -package app.coronawarn.server.services.distribution.structure.file.decorators; +package app.coronawarn.server.services.distribution.assembly.structure.file.decorators; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; -import app.coronawarn.server.services.distribution.structure.directory.Directory; -import app.coronawarn.server.services.distribution.structure.directory.DirectoryImpl; -import app.coronawarn.server.services.distribution.structure.file.File; -import app.coronawarn.server.services.distribution.structure.file.decorator.FileDecorator; -import app.coronawarn.server.services.distribution.structure.util.ImmutableStack; +import app.coronawarn.server.services.distribution.assembly.structure.directory.Directory; +import app.coronawarn.server.services.distribution.assembly.structure.directory.DirectoryImpl; +import app.coronawarn.server.services.distribution.assembly.structure.file.File; +import app.coronawarn.server.services.distribution.assembly.structure.file.decorator.FileDecorator; +import app.coronawarn.server.services.distribution.assembly.structure.util.ImmutableStack; import org.junit.jupiter.api.Test; public class FileDecoratorTest { @@ -45,7 +45,7 @@ public void checkProxiesAllMethods() { verify(decoree).getFileOnDisk(); } - private class TestFileDecorator extends FileDecorator { + private static class TestFileDecorator extends FileDecorator { protected TestFileDecorator(File file) { super(file); diff --git a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/structure/file/decorators/SigningDecoratorTest.java b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/structure/file/decorators/SigningDecoratorTest.java similarity index 84% rename from services/distribution/src/test/java/app/coronawarn/server/services/distribution/structure/file/decorators/SigningDecoratorTest.java rename to services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/structure/file/decorators/SigningDecoratorTest.java --- a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/structure/file/decorators/SigningDecoratorTest.java +++ b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assembly/structure/file/decorators/SigningDecoratorTest.java @@ -1,16 +1,16 @@ -package app.coronawarn.server.services.distribution.structure.file.decorators; +package app.coronawarn.server.services.distribution.assembly.structure.file.decorators; import static app.coronawarn.server.services.distribution.common.Helpers.prepareAndWrite; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import app.coronawarn.server.common.protocols.internal.SignedPayload; -import app.coronawarn.server.services.distribution.crypto.CryptoProvider; -import app.coronawarn.server.services.distribution.structure.directory.Directory; -import app.coronawarn.server.services.distribution.structure.directory.DirectoryImpl; -import app.coronawarn.server.services.distribution.structure.file.File; -import app.coronawarn.server.services.distribution.structure.file.FileImpl; -import app.coronawarn.server.services.distribution.structure.file.decorator.SigningDecorator; +import app.coronawarn.server.services.distribution.assembly.component.CryptoProvider; +import app.coronawarn.server.services.distribution.assembly.structure.directory.Directory; +import app.coronawarn.server.services.distribution.assembly.structure.directory.DirectoryImpl; +import app.coronawarn.server.services.distribution.assembly.structure.file.File; +import app.coronawarn.server.services.distribution.assembly.structure.file.FileImpl; +import app.coronawarn.server.services.distribution.assembly.structure.file.decorator.SigningDecorator; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; diff --git a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/common/Helpers.java b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/common/Helpers.java --- a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/common/Helpers.java +++ b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/common/Helpers.java @@ -1,8 +1,8 @@ package app.coronawarn.server.services.distribution.common; import app.coronawarn.server.common.persistence.domain.DiagnosisKey; -import app.coronawarn.server.services.distribution.structure.directory.Directory; -import app.coronawarn.server.services.distribution.structure.util.ImmutableStack; +import app.coronawarn.server.services.distribution.assembly.structure.directory.Directory; +import app.coronawarn.server.services.distribution.assembly.structure.util.ImmutableStack; import java.time.LocalDateTime; import java.time.ZoneOffset; diff --git a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/objectstore/ObjectStoreAccessTest.java b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/objectstore/ObjectStoreAccessTest.java --- a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/objectstore/ObjectStoreAccessTest.java +++ b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/objectstore/ObjectStoreAccessTest.java @@ -20,11 +20,11 @@ public class ObjectStoreAccessTest { - private Logger logger = LoggerFactory.getLogger(this.getClass()); + private final Logger logger = LoggerFactory.getLogger(this.getClass()); - private String testRunId = "testing/cwa/" + UUID.randomUUID().toString() + "/"; + private final String testRunId = "testing/cwa/" + UUID.randomUUID().toString() + "/"; - private String textFile = "objectstore/store-test-file"; + private final String textFile = "objectstore/store-test-file"; @Autowired private ObjectStoreAccess objectStoreAccess; diff --git a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/objectstore/S3PublisherTest.java b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/objectstore/S3PublisherTest.java --- a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/objectstore/S3PublisherTest.java +++ b/services/distribution/src/test/java/app/coronawarn/server/services/distribution/objectstore/S3PublisherTest.java @@ -23,11 +23,11 @@ @TestInstance(Lifecycle.PER_CLASS) public class S3PublisherTest { - private String testRunId = "testing/cwa/" + UUID.randomUUID().toString() + "/"; + private final String testRunId = "testing/cwa/" + UUID.randomUUID().toString() + "/"; - private String rootTestFolder = "objectstore/publisher/"; + private final String rootTestFolder = "objectstore/publisher/"; - private String exampleFile = rootTestFolder + "rootfile"; + private final String exampleFile = rootTestFolder + "rootfile"; @Autowired private S3Publisher s3Publisher; diff --git a/services/distribution/src/test/resources/application.properties b/services/distribution/src/test/resources/application.properties --- a/services/distribution/src/test/resources/application.properties +++ b/services/distribution/src/test/resources/application.properties @@ -3,10 +3,9 @@ logging.level.org.springframework=off logging.level.root=off spring.main.banner-mode=off -app.coronawarn.server.services.distribution.retention_days=14 -app.coronawarn.server.services.distribution.version=v1 -app.coronawarn.server.services.distribution.paths.output=out -app.coronawarn.server.services.distribution.paths.privatekey=classpath:certificates/client/private.pem -app.coronawarn.server.services.distribution.paths.certificate=classpath:certificates/chain/certificate.crt +services.distribution.retention_days=14 +services.distribution.paths.output=out +services.distribution.paths.privatekey=classpath:certificates/client/private.pem +services.distribution.paths.certificate=classpath:certificates/chain/certificate.crt spring.flyway.enabled=false
DiagnosisKeyDistributionRunner deletes exposure configuration ``DiagnosisKeyDistributionRunner`` deletes the files written by ``ExposureConfigurationDistributionRunner`` before they are published.
2020-05-15T14:41:59
corona-warn-app/cwa-server
135
corona-warn-app__cwa-server-135
[ "109" ]
8655863c4c989c437ad9b5ef84c7e2afb699be8d
diff --git a/services/submission/pom.xml b/services/submission/pom.xml --- a/services/submission/pom.xml +++ b/services/submission/pom.xml @@ -22,6 +22,12 @@ <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> + <dependency> + <groupId>org.apache.commons</groupId> + <artifactId>commons-math3</artifactId> + <version>3.2</version> + <scope>compile</scope> + </dependency> </dependencies> </project> \ No newline at end of file diff --git a/services/submission/src/main/java/app/coronawarn/server/services/submission/controller/SubmissionController.java b/services/submission/src/main/java/app/coronawarn/server/services/submission/controller/SubmissionController.java --- a/services/submission/src/main/java/app/coronawarn/server/services/submission/controller/SubmissionController.java +++ b/services/submission/src/main/java/app/coronawarn/server/services/submission/controller/SubmissionController.java @@ -5,15 +5,23 @@ import app.coronawarn.server.common.protocols.internal.SubmissionPayload; import app.coronawarn.server.services.submission.verification.TanVerifier; import java.util.Collection; +import java.util.concurrent.Executors; +import java.util.concurrent.ForkJoinPool; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import org.apache.commons.math3.distribution.PoissonDistribution; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.util.StopWatch; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.context.request.async.DeferredResult; @RestController @RequestMapping("/version/v1") @@ -24,27 +32,57 @@ public class SubmissionController { */ public static final String SUBMISSION_ROUTE = "/diagnosis-keys"; + @Value("${services.submission.fake_delay_moving_average_samples}") + private Double fakeDelayMovingAverageSamples; + + // Exponential moving average of the last N real request durations (in ms), where + // N = fakeDelayMovingAverageSamples. + @Value("${services.submission.initial_fake_delay_milliseconds}") + private Double fakeDelay; + @Autowired private DiagnosisKeyService diagnosisKeyService; @Autowired private TanVerifier tanVerifier; + private ScheduledExecutorService scheduledExecutor = Executors.newSingleThreadScheduledExecutor(); + private ForkJoinPool forkJoinPool = ForkJoinPool.commonPool(); + @PostMapping(SUBMISSION_ROUTE) - public ResponseEntity<Void> submitDiagnosisKey( + public DeferredResult<ResponseEntity<Void>> submitDiagnosisKey( @RequestBody SubmissionPayload exposureKeys, @RequestHeader(value = "cwa-fake") Integer fake, @RequestHeader(value = "cwa-authorization") String tan) { + final DeferredResult<ResponseEntity<Void>> deferredResult = new DeferredResult<>(); if (fake != 0) { - return buildSuccessResponseEntity(); - } - if (!this.tanVerifier.verifyTan(tan)) { - return buildTanInvalidResponseEntity(); + setFakeDeferredResult(deferredResult); + } else { + setRealDeferredResult(deferredResult, exposureKeys, tan); } + return deferredResult; + } - persistDiagnosisKeysPayload(exposureKeys); + private void setFakeDeferredResult(DeferredResult<ResponseEntity<Void>> deferredResult) { + long delay = new PoissonDistribution(fakeDelay).sample(); + scheduledExecutor.schedule(() -> deferredResult.setResult(buildSuccessResponseEntity()), + delay, TimeUnit.MILLISECONDS); + } - return buildSuccessResponseEntity(); + private void setRealDeferredResult(DeferredResult<ResponseEntity<Void>> deferredResult, + SubmissionPayload exposureKeys, String tan) { + forkJoinPool.submit(() -> { + StopWatch stopWatch = new StopWatch(); + stopWatch.start(); + if (!this.tanVerifier.verifyTan(tan)) { + deferredResult.setResult(buildTanInvalidResponseEntity()); + } else { + persistDiagnosisKeysPayload(exposureKeys); + deferredResult.setResult(buildSuccessResponseEntity()); + } + stopWatch.stop(); + updateFakeDelay(stopWatch.getTotalTimeMillis()); + }); } /** @@ -74,4 +112,8 @@ private void persistDiagnosisKeysPayload(SubmissionPayload protoBufDiagnosisKeys this.diagnosisKeyService.saveDiagnosisKeys(diagnosisKeys); } + + private synchronized void updateFakeDelay(long realRequestDuration) { + fakeDelay = fakeDelay + (1 / fakeDelayMovingAverageSamples) * (realRequestDuration - fakeDelay); + } } diff --git a/services/submission/src/main/resources/application.properties b/services/submission/src/main/resources/application.properties --- a/services/submission/src/main/resources/application.properties +++ b/services/submission/src/main/resources/application.properties @@ -1,5 +1,10 @@ logging.level.org.springframework.web=INFO +# The initial value of the moving average for fake request delays. +services.submission.initial_fake_delay_milliseconds=10 +# The number of samples for the calculation of the moving average for fake request delays. +services.submission.fake_delay_moving_average_samples=10 + spring.flyway.locations=classpath:db/migration/h2 spring.flyway.enabled=true spring.jpa.hibernate.ddl-auto=validate
diff --git a/services/submission/src/test/resources/application.properties b/services/submission/src/test/resources/application.properties --- a/services/submission/src/test/resources/application.properties +++ b/services/submission/src/test/resources/application.properties @@ -3,4 +3,7 @@ logging.level.org.springframework=off logging.level.root=off spring.main.banner-mode=off +services.submission.initial_fake_delay_milliseconds=1 +services.submission.fake_delay_moving_average_samples=1 + spring.flyway.enabled=false
Submission Service: Enable waiting for Fake Requests When fake requests are send to the submission service, ensure that the duration of the fake requests take as long as normal requests, so attackers sniffing the traffic are unable to distinguish between fake/normal requests.
2020-05-17T13:49:18
corona-warn-app/cwa-server
232
corona-warn-app__cwa-server-232
[ "163" ]
9a5ae8bbf8872b63578dcca32b3258c012a63866
"diff --git a/.env b/.env\n--- a/.env\n+++ b/.env\n@@ -10,9 +10,9 @@ POSTGRES_PASSWORD=postgres\n PG(...TRUNCATED)
"diff --git a/services/distribution/src/test/resources/application.properties b/services/distributio(...TRUNCATED)
"Open MinIO read access\n## Current Implementation\r\nReceiving files from local MinIO requires acce(...TRUNCATED)
2020-05-21T13:53:01
corona-warn-app/cwa-server
260
corona-warn-app__cwa-server-260
[ "122" ]
218e0c75d3890fd6c1166fc63ce287f3b9d51fa7
"diff --git a/common/protocols/src/main/proto/app/coronawarn/server/common/protocols/internal/risk_s(...TRUNCATED)
"diff --git a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assemb(...TRUNCATED)
"Exposure configuration parameters not validated\nThe exposure configuration parameters are currentl(...TRUNCATED)
2020-05-22T19:20:31
corona-warn-app/cwa-server
264
corona-warn-app__cwa-server-264
[ "78" ]
a04308e1e7f96d43224fe3b1c58125f2575a7bb7
"diff --git a/common/protocols/src/main/proto/app/coronawarn/server/common/protocols/internal/risk_s(...TRUNCATED)
"diff --git a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assemb(...TRUNCATED)
"Add mobile configuration\nMobile needs to be able to fetch additional configuration/settings from t(...TRUNCATED)
2020-05-22T22:46:48
corona-warn-app/cwa-server
272
corona-warn-app__cwa-server-272
[ "205" ]
73b566ec755cc61fc4c08da274c133535adb6ae7
"diff --git a/docker-compose-test-secrets/certificate.crt b/docker-compose-test-secrets/certificate.(...TRUNCATED)
"diff --git a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assemb(...TRUNCATED)
"Update signature algorithm to SHA-256 + ECDSA P-256\n## Feature description\r\nThe current CWA serv(...TRUNCATED)
2020-05-23T13:07:15
corona-warn-app/cwa-server
277
corona-warn-app__cwa-server-277
[ "245" ]
576fd8b20079374458ffb650fe63ca6002e84a39
"diff --git a/README.md b/README.md\n--- a/README.md\n+++ b/README.md\n@@ -6,7 +6,7 @@\n <a href(...TRUNCATED)
"diff --git a/common/persistence/src/test/resources/application.properties b/common/persistence/src/(...TRUNCATED)
"Switch application*.properties files to Yaml\nLet's switch over to YAML for better readability.\r\n(...TRUNCATED)
2020-05-23T21:07:14
corona-warn-app/cwa-server
299
corona-warn-app__cwa-server-299
[ "298" ]
c5991b2fcb894aa4a8eec41c51a2f2cc366a13b5
"diff --git a/services/distribution/src/main/java/app/coronawarn/server/services/distribution/assemb(...TRUNCATED)
"diff --git a/services/distribution/src/test/java/app/coronawarn/server/services/distribution/assemb(...TRUNCATED)
"RKI: Adjust Risk Score Parameters in master config\nRKI decided for the following risk score parame(...TRUNCATED)
"Config file that needs updating: [master.yaml](https://github.com/corona-warn-app/cwa-server/blob/m(...TRUNCATED)
2020-05-25T09:41:14

No dataset card yet

New: Create and edit this dataset card directly on the website!

Contribute a Dataset Card
Downloads last month
8
Add dataset card

Models trained or fine-tuned on feedback-to-code/cwa-server-task-instances