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

[MODINVOICE-478] Prevent conflicts when saving multiple invoice lines with data import #413

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

Conversation

damien-git
Copy link
Contributor

@damien-git damien-git commented May 25, 2023

Purpose

MODINVOICE-478 - Data import saving invoice lines in parallel can cause conflicts when invoices are updated

Approach

New implementation to save invoice and invoice lines with data import.
There will no longer be potential conflicts when the invoice is updated, which happens several times in the process.
Line creations are processed together, which should make the whole operation significantly faster.
Error reporting is a little different: some (internal) errors that were previously reported with a line number will no longer be associated with a number. Other errors (for validation) will be better reported and will prevent the creation of the invoice and lines.

TODOS and Open Questions

TODO: Integration tests, especially data-import/src/main/resources/folijet/data-import/features/import-edi-invoice.feature. I was not able to test it because I could not get Kafka messages to be sent to IDEA from mod-data-import.
Also, we should check that error reporting still matches user expectations.

Learning

I learned a way to validate objects with their Json schema. We should do that every time we don't get the objects directly with the API (such as when using Kafka).
Also I found a way to implement a helper to use semaphores without repeating that ugly pattern everywhere.

Pre-Merge Checklist:

Before merging this PR, please go through the following list and take appropriate action.

  • Does this PR meet or exceed the expected quality standards?
    • Code coverage on new code is 80% or greater
    • Duplications on new code are 3% or less
    • There are no major code smells or security issues
  • Does this introduce breaking changes?
    • Were any API paths or methods changed, added, or removed?
    • Were there any schema changes?
    • Did any of the interface versions change?
    • Were permissions changed, added, or removed?
    • Are there new interface dependencies?
    • There are no breaking changes in this PR.

If there are breaking changes, please STOP and consider the following:

  • What other modules will these changes impact?
  • Do JIRAs exist to update the impacted modules?
    • If not, please create them
    • Do they contain the appropriate level of detail? Which endpoints/schemas changed, etc.
    • Do they have all the appropriate links to blocked/related issues?
  • Are the JIRAs under active development?
    • If not, contact the project's PO and make sure they're aware of the urgency.
  • Do PRs exist for these changes?
    • If so, have they been approved?

Ideally, all the PRs involved in breaking changes would be merged on the same day
to avoid breaking the folio-testing environment.
Communication is paramount if that is to be achieved,
especially as the number of inter-module and inter-team dependencies increase.

While it's helpful for reviewers to help identify potential problems,
ensuring that it's safe to merge is ultimately the responsibility of the PR assignee.

@damien-git damien-git self-assigned this May 25, 2023
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

91.7% 91.7% Coverage
0.0% 0.0% Duplication

.map(invoiceLine -> persistInvoiceLine(invoiceLine, requestContext))
.collect(Collectors.toList());
return GenericCompositeFuture.join(futures).mapEmpty();
public Future<List<InvoiceLine>> createInvoiceLines(List<InvoiceLine> invoiceLines, RequestContext requestContext) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hello @damien-git, could you say please can we return invoiceLines creation result (something like InvoiceHelper.createInvoiceAndLines() method) with errors for particular invoice lines in case POST requests fail for some of them? So that we could build such errors for those invoice lines in the CreateInvoiceEventHandler (by INVOICE_LINES_ERRORS_KEY). It will allow to show error only for invoice lines that could not be created, but not for lines that were created.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think an error at this point (when InvoiceLineService.createInvoiceLines() is called) means that there is an error for all lines, because other related operations for all lines are not done yet. For instance, the invoice-order relations, the invoice po numbers and the invoice update. Even if an invoice line record is created, the whole operation to create the invoice line (which includes updating the invoice) is not finished. I don't think there is a way around, although I guess we could add code that deletes created lines (if any) when the code fails after the start of the line record creations. Note that this would be an internal error, so it should not happen in normal circumstances.

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.

4 participants