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 c51fb14 commit a84ff58
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
package org.hisp.dhis.category;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
Expand Down Expand Up @@ -195,6 +196,11 @@ public boolean hasOptionCombos() {
return optionCombos != null && !optionCombos.isEmpty();
}

@JsonIgnore
public List<Category> getDataDimensionCategories() {
return categories.stream().filter(Category::isDataDimension).toList();
}

// -------------------------------------------------------------------------
// Logic
// -------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,24 +398,7 @@ private String getPartitionClause(AnalyticsTablePartition partition) {
*/
private List<AnalyticsTableColumn> getColumns(Program program) {
List<AnalyticsTableColumn> columns = new ArrayList<>(fixedColumns);

if (program.hasNonDefaultCategoryCombo()) {
List<Category> categories = program.getCategoryCombo().getCategories();

for (Category category : categories) {
if (category.isDataDimension()) {
columns.add(
AnalyticsTableColumn.builder()
.name(category.getUid())
.dimensionType(AnalyticsDimensionType.DYNAMIC)
.dataType(CHARACTER_11)
.selectExpression("acs." + quote(category.getUid()))
.created(category.getCreated())
.build());
}
}
}

columns.addAll(getAttributeCategoryColumns(program));
columns.addAll(getOrganisationUnitLevelColumns());
columns.add(getOrganisationUnitNameHierarchyColumn());
columns.addAll(getOrganisationUnitGroupSetColumns());
Expand Down Expand Up @@ -447,6 +430,32 @@ protected AnalyticsTableColumn getPartitionColumn() {
.build();
}

/**
* Returns columns for attribute categories of the given program.
*
* @param program the {@link Program}.
* @return a list of {@link AnalyticsTableColumn}.
*/
private List<AnalyticsTableColumn> getAttributeCategoryColumns(Program program) {
if (program.hasNonDefaultCategoryCombo()) {
List<Category> categories = program.getCategoryCombo().getDataDimensionCategories();

return categories.stream()
.map(
category ->
AnalyticsTableColumn.builder()
.name(category.getUid())
.dimensionType(AnalyticsDimensionType.DYNAMIC)
.dataType(CHARACTER_11)
.selectExpression("acs." + quote(category.getUid()))
.created(category.getCreated())
.build())
.toList();
}

return List.of();
}

/**
* Returns columns for data elements of the given program.
*
Expand Down

0 comments on commit a84ff58

Please sign in to comment.