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: /tracker/trackedEntities?order=createdAt DHIS2-15325 [2.39] #14661

Merged
merged 1 commit into from
Jul 20, 2023

Conversation

teleivo
Copy link
Contributor

@teleivo teleivo commented Jul 20, 2023

backport of #14631

Note that < 2.40 we have some extra logic affecting the users order param field names. Due to that some field names in TrackedEntityInstanceQueryParams.OrderColumn refer to old tracker field names.

Order field name translation logic

  1. The PagingAndSortingCriteria translates from new tracker field names to old tracker ones. These field names are registered in the criteria classes (called RequestParam in master; this translation does not exist >= 2.40).

Here is where the new/old tracker names are registered

@Override
public Optional<String> translateField(String dtoFieldName, boolean isLegacy) {
return isLegacy
? translate(
dtoFieldName, TrackerTrackedEntityCriteria.LegacyDtoToEntityFieldTranslator.values())
: translate(dtoFieldName, TrackerTrackedEntityCriteria.DtoToEntityFieldTranslator.values());
}
/** Dto to database field translator for new tracker Enrollment export controller */
@RequiredArgsConstructor
private enum DtoToEntityFieldTranslator implements EntityNameSupplier {
/**
* this enum names must be the same as org.hisp.dhis.tracker.domain.TrackedEntity fields, just
* with different case
*
* <p>example: org.hisp.dhis.tracker.domain.TrackedEntity.updatedAtClient --> UPDATED_AT_CLIENT
*/
TRACKED_ENTITY("trackedEntityInstance"),
CREATED_AT("created"),
UPDATED_AT("lastUpdated");
@Getter private final String entityName;
}

I added a test

webapi/controller/event/webrequest/tracker/TrackerTrackedEntityCriteriaTest.java

to show how the translation works.

order=<fieldname> in new tracker endpoints

  • are translated to old tracker field names ONLY if there is a registered mapping
  • if there is no mapping they are left as is
  1. TrackedEntityInstanceQueryParams maps from field names to columns

For example

TRACKEDENTITY("trackedEntityInstance", "uid", MAIN_QUERY_ALIAS),

takes the old tracker field name and maps it to the uid column. This works for old and new tracker as the new tracker name trackedEntity has been translated to trackedEntityInstance in step 1. 😅

was ordering by tracked entity id instead of created column.

Lowercase column names in OrderColumn mapper.
Fix tests which asserted using the wrong order or assumed we can set the lastupdated date. lastupdated
is automatically set by HibernateGenericStore. So to assert we can order by that column we can only
update the entity in some order and expect that to be returned
@sonarcloud
Copy link

sonarcloud bot commented Jul 20, 2023

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

@teleivo teleivo merged commit 502a6da into 2.39 Jul 20, 2023
10 checks passed
@teleivo teleivo deleted the DHIS2-15325-tei-2.39 branch July 20, 2023 11:22
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.

2 participants