Skip to content

Commit

Permalink
feat: Import one object in test[DHIS2-18474]
Browse files Browse the repository at this point in the history
  • Loading branch information
muilpp committed Nov 27, 2024
1 parent f801ff3 commit 1f4131d
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 906 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -446,51 +446,77 @@ private void updateDataValue(String event, String dataElementUid, String newValu
trackerObjects.getEvents().stream()
.filter(e -> e.getEvent().getValue().equalsIgnoreCase(event))
.findFirst()
.flatMap(
e ->
e.getDataValues().stream()
.filter(
dv -> dv.getDataElement().getIdentifier().equalsIgnoreCase(dataElementUid))
.findFirst())
.ifPresent(dv -> dv.setValue(newValue));
assertNoErrors(trackerImportService.importTracker(importParams, trackerObjects));
.ifPresent(
e -> {
e.getDataValues().stream()
.filter(
dv -> dv.getDataElement().getIdentifier().equalsIgnoreCase(dataElementUid))
.findFirst()
.ifPresent(dv -> dv.setValue(newValue));

assertNoErrors(
trackerImportService.importTracker(
importParams, TrackerObjects.builder().events(List.of(e)).build()));
});
}

private void updateEventDates(UID event, Instant newDate) throws IOException {
TrackerObjects trackerObjects = fromJson("tracker/event_and_enrollment.json");

trackerObjects.getEvents().stream()
.filter(e -> e.getEvent().equals(event))
.findFirst()
.ifPresent(
e -> {
e.setOccurredAt(newDate);
e.setScheduledAt(newDate);

assertNoErrors(
trackerImportService.importTracker(
importParams, TrackerObjects.builder().events(List.of(e)).build()));
});
assertNoErrors(trackerImportService.importTracker(importParams, trackerObjects));
}

private void deleteScheduledAtDate(UID event) {
trackerObjects.getEvents().stream()
.filter(e -> e.getEvent().equals(event))
.findFirst()
.ifPresent(e -> e.setScheduledAt(null));
assertNoErrors(trackerImportService.importTracker(importParams, trackerObjects));
.ifPresent(
e -> {
e.setScheduledAt(null);

assertNoErrors(
trackerImportService.importTracker(
importParams, TrackerObjects.builder().events(List.of(e)).build()));
});
}

private void updateEventGeometry(UID event, Geometry newGeometry) {
trackerObjects.getEvents().stream()
.filter(e -> e.getEvent().equals(event))
.findFirst()
.ifPresent(e -> e.setGeometry(newGeometry));
assertNoErrors(trackerImportService.importTracker(importParams, trackerObjects));
.ifPresent(
e -> {
e.setGeometry(newGeometry);

assertNoErrors(
trackerImportService.importTracker(
importParams, TrackerObjects.builder().events(List.of(e)).build()));
});
}

private void deleteEventGeometry(UID event) {
trackerObjects.getEvents().stream()
.filter(e -> e.getEvent().equals(event))
.findFirst()
.ifPresent(e -> e.setGeometry(null));
assertNoErrors(trackerImportService.importTracker(importParams, trackerObjects));
.ifPresent(
e -> {
e.setGeometry(null);

assertNoErrors(
trackerImportService.importTracker(
importParams, TrackerObjects.builder().events(List.of(e)).build()));
});
}

private String getDataElement(String uid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,27 +330,35 @@ private void updateDataValue(String event, String dataElementUid, String newValu
trackerObjects.getEvents().stream()
.filter(e -> e.getEvent().getValue().equalsIgnoreCase(event))
.findFirst()
.flatMap(
e ->
e.getDataValues().stream()
.filter(
dv -> dv.getDataElement().getIdentifier().equalsIgnoreCase(dataElementUid))
.findFirst())
.ifPresent(dv -> dv.setValue(newValue));
assertNoErrors(trackerImportService.importTracker(importParams, trackerObjects));
.ifPresent(
e -> {
e.getDataValues().stream()
.filter(
dv -> dv.getDataElement().getIdentifier().equalsIgnoreCase(dataElementUid))
.findFirst()
.ifPresent(dataValue -> dataValue.setValue(newValue));

assertNoErrors(
trackerImportService.importTracker(
importParams, TrackerObjects.builder().events(List.of(e)).build()));
});
}

private void updateEventDates(UID event, Instant newDate) throws IOException {
TrackerObjects trackerObjects = fromJson("tracker/event_and_enrollment.json");

trackerObjects.getEvents().stream()
.filter(e -> e.getEvent().equals(event))
.findFirst()
.ifPresent(
e -> {
e.setOccurredAt(newDate);
e.setScheduledAt(newDate);

assertNoErrors(
trackerImportService.importTracker(
importParams, TrackerObjects.builder().events(List.of(e)).build()));
});
assertNoErrors(trackerImportService.importTracker(importParams, trackerObjects));
}

private Event getEvent(String uid) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,27 +319,23 @@ private void assertUser(User user, TrackedEntityChangeLog changeLog) {

private void updateAttributeValue(
String trackedEntity, String trackedEntityAttribute, String newValue) {
List<org.hisp.dhis.tracker.imports.domain.TrackedEntity> trackedEntities =
trackerObjects.getTrackedEntities().stream()
.filter(t -> t.getTrackedEntity().getValue().equalsIgnoreCase(trackedEntity))
.findFirst()
.stream()
.toList();

trackedEntities.stream()
.flatMap(
t ->
t.getAttributes().stream()
.filter(
tea ->
tea.getAttribute()
.getIdentifier()
.equalsIgnoreCase(trackedEntityAttribute)))
trackerObjects.getTrackedEntities().stream()
.filter(t -> t.getTrackedEntity().getValue().equalsIgnoreCase(trackedEntity))
.findFirst()
.ifPresent(tea -> tea.setValue(newValue));

assertNoErrors(
trackerImportService.importTracker(
importParams, TrackerObjects.builder().trackedEntities(trackedEntities).build()));
.ifPresent(
t -> {
t.getAttributes().stream()
.filter(
tea ->
tea.getAttribute()
.getIdentifier()
.equalsIgnoreCase(trackedEntityAttribute))
.findFirst()
.ifPresent(attribute -> attribute.setValue(newValue));

assertNoErrors(
trackerImportService.importTracker(
importParams, TrackerObjects.builder().trackedEntities(List.of(t)).build()));
});
}
}

This file was deleted.

Loading

0 comments on commit 1f4131d

Please sign in to comment.