Commit f3b57b0b authored by Ananas Orange's avatar Ananas Orange
Browse files

Corrected integration

parent aecea1eb
package fr.gouv.clea.consumer.configuration;
import fr.gouv.clea.clea.scoring.configuration.exposure.ExposureTimeConfiguration;
import fr.gouv.clea.clea.scoring.configuration.exposure.ExposureTimeConfigurationConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class ScoringConfiguration {
@Bean
ExposureTimeConfiguration getExposureTimeConfiguration() {
return new ExposureTimeConfiguration();
}
@Bean
ExposureTimeConfigurationConverter getExposureTimeConfigurationConverter() {
return new ExposureTimeConfigurationConverter();
}
}
......@@ -23,15 +23,17 @@ import java.util.stream.Stream;
@Slf4j
public class VisitExpositionAggregatorService implements IVisitExpositionAggregatorService {
@Autowired
private ExposureTimeConfiguration configuration;
private final static long EXPOSURE_TIME_UNIT = TimeUtils.NB_SECONDS_PER_HOUR;
private static final long EXPOSURE_TIME_UNIT = TimeUtils.NB_SECONDS_PER_HOUR;
private final IExposedVisitRepository repository;
private final ExposureTimeConfiguration configuration;
@Autowired
public VisitExpositionAggregatorService(IExposedVisitRepository repository) {
public VisitExpositionAggregatorService(
IExposedVisitRepository repository,
ExposureTimeConfiguration configuration
) {
this.repository = repository;
this.configuration = configuration;
}
@Override
......@@ -70,7 +72,7 @@ public class VisitExpositionAggregatorService implements IVisitExpositionAggrega
return TimeUtils.instantFromTimestamp((long) visit.getCompressedPeriodStartTime() * TimeUtils.NB_SECONDS_PER_HOUR);
}
protected long periodStartTimeNTPTimestamp(Visit visit){
protected long periodStartTimeNTPTimestamp(Visit visit) {
return ((long) visit.getCompressedPeriodStartTime()) * TimeUtils.NB_SECONDS_PER_HOUR;
}
......@@ -84,7 +86,6 @@ public class VisitExpositionAggregatorService implements IVisitExpositionAggrega
}
protected ExposedVisitEntity newExposedVisit(Visit visit, int slotIndex) {
// TODO: visit.getPeriodStart returning an Instant
long periodStart = periodStartTimeNTPTimestamp(visit);
return ExposedVisitEntity.builder()
.locationTemporaryPublicId(visit.getLocationTemporaryPublicId())
......@@ -106,15 +107,19 @@ public class VisitExpositionAggregatorService implements IVisitExpositionAggrega
*/
protected int getExposureTime(int venueType, int venueCategory1, int venueCategory2, boolean staff, boolean isBackward) {
ExposureTimeRule rule = configuration.getConfigurationFor(venueType, venueCategory1, venueCategory2);
int exposureTime = 3; //default
if (staff && isBackward) {
exposureTime = rule.getExposureTimeStaffBackward();
} else if (staff && !isBackward) {
exposureTime = rule.getExposureTimeStaffForward();
} else if (!staff && isBackward) {
exposureTime = rule.getExposureTimeBackward();
} else if (!staff && !isBackward) {
exposureTime = rule.getExposureTimeForward();
int exposureTime;
if (staff) {
if (isBackward) {
exposureTime = rule.getExposureTimeStaffBackward();
} else {
exposureTime = rule.getExposureTimeStaffForward();
}
} else {
if (isBackward) {
exposureTime = rule.getExposureTimeBackward();
} else {
exposureTime = rule.getExposureTimeForward();
}
}
return exposureTime;
}
......
clea:
conf:
exposure:
enabled: "true"
rules:
# venueType, venueCat1, venueCat2, exposureTimeBackward, exposureTimeForward, exposureTimeStaffBackward, exposureTimeStaffForward
- '1,1,1,3,13,23,33'
- '*,*,*,2,12,22,32'
- '3,*,*,1,11,21,31'
- '1,2,3,2,12,22,32'
- '*,2,*,2,12,22,32'
- '*,*,3,2,12,22,32'
risk:
enabled: "false"
rules:
cleaClockDriftInSecs: 300
driftBetweenDeviceAndOfficialTimeInSecs: 300
retentionDurationInDays: 14
......@@ -23,6 +10,16 @@ clea:
security:
crypto:
manualCTAuthoritySecretKey: f55d39487b91c00ad24d4fc70f54511539ed308e954ab859734598d16d047bdf
exposure:
enabled: "true"
rules:
# venueType, venueCat1, venueCat2, exposureTimeBackward, exposureTimeForward, exposureTimeStaffBackward, exposureTimeStaffForward
- '1,1,1,3,13,23,33'
- '*,*,*,2,12,22,32'
- '3,*,*,1,11,21,31'
- '1,2,3,2,12,22,32'
- '*,2,*,2,12,22,32'
- '*,*,3,2,12,22,32'
management:
endpoints:
......
package fr.gouv.clea.consumer.service.impl;
import fr.gouv.clea.clea.scoring.configuration.exposure.ExposureTimeConfiguration;
import fr.gouv.clea.clea.scoring.configuration.exposure.ExposureTimeRule;
import fr.gouv.clea.consumer.model.ExposedVisitEntity;
import fr.gouv.clea.consumer.model.Visit;
import fr.gouv.clea.consumer.repository.IExposedVisitRepository;
......@@ -12,6 +14,7 @@ import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
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.test.annotation.DirtiesContext;
import java.time.Instant;
......@@ -21,6 +24,8 @@ import java.util.UUID;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.Mockito.anyInt;
import static org.mockito.Mockito.when;
@SpringBootTest
@DirtiesContext
......@@ -32,6 +37,9 @@ class VisitExpositionAggregatorServiceTest {
@Autowired
private IVisitExpositionAggregatorService service;
@MockBean
private ExposureTimeConfiguration exposureTimeConfiguration;
private Instant yesterday;
private UUID uuid;
private byte[] locationTemporarySecretKey;
......@@ -43,6 +51,15 @@ class VisitExpositionAggregatorServiceTest {
uuid = UUID.randomUUID();
locationTemporarySecretKey = RandomUtils.nextBytes(20);
encryptedLocationContactMessage = RandomUtils.nextBytes(20);
when(exposureTimeConfiguration.getConfigurationFor(anyInt(), anyInt(), anyInt()))
.thenReturn(
ExposureTimeRule.builder()
.exposureTimeBackward(3)
.exposureTimeStaffBackward(3)
.exposureTimeForward(3)
.exposureTimeStaffForward(3)
.build()
);
}
@AfterEach
......
......@@ -10,6 +10,16 @@ clea:
security:
crypto:
manualCTAuthoritySecretKey: f55d39487b91c00ad24d4fc70f54511539ed308e954ab859734598d16d047bdf
exposure:
enabled: "true"
rules:
# venueType, venueCat1, venueCat2, exposureTimeBackward, exposureTimeForward, exposureTimeStaffBackward, exposureTimeStaffForward
- '1,1,1,3,13,23,33'
- '*,*,*,2,12,22,32'
- '3,*,*,1,11,21,31'
- '1,2,3,2,12,22,32'
- '*,2,*,2,12,22,32'
- '*,*,3,2,12,22,32'
logging:
level:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment