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

fix: program rule variable name check now also check UID to prevent duplicates [DHIS2-11330] #8220

Merged
merged 6 commits into from
Jun 22, 2021

Conversation

gnespolino
Copy link
Contributor

The case that was not covered in the previous implementation was:

  • existing PRV with same name/program
  • object to update had a different UID (generated)

in this case, the check was failing, allowing PRV to be duplicated.

With the current implementation, in case of updates, also UIDs are checked.

@gnespolino gnespolino changed the title fix: program rule variable name check should be now properly implemented fix: program rule variable name check now also check UID to prevent duplicates [DHIS2-11330] Jun 14, 2021
// 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 )
Copy link
Contributor

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?

Copy link
Contributor Author

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 ?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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 ?

@gnespolino gnespolino added Ready for review run-api-tests This label will trigger an api-test job for the PR. labels Jun 14, 2021
Copy link
Contributor

@lucaCambi77 lucaCambi77 left a 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

Comment on lines 99 to +101
{
Query<ProgramRuleVariable> query = getProgramRuleVariableQuery( programRuleVariable );
List<ProgramRuleVariable> prvWithSameNameAndSameProgram = getProgramRuleVariableQuery( programRuleVariable )
.getResultList();
Copy link
Contributor

@lucaCambi77 lucaCambi77 Jun 14, 2021

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

Copy link
Contributor Author

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

Copy link
Contributor Author

@gnespolino gnespolino Jun 21, 2021

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

@gnespolino gnespolino requested a review from lucaCambi77 June 21, 2021 09:40
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!

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

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@gnespolino gnespolino merged commit c525517 into master Jun 22, 2021
@gnespolino gnespolino deleted the DHIS2-11330_prv_validation_not_triggered branch June 22, 2021 08:14
gnespolino added a commit that referenced this pull request Jul 2, 2021
…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)
gnespolino added a commit that referenced this pull request Jul 2, 2021
…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)
gnespolino added a commit that referenced this pull request Jul 2, 2021
…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)
Philip-Larsen-Donnelly pushed a commit that referenced this pull request Jul 5, 2021
…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)
gnespolino added a commit that referenced this pull request Jul 12, 2021
…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)
gnespolino added a commit that referenced this pull request Jul 12, 2021
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready for review run-api-tests This label will trigger an api-test job for the PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants