Skip to content

Commit dfe0323

Browse files
UPL-244 Add until parameter to listMessages (#860)
1 parent 47e9954 commit dfe0323

4 files changed

Lines changed: 115 additions & 6 deletions

File tree

symphony-bdk-core/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ dependencies {
7676
}
7777

7878
// OpenAPI code generation
79-
def apiBaseUrl = "https://raw.githubusercontent.com/finos/symphony-api-spec/5526c5e81cb2313c4aab18119b526534652ba98e"
79+
def apiBaseUrl = "https://raw.githubusercontent.com/finos/symphony-api-spec/fc80c3204d8a92a0b82d3c951eab7f5cb78a7c53"
8080
def generatedFolder = "$buildDir/generated/openapi"
8181
def apisToGenerate = [
8282
Agent: 'agent/agent-api-public-deprecated.yaml',

symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/message/MessageService.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ public List<V4Message> listMessages(@Nonnull V4Stream stream, @Nonnull Instant s
143143
return listMessages(stream.getStreamId(), since, pagination);
144144
}
145145

146+
@Override
147+
public List<V4Message> listMessages(@Nonnull V4Stream stream, @Nonnull Instant since, Instant until,
148+
@Nonnull PaginationAttribute pagination) {
149+
return listMessages(stream.getStreamId(), since, until, pagination);
150+
}
151+
146152
/**
147153
* {@inheritDoc}
148154
*/
@@ -151,14 +157,26 @@ public List<V4Message> listMessages(@Nonnull V4Stream stream, @Nonnull Instant s
151157
return listMessages(stream.getStreamId(), since);
152158
}
153159

160+
@Override
161+
public List<V4Message> listMessages(@Nonnull V4Stream stream, @Nonnull Instant since, Instant until) {
162+
return listMessages(stream.getStreamId(), since, until);
163+
}
164+
154165
/**
155166
* {@inheritDoc}
156167
*/
157168
@Override
158169
public List<V4Message> listMessages(@Nonnull String streamId, @Nonnull Instant since,
159170
@Nonnull PaginationAttribute pagination) {
171+
return listMessages(streamId, since, null, pagination);
172+
}
173+
174+
@Override
175+
public List<V4Message> listMessages(@Nonnull String streamId, @Nonnull Instant since, Instant until,
176+
@Nonnull PaginationAttribute pagination) {
160177
return executeAndRetry("getMessages", messageApi.getApiClient().getBasePath(),
161178
() -> messagesApi.v4StreamSidMessageGet(toUrlSafeIdIfNeeded(streamId), getEpochMillis(since),
179+
getEpochMillis(until),
162180
pagination.getSkip(),
163181
pagination.getLimit(),
164182
authSession.getSessionToken(),
@@ -170,8 +188,13 @@ public List<V4Message> listMessages(@Nonnull String streamId, @Nonnull Instant s
170188
*/
171189
@Override
172190
public List<V4Message> listMessages(@Nonnull String streamId, @Nonnull Instant since) {
191+
return listMessages(streamId, since, (Instant) null);
192+
}
193+
194+
@Override
195+
public List<V4Message> listMessages(@Nonnull String streamId, @Nonnull Instant since, Instant until) {
173196
return executeAndRetry("getMessages", messageApi.getApiClient().getBasePath(),
174-
() -> messagesApi.v4StreamSidMessageGet(toUrlSafeIdIfNeeded(streamId), getEpochMillis(since), null, null,
197+
() -> messagesApi.v4StreamSidMessageGet(toUrlSafeIdIfNeeded(streamId), getEpochMillis(since), getEpochMillis(until),null, null,
175198
authSession.getSessionToken(), authSession.getKeyManagerToken()));
176199
}
177200

symphony-bdk-core/src/main/java/com/symphony/bdk/core/service/message/OboMessageService.java

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ public interface OboMessageService {
4141
*/
4242
List<V4Message> listMessages(@Nonnull V4Stream stream, @Nonnull Instant since, @Nonnull PaginationAttribute pagination);
4343

44+
/**
45+
* Get messages from an existing stream. Additionally returns any attachments associated with the message.
46+
*
47+
* @param stream the stream where to look for messages
48+
* @param since instant of the earliest possible date of the first message returned.
49+
* @param until instant of the last possible date of the last message returned.
50+
* @param pagination The skip and limit for pagination.
51+
* @return the list of matching messages in the stream.
52+
* @see <a href="https://developers.symphony.com/restapi/reference/messages-v4">Messages</a>
53+
*/
54+
List<V4Message> listMessages(@Nonnull V4Stream stream, @Nonnull Instant since, Instant until, @Nonnull PaginationAttribute pagination);
55+
4456
/**
4557
* Get messages from an existing stream with default limit equals 50.
4658
* Additionally returns any attachments associated with the message.
@@ -52,6 +64,19 @@ public interface OboMessageService {
5264
*/
5365
List<V4Message> listMessages(@Nonnull V4Stream stream, @Nonnull Instant since);
5466

67+
/**
68+
* Get messages from an existing stream with default limit equals 50.
69+
* Additionally returns any attachments associated with the message.
70+
*
71+
* @param stream the stream where to look for messages
72+
* @param since instant of the earliest possible date of the first message returned.
73+
* @param until instant of the last possible date of the last message returned.
74+
* @return the list of matching messages in the stream.
75+
* @see <a href="https://developers.symphony.com/restapi/reference/messages-v4">Messages</a>
76+
*/
77+
List<V4Message> listMessages(@Nonnull V4Stream stream, @Nonnull Instant since, Instant until);
78+
79+
5580
/**
5681
* Get messages from an existing stream. Additionally returns any attachments associated with the message.
5782
*
@@ -63,6 +88,18 @@ public interface OboMessageService {
6388
*/
6489
List<V4Message> listMessages(@Nonnull String streamId, @Nonnull Instant since, @Nonnull PaginationAttribute pagination);
6590

91+
/**
92+
* Get messages from an existing stream. Additionally returns any attachments associated with the message.
93+
*
94+
* @param streamId the streamID where to look for messages
95+
* @param since instant of the earliest possible date of the first message returned.
96+
* @param until instant of the last possible date of the last message returned.
97+
* @param pagination The skip and limit for pagination.
98+
* @return the list of matching messages in the stream.
99+
* @see <a href="https://developers.symphony.com/restapi/reference/messages-v4">Messages</a>
100+
*/
101+
List<V4Message> listMessages(@Nonnull String streamId, @Nonnull Instant since, Instant until, @Nonnull PaginationAttribute pagination);
102+
66103
/**
67104
* Get messages from an existing stream with default limit equals 50.
68105
* Additionally returns any attachments associated with the message.
@@ -74,6 +111,18 @@ public interface OboMessageService {
74111
*/
75112
List<V4Message> listMessages(@Nonnull String streamId, @Nonnull Instant since);
76113

114+
/**
115+
* Get messages from an existing stream with default limit equals 50.
116+
* Additionally returns any attachments associated with the message.
117+
*
118+
* @param streamId the streamID where to look for messages
119+
* @param since instant of the earliest possible date of the first message returned.
120+
* @param until instant of the last possible date of the last message returned.
121+
* @return the list of matching messages in the stream.
122+
* @see <a href="https://developers.symphony.com/restapi/reference/messages-v4">Messages</a>
123+
*/
124+
List<V4Message> listMessages(@Nonnull String streamId, @Nonnull Instant since, Instant until);
125+
77126
/**
78127
* Sends a message to the stream ID of the passed {@link V4Stream} object.
79128
*

symphony-bdk-core/src/test/java/com/symphony/bdk/core/service/message/MessageServiceTest.java

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
import java.nio.charset.StandardCharsets;
6565
import java.nio.file.Path;
6666
import java.time.Instant;
67+
import java.time.temporal.ChronoUnit;
6768
import java.util.Arrays;
6869
import java.util.Collections;
6970
import java.util.HashMap;
@@ -151,18 +152,18 @@ void testSendMessageObo() throws IOException {
151152
@Test
152153
void testGetMessagesWithStreamObject() {
153154
MessageService service = spy(messageService);
154-
doReturn(Collections.emptyList()).when(service).listMessages(anyString(), any());
155+
doReturn(Collections.emptyList()).when(service).listMessages(anyString(), any(Instant.class), any(Instant.class));
155156

156157
final V4Stream v4Stream = new V4Stream().streamId(STREAM_ID);
157158
Instant now = Instant.now();
158-
assertNotNull(service.listMessages(v4Stream, now));
159-
verify(service).listMessages(STREAM_ID, now);
159+
assertNotNull(service.listMessages(v4Stream, now, now.plus(10, ChronoUnit.SECONDS)));
160+
verify(service).listMessages(STREAM_ID, now, now.plus(10, ChronoUnit.SECONDS));
160161
}
161162

162163
@Test
163164
void testGetPaginationMessagesWithStreamObject() {
164165
MessageService service = spy(messageService);
165-
doReturn(Collections.emptyList()).when(service).listMessages(anyString(), any(), any());
166+
doReturn(Collections.emptyList()).when(service).listMessages(anyString(), any(Instant.class), any(PaginationAttribute.class));
166167

167168
final V4Stream v4Stream = new V4Stream().streamId(STREAM_ID);
168169
Instant now = Instant.now();
@@ -171,6 +172,42 @@ void testGetPaginationMessagesWithStreamObject() {
171172
verify(service).listMessages(STREAM_ID, now, pagination);
172173
}
173174

175+
@Test
176+
void testGetPaginationMessagesWithStreamObjectUntil() {
177+
MessageService service = spy(messageService);
178+
doReturn(Collections.emptyList()).when(service).listMessages(anyString(), any(Instant.class), any(Instant.class), any(PaginationAttribute.class));
179+
180+
final V4Stream v4Stream = new V4Stream().streamId(STREAM_ID);
181+
Instant now = Instant.now();
182+
PaginationAttribute pagination = new PaginationAttribute(2, 2);
183+
assertNotNull(service.listMessages(v4Stream, now, now.plus(10, ChronoUnit.SECONDS), pagination));
184+
verify(service).listMessages(STREAM_ID, now, now.plus(10, ChronoUnit.SECONDS), pagination);
185+
}
186+
187+
@Test
188+
void testGetMessagesUntil() throws IOException {
189+
final String streamId = "streamid";
190+
mockApiClient.onGet(V4_STREAM_MESSAGE.replace("{sid}", streamId),
191+
JsonHelper.readFromClasspath("/message/get_message_stream_id.json"));
192+
193+
final List<V4Message> messages = messageService.listMessages(streamId, Instant.now(), Instant.now());
194+
195+
assertEquals(2, messages.size());
196+
assertEquals(Arrays.asList("messageId1", "messageId2"),
197+
messages.stream().map(V4Message::getMessageId).collect(Collectors.toList()));
198+
}
199+
200+
@Test
201+
void testGetMessagesWithStreamObjectUntil() {
202+
MessageService service = spy(messageService);
203+
doReturn(Collections.emptyList()).when(service).listMessages(anyString(), any(Instant.class));
204+
205+
final V4Stream v4Stream = new V4Stream().streamId(STREAM_ID);
206+
Instant now = Instant.now();
207+
assertNotNull(service.listMessages(v4Stream, now));
208+
verify(service).listMessages(STREAM_ID, now);
209+
}
210+
174211
@Test
175212
void testGetMessages() throws IOException {
176213
final String streamId = "streamid";

0 commit comments

Comments
 (0)