vidakovic commented on code in PR #5674:
URL: https://github.com/apache/fineract/pull/5674#discussion_r2972110675


##########
fineract-core/src/main/java/org/apache/fineract/commands/service/DeterministicIdempotencyKeyGenerator.java:
##########
@@ -0,0 +1,49 @@
+package org.apache.fineract.commands.service;
+
+
+import org.apache.fineract.commands.domain.CommandWrapper;
+import org.springframework.stereotype.Component;
+
+import java.nio.charset.StandardCharsets;
+import java.security.MessageDigest;
+import java.util.Base64;
+
+@Component
+public class DeterministicIdempotencyKeyGenerator {
+
+    private static final int BUCKET_MINUTES = 2;
+
+    public String generate(CommandWrapper wrapper) {
+        String json = wrapper.getJson();
+
+        String normalizedPayload = normalize(json);
+
+        String bucket = currentTimeBucket();
+
+        String raw = normalizedPayload + "|" + bucket;
+
+        return sha256(raw);
+    }
+
+    private String normalize(String json) {
+        // IMPORTANT: make deterministic (order, spacing, etc.)
+        return json.replaceAll("\\s+", "");
+    }
+
+    private String currentTimeBucket() {

Review Comment:
   I guess you mean "window" (not "bucket")?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to