Skip to content

Commit

Permalink
Merge branch 'master' into DHIS2-18417
Browse files Browse the repository at this point in the history
  • Loading branch information
larshelge committed Nov 26, 2024
2 parents 7c725c7 + 7306b5b commit e58f104
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ jobs:
- name: Run unit tests
run: mvn clean test --threads 2C --batch-mode --no-transfer-progress --update-snapshots --file ./dhis-2/pom.xml --activate-profiles unit-test
timeout-minutes: 30
- name: Run dependency analysis
run: mvn dependency:analyze --file ./dhis-2/pom.xml
timeout-minutes: 2
- name: Report coverage to codecov
uses: codecov/codecov-action@v3
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ private List<Event> fetchEvents(EventQueryParams queryParams, PageParams pagePar
mapSqlParameterSource,
resultSet -> {
Set<String> notes = new HashSet<>();
Set<String> dataElementUids = new HashSet<>();
// data elements per event
Map<String, Set<String>> dataElementUids = new HashMap<>();

while (resultSet.next()) {
if (resultSet.getString(COLUMN_EVENT_UID) == null) {
Expand All @@ -305,6 +306,7 @@ private List<Event> fetchEvents(EventQueryParams queryParams, PageParams pagePar
event.setId(resultSet.getLong(COLUMN_EVENT_ID));
event.setUid(eventUid);
eventsByUid.put(eventUid, event);
dataElementUids.put(eventUid, new HashSet<>());

TrackedEntity te = new TrackedEntity();
te.setUid(resultSet.getString(COLUMN_TRACKEDENTITY_UID));
Expand Down Expand Up @@ -437,11 +439,11 @@ private List<Event> fetchEvents(EventQueryParams queryParams, PageParams pagePar
// data value per data element. The same data element can be in the result set
// multiple times if the event also has notes.
String dataElementUid = resultSet.getString("de_uid");
if (!dataElementUids.contains(dataElementUid)) {
if (!dataElementUids.get(eventUid).contains(dataElementUid)) {
EventDataValue eventDataValue = parseEventDataValue(dataElementIdScheme, resultSet);
if (eventDataValue != null) {
event.getEventDataValues().add(eventDataValue);
dataElementUids.add(dataElementUid);
dataElementUids.get(eventUid).add(dataElementUid);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,27 @@ private Assertions() {
* @param actual the actual collection.
*/
public static <E> void assertContainsOnly(Collection<E> expected, Collection<E> actual) {
assertContainsOnly(expected, actual, "assertContainsOnly found mismatch");
}

/**
* Asserts that the given collection contains exactly the given items in any order.
*
* @param <E> the type.
* @param expected the expected items.
* @param actual the actual collection.
* @param heading the assertAll heading
*/
public static <E> void assertContainsOnly(
Collection<E> expected, Collection<E> actual, String heading) {
assertNotNull(
actual,
() -> String.format("Expected collection to contain %s, got null instead", expected));

List<E> missing = CollectionUtils.difference(expected, actual);
List<E> extra = CollectionUtils.difference(actual, expected);
assertAll(
"assertContainsOnly found mismatch",
heading,
() ->
assertTrue(
missing.isEmpty(), () -> String.format("Expected %s to be in %s", missing, actual)),
Expand Down
2 changes: 1 addition & 1 deletion dhis-2/dhis-test-e2e/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<awaitility.version>4.2.2</awaitility.version>
<lombok.version>1.18.36</lombok.version>
<allure.version>2.29.0</allure.version>
<selenium-java.version>4.26.0</selenium-java.version>
<selenium-java.version>4.27.0</selenium-java.version>
<slf4j-simple.version>2.0.16</slf4j-simple.version>
<fluent-hc.version>4.5.14</fluent-hc.version>
<httpclient5.version>5.4.1</httpclient5.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,18 @@
import org.hisp.dhis.attribute.Attribute;
import org.hisp.dhis.common.IdentifiableObject;
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.common.collection.CollectionUtils;
import org.hisp.dhis.dataelement.DataElement;
import org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundle;
import org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleMode;
import org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleParams;
import org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleService;
import org.hisp.dhis.dxf2.metadata.objectbundle.ObjectBundleValidationService;
import org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport;
import org.hisp.dhis.eventdatavalue.EventDataValue;
import org.hisp.dhis.http.HttpStatus;
import org.hisp.dhis.importexport.ImportStrategy;
import org.hisp.dhis.jsontree.JsonList;
import org.hisp.dhis.jsontree.JsonObject;
import org.hisp.dhis.program.Event;
import org.hisp.dhis.render.RenderFormat;
Expand Down Expand Up @@ -282,6 +285,35 @@ void shouldExportEventUsingNonUIDDataElementIdSchemeEvenIfItHasNoDataValues() {
assertEquals("jxgFyJEMUPf", actual.getEvent());
}

@Test
void shouldExportEventsUsingNonUIDDataElementIdScheme() {
Event event1 = get(Event.class, "QRYjLTiJTrA");
Event event2 = get(Event.class, "kWjSezkXHVp");
assertNotEmpty(
CollectionUtils.intersection(
event1.getEventDataValues().stream()
.map(EventDataValue::getDataElement)
.collect(Collectors.toSet()),
event2.getEventDataValues().stream()
.map(EventDataValue::getDataElement)
.collect(Collectors.toSet())),
"test expects both events to have at least one data value for the same data element");

JsonList<JsonEvent> jsonEvents =
GET("/tracker/events?events=QRYjLTiJTrA,kWjSezkXHVp&fields=event,dataValues&dataElementIdScheme=NAME")
.content(HttpStatus.OK)
.getList("events", JsonEvent.class);

Map<String, JsonEvent> events =
jsonEvents.stream().collect(Collectors.toMap(JsonEvent::getEvent, Function.identity()));
assertContainsOnly(List.of(event1.getUid(), event2.getUid()), events.keySet());

TrackerIdSchemeParam idSchemeParam = TrackerIdSchemeParam.NAME;
assertAll(
() -> assertDataValues(events.get("QRYjLTiJTrA"), event1, idSchemeParam),
() -> assertDataValues(events.get("kWjSezkXHVp"), event2, idSchemeParam));
}

@ParameterizedTest
@ValueSource(strings = {"/{id}?", "?events={id}&paging=true&", "?events={id}&paging=false&"})
void shouldReportMetadataWhichDoesNotHaveAnIdentifierForGivenIdScheme(String urlPortion) {
Expand Down Expand Up @@ -350,6 +382,35 @@ private static void assertIdScheme(
field, idSchemeParam));
}

private void assertDataValues(
JsonEvent actual, Event expected, TrackerIdSchemeParam idSchemeParam) {
String field = "dataValues";
List<String> expectedDataElement =
expected.getEventDataValues().stream()
.map(dv -> idSchemeParam.getIdentifier(get(DataElement.class, dv.getDataElement())))
.toList();
assertNotEmpty(
expectedDataElement,
String.format(
"metadata corresponding to field \"%s\" has no value in test data for"
+ " idScheme '%s'",
field, idSchemeParam));
assertTrue(
actual.has(field),
() ->
String.format(
"field \"%s\" is not in response %s for idScheme '%s'",
field, actual, idSchemeParam));
List<String> actualDataElement =
actual
.getList(field, JsonObject.class)
.toList(el -> el.getString("dataElement").string(""));
assertContainsOnly(
expectedDataElement,
actualDataElement,
"mismatch in data elements of event " + expected.getUid());
}

private <T extends IdentifiableObject> T get(Class<T> type, String uid) {
T t = manager.get(type, uid);
assertNotNull(
Expand Down
4 changes: 2 additions & 2 deletions dhis-2/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
<postgis-jdbc.version>2.5.1</postgis-jdbc.version>
<datasource-proxy.version>1.10.1</datasource-proxy.version>
<mysql-connector-j.version>9.1.0</mysql-connector-j.version>
<clickhouse-jdbc.version>0.7.1</clickhouse-jdbc.version>
<clickhouse-jdbc.version>0.7.1-patch1</clickhouse-jdbc.version>

<!-- Servlet -->
<jakarta.servlet-api.version>6.1.0</jakarta.servlet-api.version>
Expand Down Expand Up @@ -231,7 +231,7 @@
<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
<maven-exec-plugin.version>3.4.1</maven-exec-plugin.version>
<maven-resources-plugin.version>3.3.1</maven-resources-plugin.version>
<maven-failsafe-plugin.version>3.5.1</maven-failsafe-plugin.version>
<maven-failsafe-plugin.version>3.5.2</maven-failsafe-plugin.version>
<maven-javadoc-plugin.version>3.11.1</maven-javadoc-plugin.version>
<maven-antrun-plugin.version>3.1.0</maven-antrun-plugin.version>
<maven-enforcer-plugin.version>3.5.0</maven-enforcer-plugin.version>
Expand Down

0 comments on commit e58f104

Please sign in to comment.