Skip to content

fix: Add event validation when updating status [DHIS2-17658] #17890

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

Merged
merged 6 commits into from
Jun 27, 2024

Conversation

enricocolasante
Copy link
Contributor

@enricocolasante enricocolasante commented Jun 26, 2024

This is the first PR to fix https://dhis2.atlassian.net/browse/DHIS2-17658.
We were missing the validation on event status update.
Some statuses are meant to be used for events that will be handled at a later point in time ('SCHEDULE', 'SKIPPED', 'OVERDUE') and they do not allow data values to be defined and other statuses are meant to be used for events that are being worked on ('ACTIVE', 'COMPLETED', 'VISITED').
Updating from the first ones to the second ones is always allowed while going back from the second ones to the first ones does not make sense and it has to be blocked.

return eventStatus;
}
}
public static final Set<EventStatus> ALLOW_DATA_VALUES_STATUSES =
Copy link
Contributor

Choose a reason for hiding this comment

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

wouldn't it make more sense to name it ALLOWED_STATUSES?
we are not referencing event data values here, are we?

Copy link
Contributor

Choose a reason for hiding this comment

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

Anyway, is this used somewhere?

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 yet :)
I extracted this PR from the other one, so it will be used at some point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ALLOWED_STATUSES is not true. These are the statuses that allow to have data values defined.
ALLOWED_STATUSES gets you the idea that those statuses are not allowed at all, which is not true.

Copy link
Contributor

Choose a reason for hiding this comment

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

How about STATUSES_ALLOWING_DATA_VALUES or STATUSES_WITH_DATA_VALUES?

public static boolean isExistingEvent(EventStatus status) {
return status != null && (COMPLETED.equals(status) || VISITED.equals(status));
}
public static final Set<EventStatus> NO_ALLOW_DATA_VALUES_STATUSES =
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd call this one DISALLOWED_DATA_VALUES_STATUSES, and in case the comment above makes sense, just DISALLOWED_STATUSES

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 not allowed and disallowed are not synonyms, but we could ask a native speaker about it.
The idea here is the same as above, these statuses are valid, the just do not permit to define data values.
Maybe because this was extracted from a bigger PR is not clear, but we will add another validation that is simply going to fail if the event has a status in NO_ALLOW_DATA_VALUES_STATUSES and dataValues is not empty

Copy link
Contributor

Choose a reason for hiding this comment

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

STATUSES_DISALLOWING_DATA_VALUES or STATUSES_WITHOUT_DATA_VALUES

@enricocolasante enricocolasante requested a review from muilpp June 26, 2024 14:21
return eventStatus;
}
}
public static final Set<EventStatus> ALLOW_DATA_VALUES_STATUSES =
Copy link
Contributor

Choose a reason for hiding this comment

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

How about STATUSES_ALLOWING_DATA_VALUES or STATUSES_WITH_DATA_VALUES?

public static boolean isExistingEvent(EventStatus status) {
return status != null && (COMPLETED.equals(status) || VISITED.equals(status));
}
public static final Set<EventStatus> NO_ALLOW_DATA_VALUES_STATUSES =
Copy link
Contributor

Choose a reason for hiding this comment

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

STATUSES_DISALLOWING_DATA_VALUES or STATUSES_WITHOUT_DATA_VALUES


private boolean checkInvalidStatusTransition(EventStatus fromStatus, EventStatus toStatus) {
return switch (fromStatus) {
case VISITED, ACTIVE, COMPLETED ->
Copy link
Contributor

Choose a reason for hiding this comment

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

These are ALLOW_DATA_VALUES_STATUSES, should we not use that then? like you do with NO_ALLOW_DATA_VALUES_STATUSES.

@enricocolasante enricocolasante requested a review from teleivo June 27, 2024 14:03
Copy link

@enricocolasante enricocolasante merged commit 39a31c8 into master Jun 27, 2024
15 checks passed
@enricocolasante enricocolasante deleted the DHIS2-17658 branch June 27, 2024 14:57
@enricocolasante enricocolasante restored the DHIS2-17658 branch July 1, 2024 08:55
enricocolasante added a commit that referenced this pull request Jul 8, 2024
* fix: Add event validation when updating status [DHIS2-17658]

* Fix sonar issues

* Fix code review comments

* Fix code review comments

* Fix code review comments

* Fix code review comments
enricocolasante added a commit that referenced this pull request Jul 8, 2024
….41) (#18015)

* fix: Add event validation when updating status [DHIS2-17658] (#17890)

* fix: Add event validation when updating status [DHIS2-17658]

* Fix sonar issues

* Fix code review comments

* Fix code review comments

* Fix code review comments

* Fix code review comments

* fix: Validate no datavalues for some event statuses [DHIS2-17658] (#17934)

* fix: Validate no datavalues for some event statuses [DHIS2-17658]

* Fix tests

* Fix code review comments

* Update dhis-2/dhis-api/src/main/java/org/hisp/dhis/tracker/imports/validation/ValidationCode.java

Co-authored-by: teleivo <[email protected]>

---------

Co-authored-by: teleivo <[email protected]>

* fix: Skip mandatory data value validation for UPDATE [DHIS2-17560] (#17835)

* fix: Skip mandatory data value validation for UPDATE [DHIS2-17560]

* More clean up

* Fix tests

* Add tests

* Add tests

---------

Co-authored-by: teleivo <[email protected]>
enricocolasante added a commit that referenced this pull request Jul 8, 2024
* fix: Add event validation when updating status [DHIS2-17658]

* Fix sonar issues

* Fix code review comments

* Fix code review comments

* Fix code review comments

* Fix code review comments
enricocolasante added a commit that referenced this pull request Jul 9, 2024
….40) (#18017)

* fix: Add event validation when updating status [DHIS2-17560]

* fix: Add event validation when updating status [DHIS2-17658] (#17890)

* fix: Add event validation when updating status [DHIS2-17658]

* Fix sonar issues

* Fix code review comments

* Fix code review comments

* Fix code review comments

* Fix code review comments

* fix: Skip mandatory data value validation for UPDATE [DHIS2-17560] (#17835)

* fix: Skip mandatory data value validation for UPDATE [DHIS2-17560]

* More clean up

* Fix tests

* Add tests

* Add tests
enricocolasante added a commit that referenced this pull request Jul 9, 2024
* fix: Add event validation when updating status [DHIS2-17658]

* Fix sonar issues

* Fix code review comments

* Fix code review comments

* Fix code review comments

* Fix code review comments
enricocolasante added a commit that referenced this pull request Jul 9, 2024
….39) (#18018)

* fix: Add event validation when updating status [DHIS2-17560]

* fix: Add event validation when updating status [DHIS2-17658] (#17890)

* fix: Add event validation when updating status [DHIS2-17658]

* Fix sonar issues

* Fix code review comments

* Fix code review comments

* Fix code review comments

* Fix code review comments

* fix: Skip mandatory data value validation for UPDATE [DHIS2-17560] (#17835)

* fix: Skip mandatory data value validation for UPDATE [DHIS2-17560]

* More clean up

* Fix tests

* Add tests

* Add tests

* Fix test
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