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: use importer for update object property [DHIS2-11944] #9079

Merged
merged 3 commits into from
Oct 21, 2021

Conversation

jbee
Copy link
Contributor

@jbee jbee commented Oct 18, 2021

Summary

Goal of this PR was to use importer to apply single object property updates so that additional validation performed in the object bundle hooks would execute for these updates as well.

Using the importer has revealed a few issues that have been addressed. I pointed these out in comments on the line in question.

Automatic Tests

This adds a test scenario that might look overly complicated at first sight. This is because this more complex scenario would show an issue with the update so the test make sure this issue is not present. A similar scenario was added to full object update to check and make sure a similar problem does not exist there.

@jbee jbee self-assigned this Oct 18, 2021
@jbee jbee added the run-api-tests This label will trigger an api-test job for the PR. label Oct 18, 2021
new MergeParams<>( userCredentials, persistedUserCredentials ).setMergeMode( bundle.getMergeMode() ) );
preheatService.connectReferences( persistedUserCredentials, bundle.getPreheat(),
bundle.getPreheatIdentifier() );
if ( userCredentials != persistedUserCredentials )
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure when or why but apparently these can be the very same instance and merging them messes up proxy collections I guess. Anyhow, only merging dissimilar instances should not be less correct.

Comment on lines +104 to +105
&& (PropertyType.REFERENCE == p.getPropertyType() && schema.getKlass() != p.getKlass()
|| PropertyType.REFERENCE == p.getItemPropertyType() && schema.getKlass() != p.getItemKlass()) )
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is so we don't process self-referencing fields like User in a User like it does occur for createdBy and lastUpdatedBy.

@@ -269,7 +267,7 @@ private Patch diff( HttpServletRequest request )
return patchService.diff( new PatchParams( mapper.readTree( request.getInputStream() ) ) );
}

@RequestMapping( value = "/{uid}/{property}", method = { RequestMethod.PUT, RequestMethod.PATCH } )
@PatchMapping( "/{uid}/{property}" )
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We talked about PUT being mapped twice so it got removed here. Only PATCH ever worked and as I understood it was documented.

@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

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@jbee jbee requested review from mortenoh and larshelge October 19, 2021 13:12
@jbee jbee marked this pull request as ready for review October 19, 2021 13:12
@larshelge larshelge merged commit 5079a0a into dhis2:master Oct 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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