Change aggregate identifier to uppercase?

119 views
Skip to first unread message

CBloch

unread,
Nov 27, 2017, 5:42:18 PM11/27/17
to Axon Framework Users
We have an aggregate which has both lower case and upper case values for the aggregateId.  I want to be able to convert the aggregateId for all the events to uppercase.  
I'm just starting to work with upcasters, but I don't see how to do this without creating an upcaster for every event type.  Is there another method I should be looking at to do this?


Steven van Beelen

unread,
Nov 28, 2017, 3:26:25 AM11/28/17
to axonfr...@googlegroups.com
Hi Carol,

The upcaster set up in Axon can only upcast the event payload, the event payload type, the event revision number and the metadata.
As the aggregate identifier is typically in the event payload, you thus can adjust that field to the desired form. 
You however cannot adjust the aggregate identifier column in the domain event entry table with the Upcaster set up.

So, that's for an FYI, now to answer you question: guessing you're running on Axon 3 (3.1 coming out this week!), you can utilize the SingleEventUpcaster for you upcaster implementation.
That extending from that abstract class requires you to implement the 'canUpcast()' and 'doUpcast()' functions.

The 'doUpcast()' function does the actual upcasting working, so in your case adjusting the event-payload it's aggregate identifier to be capitalized.
The 'canUpcast()' function checks whether the 'IntermediateEventRepresentation' is of a type you want to upcast. For your upcaster to work for all events in you system, the 'canUpcast()' should simply return 'true' for all event types with expected revision.

Do note, that if you're upcasting all your events, all the event classes should be annotated with the '@Revision' annotation to signal that they have a new form.
Additionally adding the revision numbers to your events makes it so that the 'canUpcast()' will not trigger for your new events which already have capitalized aggregate identifiers in your event payload.

Hope this sheds some light on the situation.

Cheers,

Steven

On Mon, Nov 27, 2017 at 11:42 PM CBloch <ca...@fit-pay.com> wrote:
We have an aggregate which has both lower case and upper case values for the aggregateId.  I want to be able to convert the aggregateId for all the events to uppercase.  
I'm just starting to work with upcasters, but I don't see how to do this without creating an upcaster for every event type.  Is there another method I should be looking at to do this?


--
You received this message because you are subscribed to the Google Groups "Axon Framework Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to axonframewor...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

CBloch

unread,
Nov 30, 2017, 1:20:44 PM11/30/17
to Axon Framework Users
Hi Steven, 
Thanks for your responses.  This project is still using 2.4 version.  I don't see the SingleEventUpcaster in 2.4  Is there some other way I could convert this?

Carol

Allard Buijze

unread,
Dec 4, 2017, 4:22:49 AM12/4/17
to axonfr...@googlegroups.com
Hi Carol,

upcasting has been redesigned in Axon 3, mainly to provide a better API to write (efficient) upcasters.

In Axon 2.4, you can use the AbstractSingleEntryUpcaster, which is very similar to the SingleEventUpcaster in Axon 3.
You'll need to implement a few methods: in "canUpcast", you indicate whether an event with given type and revision is something the upcaster needs to work on. The actual conversion is done in the doUpcast method.

Hope this helps.
Cheers,

Allard

Op do 30 nov. 2017 om 19:20 schreef CBloch <ca...@fit-pay.com>:
--

CBloch

unread,
Dec 4, 2017, 5:48:15 PM12/4/17
to Axon Framework Users
Hi Allard.

Since the targetAggregateIdentifier is on each of my events, do I have to have an upcaster for every event type?  I have about 70 event types, so that is what I was trying to avoid. 

Carol

Allard Buijze

unread,
Dec 5, 2017, 3:11:21 AM12/5/17
to axonfr...@googlegroups.com
Hi Carol,

no, if it's the same conversion, it doesn't matter which type of event you do it on. Axon works on an "intermediate representation", which is probably XML or JSON in your case and can be represented as a Dom4J Document or Jackson Node, for instance. Just make sure the "canUpcast" method returns true on these 70 types of events and that the doUpcast does the necessary structure changes in the XML/JSON document.

Cheers,

Allard

Op ma 4 dec. 2017 om 23:48 schreef CBloch <ca...@fit-pay.com>:
Reply all
Reply to author
Forward
0 new messages