commercetools/commercetools-sdk-java-v2

MessageDeliveryPayload missing message content

rochadio opened this issue · 1 comments

I'm trying to use MessageDeliveryPayload class as substitute of the "v1" MessageSubscriptionPayload class, but I'm having issues when trying to access the type of the message, or its content, as it doesn't have a "getMessage", or a "getType", as in the v1 class, and the notificationType of the message will always be "Message"..

So, e.g., im not really able to catch/listen for events that are of 'OrderStateTransition' type, and what content/state is sent in it.

Is it possible that we have the "getMessage" added to MessageDeliveryPayload interface also?

v1 MessageSubscriptionPayload getMessage: https://commercetools.github.io/commercetools-jvm-sdk/apidocs/io/sphere/sdk/subscriptions/MessageSubscriptionPayload.html#getMessage--

v2 MessageDeliveryPayload : https://commercetools.github.io/commercetools-sdk-java-v2/javadoc/com/commercetools/api/models/subscription/MessageDeliveryPayload.html#MESSAGE

I've also tried to use the generic Message class, that I can catch and then convert into the desired OrderStateTransitionMessage class and get its content, but however is not possible to retrieve the projectKey from it..

Should it also be accessible in this Message type?
Or is there any other way to do this?

Thanks!

I released 17.2.0 today.

This includes helper methods comparable to v1 for the MessageDeliveryPayload class. See details in the test class:

@Test
public void deserializeMessageDeliveryPayload() {
MessageDeliveryPayload delivery = JsonUtils.fromJsonString(stringFromResource("messagedeliverypayload.json"),
MessageDeliveryPayload.class);
Assertions.assertThat(delivery.getMessagePayload()).isInstanceOf(CustomerLastNameSetMessagePayload.class);
Assertions.assertThat(delivery.getMessagePayload().as(CustomerLastNameSetMessagePayload.class))
.isInstanceOf(CustomerLastNameSetMessagePayload.class);
Assertions.assertThat(delivery.hasCompleteMessage()).isTrue();
Assertions.assertThatThrownBy(() -> delivery.getMessagePayload().as(CustomerFirstNameSetMessagePayload.class))
.isInstanceOf(IllegalArgumentException.class);
}
@Test
public void deserializeDeliveryPayload() {
DeliveryPayload delivery = JsonUtils.fromJsonString(stringFromResource("messagedeliverypayload.json"),
DeliveryPayload.class);
Assertions.assertThat(delivery).isInstanceOf(MessageDeliveryPayload.class);
MessageDeliveryPayload messageDelivery = (MessageDeliveryPayload) delivery;
Assertions.assertThat(messageDelivery.getMessagePayload())
.isInstanceOf(CustomerLastNameSetMessagePayload.class);
Assertions.assertThat(messageDelivery.getMessagePayload().as(CustomerLastNameSetMessagePayload.class))
.isInstanceOf(CustomerLastNameSetMessagePayload.class);
Assertions.assertThat(messageDelivery.hasCompleteMessage()).isTrue();
Assertions
.assertThatThrownBy(
() -> messageDelivery.getMessagePayload().as(CustomerFirstNameSetMessagePayload.class))
.isInstanceOf(IllegalArgumentException.class);
}