Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[upcaster] Provide the other upcaster examples #83

Closed
lfgcampos opened this issue Jul 20, 2021 · 7 comments · Fixed by #116
Closed

[upcaster] Provide the other upcaster examples #83

lfgcampos opened this issue Jul 20, 2021 · 7 comments · Fixed by #116

Comments

@lfgcampos
Copy link
Contributor

Our current upcaster sample only provides a SingleEventUpcaster example. We should expand it to provide the other types as well.

Starting from the EventMultiUpcaster would be a good choice.

@VladimirTitov4
Copy link

Hello, any updates on that issue? Still waiting for some examples on EventMultiUpcaster

@smcvb
Copy link
Collaborator

smcvb commented Oct 28, 2021

You can find an EventMultiUpcaster sample there right now, @VladimirTitov4.
Let us know what you think!

@VladimirTitov4
Copy link

You can find an EventMultiUpcaster sample there right now, @VladimirTitov4. Let us know what you think!

Thank you for the answer @smcvb ! Actually now I doubt whether I understood EventMultiUpcaster correctly.
In javadoc it says "... upcasting one intermediate event representation to several other representations ... "

but my case was "... upcasting several intermediate event representation to several other representations ... "

e.g. I have 10 Events with one specific field, that needs to be changed to other field, and keep original event name the same.
So, I would like to upcast

1. MenuCreatedEvent {
    private String sort;
}

2. MenuUpdatedEvent {
    private String sort;
}
...
10. MenuSomethingEvent {
    private String sort;
}

so I wanted to upcast all 10 events with "sort" to "position" field in one upcaster. Is that possible ?
The reason, because I wanted to use one multi upcaster for all 10 events, because all the changes are the same

@smcvb
Copy link
Collaborator

smcvb commented Oct 29, 2021

I think I understand @VladimirTitov4. You have ten event types which all should be pushed through an upcaster, correct?

Well, what you can do is make the canUpcast method react to all ten event types.
In doing so, the doUpcast method of your EventUpcaster will be invoked for all ten types.
I have a different opinion on whether this is smart, however.

Sure, it minimizes the number of upcasters you have to write.
But, it will make it tough to reason about your upcaster chain.
Also, how would you name the upcaster?
Ideally, it's tied directly to the event name it upcasts.
However, if the upcaster is in charge of ten events, you'd have an extremely long class name or a class name that no longer directly reflects what it adjusts.

I'd thus go for separate upcaster implementation for each event type.
To deduplicate your code, I would introduce an abstract upcaster implementation, though.

Next to the above, I have another doubt.
From your description, I think you don't need a one-to-many upcaster.
If you want to rename the field of event-x, that's a SingleEventUpcaster acting on that event to introduce the rename.
The EventMultiUpcaster is needed as soon as a single event should change in several events.

@dxp227
Copy link

dxp227 commented Jan 4, 2023

Would love an example of ContextAwareSingleEventUpcaster; I'm specifically struggling to see how one can extract event payload data from the IntermediateEventRepresentation for the purpose of adding that data to the context.

@smcvb
Copy link
Collaborator

smcvb commented Jan 5, 2023

Good idea, @dxp227. As it stands, I think it might take some time before we can come back to your request.
I did make an issue for it (which you can find here), by the way.

In the meantime, I would recommend you take a look at the test cases of the ContextAwareSingleEventUpcaster.
Those are, in essence, samples on how to construct a ContextAwareSingleEventUpcaster too.
You can find the test case here, by the way.

@dxp227
Copy link

dxp227 commented Jan 5, 2023

I'm specifically struggling to see how one can extract event payload data from the IntermediateEventRepresentation for the purpose of adding that data to the context.

Perhaps this was non-obvious to me only 😅 but here's my solution.

@smcvb The test case provides helpful direction as well - thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants