Implementation of jpa saving for traffic traces.

This commit is contained in:
Florian THIERRY
2024-09-26 10:21:20 +02:00
parent c817371a15
commit 5647a5a959
11 changed files with 161 additions and 26 deletions

View File

@@ -25,6 +25,10 @@ public class CustomUserDetails implements UserDetails {
.toList();
}
public User getUser() {
return user;
}
@Override
public String getUsername() {
return user.id().toString();

View File

@@ -26,7 +26,11 @@ public class TrafficTraceUseCases {
}
@Async
public void saveNewTrace(TrafficEndpoint trafficEndpoint, @Nullable String correlationId) {
public void saveNewTrace(
TrafficEndpoint trafficEndpoint,
@Nullable UUID userId,
@Nullable String correlationId
) {
if (isNull(trafficEndpoint)) {
throw new TrafficTraceCreationException("Traffic endpoint should not be null.");
}
@@ -35,6 +39,7 @@ public class TrafficTraceUseCases {
.withId(UUID.randomUUID())
.withDateTime(ZonedDateTime.now(clock))
.withEndpoint(trafficEndpoint)
.withUserId(userId)
.withCorrelationId(correlationId)
.build();
trafficTracePort.save(newTrace);

View File

@@ -87,9 +87,7 @@ public class UserUseCases {
.map(Authentication::getPrincipal)
.filter(CustomUserDetails.class::isInstance)
.map(CustomUserDetails.class::cast)
.map(CustomUserDetails::getUsername)
.map(UUID::fromString)
.flatMap(userPort::findById);
.map(CustomUserDetails::getUser);
}
private UserAuthenticationData generateAuthenticationData(User user) {