Skip to content

Commit

Permalink
fix: Update code
Browse files Browse the repository at this point in the history
  • Loading branch information
larshelge committed Nov 26, 2024
1 parent a7d2298 commit 098c071
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,12 @@ private List<AnalyticsTableColumn> getColumns(Program program) {
return filterDimensionColumns(columns);
}

protected AnalyticsTableColumn getPartitionColumn() {
/**
* Returns a partition column.
*
* @return an {@link AnalyticsTableColumn}.
*/
private AnalyticsTableColumn getPartitionColumn() {
return AnalyticsTableColumn.builder()
.name("year")
.dataType(INTEGER)
Expand Down Expand Up @@ -513,6 +518,13 @@ private List<AnalyticsTableColumn> getColumnForDataElement(
: columns;
}

/**
* Returns a list of columns.
*
* @param dataElement the {@link DataElement}.
* @param dataFilterClause the data filter SQL clause.
* @return a list of {@link AnalyticsTableColumn}.
*/
private List<AnalyticsTableColumn> getColumnForOrgUnitDataElement(
DataElement dataElement, String dataFilterClause) {
List<AnalyticsTableColumn> columns = new ArrayList<>();
Expand Down Expand Up @@ -561,12 +573,12 @@ private List<AnalyticsTableColumn> getAttributeColumns(Program program) {
List<AnalyticsTableColumn> columns = new ArrayList<>();
columns.addAll(
program.getNonConfidentialTrackedEntityAttributes().stream()
.map(tea -> getColumnForTrackedEntityAttribute(tea, false))
.map(tea -> getColumnForAttribute(tea))
.flatMap(Collection::stream)
.toList());
columns.addAll(
program.getNonConfidentialTrackedEntityAttributesWithLegendSet().stream()
.map(tea -> getColumnForTrackedEntityAttribute(tea, true))
.map(tea -> getColumnForAttributeWithLegendSet(tea))
.flatMap(Collection::stream)
.toList());
return columns;
Expand All @@ -579,8 +591,7 @@ private List<AnalyticsTableColumn> getAttributeColumns(Program program) {
* @param withLegendSet indicates whether the attribute has a legend set.
* @return a list of {@link AnaylyticsTableColumn}.
*/
private List<AnalyticsTableColumn> getColumnForTrackedEntityAttribute(
TrackedEntityAttribute attribute, boolean withLegendSet) {
private List<AnalyticsTableColumn> getColumnForAttribute(TrackedEntityAttribute attribute) {
List<AnalyticsTableColumn> columns = new ArrayList<>();

DataType dataType = getColumnType(attribute.getValueType(), isSpatialSupport());
Expand All @@ -602,7 +613,7 @@ private List<AnalyticsTableColumn> getColumnForTrackedEntityAttribute(
.skipIndex(skipIndex)
.build());

return withLegendSet ? getColumnForAttributeWithLegendSet(attribute) : columns;
return columns;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,15 +237,12 @@ private List<AnalyticsTableColumn> getColumns(
private Stream<TrackedEntityAttribute> getAllTrackedEntityAttributes(
TrackedEntityType trackedEntityType, Map<String, List<Program>> programsByTetUid) {

// Given TET has program(s) defined.
if (programsByTetUid.containsKey(trackedEntityType.getUid())) {

// Programs defined for TET -> get attr from program and TET.
return getAllTrackedEntityAttributesByPrograms(
trackedEntityType, programsByTetUid.get(trackedEntityType.getUid()));
}

// No programs defined for TET -> get only attributes from TET.
return getAllTrackedEntityAttributesByEntityType(trackedEntityType);
}

Expand Down Expand Up @@ -297,9 +294,7 @@ private String castBasedOnType(ValueType valueType, String columnName) {
private Stream<TrackedEntityAttribute> getAllTrackedEntityAttributesByPrograms(
TrackedEntityType trackedEntityType, List<Program> programs) {
return Stream.concat(
/* all attributes of programs */
trackedEntityAttributeService.getProgramTrackedEntityAttributes(programs).stream(),
/* all attributes of the trackedEntityType */
getAllTrackedEntityAttributesByEntityType(trackedEntityType))
.distinct();
}
Expand Down Expand Up @@ -374,8 +369,8 @@ public void populateTable(AnalyticsTableUpdateParams params, AnalyticsTableParti
sql.append(
replaceQualify(
"""
\s left join ${trackedentityattributevalue} ${teaUid} on ${teaUid}.trackedentityid=te.trackedentityid \
and ${teaUid}.trackedentityattributeid = ${teaId}""",
\s left join ${trackedentityattributevalue} ${teaUid} on ${teaUid}.trackedentityid=te.trackedentityid \
and ${teaUid}.trackedentityattributeid = ${teaId}""",
Map.of(
"teaUid", quote(tea.getUid()),
"teaId", String.valueOf(tea.getId())))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ private List<AnalyticsTableColumn> getFixedCols() {
return columns;
}

/**
* Returns a list of geospatial columns.
*
* @return a list of {@link AnalyticsTableColumn}.
*/
private List<AnalyticsTableColumn> getGeospatialCols() {

return List.of(
Expand All @@ -319,6 +324,11 @@ private List<AnalyticsTableColumn> getGeospatialCols() {
.build());
}

/**
* Returns a partition column.
*
* @return an {@link AnalyticsTableColumn}.
*/
private AnalyticsTableColumn getPartitionColumn() {
return AnalyticsTableColumn.builder()
.name("year")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,9 +193,8 @@ public class JdbcTrackedEntityEventsAnalyticsTableManager extends AbstractJdbcTa
.selectExpression("ous.level")
.build());

private static final String AND = " and (";

private final TrackedEntityTypeService trackedEntityTypeService;

private final AnalyticsSqlBuilder analyticsSqlBuilder;

public JdbcTrackedEntityEventsAnalyticsTableManager(
Expand Down Expand Up @@ -340,7 +339,8 @@ private List<Integer> getDataYears(AnalyticsTableUpdateParams params, TrackedEnt
"tetId", String.valueOf(tet.getId()))));

if (params.getFromDate() != null) {
sql.append(AND + eventDateExpression + ") >= '" + toMediumDate(params.getFromDate()) + "'");
sql.append(
" and (" + eventDateExpression + ") >= '" + toMediumDate(params.getFromDate()) + "'");
}

List<Integer> availableDataYears =
Expand Down Expand Up @@ -451,6 +451,11 @@ private String getPartitionClause(AnalyticsTablePartition partition) {
: emptyIfTrue(partitionFilter, sqlBuilder.supportsDeclarativePartitioning());
}

/**
* Returns a partition column.
*
* @return an {@link AnalyticsTableColumn}.
*/
private AnalyticsTableColumn getPartitionColumn() {
return AnalyticsTableColumn.builder()
.name("year")
Expand Down

0 comments on commit 098c071

Please sign in to comment.