Commit cf82e161 authored by Deniro StopCovid's avatar Deniro StopCovid

Merge branch 'release/v1.4.1' into 'develop'

Merge Back Release/v1.4.1

See merge request !87
parents a61c5dcd d08544b5
package fr.gouv.stopc.robert.crypto.grpc.server.service.impl;
import fr.gouv.stopc.robert.server.common.utils.TimeUtils;
import org.springframework.stereotype.Service;
import fr.gouv.stopc.robert.crypto.grpc.server.service.ICryptoServerConfigurationService;
import fr.gouv.stopc.robert.crypto.grpc.server.utils.PropertyLoader;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import javax.annotation.PostConstruct;
import javax.inject.Inject;
import org.springframework.stereotype.Service;
import fr.gouv.stopc.robert.crypto.grpc.server.service.ICryptoServerConfigurationService;
import fr.gouv.stopc.robert.crypto.grpc.server.utils.PropertyLoader;
import fr.gouv.stopc.robert.server.common.utils.TimeUtils;
/**
* Default implementation of the ICryptoServerConfigurationService
......
......@@ -10,6 +10,7 @@ import java.io.IOException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
......@@ -85,6 +86,7 @@ import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import test.fr.gouv.stopc.robert.crypto.grpc.server.utils.CryptoTestUtils;
@Slf4j
@ExtendWith(SpringExtension.class)
@TestPropertySource(locations = "classpath:application.properties")
......@@ -819,7 +821,6 @@ class CryptoServiceGrpcServerTest {
assertTrue(Arrays.equals(clientIdentifierBundle.get().getId(), response.getIdA().toByteArray()));
}
@Test
void testGetIdFromAuthWithEbidEncodedWithFutureKSFails() {
Optional<ClientIdentifierBundle> clientIdentifierBundle = createId();
......@@ -1763,7 +1764,6 @@ class CryptoServiceGrpcServerTest {
assertTrue(!res.isError());
assertTrue(response.hasError());
assertTrue(response.getError().getCode() == 400);
}
@AllArgsConstructor
......
package test.fr.gouv.stopc.robert.crypto.grpc.server.utils;
import java.security.*;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.spec.ECGenParameterSpec;
import lombok.extern.slf4j.Slf4j;
import javax.crypto.spec.DHGenParameterSpec;
@Slf4j
public final class CryptoTestUtils {
......
......@@ -10,7 +10,6 @@ import org.springframework.batch.item.ItemProcessor;
import org.springframework.util.CollectionUtils;
import com.google.protobuf.ByteString;
import fr.gouv.stopc.robert.crypto.grpc.server.client.service.ICryptoServerGrpcClient;
import fr.gouv.stopc.robert.crypto.grpc.server.messaging.GetInfoFromHelloMessageRequest;
import fr.gouv.stopc.robert.crypto.grpc.server.messaging.GetInfoFromHelloMessageResponse;
......@@ -29,6 +28,7 @@ import fr.gouv.stopc.robertserver.database.model.Registration;
import fr.gouv.stopc.robertserver.database.service.IRegistrationService;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class ContactProcessor implements ItemProcessor<Contact, Contact> {
......
......@@ -13,6 +13,7 @@ import fr.gouv.stopc.robertserver.database.model.EpochExposition;
import fr.gouv.stopc.robertserver.database.model.Registration;
import lombok.AllArgsConstructor;
@AllArgsConstructor
public class RegistrationProcessor implements ItemProcessor<Registration, Registration> {
......
......@@ -11,8 +11,6 @@ import fr.gouv.stopc.robert.server.common.utils.TimeUtils;
import fr.gouv.stopc.robertserver.database.model.EpochExposition;
import fr.gouv.stopc.robertserver.database.model.Registration;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
@Slf4j
public final class ScoringUtils {
......
......@@ -34,7 +34,6 @@ robert.scoring.soft-max-a=${ROBERT_SCORING_SOFT_MAX_A:4.342}
robert.scoring.soft-max-b=${ROBERT_SCORING_SOFT_MAX_B:0.2}
robert.scoring.algo-version=${ROBERT_SCORING_ALGO_VERSION:2}
robert.scoring.scoring-algo-r0=${ROBERT_SCORING_R0:0.0071}
robert.scoring.batch-mode=${ROBERT_SCORING_BATCH_MODE:SCORE_CONTACTS_AND_COMPUTE_RISK}
robert.protocol.hello-message-timestamp-tolerance=${ROBERT_PROTOCOL_HELLO_TOLERANCE:180}
......
......@@ -38,7 +38,6 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.util.CollectionUtils;
import com.google.protobuf.ByteString;
import fr.gouv.stopc.robert.crypto.grpc.server.client.service.ICryptoServerGrpcClient;
import fr.gouv.stopc.robert.crypto.grpc.server.messaging.GetInfoFromHelloMessageResponse;
import fr.gouv.stopc.robert.server.batch.RobertServerBatchApplication;
......@@ -1178,6 +1177,7 @@ public class ContactProcessorTest {
private void assertRiskThresholdExceededBasedOnConfiguration(Registration expectedRegistration) {
boolean atRisk = expectedRegistration.isAtRisk();
if (this.propertyLoader.getRiskThreshold() >= sumRiskScores(expectedRegistration.getExposedEpochs())) {
assertFalse(atRisk);
} else {
......
......@@ -29,6 +29,7 @@ import fr.gouv.stopc.robert.server.common.utils.TimeUtils;
import fr.gouv.stopc.robertserver.database.model.EpochExposition;
import fr.gouv.stopc.robertserver.database.model.Registration;
import fr.gouv.stopc.robertserver.database.service.IRegistrationService;
import test.fr.gouv.stopc.robertserver.batch.utils.ProcessorTestUtils;
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
......
package test.fr.gouv.stopc.robertserver.batch.processor;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
......@@ -32,6 +33,7 @@ import fr.gouv.stopc.robert.server.common.utils.TimeUtils;
import fr.gouv.stopc.robertserver.database.model.EpochExposition;
import fr.gouv.stopc.robertserver.database.model.Registration;
import fr.gouv.stopc.robertserver.database.service.IRegistrationService;
import test.fr.gouv.stopc.robertserver.batch.utils.ProcessorTestUtils;
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
......@@ -73,7 +75,6 @@ public class RegistrationProcessorTest {
public void beforeEach() {
this.registrationProcessor = new RegistrationProcessor(
serverConfigurationService,
registrationService,
scoringStrategyService,
propertyLoader
);
......
......@@ -28,11 +28,9 @@ robert.scoring.p0=-66.0
robert.scoring.soft-max-a=4.342
robert.scoring.soft-max-b=0.2
robert.scoring.scoring-algo-r0=0.0071
robert.scoring.batch-mode=${ROBERT_SCORING_BATCH_MODE:SCORE_CONTACTS_AND_COMPUTE_RISK}
robert.server.time-start=20200601
robert.protocol.contagious-period=14
robert.protocol.hello-message-timestamp-tolerance=180
......@@ -24,5 +24,4 @@ public interface IServerConfigurationService {
* @return The duration that must be covered by an epoch bundle returned in /register and /status (in days)
*/
int getEpochBundleDurationInDays();
}
......@@ -38,6 +38,7 @@ public class TimeUtilsTest {
final ZonedDateTime zdt = ldt.atZone(ZoneId.of("UTC"));
return TimeUtils.convertUnixMillistoNtpSeconds(zdt.toInstant().toEpochMilli());
}
@Test
void testGetDateFromEpochTimezone() {
for (int i = 0; i < 96 * 2; i++) {
......
......@@ -9,7 +9,6 @@ import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.repository.NoRepositoryBean;
import org.springframework.data.util.StreamUtils;
import org.springframework.data.util.Streamable;
import org.springframework.util.Assert;
import fr.gouv.stopc.robertserver.database.model.Contact;
......
......@@ -42,6 +42,14 @@ public interface RegistrationRepository extends MongoRepository<Registration, by
@Query(value = "{ atRisk: {$eq: false}, isNotified: {$eq: false} , exposedEpochs: {$exists:true, $ne: []}}", count = true)
Long countNbExposedUsersButNotAtRisk();
/**
* Retrieve the number of users already notified and scored again
*
* @return the count result
*/
@Query(value = "{ atRisk: {$eq: false}, isNotified: {$eq: true} , exposedEpochs: {$exists:true, $ne: []}}", count = true)
Long countNbNotifiedUsersScoredAgain();
/**
* Retrieve the number of users than epoch exposition with an epochId <= the epochId in parameter.
*
......
......@@ -51,6 +51,13 @@ public interface IRegistrationService {
*/
Long countNbExposedUsersButNotAtRisk();
/**
* Return the number of users notified and scored again (isNotified = true, atRisk = false, exposedEpochs not empty)
*
* @return the number
*/
Long countNbNotifiedUsersScoredAgain();
Long count();
/**
......
......@@ -12,7 +12,6 @@ import org.springframework.util.CollectionUtils;
import fr.gouv.stopc.robertserver.database.model.Contact;
import fr.gouv.stopc.robertserver.database.repository.ContactRepository;
import fr.gouv.stopc.robertserver.database.service.ContactService;
import org.springframework.util.CollectionUtils;
@Service
......
......@@ -11,9 +11,7 @@ import fr.gouv.stopc.robertserver.database.model.Registration;
import fr.gouv.stopc.robertserver.database.repository.RegistrationRepository;
import fr.gouv.stopc.robertserver.database.service.IRegistrationService;
import org.springframework.util.CollectionUtils;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Service
public class RegistrationService implements IRegistrationService {
......@@ -66,45 +64,53 @@ public class RegistrationService implements IRegistrationService {
return this.registrationRepository.findAll();
}
/**
* {@inheritDoc}
*/
@Override
public Long countNbUsersAtRiskAgain() {
return this.registrationRepository.countNbUsersAtRiskAgain();
}
/**
* {@inheritDoc}
*/
@Override
public Long countNbUsersAtRiskAgain() {
return this.registrationRepository.countNbUsersAtRiskAgain();
}
/**
* {@inheritDoc}
*/
@Override
public Long countNbUsersAtRiskAndNotNotified() {
return this.registrationRepository.countNbUsersAtRiskAndNotNotified();
}
/**
* {@inheritDoc}
*/
@Override
public Long countNbUsersAtRiskAndNotNotified() {
return this.registrationRepository.countNbUsersAtRiskAndNotNotified();
}
/**
* {@inheritDoc}
*/
@Override
public Long countNbUsersNotified() {
return this.registrationRepository.countNbUsersNotified();
}
/**
* {@inheritDoc}
*/
@Override
public Long countNbUsersNotified() {
return this.registrationRepository.countNbUsersNotified();
}
/**
* {@inheritDoc}
*/
@Override
public Long countNbExposedUsersButNotAtRisk() {
return this.registrationRepository.countNbExposedUsersButNotAtRisk();
}
/**
* {@inheritDoc}
*/
@Override
public Long countNbExposedUsersButNotAtRisk() {
return this.registrationRepository.countNbExposedUsersButNotAtRisk();
}
/**
* {@inheritDoc}
*/
@Override
public Long countNbNotifiedUsersScoredAgain() {
return this.registrationRepository.countNbNotifiedUsersScoredAgain();
}
@Override
public Long count() {
return registrationRepository.count();
return this.registrationRepository.count();
}
@Override
public Long countNbUsersWithOldEpochExpositions(int minEpochId){
return registrationRepository.countNbUsersWithOldEpochExpositions(minEpochId);
public Long countNbUsersWithOldEpochExpositions(int minEpochId) {
return this.registrationRepository.countNbUsersWithOldEpochExpositions(minEpochId);
}
}
package test.fr.gouv.stopc.robertserver.database.repository;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.List;
import fr.gouv.stopc.robertserver.database.model.EpochExposition;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest;
import org.springframework.test.context.ContextConfiguration;
import fr.gouv.stopc.robertserver.database.RobertServerDatabaseApplication;
import fr.gouv.stopc.robertserver.database.model.EpochExposition;
import fr.gouv.stopc.robertserver.database.model.Registration;
import fr.gouv.stopc.robertserver.database.repository.RegistrationRepository;
import lombok.extern.slf4j.Slf4j;
import static org.junit.jupiter.api.Assertions.*;
@Slf4j
@ContextConfiguration(classes = {RobertServerDatabaseApplication.class})
@DataMongoTest
public class RegistrationRepositoryTest {
......
......@@ -13,7 +13,7 @@
<parent>
<groupId>fr.gouv.stopc</groupId>
<artifactId>robert-server</artifactId>
<version>1.4.0-SNAPSHOT</version>
<version>1.5.0-SNAPSHOT</version>
</parent>
......
......@@ -13,8 +13,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import fr.gouv.stopc.robertserver.ws.dto.RobertServerKpi;
import fr.gouv.stopc.robertserver.ws.service.IKpiService;
import fr.gouv.stopc.robertserver.ws.vo.RobertServerKpi;
/**
* Endpoint definition for Kpi generation
......
package fr.gouv.stopc.robertserver.ws.dto;
import java.time.LocalDate;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* Aggregation of Kpi on exposition and notification of users
*
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class RobertServerKpi {
/**
* Date of computation of the KPI
*/
private LocalDate date;
/**
* Number of alerted (notified) users
*/
private Long nbAlertedUsers;
/**
* Number of users exposed to a user declared positive but not at risk
*/
private Long nbExposedButNotAtRiskUsers;
/**
* Number of users exposed to a user declared positive, at risk but not yet
* notified
*/
private Long nbInfectedUsersNotNotified;
/**
* Number of users already notified and scored again
*/
private Long nbNotifiedUsersScoredAgain;
}
......@@ -3,7 +3,7 @@ package fr.gouv.stopc.robertserver.ws.service;
import java.time.LocalDate;
import java.util.List;
import fr.gouv.stopc.robertserver.ws.vo.RobertServerKpi;
import fr.gouv.stopc.robertserver.ws.dto.RobertServerKpi;
/**
* Service for Kpis generation
......
......@@ -234,5 +234,4 @@ public class AuthRequestValidationServiceImpl implements AuthRequestValidationSe
}
return Optional.empty();
}
}
......@@ -7,8 +7,8 @@ import java.util.List;
import org.springframework.stereotype.Service;
import fr.gouv.stopc.robertserver.database.service.IRegistrationService;
import fr.gouv.stopc.robertserver.ws.dto.RobertServerKpi;
import fr.gouv.stopc.robertserver.ws.service.IKpiService;
import fr.gouv.stopc.robertserver.ws.vo.RobertServerKpi;
/**
* Default implementation of the <code>IKpiService</code>
......@@ -44,9 +44,10 @@ public class KpiServiceImpl implements IKpiService {
+ registrationDbService.countNbUsersNotified();
Long nbExposedUsersNotAtRisk = registrationDbService.countNbExposedUsersButNotAtRisk();
Long nbInfectedUsersNotNotified = registrationDbService.countNbUsersAtRiskAndNotNotified();
Long nbNotifiedUsersScoredAgain = registrationDbService.countNbNotifiedUsersScoredAgain();
return Arrays.asList(new RobertServerKpi(LocalDate.now(), nbAlertedUsers, nbExposedUsersNotAtRisk,
nbInfectedUsersNotNotified));
nbInfectedUsersNotNotified, nbNotifiedUsersScoredAgain));
}
}
......@@ -134,7 +134,7 @@ public class RegisterControllerWsRestTest {
assertEquals(HttpStatus.BAD_REQUEST, response.getStatusCode());
verify(this.registrationService, times(0)).saveRegistration(ArgumentMatchers.any());
}
@Test
public void testNoCaptcha() {
this.body = RegisterVo.builder().build();
......@@ -148,6 +148,7 @@ public class RegisterControllerWsRestTest {
verify(this.registrationService, times(0)).saveRegistration(ArgumentMatchers.any());
}
@Test
public void testBadRequests() {
......@@ -168,7 +169,7 @@ public class RegisterControllerWsRestTest {
RegisterInternalVo.builder().captcha("mycaptcha").build()
, this.headers), String.class).getStatusCode());
}
@Test
public void testCaptchaFailure() {
this.body = RegisterVo.builder()
......
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