diff --git a/symphony-bdk-core/build.gradle b/symphony-bdk-core/build.gradle index 60ee1a945..337d05ecc 100644 --- a/symphony-bdk-core/build.gradle +++ b/symphony-bdk-core/build.gradle @@ -76,7 +76,7 @@ dependencies { } // OpenAPI code generation -def apiBaseUrl = "https://raw.githubusercontent.com/finos/symphony-api-spec/5526c5e81cb2313c4aab18119b526534652ba98e" +def apiBaseUrl = "https://raw.githubusercontent.com/finos/symphony-api-spec/fc80c3204d8a92a0b82d3c951eab7f5cb78a7c53" def generatedFolder = "$buildDir/generated/openapi" def apisToGenerate = [ Agent: 'agent/agent-api-public-deprecated.yaml', diff --git a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/message/MessageService.java b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/message/MessageService.java index cdbae7691..460f400fb 100644 --- a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/message/MessageService.java +++ b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/message/MessageService.java @@ -143,6 +143,12 @@ public List listMessages(@Nonnull V4Stream stream, @Nonnull Instant s return listMessages(stream.getStreamId(), since, pagination); } + @Override + public List listMessages(@Nonnull V4Stream stream, @Nonnull Instant since, Instant until, + @Nonnull PaginationAttribute pagination) { + return listMessages(stream.getStreamId(), since, until, pagination); + } + /** * {@inheritDoc} */ @@ -151,14 +157,26 @@ public List listMessages(@Nonnull V4Stream stream, @Nonnull Instant s return listMessages(stream.getStreamId(), since); } + @Override + public List listMessages(@Nonnull V4Stream stream, @Nonnull Instant since, Instant until) { + return listMessages(stream.getStreamId(), since, until); + } + /** * {@inheritDoc} */ @Override public List listMessages(@Nonnull String streamId, @Nonnull Instant since, @Nonnull PaginationAttribute pagination) { + return listMessages(streamId, since, null, pagination); + } + + @Override + public List listMessages(@Nonnull String streamId, @Nonnull Instant since, Instant until, + @Nonnull PaginationAttribute pagination) { return executeAndRetry("getMessages", messageApi.getApiClient().getBasePath(), () -> messagesApi.v4StreamSidMessageGet(toUrlSafeIdIfNeeded(streamId), getEpochMillis(since), + getEpochMillis(until), pagination.getSkip(), pagination.getLimit(), authSession.getSessionToken(), @@ -170,8 +188,13 @@ public List listMessages(@Nonnull String streamId, @Nonnull Instant s */ @Override public List listMessages(@Nonnull String streamId, @Nonnull Instant since) { + return listMessages(streamId, since, (Instant) null); + } + + @Override + public List listMessages(@Nonnull String streamId, @Nonnull Instant since, Instant until) { return executeAndRetry("getMessages", messageApi.getApiClient().getBasePath(), - () -> messagesApi.v4StreamSidMessageGet(toUrlSafeIdIfNeeded(streamId), getEpochMillis(since), null, null, + () -> messagesApi.v4StreamSidMessageGet(toUrlSafeIdIfNeeded(streamId), getEpochMillis(since), getEpochMillis(until),null, null, authSession.getSessionToken(), authSession.getKeyManagerToken())); } diff --git a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/message/OboMessageService.java b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/message/OboMessageService.java index 1fde3fc46..2712c1bf0 100644 --- a/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/message/OboMessageService.java +++ b/symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/message/OboMessageService.java @@ -41,6 +41,18 @@ public interface OboMessageService { */ List listMessages(@Nonnull V4Stream stream, @Nonnull Instant since, @Nonnull PaginationAttribute pagination); + /** + * Get messages from an existing stream. Additionally returns any attachments associated with the message. + * + * @param stream the stream where to look for messages + * @param since instant of the earliest possible date of the first message returned. + * @param until instant of the last possible date of the last message returned. + * @param pagination The skip and limit for pagination. + * @return the list of matching messages in the stream. + * @see Messages + */ + List listMessages(@Nonnull V4Stream stream, @Nonnull Instant since, Instant until, @Nonnull PaginationAttribute pagination); + /** * Get messages from an existing stream with default limit equals 50. * Additionally returns any attachments associated with the message. @@ -52,6 +64,19 @@ public interface OboMessageService { */ List listMessages(@Nonnull V4Stream stream, @Nonnull Instant since); + /** + * Get messages from an existing stream with default limit equals 50. + * Additionally returns any attachments associated with the message. + * + * @param stream the stream where to look for messages + * @param since instant of the earliest possible date of the first message returned. + * @param until instant of the last possible date of the last message returned. + * @return the list of matching messages in the stream. + * @see Messages + */ + List listMessages(@Nonnull V4Stream stream, @Nonnull Instant since, Instant until); + + /** * Get messages from an existing stream. Additionally returns any attachments associated with the message. * @@ -63,6 +88,18 @@ public interface OboMessageService { */ List listMessages(@Nonnull String streamId, @Nonnull Instant since, @Nonnull PaginationAttribute pagination); + /** + * Get messages from an existing stream. Additionally returns any attachments associated with the message. + * + * @param streamId the streamID where to look for messages + * @param since instant of the earliest possible date of the first message returned. + * @param until instant of the last possible date of the last message returned. + * @param pagination The skip and limit for pagination. + * @return the list of matching messages in the stream. + * @see Messages + */ + List listMessages(@Nonnull String streamId, @Nonnull Instant since, Instant until, @Nonnull PaginationAttribute pagination); + /** * Get messages from an existing stream with default limit equals 50. * Additionally returns any attachments associated with the message. @@ -74,6 +111,18 @@ public interface OboMessageService { */ List listMessages(@Nonnull String streamId, @Nonnull Instant since); + /** + * Get messages from an existing stream with default limit equals 50. + * Additionally returns any attachments associated with the message. + * + * @param streamId the streamID where to look for messages + * @param since instant of the earliest possible date of the first message returned. + * @param until instant of the last possible date of the last message returned. + * @return the list of matching messages in the stream. + * @see Messages + */ + List listMessages(@Nonnull String streamId, @Nonnull Instant since, Instant until); + /** * Sends a message to the stream ID of the passed {@link V4Stream} object. * diff --git a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/message/MessageServiceTest.java b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/message/MessageServiceTest.java index 7e3eb4bbd..91c9c0dbc 100644 --- a/symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/message/MessageServiceTest.java +++ b/symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/message/MessageServiceTest.java @@ -64,6 +64,7 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.time.Instant; +import java.time.temporal.ChronoUnit; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -151,18 +152,18 @@ void testSendMessageObo() throws IOException { @Test void testGetMessagesWithStreamObject() { MessageService service = spy(messageService); - doReturn(Collections.emptyList()).when(service).listMessages(anyString(), any()); + doReturn(Collections.emptyList()).when(service).listMessages(anyString(), any(Instant.class), any(Instant.class)); final V4Stream v4Stream = new V4Stream().streamId(STREAM_ID); Instant now = Instant.now(); - assertNotNull(service.listMessages(v4Stream, now)); - verify(service).listMessages(STREAM_ID, now); + assertNotNull(service.listMessages(v4Stream, now, now.plus(10, ChronoUnit.SECONDS))); + verify(service).listMessages(STREAM_ID, now, now.plus(10, ChronoUnit.SECONDS)); } @Test void testGetPaginationMessagesWithStreamObject() { MessageService service = spy(messageService); - doReturn(Collections.emptyList()).when(service).listMessages(anyString(), any(), any()); + doReturn(Collections.emptyList()).when(service).listMessages(anyString(), any(Instant.class), any(PaginationAttribute.class)); final V4Stream v4Stream = new V4Stream().streamId(STREAM_ID); Instant now = Instant.now(); @@ -171,6 +172,42 @@ void testGetPaginationMessagesWithStreamObject() { verify(service).listMessages(STREAM_ID, now, pagination); } + @Test + void testGetPaginationMessagesWithStreamObjectUntil() { + MessageService service = spy(messageService); + doReturn(Collections.emptyList()).when(service).listMessages(anyString(), any(Instant.class), any(Instant.class), any(PaginationAttribute.class)); + + final V4Stream v4Stream = new V4Stream().streamId(STREAM_ID); + Instant now = Instant.now(); + PaginationAttribute pagination = new PaginationAttribute(2, 2); + assertNotNull(service.listMessages(v4Stream, now, now.plus(10, ChronoUnit.SECONDS), pagination)); + verify(service).listMessages(STREAM_ID, now, now.plus(10, ChronoUnit.SECONDS), pagination); + } + + @Test + void testGetMessagesUntil() throws IOException { + final String streamId = "streamid"; + mockApiClient.onGet(V4_STREAM_MESSAGE.replace("{sid}", streamId), + JsonHelper.readFromClasspath("/message/get_message_stream_id.json")); + + final List messages = messageService.listMessages(streamId, Instant.now(), Instant.now()); + + assertEquals(2, messages.size()); + assertEquals(Arrays.asList("messageId1", "messageId2"), + messages.stream().map(V4Message::getMessageId).collect(Collectors.toList())); + } + + @Test + void testGetMessagesWithStreamObjectUntil() { + MessageService service = spy(messageService); + doReturn(Collections.emptyList()).when(service).listMessages(anyString(), any(Instant.class)); + + final V4Stream v4Stream = new V4Stream().streamId(STREAM_ID); + Instant now = Instant.now(); + assertNotNull(service.listMessages(v4Stream, now)); + verify(service).listMessages(STREAM_ID, now); + } + @Test void testGetMessages() throws IOException { final String streamId = "streamid";