From 7879952043b9b16ca1c045af33a9c9b3eed99415 Mon Sep 17 00:00:00 2001 From: alexsilaghi Date: Tue, 29 Oct 2024 12:33:49 +0200 Subject: [PATCH] refactor saving revision timestamp --- .../model/LinearizationRevision.java | 12 +----------- .../services/LinearizationHistoryServiceImpl.java | 2 +- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/src/main/java/edu/stanford/protege/webprotege/linearizationservice/model/LinearizationRevision.java b/src/main/java/edu/stanford/protege/webprotege/linearizationservice/model/LinearizationRevision.java index a830192..b45d4a4 100644 --- a/src/main/java/edu/stanford/protege/webprotege/linearizationservice/model/LinearizationRevision.java +++ b/src/main/java/edu/stanford/protege/webprotege/linearizationservice/model/LinearizationRevision.java @@ -18,18 +18,8 @@ public record LinearizationRevision(@Indexed(name = "timestamp", direction = Ind public static final String USER_ID = "userId"; public static final String LINEARIZATION_EVENTS = "linearizationEvents"; - private static long lastTimestamp = 0; - private static int counter = 0; - public static LinearizationRevision create(UserId userId, Set linearizationEvents) { - long currentTimestamp = Instant.now().toEpochMilli(); - if (currentTimestamp == lastTimestamp) { - counter++; - } else { - lastTimestamp = currentTimestamp; - counter = 0; - } - return new LinearizationRevision(currentTimestamp + counter, userId, linearizationEvents); + return new LinearizationRevision(new Date().getTime(), userId, linearizationEvents); } @Override diff --git a/src/main/java/edu/stanford/protege/webprotege/linearizationservice/services/LinearizationHistoryServiceImpl.java b/src/main/java/edu/stanford/protege/webprotege/linearizationservice/services/LinearizationHistoryServiceImpl.java index 7d55f7b..d46a57c 100644 --- a/src/main/java/edu/stanford/protege/webprotege/linearizationservice/services/LinearizationHistoryServiceImpl.java +++ b/src/main/java/edu/stanford/protege/webprotege/linearizationservice/services/LinearizationHistoryServiceImpl.java @@ -69,7 +69,7 @@ public Optional getExistingHistoryOrderedByRevision( .map(history -> { Set sortedRevisions = history.getLinearizationRevisions() .stream() - .sorted(Comparator.comparingLong(LinearizationRevision::timestamp)) + .sorted(Comparator.comparingLong(LinearizationRevision::timestamp).reversed()) .collect(Collectors.toCollection(TreeSet::new)); // Return a new EntityLinearizationHistory object with the sorted revisions return new EntityLinearizationHistory(history.getWhoficEntityIri(), history.getProjectId(), sortedRevisions);