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

[MODSOURCE-840] Extend domain event with source MARC #664

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

RomanChernetskyi
Copy link
Contributor

@RomanChernetskyi RomanChernetskyi commented Jan 21, 2025

Purpose

Create/Update/Delete operations in the module should generate related events with the new/old body for the entity (instances/authorities)
Acceptance Criteria:

  • The domain event has new/old fields
  • The domain has a unique identifier for the message and a timestamp of the event

Approach

Send domain events with old and new record

Jira

https://folio-org.atlassian.net/browse/MODSOURCE-840

@PBobylev PBobylev requested review from pkjacob and PBobylev January 22, 2025 12:04
.onSuccess(v -> recordDomainEventPublisher.publishRecordUpdated(oldRecord,
updatedRecord
.withErrorRecord(oldRecord.getErrorRecord())
.withRawRecord(oldRecord.getRawRecord())
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct? Here we assign oldRecord.getRawRecord() to updatedRecord. Same comment on previous line .withErrorRecord(oldRecord.getErrorRecord())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is correct, but I already removed this piece of code because we decided not to send raw records and error records to make the domain event less overwhelmed with unneeded data

return getRecordById(txQE, oldRecord.getId())
.compose(optionalRecord -> optionalRecord.map(exisitngRecord ->
insertOrUpdateRecord(txQE, oldRecord).compose(r -> insertOrUpdateRecord(txQE, newRecord))
.onSuccess(updatedRecord -> recordDomainEventPublisher.publishRecordUpdated(exisitngRecord, updatedRecord, okapiHeaders)))
Copy link

@pkjacob pkjacob Jan 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo in exisitngRecord. Should be existingRecord

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, thanks

.compose(optionalRecord -> optionalRecord.map(exisitngRecord ->
insertOrUpdateRecord(txQE, oldRecord).compose(r -> insertOrUpdateRecord(txQE, newRecord))
.onSuccess(updatedRecord -> recordDomainEventPublisher.publishRecordUpdated(exisitngRecord, updatedRecord, okapiHeaders)))
.orElse(Future.failedFuture(new NotFoundException(format(RECORD_NOT_FOUND_TEMPLATE, oldRecord.getId())))));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the existing logic, we insert new record to DB if the record do not already exist. Per the new logic, new throw NotFoundException when record do not exist in DB. Is it ok? (I don't know as I am not familiar with this module)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's ok because this method updates the existing oldRecord and creates newRecord, so we expect to have oldRecord at DB before executing insert operation

@pkjacob
Copy link

pkjacob commented Jan 28, 2025

Hi @RomanChernetskyi, Changes looks good to me except few minor comments. This change is going to break mod-linked-data application. Is it possible to wait few days for merging this PR? We will create a ticket & make changes in linked data per the new event payload.

Here is my understanding about the payload change:

Before:

eventPayload property of the event contains the impacted Record object

After this change:

eventPayload property will contain a old and new property. Each of these properties will contain a Record object. For SOURCE_RECORD_CREATED event, old will contain null

@PBobylev What do you think? May be we can make change in linked-data soon? If the payload change I mentioned above is correct, I think this is a minor change in linked-data.

@@ -48,7 +55,7 @@ public Future<String> handle(KafkaConsumerRecord<String, String> consumerRecord)
logInput(authorityId, eventSubType, tenantId);
return (switch (eventSubType) {
case SOFT_DELETE -> performSoftDelete(authorityId, tenantId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be a delete event on soft delete?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So far, we decided to send an update on the soft delete of Marc's records, but during further refinements, requirements could be changes

@pkjacob
Copy link

pkjacob commented Feb 5, 2025

@RomanChernetskyi ,

Here is the PR to do the corresponding change in mod-linked-data: folio-org/mod-linked-data#111

@pkjacob
Copy link

pkjacob commented Feb 6, 2025

@RomanChernetskyi Here is the corresponding change in mod-linked-data folio-org/mod-linked-data#111

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

Successfully merging this pull request may close these issues.

3 participants