Skip to content

Commit

Permalink
chore: Update default values in Tracker importer OpenAPI [TECH-1580] (#…
Browse files Browse the repository at this point in the history
…15725)

* chore: Update default values in Tracker importer OpenAPI [TECH-1580]

* Fix formatting

* feat: Add atClient dates order capabilities for events [DHIS2-15900]

* chore: Update default values in Tracker importer OpenAPI [TECH-1580]

* chore: Update default values in Tracker importer OpenAPI [TECH-1580]
  • Loading branch information
enricocolasante authored Nov 27, 2023
1 parent 1e3f986 commit 534dea4
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ class JdbcEventStore implements EventStore {
private static final String COLUMN_EVENT_LAST_UPDATED_BY = "ev_lastupdatedbyuserinfo";
private static final String COLUMN_EVENT_CREATED_BY = "ev_createdbyuserinfo";
private static final String COLUMN_EVENT_CREATED = "ev_created";
private static final String COLUMN_EVENT_CREATED_AT_CLIENT = "ev_createdatclient";
private static final String COLUMN_EVENT_LAST_UPDATED = "ev_lastupdated";
private static final String COLUMN_EVENT_LAST_UPDATED_AT_CLIENT = "ev_lastupdatedatclient";
private static final String COLUMN_EVENT_COMPLETED_BY = "ev_completedby";
private static final String COLUMN_EVENT_ATTRIBUTE_OPTION_COMBO_UID = "coc_uid";
private static final String COLUMN_EVENT_COMPLETED_DATE = "ev_completeddate";
Expand Down Expand Up @@ -206,7 +208,9 @@ class JdbcEventStore implements EventStore {
entry("lastUpdatedBy", COLUMN_EVENT_LAST_UPDATED_BY),
entry("createdBy", COLUMN_EVENT_CREATED_BY),
entry("created", COLUMN_EVENT_CREATED),
entry("createdAtClient", COLUMN_EVENT_CREATED_AT_CLIENT),
entry("lastUpdated", COLUMN_EVENT_LAST_UPDATED),
entry("lastUpdatedAtClient", COLUMN_EVENT_LAST_UPDATED_AT_CLIENT),
entry("completedBy", COLUMN_EVENT_COMPLETED_BY),
entry("attributeOptionCombo.uid", COLUMN_EVENT_ATTRIBUTE_OPTION_COMBO_UID),
entry("completedDate", COLUMN_EVENT_COMPLETED_DATE),
Expand Down Expand Up @@ -329,10 +333,13 @@ private List<Event> fetchEvents(EventQueryParams queryParams, PageParams pagePar
event.setScheduledDate(resultSet.getTimestamp(COLUMN_EVENT_SCHEDULED_DATE));
event.setOccurredDate(resultSet.getTimestamp(COLUMN_EVENT_OCCURRED_DATE));
event.setCreated(resultSet.getTimestamp(COLUMN_EVENT_CREATED));
event.setCreatedAtClient(resultSet.getTimestamp(COLUMN_EVENT_CREATED_AT_CLIENT));
event.setCreatedByUserInfo(
EventUtils.jsonToUserInfo(
resultSet.getString(COLUMN_EVENT_CREATED_BY), jsonMapper));
event.setLastUpdated(resultSet.getTimestamp(COLUMN_EVENT_LAST_UPDATED));
event.setLastUpdatedAtClient(
resultSet.getTimestamp(COLUMN_EVENT_LAST_UPDATED_AT_CLIENT));
event.setLastUpdatedByUserInfo(
EventUtils.jsonToUserInfo(
resultSet.getString(COLUMN_EVENT_LAST_UPDATED_BY), jsonMapper));
Expand Down Expand Up @@ -745,10 +752,15 @@ private String getEventSelectQuery(
.append(", ")
.append("ev.created as ")
.append(COLUMN_EVENT_CREATED)
.append(", ")
.append("ev.createdatclient as ")
.append(COLUMN_EVENT_CREATED_AT_CLIENT)
.append(", ev.createdbyuserinfo as ")
.append(COLUMN_EVENT_CREATED_BY)
.append(", ev.lastupdated as ")
.append(COLUMN_EVENT_LAST_UPDATED)
.append(", ev.lastupdatedatclient as ")
.append(COLUMN_EVENT_LAST_UPDATED_AT_CLIENT)
.append(", ev.lastupdatedbyuserinfo as ")
.append(COLUMN_EVENT_LAST_UPDATED_BY)
.append(", ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public interface EventMapper
entry("completedAt", "completedDate"),
entry("completedBy", "completedBy"),
entry("createdAt", "created"),
entry("createdAtClient", "createdAtClient"),
entry("createdBy", "createdBy"),
entry("deleted", "deleted"),
entry("enrolledAt", "enrollment.enrollmentDate"),
Expand All @@ -81,6 +82,7 @@ public interface EventMapper
entry("storedBy", "storedBy"),
entry("trackedEntity", "enrollment.trackedEntity.uid"),
entry("updatedAt", "lastUpdated"),
entry("updatedAtClient", "lastUpdatedAtClient"),
entry("updatedBy", "lastUpdatedBy"));

@Mapping(target = "event", source = "uid")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
@NoArgsConstructor
@AllArgsConstructor
@Builder
class RequestParams {
public class ImportRequestParams {
/** Should import be imported or just validated. */
@JsonProperty @Builder.Default private TrackerBundleMode importMode = TrackerBundleMode.COMMIT;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ public class TrackerImportController {
@ResponseBody
public WebMessage asyncPostJsonTracker(
HttpServletRequest request,
RequestParams requestParams,
ImportRequestParams importRequestParams,
@CurrentUser User currentUser,
@RequestBody Body body)
throws ConflictException, NotFoundException, IOException {
TrackerImportParams trackerImportParams =
TrackerImportParamsMapper.trackerImportParams(currentUser.getUid(), requestParams);
TrackerImportParamsMapper.trackerImportParams(currentUser.getUid(), importRequestParams);
TrackerObjects trackerObjects =
TrackerImportParamsMapper.trackerObjects(body, trackerImportParams.getIdSchemes());

Expand Down Expand Up @@ -151,9 +151,11 @@ private WebMessage startAsyncTracker(
consumes = APPLICATION_JSON_VALUE,
params = {"async=false"})
public ResponseEntity<ImportReport> syncPostJsonTracker(
RequestParams requestParams, @CurrentUser User currentUser, @RequestBody Body body) {
ImportRequestParams importRequestParams,
@CurrentUser User currentUser,
@RequestBody Body body) {
TrackerImportParams params =
TrackerImportParamsMapper.trackerImportParams(currentUser.getUid(), requestParams);
TrackerImportParamsMapper.trackerImportParams(currentUser.getUid(), importRequestParams);
TrackerObjects trackerObjects =
TrackerImportParamsMapper.trackerObjects(body, params.getIdSchemes());
ImportReport importReport =
Expand All @@ -175,7 +177,7 @@ public ResponseEntity<ImportReport> syncPostJsonTracker(
@ResponseBody
public WebMessage asyncPostCsvTracker(
HttpServletRequest request,
RequestParams importRequest,
ImportRequestParams importRequest,
@CurrentUser User currentUser,
@RequestParam(required = false, defaultValue = "true") boolean skipFirst)
throws IOException, ParseException, ConflictException, NotFoundException {
Expand Down Expand Up @@ -206,7 +208,7 @@ public WebMessage asyncPostCsvTracker(
params = {"async=false"})
public ResponseEntity<ImportReport> syncPostCsvTracker(
HttpServletRequest request,
RequestParams importRequest,
ImportRequestParams importRequest,
@RequestParam(required = false, defaultValue = "true") boolean skipFirst,
@RequestParam(defaultValue = "errors", required = false) TrackerBundleReportMode reportMode,
@CurrentUser User currentUser)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public static TrackerObjects trackerObjects(Body body, TrackerIdSchemeParams idS

private TrackerImportParamsMapper() {}

public static TrackerImportParams trackerImportParams(String userId, RequestParams request) {
public static TrackerImportParams trackerImportParams(
String userId, ImportRequestParams request) {
TrackerIdSchemeParam defaultIdSchemeParam = request.getIdScheme();
TrackerIdSchemeParams idSchemeParams =
TrackerIdSchemeParams.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
import org.junit.jupiter.params.provider.ValueSource;

/** Tests {@link RequestParamsValidator}. */
class RequestParamsValidatorTest {
class ImportRequestParamsValidatorTest {

private static final String TEA_1_UID = "TvjwTPToKHO";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import lombok.Data;
import org.junit.jupiter.api.Test;

class PageRequestParamsTest {
class PageImportRequestParamsTest {

@Data
private static class PaginationParameters implements PageRequestParams {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

@MockitoSettings(strictness = Strictness.LENIENT) // common setup
@ExtendWith(MockitoExtension.class)
class EnrollmentRequestParamsMapperTest {
class EnrollmentImportRequestParamsMapperTest {

private static final String ORG_UNIT_1_UID = "lW0T2U7gZUi";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@

@MockitoSettings(strictness = Strictness.LENIENT) // common setup
@ExtendWith(MockitoExtension.class)
class EventRequestParamsMapperTest {
class EventImportRequestParamsMapperTest {

private static final String DE_1_UID = "OBzmpRP6YUh";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import org.hisp.dhis.webapi.controller.event.webrequest.OrderCriteria;
import org.junit.jupiter.api.Test;

class RelationshipRequestParamsMapperTest {
class RelationshipImportRequestParamsMapperTest {

private final RelationshipRequestParamsMapper mapper = new RelationshipRequestParamsMapper();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
import org.mockito.junit.jupiter.MockitoExtension;

@ExtendWith(MockitoExtension.class)
class TrackedEntityRequestParamsMapperTest {
class TrackedEntityImportRequestParamsMapperTest {
public static final String TEA_1_UID = "TvjwTPToKHO";

public static final String TEA_2_UID = "cy2oRh2sNr6";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,10 @@ void testValidationMode() {
Arrays.stream(ValidationMode.values())
.forEach(
e -> {
RequestParams requestParams = RequestParams.builder().validationMode(e).build();
ImportRequestParams importRequestParams =
ImportRequestParams.builder().validationMode(e).build();
TrackerImportParams params =
TrackerImportParamsMapper.trackerImportParams("userId", requestParams);
TrackerImportParamsMapper.trackerImportParams("userId", importRequestParams);
assertThat(params.getValidationMode(), is(e));
});
}
Expand All @@ -73,9 +74,10 @@ void testImportMode() {
Arrays.stream(TrackerBundleMode.values())
.forEach(
e -> {
RequestParams requestParams = RequestParams.builder().importMode(e).build();
ImportRequestParams importRequestParams =
ImportRequestParams.builder().importMode(e).build();
TrackerImportParams params =
TrackerImportParamsMapper.trackerImportParams("userId", requestParams);
TrackerImportParamsMapper.trackerImportParams("userId", importRequestParams);
assertThat(params.getImportMode(), is(e));
});
}
Expand All @@ -85,9 +87,10 @@ void testAtomicMode() {
Arrays.stream(AtomicMode.values())
.forEach(
e -> {
RequestParams requestParams = RequestParams.builder().atomicMode(e).build();
ImportRequestParams importRequestParams =
ImportRequestParams.builder().atomicMode(e).build();
TrackerImportParams params =
TrackerImportParamsMapper.trackerImportParams("userId", requestParams);
TrackerImportParamsMapper.trackerImportParams("userId", importRequestParams);
assertThat(params.getAtomicMode(), is(e));
});
}
Expand All @@ -97,9 +100,10 @@ void testFlushMode() {
Arrays.stream(FlushMode.values())
.forEach(
e -> {
RequestParams requestParams = RequestParams.builder().flushMode(e).build();
ImportRequestParams importRequestParams =
ImportRequestParams.builder().flushMode(e).build();
TrackerImportParams params =
TrackerImportParamsMapper.trackerImportParams("userId", requestParams);
TrackerImportParamsMapper.trackerImportParams("userId", importRequestParams);
assertThat(params.getFlushMode(), is(e));
});
}
Expand All @@ -109,19 +113,20 @@ void testImportStrategy() {
Arrays.stream(TrackerImportStrategy.values())
.forEach(
e -> {
RequestParams requestParams = RequestParams.builder().importStrategy(e).build();
ImportRequestParams importRequestParams =
ImportRequestParams.builder().importStrategy(e).build();
TrackerImportParams params =
TrackerImportParamsMapper.trackerImportParams("userId", requestParams);
TrackerImportParamsMapper.trackerImportParams("userId", importRequestParams);
assertThat(params.getImportStrategy(), is(e));
});
}

@Test
void testIdSchemeUsingIdSchemeName() {
RequestParams requestParams =
RequestParams.builder().idScheme(TrackerIdSchemeParam.NAME).build();
ImportRequestParams importRequestParams =
ImportRequestParams.builder().idScheme(TrackerIdSchemeParam.NAME).build();
TrackerImportParams params =
TrackerImportParamsMapper.trackerImportParams("userId", requestParams);
TrackerImportParamsMapper.trackerImportParams("userId", importRequestParams);

TrackerIdSchemeParam expected = TrackerIdSchemeParam.NAME;
assertEquals(expected, params.getIdSchemes().getIdScheme());
Expand All @@ -135,10 +140,12 @@ void testIdSchemeUsingIdSchemeName() {

@Test
void testIdSchemeUsingIdSchemeAttribute() {
RequestParams requestParams =
RequestParams.builder().idScheme(TrackerIdSchemeParam.ofAttribute("WSiOAALYocA")).build();
ImportRequestParams importRequestParams =
ImportRequestParams.builder()
.idScheme(TrackerIdSchemeParam.ofAttribute("WSiOAALYocA"))
.build();
TrackerImportParams params =
TrackerImportParamsMapper.trackerImportParams("userId", requestParams);
TrackerImportParamsMapper.trackerImportParams("userId", importRequestParams);

TrackerIdSchemeParam expected = TrackerIdSchemeParam.ofAttribute("WSiOAALYocA");
assertEquals(expected, params.getIdSchemes().getIdScheme());
Expand All @@ -155,9 +162,10 @@ void testOrgUnitIdentifier() {
idSchemeParams()
.forEach(
e -> {
RequestParams requestParams = RequestParams.builder().orgUnitIdScheme(e).build();
ImportRequestParams importRequestParams =
ImportRequestParams.builder().orgUnitIdScheme(e).build();
TrackerImportParams params =
TrackerImportParamsMapper.trackerImportParams("userId", requestParams);
TrackerImportParamsMapper.trackerImportParams("userId", importRequestParams);
assertThat(
params.getIdSchemes().getOrgUnitIdScheme().getIdScheme(), is(e.getIdScheme()));
});
Expand All @@ -168,22 +176,23 @@ void testProgramIdentifier() {
idSchemeParams()
.forEach(
e -> {
RequestParams requestParams = RequestParams.builder().programIdScheme(e).build();
ImportRequestParams importRequestParams =
ImportRequestParams.builder().programIdScheme(e).build();
TrackerImportParams params =
TrackerImportParamsMapper.trackerImportParams("userId", requestParams);
TrackerImportParamsMapper.trackerImportParams("userId", importRequestParams);
assertThat(
params.getIdSchemes().getProgramIdScheme().getIdScheme(), is(e.getIdScheme()));
});
}

@Test
void testProgramIdentifierUsingIdSchemeAttribute() {
RequestParams requestParams =
RequestParams.builder()
ImportRequestParams importRequestParams =
ImportRequestParams.builder()
.programIdScheme(TrackerIdSchemeParam.ofAttribute("WSiOAALYocA"))
.build();
TrackerImportParams params =
TrackerImportParamsMapper.trackerImportParams("userId", requestParams);
TrackerImportParamsMapper.trackerImportParams("userId", importRequestParams);

assertEquals(
TrackerIdSchemeParam.ofAttribute("WSiOAALYocA"),
Expand All @@ -195,9 +204,10 @@ void testProgramStageIdentifier() {
idSchemeParams()
.forEach(
e -> {
RequestParams requestParams = RequestParams.builder().programStageIdScheme(e).build();
ImportRequestParams importRequestParams =
ImportRequestParams.builder().programStageIdScheme(e).build();
TrackerImportParams params =
TrackerImportParamsMapper.trackerImportParams("userId", requestParams);
TrackerImportParamsMapper.trackerImportParams("userId", importRequestParams);
assertThat(
params.getIdSchemes().getProgramStageIdScheme().getIdScheme(),
is(e.getIdScheme()));
Expand All @@ -209,9 +219,10 @@ void testDataElementIdentifier() {
idSchemeParams()
.forEach(
e -> {
RequestParams requestParams = RequestParams.builder().dataElementIdScheme(e).build();
ImportRequestParams importRequestParams =
ImportRequestParams.builder().dataElementIdScheme(e).build();
TrackerImportParams params =
TrackerImportParamsMapper.trackerImportParams("userId", requestParams);
TrackerImportParamsMapper.trackerImportParams("userId", importRequestParams);
assertThat(
params.getIdSchemes().getDataElementIdScheme().getIdScheme(),
is(e.getIdScheme()));
Expand All @@ -223,10 +234,10 @@ void testCategoryOptionComboIdentifier() {
idSchemeParams()
.forEach(
e -> {
RequestParams requestParams =
RequestParams.builder().categoryOptionComboIdScheme(e).build();
ImportRequestParams importRequestParams =
ImportRequestParams.builder().categoryOptionComboIdScheme(e).build();
TrackerImportParams params =
TrackerImportParamsMapper.trackerImportParams("userId", requestParams);
TrackerImportParamsMapper.trackerImportParams("userId", importRequestParams);
assertThat(
params.getIdSchemes().getCategoryOptionComboIdScheme().getIdScheme(),
is(e.getIdScheme()));
Expand All @@ -238,10 +249,10 @@ void testCategoryOptionIdentifier() {
idSchemeParams()
.forEach(
e -> {
RequestParams requestParams =
RequestParams.builder().categoryOptionIdScheme(e).build();
ImportRequestParams importRequestParams =
ImportRequestParams.builder().categoryOptionIdScheme(e).build();
TrackerImportParams params =
TrackerImportParamsMapper.trackerImportParams("userId", requestParams);
TrackerImportParamsMapper.trackerImportParams("userId", importRequestParams);
assertThat(
params.getIdSchemes().getCategoryOptionIdScheme().getIdScheme(),
is(e.getIdScheme()));
Expand Down

0 comments on commit 534dea4

Please sign in to comment.