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: Move converters into the bundle package [DHIS2-18093] #18807

Merged
merged 3 commits into from
Oct 15, 2024

Conversation

enricocolasante
Copy link
Contributor

@enricocolasante enricocolasante commented Oct 11, 2024

This PR moves the converters inside the bundle package and merge them in one single static mapper.

While at it, a few small fixes were performed:

@enricocolasante enricocolasante force-pushed the DHIS2-18093-converters branch 3 times, most recently from 9069b97 to 114cacb Compare October 11, 2024 14:03
@enricocolasante enricocolasante force-pushed the DHIS2-18093-converters branch 3 times, most recently from 460ea37 to 13fc56d Compare October 14, 2024 09:53
Date occurredDate = DateUtils.fromInstant(enrollment.getOccurredAt());

dbEnrollment.setEnrollmentDate(enrollmentDate);
dbEnrollment.setOccurredDate(occurredDate != null ? occurredDate : enrollmentDate);
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the difference between this one and enrollmentDate? and why do we set it to enrollmentDate if occurredDate is null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now the there is less code and it is easier to understand this logic I created https://dhis2.atlassian.net/browse/DHIS2-18224 to reason about this kind of stuff.
I am not sure what is the logic here

}

@Override
protected org.hisp.dhis.relationship.Relationship convert(
TrackerBundle bundle, Relationship trackerDto) {
return relationshipConverter.from(bundle.getPreheat(), trackerDto, bundle.getUser());
if (bundle.getStrategy(trackerDto) == TrackerImportStrategy.UPDATE) {
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

why do we not map the object in case of UPDATE?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Relationships cannot be updated.
If this is the case, we are ignoring the object in the payload and send a warning.
Ivo created a bug https://dhis2.atlassian.net/browse/DHIS2-18110 where we should improve the way we set the ignored objects to always provide an error/warning. Here it is happening but it is not enforced by the code.

dbEnrollment.setCompletedDate(now);
dbEnrollment.setCompletedBy(user.getUsername());
}
case CANCELLED -> {
Copy link
Contributor

Choose a reason for hiding this comment

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

unrelated to this PR, but I've seen that when the enrollment is CANCELLED, the related event(s) are not modified, so it could happen that an event is ACTIVE while the parent enrollment is CANCELLED, does that make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as before, I just didn't change the logic, but in https://dhis2.atlassian.net/browse/DHIS2-18224 we should try to understand if it makes sense or not.

@teleivo
Copy link
Contributor

teleivo commented Oct 15, 2024

  • EnrollmentStatus default is ACTIVE. Added default value in the view and the model and removed it from the mapper.

Why is a default needed in both places?

@enricocolasante
Copy link
Contributor Author

  • EnrollmentStatus default is ACTIVE. Added default value in the view and the model and removed it from the mapper.

Why is a default needed in both places?

Yeah, I don't think it is.
I started adding the default in the view and then I realized that I needed in the service, because tracker importer endpoint is not the only client, but then I didn't remove it from the view.

Copy link
Contributor

@teleivo teleivo left a comment

Choose a reason for hiding this comment

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

Is the TrackerObjectsMapper only used by the persisters? if so move it their and make package private

@enricocolasante
Copy link
Contributor Author

Is the TrackerObjectsMapper only used by the persisters? if so move it their and make package private

Unfortunately it is used in here

.

I would like to remove it at some point but it is out of the scope of this PR.

@enricocolasante
Copy link
Contributor Author

  • EnrollmentStatus default is ACTIVE. Added default value in the view and the model and removed it from the mapper.

Why is a default needed in both places?

Yeah, I don't think it is. I started adding the default in the view and then I realized that I needed in the service, because tracker importer endpoint is not the only client, but then I didn't remove it from the view.

It is actually needed in both places.
If I don't add it in the view, than the null will be propagated.
If I don't set it in the service, than any other client will not have a default value.

Copy link

sonarcloud bot commented Oct 15, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
8 New issues
8 New Code Smells (required ≤ 0)

See analysis details on SonarCloud

Catch issues before they fail your Quality Gate with our IDE extension SonarLint

@enricocolasante enricocolasante merged commit be67efb into master Oct 15, 2024
14 of 15 checks passed
@enricocolasante enricocolasante deleted the DHIS2-18093-converters branch October 15, 2024 13:27
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