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

refactor: Allow event columns to access SQL builder [DHIS2-16705] #19471

Merged
merged 66 commits into from
Dec 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
a1261b9
fix: Update code
larshelge Dec 2, 2024
bf145f6
fix: Update code
larshelge Dec 2, 2024
2c933d8
fix: Update code
larshelge Dec 2, 2024
754da7f
fix: Update code
larshelge Dec 2, 2024
5e164c7
fix: Update code
larshelge Dec 2, 2024
4edfd49
fix: Update code
larshelge Dec 2, 2024
c82b6f7
fix: Update code
larshelge Dec 2, 2024
aa7625b
fix: Update code
larshelge Dec 2, 2024
c0d12da
fix: Update code
larshelge Dec 2, 2024
392d07d
Merge branch 'master' into lars-dev
larshelge Dec 2, 2024
057cdf0
fix: Update code
larshelge Dec 2, 2024
60c8ad6
fix: Update code
larshelge Dec 2, 2024
ee780bb
fix: Update code
larshelge Dec 2, 2024
db9651b
fix: Update code
larshelge Dec 2, 2024
8002118
fix: Update code
larshelge Dec 2, 2024
7fc3b92
fix: Update code
larshelge Dec 2, 2024
43a69e3
fix: Update code
larshelge Dec 2, 2024
c2b8afc
Merge branch 'master' into lars-dev
larshelge Dec 2, 2024
3f162fb
fix: Update code
larshelge Dec 2, 2024
6024282
fix: Update code
larshelge Dec 2, 2024
35a8daa
fix: Update code
larshelge Dec 2, 2024
41ca710
fix: Update code
larshelge Dec 2, 2024
7d7360d
fix: Update code
larshelge Dec 2, 2024
4fff29e
fix: Update code
larshelge Dec 2, 2024
2125b91
fix: Update code
larshelge Dec 2, 2024
3858aa7
fix: Update code
larshelge Dec 2, 2024
64c4765
Merge branch 'master' into lars-dev
larshelge Dec 3, 2024
4a7452f
Revert "feat: skipAnalytics and ConfidentialFlag only for QUERY Analy…
larshelge Dec 4, 2024
a0fc292
Merge branch 'master' into lars-dev
larshelge Dec 4, 2024
1efcccc
Merge branch 'master' into lars-dev
larshelge Dec 4, 2024
f6a2245
Merge branch 'master' into lars-dev
larshelge Dec 4, 2024
e8ccde7
Merge branch 'master' into lars-dev
larshelge Dec 5, 2024
90aa73e
Merge branch 'master' into lars-dev
larshelge Dec 10, 2024
16429cc
fix: Update code
larshelge Dec 10, 2024
d0df6ce
Merge branch 'master' into lars-dev
larshelge Dec 10, 2024
912c69e
Merge branch 'master' into lars-dev
larshelge Dec 10, 2024
5dab606
Merge branch 'master' into lars-dev
larshelge Dec 11, 2024
ea86360
Merge branch 'master' into lars-dev
larshelge Dec 11, 2024
35a2526
fix: Update code
larshelge Dec 11, 2024
022ab1a
Merge branch 'master' into lars-dev
larshelge Dec 11, 2024
82deae7
fix: Update code
larshelge Dec 11, 2024
284e86a
fix: Update code
larshelge Dec 11, 2024
3608b81
fix: Update code
larshelge Dec 11, 2024
e47ed4d
fix: Update code
larshelge Dec 11, 2024
0f7e863
fix: Update code
larshelge Dec 11, 2024
fa5f410
Merge branch 'master' into lars-dev
larshelge Dec 11, 2024
86fb1aa
Merge branch 'master' into lars-dev
larshelge Dec 13, 2024
6ec2dcf
fix: Update code
larshelge Dec 13, 2024
5ad2770
Merge branch 'master' into lars-dev
larshelge Dec 13, 2024
2c6e9c4
fix: Update code
larshelge Dec 13, 2024
0cf2a4e
fix: Update code
larshelge Dec 13, 2024
00cd214
fix: Update code
larshelge Dec 13, 2024
dd44d68
fix: Update code
larshelge Dec 14, 2024
68ef8e0
fix: Update code
larshelge Dec 14, 2024
0d1f09e
fix: Update code
larshelge Dec 14, 2024
4756e64
fix: Update code
larshelge Dec 14, 2024
6029a06
fix: Update code
larshelge Dec 14, 2024
79e7a9c
fix: Update code
larshelge Dec 14, 2024
8144d52
fix: Update code
larshelge Dec 14, 2024
62ee0e2
fix: Update code
larshelge Dec 14, 2024
1795f7e
fix: Update code
larshelge Dec 14, 2024
deedbd0
Merge branch 'master' into lars-dev
larshelge Dec 14, 2024
64b3d07
Merge branch 'master' into lars-dev
larshelge Dec 15, 2024
02b523f
fix: Update code
larshelge Dec 15, 2024
3a368d1
fix: Update code
larshelge Dec 15, 2024
2a7b18f
fix: Update code
larshelge Dec 15, 2024
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 @@ -31,7 +31,6 @@

@NoArgsConstructor(access = lombok.AccessLevel.PRIVATE)
public final class EnrollmentAnalyticsColumnName {

public static final String ENROLLMENT_COLUMN_NAME = "enrollment";
public static final String TRACKED_ENTITY_COLUMN_NAME = "trackedentity";
public static final String ENROLLMENT_DATE_COLUMN_NAME = "enrollmentdate";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,137 +49,146 @@
@NoArgsConstructor(access = lombok.AccessLevel.PRIVATE)
public final class EnrollmentAnalyticsColumn {

private static final AnalyticsTableColumn ENROLLMENT =
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.ENROLLMENT_COLUMN_NAME)
.dataType(CHARACTER_11)
.nullable(NOT_NULL)
.selectExpression("en.uid")
.build();
static final AnalyticsTableColumn TRACKED_ENTITY =
public static final AnalyticsTableColumn TRACKED_ENTITY =
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.TRACKED_ENTITY_COLUMN_NAME)
.dataType(CHARACTER_11)
.selectExpression("te.uid")
.build();
private static final AnalyticsTableColumn ENROLLMENT_DATE =
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.ENROLLMENT_DATE_COLUMN_NAME)
.dataType(TIMESTAMP)
.selectExpression("en.enrollmentdate")
.build();
private static final AnalyticsTableColumn OCCURRED_DATE =
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.OCCURRED_DATE_COLUMN_NAME)
.dataType(TIMESTAMP)
.selectExpression("en.occurreddate")
.build();
private static final AnalyticsTableColumn COMPLETED_DATE =
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.COMPLETED_DATE_COLUMN_NAME)
.dataType(TIMESTAMP)
.selectExpression("case en.status when 'COMPLETED' then en.completeddate end")
.build();
private static final AnalyticsTableColumn LAST_UPDATED =
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.LAST_UPDATED_COLUMN_NAME)
.dataType(TIMESTAMP)
.selectExpression("en.lastupdated")
.build();
private static final AnalyticsTableColumn STORED_BY =
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.STORED_BY_COLUMN_NAME)
.dataType(VARCHAR_255)
.selectExpression("en.storedby")
.build();
private static final AnalyticsTableColumn ENROLLMENT_STATUS =
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.ENROLLMENT_STATUS_COLUMN_NAME)
.dataType(VARCHAR_50)
.selectExpression("en.status")
.build();
private static final AnalyticsTableColumn LONGITUDE =
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.LONGITUDE_COLUMN_NAME)
.dataType(DOUBLE)
.selectExpression(
"CASE WHEN 'POINT' = GeometryType(en.geometry) THEN ST_X(en.geometry) ELSE null END")
.build();
private static final AnalyticsTableColumn LATITUDE =
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.LATITUDE_COLUMN_NAME)
.dataType(DOUBLE)
.selectExpression(
"CASE WHEN 'POINT' = GeometryType(en.geometry) THEN ST_Y(en.geometry) ELSE null END")
.build();
private static final AnalyticsTableColumn OU =
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.OU_COLUMN_NAME)
.dataType(CHARACTER_11)
.nullable(NOT_NULL)
.selectExpression("ou.uid")
.build();
private static final AnalyticsTableColumn OU_NAME =
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.OU_NAME_COLUMN_NAME)
.dataType(TEXT)
.nullable(NOT_NULL)
.selectExpression("ou.name")
.build();
private static final AnalyticsTableColumn OU_CODE =
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.OU_CODE_COLUMN_NAME)
.dataType(TEXT)
.selectExpression("ou.code")
.build();
private static final AnalyticsTableColumn OU_LEVEL =
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.OU_LEVEL_COLUMN_NAME)
.dataType(INTEGER)
.selectExpression("ous.level")
.build();
private static final AnalyticsTableColumn ENROLLMENT_GEOMETRY =
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.ENROLLMENT_GEOMETRY_COLUMN_NAME)
.dataType(GEOMETRY)
.selectExpression("en.geometry")
.indexType(IndexType.GIST)
.build();
private static final AnalyticsTableColumn REGISTRATION_OU =
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.REGISTRATION_OU_COLUMN_NAME)
.dataType(CHARACTER_11)
.nullable(NOT_NULL)
.selectExpression("coalesce(registrationou.uid,ou.uid)")
.build();
static final AnalyticsTableColumn TRACKED_ENTITY_GEOMETRY =
public static final AnalyticsTableColumn TRACKED_ENTITY_GEOMETRY =
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.TRACKED_ENTITY_GEOMETRY_COLUMN_NAME)
.dataType(GEOMETRY)
.selectExpression("te.geometry")
.build();

private static final List<AnalyticsTableColumn> COMMON_COLUMNS =
List.of(
ENROLLMENT,
ENROLLMENT_DATE,
OCCURRED_DATE,
COMPLETED_DATE,
LAST_UPDATED,
STORED_BY,
ENROLLMENT_STATUS,
OU,
OU_NAME,
OU_CODE,
OU_LEVEL,
REGISTRATION_OU);
/**
* Returns a list of {@link AnalyticsTableColumn}.
*
* @param sqlBuilder the {@link SqlBuilder}.
* @return a list of {@link AnalyticsTableColumn}.
*/
public static List<AnalyticsTableColumn> getColumns(SqlBuilder sqlBuilder) {
List<AnalyticsTableColumn> columns = new ArrayList<>();
columns.addAll(getCommonColumns(sqlBuilder));
columns.addAll(getJsonColumns(sqlBuilder));

if (sqlBuilder.supportsGeospatialData()) {
columns.addAll(getGeometryColumns(sqlBuilder));
}

return columns;
}

// Geometry-specific columns
private static final List<AnalyticsTableColumn> GEOMETRY_COLUMNS =
List.of(ENROLLMENT_GEOMETRY, LONGITUDE, LATITUDE);
/**
* Returns a list of {@link AnalyticsTableColumn}.
*
* @param sqlBuilder the {@link SqlBuilder}.
* @return a list of {@link AnalyticsTableColumn}.
*/
private static List<AnalyticsTableColumn> getCommonColumns(SqlBuilder sqlBuilder) {

Check notice

Code scanning / CodeQL

Useless parameter Note

The parameter 'sqlBuilder' is never used.
return List.of(
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.ENROLLMENT_COLUMN_NAME)
.dataType(CHARACTER_11)
.nullable(NOT_NULL)
.selectExpression("en.uid")
.build(),
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.ENROLLMENT_DATE_COLUMN_NAME)
.dataType(TIMESTAMP)
.selectExpression("en.enrollmentdate")
.build(),
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.OCCURRED_DATE_COLUMN_NAME)
.dataType(TIMESTAMP)
.selectExpression("en.occurreddate")
.build(),
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.COMPLETED_DATE_COLUMN_NAME)
.dataType(TIMESTAMP)
.selectExpression("case en.status when 'COMPLETED' then en.completeddate end")
.build(),
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.LAST_UPDATED_COLUMN_NAME)
.dataType(TIMESTAMP)
.selectExpression("en.lastupdated")
.build(),
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.STORED_BY_COLUMN_NAME)
.dataType(VARCHAR_255)
.selectExpression("en.storedby")
.build(),
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.ENROLLMENT_STATUS_COLUMN_NAME)
.dataType(VARCHAR_50)
.selectExpression("en.status")
.build(),
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.OU_COLUMN_NAME)
.dataType(CHARACTER_11)
.nullable(NOT_NULL)
.selectExpression("ou.uid")
.build(),
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.OU_NAME_COLUMN_NAME)
.dataType(TEXT)
.nullable(NOT_NULL)
.selectExpression("ou.name")
.build(),
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.OU_CODE_COLUMN_NAME)
.dataType(TEXT)
.selectExpression("ou.code")
.build(),
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.OU_LEVEL_COLUMN_NAME)
.dataType(INTEGER)
.selectExpression("ous.level")
.build(),
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.REGISTRATION_OU_COLUMN_NAME)
.dataType(CHARACTER_11)
.nullable(NOT_NULL)
.selectExpression("coalesce(registrationou.uid,ou.uid)")
.build());
}

private static List<AnalyticsTableColumn> createJsonColumns(SqlBuilder sqlBuilder) {
/**
* Returns a list of geometry {@link AnalyticsTableColumn}.
*
* @param sqlBuilder the {@link SqlBuilder}.
* @return a list of {@link AnalyticsTableColumn}.
*/
private static List<AnalyticsTableColumn> getGeometryColumns(SqlBuilder sqlBuilder) {

Check notice

Code scanning / CodeQL

Useless parameter Note

The parameter 'sqlBuilder' is never used.
return List.of(
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.ENROLLMENT_GEOMETRY_COLUMN_NAME)
.dataType(GEOMETRY)
.selectExpression("en.geometry")
.indexType(IndexType.GIST)
.build(),
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.LONGITUDE_COLUMN_NAME)
.dataType(DOUBLE)
.selectExpression(
"CASE WHEN 'POINT' = GeometryType(en.geometry) THEN ST_X(en.geometry) ELSE null END")
.build(),
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.LATITUDE_COLUMN_NAME)
.dataType(DOUBLE)
.selectExpression(
"CASE WHEN 'POINT' = GeometryType(en.geometry) THEN ST_Y(en.geometry) ELSE null END")
.build());
}

/**
* Returns a list of {@link AnalyticsTableColumn}.
*
* @param sqlBuilder the {@link SqlBuilder}.
* @return a list of {@link AnalyticsTableColumn}.
*/
private static List<AnalyticsTableColumn> getJsonColumns(SqlBuilder sqlBuilder) {
return List.of(
AnalyticsTableColumn.builder()
.name(EnrollmentAnalyticsColumnName.CREATED_BY_USERNAME_COLUMN_NAME)
Expand Down Expand Up @@ -241,14 +250,4 @@
.skipIndex(Skip.SKIP)
.build());
}

public static List<AnalyticsTableColumn> getColumns(SqlBuilder sqlBuilder) {
List<AnalyticsTableColumn> columns = new ArrayList<>(COMMON_COLUMNS);
columns.addAll(createJsonColumns(sqlBuilder));
// Add database-specific columns based on SqlBuilder capabilities
if (sqlBuilder.supportsGeospatialData()) {
columns.addAll(GEOMETRY_COLUMNS);
}
return columns;
}
}
Loading
Loading