Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
TousAntiCovid sources
Cléa Server
Commits
e81de0dc
Commit
e81de0dc
authored
Apr 21, 2021
by
Ananas Orange
Browse files
Minor
parent
a66b360e
Changes
2
Hide whitespace changes
Inline
Side-by-side
clea-venue-consumer/src/main/java/fr/gouv/clea/consumer/service/impl/VisitExpositionAggregatorService.java
View file @
e81de0dc
package
fr.gouv.clea.consumer.service.impl
;
import
java.time.Duration
;
import
java.time.Instant
;
import
java.time.temporal.ChronoUnit
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
java.util.stream.IntStream
;
import
java.util.stream.Stream
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
fr.gouv.clea.consumer.configuration.VenueConsumerConfiguration
;
import
fr.gouv.clea.consumer.model.ExposedVisitEntity
;
import
fr.gouv.clea.consumer.model.Visit
;
...
...
@@ -20,6 +8,17 @@ import fr.gouv.clea.consumer.service.IStatService;
import
fr.gouv.clea.consumer.service.IVisitExpositionAggregatorService
;
import
fr.inria.clea.lsp.utils.TimeUtils
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Component
;
import
java.time.Duration
;
import
java.time.Instant
;
import
java.time.temporal.ChronoUnit
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.stream.Collectors
;
import
java.util.stream.IntStream
;
import
java.util.stream.Stream
;
@Component
@Slf4j
...
...
@@ -89,7 +88,7 @@ public class VisitExpositionAggregatorService implements IVisitExpositionAggrega
protected
int
getPeriodMaxSlot
(
int
periodDuration
)
{
// This check should go in venue consumer configuration validation
if
(
Duration
.
ofHours
(
1
).
toSeconds
()
%
periodDuration
==
0
)
{
log
.
error
(
"durationUnitInSeconds does not have a valid value: {}.
1 hour
/ durationUnitInSeconds has a reminder!"
);
log
.
error
(
"durationUnitInSeconds does not have a valid value: {}.
60(secs)
/ durationUnitInSeconds has a reminder!"
,
periodDuration
);
}
if
(
periodDuration
==
255
)
{
return
Integer
.
MAX_VALUE
;
...
...
clea-ws-rest/src/test/java/fr/gouv/clea/ws/service/impl/ReportServiceTest.java
View file @
e81de0dc
...
...
@@ -193,6 +193,40 @@ class ReportServiceTest {
assertThat
(
processed
.
stream
().
filter
(
DecodedVisit:
:
isForward
).
count
()).
isEqualTo
(
3L
);
}
@Test
@DisplayName
(
"if pivot date is before or equal qrScanTime, visits should be marked as forward"
)
void
testForward
()
throws
CleaEncodingException
{
long
pivotDate
=
TimeUtils
.
ntpTimestampFromInstant
(
now
.
minus
(
1
,
ChronoUnit
.
DAYS
));
long
qrScan
=
TimeUtils
.
ntpTimestampFromInstant
(
now
);
UUID
uuid1
=
UUID
.
randomUUID
();
UUID
uuid2
=
UUID
.
randomUUID
();
List
<
Visit
>
visits
=
List
.
of
(
newVisit
(
uuid1
,
qrScan
),
newVisit
(
uuid2
,
pivotDate
)
);
List
<
DecodedVisit
>
processed
=
reportService
.
report
(
new
ReportRequest
(
visits
,
pivotDate
));
assertThat
(
processed
.
size
()).
isEqualTo
(
2
);
assertThat
(
processed
.
get
(
0
).
isForward
()).
isTrue
();
assertThat
(
processed
.
get
(
1
).
isForward
()).
isTrue
();
}
@Test
@DisplayName
(
"if pivot date is strictly after qrScanTime, visits should be marked as backward"
)
void
testBackward
()
throws
CleaEncodingException
{
long
pivotDate
=
TimeUtils
.
ntpTimestampFromInstant
(
now
);
long
qrScan
=
TimeUtils
.
ntpTimestampFromInstant
(
now
.
minus
(
1
,
ChronoUnit
.
DAYS
));
UUID
uuid
=
UUID
.
randomUUID
();
List
<
Visit
>
visits
=
List
.
of
(
newVisit
(
uuid
,
qrScan
));
List
<
DecodedVisit
>
processed
=
reportService
.
report
(
new
ReportRequest
(
visits
,
pivotDate
));
assertThat
(
processed
.
size
()).
isEqualTo
(
1
);
assertThat
(
processed
.
get
(
0
).
isBackward
()).
isTrue
();
}
private
EncryptedLocationSpecificPart
createEncryptedLocationSpecificPart
(
UUID
locationTemporaryPublicId
)
{
return
EncryptedLocationSpecificPart
.
builder
()
.
locationTemporaryPublicId
(
locationTemporaryPublicId
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment