Skip to content

Commit

Permalink
chore: align fetching a single vs multiple TEs more DHIS2-18541 (#19647)
Browse files Browse the repository at this point in the history
* chore: align fetching a single vs multiple TEs more

* chore: one test

* test: pass

* test: finally
  • Loading branch information
teleivo authored Jan 15, 2025
1 parent 19ef0f9 commit 8cc485b
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 154 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public Multimap<String, TrackedEntityProgramOwner> getProgramOwners(List<Long> i
}

@Override
public Multimap<String, String> getOwnedTeis(
public Multimap<String, String> getOwnedTrackedEntities(
List<Long> ids, Context ctx, boolean skipUserScopeValidation) {
List<List<Long>> teds = Lists.partition(ids, PARITITION_SIZE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Multimap<String, Event> findByEnrollmentIds(List<Long> ids, Context ctx) {
Multimap<String, RelationshipItem> relationships = relationshipAsync.join();

for (Event event : events.values()) {
if (ctx.getParams().isIncludeRelationships()) {
if (ctx.getParams().getEventParams().isIncludeRelationships()) {
event.setRelationshipItems(new HashSet<>(relationships.get(event.getUid())));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,13 @@ public List<TrackedEntity> find(
supplyAsync(() -> trackedEntityStore.getAttributes(ids), getPool());

/*
* Async fetch Owned Tei mapped to the provided program attributes by
* Async fetch Owned TE mapped to the provided program attributes by
* TrackedEntity id
*/
final CompletableFuture<Multimap<String, String>> ownedTeiAsync =
conditionalAsyncFetch(
user.isPresent(),
() -> trackedEntityStore.getOwnedTeis(ids, ctx, orgUnitMode == ALL),
() -> trackedEntityStore.getOwnedTrackedEntities(ids, ctx, orgUnitMode == ALL),
getPool());
/*
* Execute all queries and merge the results
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ public interface TrackedEntityStore {
* @param ctx aggregate context
* @return Tei uids mapped to a list of program uids to which user has ownership
*/
Multimap<String, String> getOwnedTeis(
Multimap<String, String> getOwnedTrackedEntities(
List<Long> ids, Context ctx, boolean skipUserScopeValidation);
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@ public TrackedEntityRowCallbackHandler() {
this.items = new LinkedHashMap<>();
}

private TrackedEntity getTei(ResultSet rs) throws SQLException {

private TrackedEntity getTrackedEntity(ResultSet rs) throws SQLException {
TrackedEntity te = new TrackedEntity();
te.setUid(rs.getString(TrackedEntityQuery.getColumnName(COLUMNS.UID)));
TrackedEntityType trackedEntityType = new TrackedEntityType();
Expand Down Expand Up @@ -85,7 +84,7 @@ private TrackedEntity getTei(ResultSet rs) throws SQLException {

@Override
public void processRow(ResultSet rs) throws SQLException {
this.items.put(rs.getString("te_uid"), getTei(rs));
this.items.put(rs.getString("te_uid"), getTrackedEntity(rs));
}

public Map<String, TrackedEntity> getItems() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ void shouldTrackedEntityIncludeSpecificOpenProgram()

List<TrackedEntity> trackedEntities = trackedEntityService.getTrackedEntities(operationParams);

assertContainsOnly(List.of(trackedEntityA), trackedEntities);
assertContainsOnly(List.of(trackedEntityA), trackedEntities, TrackedEntity::getUid);
assertContainsOnly(
Set.of("A", "B", "C"),
attributeNames(trackedEntities.get(0).getTrackedEntityAttributeValues()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
import org.hisp.dhis.webapi.controller.tracker.JsonTrackedEntity;
import org.hisp.dhis.webapi.utils.ContextUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
Expand Down Expand Up @@ -542,6 +543,8 @@ void shouldGetNoEventRelationshipsWhenEventsHasNoRelationshipsAndFieldsIncludeAl
assertTrue(jsonEvent.getRelationships().isEmpty());
}

@Disabled(
"TODO(DHIS2-18541) test fixtures will be fixed in next PR: org.hisp.dhis.feedback.ForbiddenException: User needs to be assigned either search or data capture org units")
@Test
void shouldGetEventRelationshipsWhenEventHasRelationshipsAndFieldsIncludeEventRelationships() {
TrackedEntity trackedEntity = trackedEntity();
Expand Down

0 comments on commit 8cc485b

Please sign in to comment.