diff --git a/pom.xml b/pom.xml index 8f29a8c..bc2448c 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ ch.admin.bag.covidcode ha-authcode-generation-service - 1.0.4-SNAPSHOT + 1.0.5-SNAPSHOT ha-authcode-generation-service Service for generating an authorization code for the proximity tracing app diff --git a/src/main/java/ch/admin/bag/covidcode/authcodegeneration/service/AuthCodeDeletionService.java b/src/main/java/ch/admin/bag/covidcode/authcodegeneration/service/AuthCodeDeletionService.java index 35b658d..a7c65b6 100644 --- a/src/main/java/ch/admin/bag/covidcode/authcodegeneration/service/AuthCodeDeletionService.java +++ b/src/main/java/ch/admin/bag/covidcode/authcodegeneration/service/AuthCodeDeletionService.java @@ -4,16 +4,21 @@ import ch.admin.bag.covidcode.authcodegeneration.domain.AuthorizationCodeRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.time.ZonedDateTime; +import java.time.format.DateTimeFormatter; import java.util.List; +import static net.logstash.logback.argument.StructuredArguments.kv; + @Slf4j @RequiredArgsConstructor @Service +@ConditionalOnProperty(value="CF_INSTANCE_INDEX", havingValue = "0") public class AuthCodeDeletionService { private final AuthorizationCodeRepository authorizationCodeRepository; @@ -28,6 +33,11 @@ public void deleteOldAuthCode() { log.info("Found {} AuthCodes to delete.", expiredAuthCodes.size()); expiredAuthCodes.forEach(ac -> { + + if (ac.getCallCount() > 0) { + log.info("AuthorizationCode verified: '{}', '{}', '{}', '{}', '{}'", kv("id", ac.getId()), kv("callCount", ac.getCallCount()), kv("creationDateTime", ac.getCreationDateTime().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)), kv("onsetDate",ac.getOnsetDate()), kv("originalOnsetDate",ac.getOriginalOnsetDate())); + } + log.info("Deleting code '{}' with expiryDate '{}'.", ac.getCode(), ac.getExpiryDate()); authorizationCodeRepository.delete(ac); }); diff --git a/src/main/java/ch/admin/bag/covidcode/authcodegeneration/service/AuthCodeVerificationService.java b/src/main/java/ch/admin/bag/covidcode/authcodegeneration/service/AuthCodeVerificationService.java index 85df229..613f961 100644 --- a/src/main/java/ch/admin/bag/covidcode/authcodegeneration/service/AuthCodeVerificationService.java +++ b/src/main/java/ch/admin/bag/covidcode/authcodegeneration/service/AuthCodeVerificationService.java @@ -50,7 +50,7 @@ public AuthorizationCodeVerifyResponseDto verify(String code, String fake) { } existingCode.incrementCallCount(); - log.info("AuthorizationCode verified: '{}', '{}', '{}', '{}', '{}'", kv("id", existingCode.getId()), kv("callCount", existingCode.getCallCount()), kv("creationDateTime", existingCode.getCreationDateTime().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)), kv("onsetDate",existingCode.getOnsetDate()), kv("originalOnsetDate",existingCode.getOriginalOnsetDate())); + log.debug("AuthorizationCode verified: '{}', '{}', '{}', '{}', '{}'", kv("id", existingCode.getId()), kv("callCount", existingCode.getCallCount()), kv("creationDateTime", existingCode.getCreationDateTime().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)), kv("onsetDate",existingCode.getOnsetDate()), kv("originalOnsetDate",existingCode.getOriginalOnsetDate())); return new AuthorizationCodeVerifyResponseDto(tokenProvider.createToken(existingCode.getOnsetDate().format(DATE_FORMATTER), fake)); } diff --git a/src/test/java/ch/admin/bag/covidcode/authcodegeneration/service/AuthCodeDeletionServiceITTest.java b/src/test/java/ch/admin/bag/covidcode/authcodegeneration/service/AuthCodeDeletionServiceITTest.java index 1b6f946..c106682 100644 --- a/src/test/java/ch/admin/bag/covidcode/authcodegeneration/service/AuthCodeDeletionServiceITTest.java +++ b/src/test/java/ch/admin/bag/covidcode/authcodegeneration/service/AuthCodeDeletionServiceITTest.java @@ -20,7 +20,8 @@ "spring.datasource.driver-class-name=org.h2.Driver", "spring.datasource.url=jdbc:h2:~/test;MODE=PostgreSQL;DATABASE_TO_LOWER=TRUE", "spring.datasource.username=sa", - "spring.datasource.password=sa" + "spring.datasource.password=sa", + "CF_INSTANCE_INDEX=0" }) @ActiveProfiles("local") @DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS)