Change aggregate identifier to uppercase?

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?

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

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

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

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

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