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/events not returning event relationships [DHIS2-16117] [ 2.38 ] #15669

Merged
merged 2 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,17 @@ protected TrackerApiResponse importRelationshipEnrollmentToTei(String enrollment
return trackerActions.postAndGetJobReport(payload).validateSuccessfulImport();
}

protected TrackerApiResponse importRelationshipEventToTei(String event, String tei) {
JsonObject payload =
new RelationshipDataBuilder()
.setFromEntity("event", event)
.setToTrackedEntity(tei)
.setRelationshipType("gdc6uOvgoji")
.array();

return trackerActions.postAndGetJobReport(payload).validateSuccessfulImport();
}

@AfterEach
public void afterEachNTI() {
loginActions.loginAsSuperUser();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.emptyIterable;
import static org.hamcrest.Matchers.emptyOrNullString;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.everyItem;
Expand Down Expand Up @@ -87,6 +88,8 @@ public class TrackerExportTests extends TrackerNtiApiTest {

private static final String TEI_POTENTIAL_DUPLICATE = "Nav6inZRw1u";

private static String eventToTeiRelationship;

private static JsonObject teiWithEnrollmentAndEventsTemplate;

@BeforeAll
Expand All @@ -102,12 +105,15 @@ public void beforeAll() throws Exception {

enrollment = response.extractImportedEnrollments().get(0);

event = response.extractImportedEvents().get(0);

teiToTeiRelationship =
importRelationshipBetweenTeis(teiA, teiB).extractImportedRelationships().get(0);
enrollmentToTeiRelationship =
importRelationshipEnrollmentToTei(enrollment, teiB).extractImportedRelationships().get(0);

event = response.extractImportedEvents().get(0);
eventToTeiRelationship =
importRelationshipEventToTei(event, teiB).extractImportedRelationships().get(0);

teiWithEnrollmentAndEventsTemplate =
new FileReaderUtils()
Expand Down Expand Up @@ -400,6 +406,39 @@ public void shouldReturnRelationshipsByTei() {
.body("to.trackedEntity.trackedEntity", equalTo(teiB));
}

@Test
public void shouldReturnRelationshipsWhenEventHasRelationshipsAndFieldsIncludeRelationships() {
trackerActions
.get("events?event=" + event + "&fields=relationships")
.validate()
.statusCode(200)
.body("instances", hasSize(greaterThanOrEqualTo(1)))
.rootPath("instances[0].relationships[0]")
.body("relationship", equalTo(eventToTeiRelationship))
.body("from.event.event", equalTo(event))
.body("to.trackedEntity.trackedEntity", equalTo(teiB));
}

@Test
public void shouldNotReturnRelationshipsWhenEventHasRelationshipsAndFieldsExcludeRelationships() {
trackerActions
.get("events?event=" + event)
.validate()
.statusCode(200)
.body("instances[0].relationships", emptyOrNullString());
}

@Test
public void shouldReturnFilteredEvent() {
trackerActions
.get(
"events?enrollmentOccurredAfter=2019-08-16&enrollmentOccurredBefore=2019-08-20&event=ZwwuwNp6gVd")
.validate()
.statusCode(200)
.rootPath("instances[0]")
.body("event", equalTo("ZwwuwNp6gVd"));
}

@Test
public void
shouldReturnProgramStageListOrderedByProgramStageAscWhenFieldsAndOrderEqualToProgramStage() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3152,6 +3152,41 @@
"id": "OPVIvvXzNTw"
}
]
},
{
"lastUpdated": "2020-11-20T09:06:23.348",
"id": "gdc6uOvgoji",
"created": "2020-11-20T09:06:23.348",
"name": "Person to Event",
"code": "Person to Event",
"bidirectional": false,
"displayName": "Person to Event",
"fromToName": "Person to Event",
"displayFromToName": "Person to Event",
"favorite": false,
"toConstraint": {
"relationshipEntity": "TRACKED_ENTITY_INSTANCE",
"trackedEntityType": {
"id": "Q9GufDoplCL",
"code": "TA_PERSON_TET"
}
},
"fromConstraint": {
"relationshipEntity": "PROGRAM_STAGE_INSTANCE",
"programStage": {
"id": "PaOOjwLVW23"
}
},
"sharing": {
"public": "rw------",
"external": false,
"userGroups": {
"OPVIvvXzNTw": {
"id": "OPVIvvXzNTw",
"access": "rwrw----"
}
}
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ public PagingWrapper<ObjectNode> getEvents(
throws WebMessageException {
EventQueryParams eventQueryParams = requestToSearchParamsMapper.map(eventCriteria);

EventParams eventParams = eventsMapper.map(fields);

eventQueryParams.setIncludeRelationships(eventParams.isIncludeRelationships());

if (areAllEnrollmentsInvalid(eventCriteria, eventQueryParams)) {
return new PagingWrapper<ObjectNode>().withInstances(Collections.emptyList());
}
Expand Down
Loading