-
Notifications
You must be signed in to change notification settings - Fork 355
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
fix: program rule variable name check now also check UID to prevent duplicates [DHIS2-11330] #8220
Conversation
// since prvWithSameNameAndSameProgram is not empty, fail if it's an | ||
// insert or if there is more than one prv with same name and same | ||
// program. | ||
if ( !UPDATE_STRATEGIES.contains( bundle.getImportMode() ) || prvWithSameNameAndSameProgram.size() > 1 ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is more than one in the DB already, doesn't mean that data in DB is wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's true, but this specific case means that if INSERT, in DB it is expected to be 0, if UPDATE, in DB there can be at most 1.
when in database there are 2 or more, the check will fail anyway. Or am I missing something ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok maybe I got it... maybe we can have a failing "legal" update just because data in DB is bad. Yes this might happen as well, but it shouldn't honestly. Here I just wanted to make it simpler the following part by assuming that the list only contained one element.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then what I can do is remove size()>1 condition and since it's an update, ensure at least one in the List have the same UID as the PRV we are processing in the validator, what would you think ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use also prv uid in the query, it should be easier that way
{ | ||
Query<ProgramRuleVariable> query = getProgramRuleVariableQuery( programRuleVariable ); | ||
List<ProgramRuleVariable> prvWithSameNameAndSameProgram = getProgramRuleVariableQuery( programRuleVariable ) | ||
.getResultList(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this approach is too verbose, in my opinion we should simply try to do a query also using prv UID.
After that if it is a create strategy and we get a record, we have an error. We also have an error if we don't get a result and it is an update.
I think this way is much cleaner, less code and maintenable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you're right, I'll review it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better thinking, we should
- fail when it's an insert and a PRV with same name/program already exists
- fail when it's an update and a PRV with same name/program/uid already exists
so I think it's not possible to verify the first check adding UID in the query filter
Kudos, SonarCloud Quality Gate passed! |
…uplicates [DHIS2-11330] (#8220) * fix: program rule variable name check should be now properly implemented * fix: changed check implementation to tolerate bad database data * fix: added test case * style: formatting * fix: compilation issue with JDK 9 * style: formatting (cherry picked from commit c525517)
…uplicates [DHIS2-11330] (#8220) * fix: program rule variable name check should be now properly implemented * fix: changed check implementation to tolerate bad database data * fix: added test case * style: formatting * fix: compilation issue with JDK 9 * style: formatting (cherry picked from commit c525517)
…uplicates [DHIS2-11330] (#8220) * fix: program rule variable name check should be now properly implemented * fix: changed check implementation to tolerate bad database data * fix: added test case * style: formatting * fix: compilation issue with JDK 9 * style: formatting (cherry picked from commit c525517)
…uplicates [DHIS2-11330] (#8220) (#8365) * fix: program rule variable name check should be now properly implemented * fix: changed check implementation to tolerate bad database data * fix: added test case * style: formatting * fix: compilation issue with JDK 9 * style: formatting (cherry picked from commit c525517)
…uplicates [DHIS2-11330] (#8220) (#8367) * fix: program rule variable name check should be now properly implemented * fix: changed check implementation to tolerate bad database data * fix: added test case * style: formatting * fix: compilation issue with JDK 9 * style: formatting (cherry picked from commit c525517)
…uplicates [DHIS2-11330] (#8220) (#8366) * fix: program rule variable name check should be now properly implemented * fix: changed check implementation to tolerate bad database data * fix: added test case * style: formatting * fix: compilation issue with JDK 9 * style: formatting (cherry picked from commit c525517)
The case that was not covered in the previous implementation was:
in this case, the check was failing, allowing PRV to be duplicated.
With the current implementation, in case of updates, also UIDs are checked.