From 33c576a5b2033ae70dfc0fe58b7981d1b39b2923 Mon Sep 17 00:00:00 2001 From: Thiago Cardoso Date: Wed, 17 Jul 2024 14:28:35 -0300 Subject: [PATCH] feat: add/use RFC3339 fields in requests Timestamp fields that store time as milliseconds since epoch are being replaced by fields that store it as a RFC 3339 string. This commit: - Removes POST /feedbacks `timestamp` field, replacing it with `occurred_at`. Removal is possible because this field is not in the public API. - Add `collected_at` to POST /signups' `additional_locations`. This field should be used instead of the existing `timestamp`. --- build.gradle | 1 + src/main/java/com/incognia/api/IncogniaAPI.java | 4 ++-- .../java/com/incognia/api/clients/ObjectMapperFactory.java | 2 ++ src/main/java/com/incognia/common/AdditionalLocation.java | 4 +++- .../java/com/incognia/feedback/PostFeedbackRequestBody.java | 3 ++- src/test/java/com/incognia/api/IncogniaAPITest.java | 2 +- 6 files changed, 11 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index c7f849e..c1d6ac4 100644 --- a/build.gradle +++ b/build.gradle @@ -43,6 +43,7 @@ dependencies { implementation platform("com.squareup.okhttp3:okhttp-bom:4.12.0") implementation "com.squareup.okhttp3:okhttp" implementation "com.fasterxml.jackson.core:jackson-databind:2.17.1" + implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.17.1" testImplementation 'com.auth0:java-jwt:4.4.0' testImplementation 'commons-io:commons-io:2.16.1' diff --git a/src/main/java/com/incognia/api/IncogniaAPI.java b/src/main/java/com/incognia/api/IncogniaAPI.java index 338590d..2c729cf 100644 --- a/src/main/java/com/incognia/api/IncogniaAPI.java +++ b/src/main/java/com/incognia/api/IncogniaAPI.java @@ -408,14 +408,14 @@ public void registerFeedback( public void registerFeedback( FeedbackEvent feedbackEvent, - Instant timestamp, + Instant occurredAt, FeedbackIdentifiers identifiers, boolean dryRun) throws IncogniaException { PostFeedbackRequestBody requestBody = PostFeedbackRequestBody.builder() .event(feedbackEvent) - .timestamp(timestamp.toEpochMilli()) + .occurredAt(occurredAt) .installationId(identifiers.getInstallationId()) .sessionToken(identifiers.getSessionToken()) .accountId(identifiers.getAccountId()) diff --git a/src/main/java/com/incognia/api/clients/ObjectMapperFactory.java b/src/main/java/com/incognia/api/clients/ObjectMapperFactory.java index 472d72f..a1fc400 100644 --- a/src/main/java/com/incognia/api/clients/ObjectMapperFactory.java +++ b/src/main/java/com/incognia/api/clients/ObjectMapperFactory.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.PropertyNamingStrategy; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; public class ObjectMapperFactory { @SuppressWarnings("deprecation") @@ -11,6 +12,7 @@ public class ObjectMapperFactory { // jackson versions public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper() + .registerModule(new JavaTimeModule()) .setPropertyNamingStrategy(PropertyNamingStrategy.SNAKE_CASE) .setSerializationInclusion(Include.NON_NULL) .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); diff --git a/src/main/java/com/incognia/common/AdditionalLocation.java b/src/main/java/com/incognia/common/AdditionalLocation.java index 0163dd2..83fe175 100644 --- a/src/main/java/com/incognia/common/AdditionalLocation.java +++ b/src/main/java/com/incognia/common/AdditionalLocation.java @@ -1,5 +1,6 @@ package com.incognia.common; +import java.time.Instant; import lombok.Builder; import lombok.Value; @@ -8,5 +9,6 @@ public class AdditionalLocation { Double lat; Double lng; - Long timestamp; + @Deprecated Long timestamp; + Instant collectedAt; } diff --git a/src/main/java/com/incognia/feedback/PostFeedbackRequestBody.java b/src/main/java/com/incognia/feedback/PostFeedbackRequestBody.java index e8299d5..79c183d 100644 --- a/src/main/java/com/incognia/feedback/PostFeedbackRequestBody.java +++ b/src/main/java/com/incognia/feedback/PostFeedbackRequestBody.java @@ -1,5 +1,6 @@ package com.incognia.feedback; +import java.time.Instant; import lombok.Builder; import lombok.Value; @@ -7,7 +8,7 @@ @Builder public class PostFeedbackRequestBody { FeedbackEvent event; - Long timestamp; + Instant occurredAt; String accountId; String externalId; String installationId; diff --git a/src/test/java/com/incognia/api/IncogniaAPITest.java b/src/test/java/com/incognia/api/IncogniaAPITest.java index a398186..ea3c0d8 100644 --- a/src/test/java/com/incognia/api/IncogniaAPITest.java +++ b/src/test/java/com/incognia/api/IncogniaAPITest.java @@ -556,7 +556,7 @@ void testRegisterFeedback_whenDataIsValid(boolean dryRun) { .signupId(signupId) .accountId(accountId) .event(FeedbackEvent.ACCOUNT_TAKEOVER) - .timestamp(timestamp.toEpochMilli()) + .occurredAt(timestamp) .build()); mockServer.setDispatcher(dispatcher); client.registerFeedback(