Add skeletton to save traces.

This commit is contained in:
Florian THIERRY
2024-09-25 21:29:53 +02:00
parent ff52a198dc
commit c817371a15
11 changed files with 252 additions and 29 deletions

View File

@@ -0,0 +1,9 @@
package org.codiki.domain.traffic.exception;
import org.codiki.domain.exception.FunctionnalException;
public class TrafficTraceCreationException extends FunctionnalException {
public TrafficTraceCreationException(String message) {
super(message);
}
}

View File

@@ -0,0 +1,14 @@
package org.codiki.domain.traffic.model;
import java.util.Arrays;
import java.util.Optional;
public enum HttpMethod {
GET, POST, PUT, DELETE;
public static Optional<HttpMethod> fromString(String methodAsString) {
return Arrays.stream(values())
.filter(method -> method.name().equals(methodAsString))
.findFirst();
}
}

View File

@@ -0,0 +1,6 @@
package org.codiki.domain.traffic.model;
public record TrafficEndpoint(
HttpMethod method,
String path
) {}

View File

@@ -0,0 +1,48 @@
package org.codiki.domain.traffic.model;
import java.time.ZonedDateTime;
import java.util.UUID;
public record TrafficTrace(
UUID id,
ZonedDateTime dateTime,
TrafficEndpoint endpoint,
String correlationId
) {
public static Builder aTrafficTrace() {
return new Builder();
}
public static class Builder {
private UUID id;
private ZonedDateTime dateTime;
private TrafficEndpoint endpoint;
private String correlationId;
private Builder() {}
public Builder withId(UUID id) {
this.id = id;
return this;
}
public Builder withDateTime(ZonedDateTime dateTime) {
this.dateTime = dateTime;
return this;
}
public Builder withEndpoint(TrafficEndpoint endpoint) {
this.endpoint = endpoint;
return this;
}
public Builder withCorrelationId(String correlationId) {
this.correlationId = correlationId;
return this;
}
public TrafficTrace build() {
return new TrafficTrace(id, dateTime, endpoint, correlationId);
}
}
}

View File

@@ -0,0 +1,14 @@
package org.codiki.domain.traffic.port;
import org.codiki.domain.traffic.model.TrafficTrace;
import java.time.ZonedDateTime;
import java.util.List;
public interface TrafficTracePort {
void save(TrafficTrace trace);
List<TrafficTrace> getAllInPeriod(ZonedDateTime startDate, ZonedDateTime endDate);
List<TrafficTrace> getAllByCorrelationId(String correlationId);
Integer countAllInPeriod(ZonedDateTime startDate, ZonedDateTime endDate);
Integer countByCorrelationId(String correlationId);
}