Skip to content

Commit

Permalink
Merge branch 'master' into 2.42-DHIS2-18368_3
Browse files Browse the repository at this point in the history
  • Loading branch information
d-bernat authored Dec 28, 2024
2 parents 9614438 + f84d286 commit e898458
Show file tree
Hide file tree
Showing 23 changed files with 662 additions and 277 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ public class DataItem implements Serializable {
@JacksonXmlProperty(namespace = DXF_2_0)
private String expression;

@JsonProperty
@JacksonXmlProperty(namespace = DXF_2_0)
private String optionSetId;

public ValueType getSimplifiedValueType() {
return valueType != null ? valueType.toSimplifiedValueType() : null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ public enum Authorities {
F_DATAVALUE_ADD,
F_IMPERSONATE_USER,
F_SYSTEM_SETTING,
F_MAP_EXTERNAL_LAYER_ADD,
F_LEGEND_SET_PUBLIC_ADD,
F_LEGEND_SET_PRIVATE_ADD,
F_LEGEND_SET_DELETE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
package org.hisp.dhis.dataitem.query;

import static java.util.stream.Collectors.joining;
import static java.util.stream.Collectors.toSet;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.hisp.dhis.common.ValueType.getAggregatables;
Expand All @@ -37,6 +38,7 @@
import static org.hisp.dhis.dataitem.query.shared.FilteringStatement.ifAny;
import static org.hisp.dhis.dataitem.query.shared.FilteringStatement.ifSet;
import static org.hisp.dhis.dataitem.query.shared.FilteringStatement.nameFiltering;
import static org.hisp.dhis.dataitem.query.shared.FilteringStatement.optionSetIdFiltering;
import static org.hisp.dhis.dataitem.query.shared.FilteringStatement.rootJunction;
import static org.hisp.dhis.dataitem.query.shared.FilteringStatement.shortNameFiltering;
import static org.hisp.dhis.dataitem.query.shared.FilteringStatement.uidFiltering;
Expand All @@ -54,8 +56,10 @@
import static org.hisp.dhis.dataitem.query.shared.UserAccessStatement.READ_ACCESS;
import static org.hisp.dhis.dataitem.query.shared.UserAccessStatement.sharingConditions;

import java.util.List;
import java.util.Set;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.Pair;
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.dataitem.query.shared.OptionalFilterBuilder;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
Expand All @@ -70,12 +74,28 @@
@Component
public class DataElementQuery implements DataItemQuery {
private static final String COMMON_COLUMNS =
"cast (null as text) as program_name, cast (null as text) as program_uid,"
+ " cast (null as text) as program_shortname, dataelement.uid as item_uid, dataelement.name as item_name,"
+ " dataelement.shortname as item_shortname, dataelement.valuetype as item_valuetype,"
+ " dataelement.code as item_code, dataelement.sharing as item_sharing, dataelement.domaintype as item_domaintype,"
+ " cast ('DATA_ELEMENT' as text) as item_type,"
+ " cast (null as text) as expression";
List.of(
Pair.of("program_name", CAST_NULL_AS_TEXT),
Pair.of("program_uid", CAST_NULL_AS_TEXT),
Pair.of("program_shortname", CAST_NULL_AS_TEXT),
Pair.of("item_uid", "dataelement.uid"),
Pair.of("item_name", "dataelement.name"),
Pair.of("item_shortname", "dataelement.shortname"),
Pair.of("item_valuetype", "dataelement.valuetype"),
Pair.of("item_code", "dataelement.code"),
Pair.of("item_sharing", "dataelement.sharing"),
Pair.of("item_domaintype", "dataelement.domaintype"),
Pair.of("item_type", "cast ('DATA_ELEMENT' as text)"),
Pair.of("expression", CAST_NULL_AS_TEXT),
Pair.of("optionset_uid", "optionset.uid"))
.stream()
.map(pair -> pair.getRight() + " as " + pair.getLeft())
.collect(joining(", "));

private static final String JOINS =
"left join optionset on dataelement.optionsetid = optionset.optionsetid";

private static final String SPACED_FROM_DATA_ELEMENT = " from dataelement ";

@Override
public String getStatement(MapSqlParameterSource paramsMap) {
Expand All @@ -95,7 +115,7 @@ public String getStatement(MapSqlParameterSource paramsMap) {
}

sql.append(
" group by item_name, item_uid, item_valuetype, item_code, item_domaintype, item_sharing, item_shortname,"
" group by optionset.uid, item_name, item_uid, item_valuetype, item_code, item_domaintype, item_sharing, item_shortname,"
+ " i18n_first_name, i18n_first_shortname, i18n_second_name, i18n_second_shortname");

// Closing the temp table.
Expand Down Expand Up @@ -131,6 +151,7 @@ public String getStatement(MapSqlParameterSource paramsMap) {
optionalFilters.append(ifSet(nameFiltering("t.item_name", paramsMap)));
optionalFilters.append(ifSet(shortNameFiltering("t.item_shortname", paramsMap)));
optionalFilters.append(ifSet(uidFiltering("t.item_uid", paramsMap)));
optionalFilters.append(ifSet(optionSetIdFiltering("t.optionset_uid", paramsMap)));
sql.append(ifAny(optionalFilters.toString()));

String identifiableStatement =
Expand Down Expand Up @@ -180,9 +201,11 @@ public Class<? extends BaseIdentifiableObject> getRootEntity() {
private String selectRowsContainingTranslatedName() {
StringBuilder sql = new StringBuilder();

sql.append(SPACED_SELECT + COMMON_COLUMNS).append(translationNamesColumnsFor("dataelement"));

sql.append(" from dataelement ").append(translationNamesJoinsOn("dataelement"));
sql.append(SPACED_SELECT + COMMON_COLUMNS)
.append(translationNamesColumnsFor("dataelement"))
.append(SPACED_FROM_DATA_ELEMENT)
.append(JOINS)
.append(translationNamesJoinsOn("dataelement"));

return sql.toString();
}
Expand All @@ -193,7 +216,8 @@ private String selectAllRowsIgnoringAnyTranslation() {
.append(", dataelement.name as i18n_first_name, cast (null as text) as i18n_second_name")
.append(
", dataelement.shortname as i18n_first_shortname, cast (null as text) as i18n_second_shortname")
.append(" from dataelement ")
.append(SPACED_FROM_DATA_ELEMENT)
.append(JOINS)
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
* @author maikel arabori
*/
public interface DataItemQuery {
String CAST_NULL_AS_TEXT = "cast (null as text)";

/**
* Builds and returns the SQL statement required by the implementation.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
package org.hisp.dhis.dataitem.query;

import static java.util.stream.Collectors.joining;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.hisp.dhis.dataitem.query.shared.FilteringStatement.always;
import static org.hisp.dhis.dataitem.query.shared.FilteringStatement.displayNameFiltering;
Expand All @@ -50,7 +51,9 @@
import static org.hisp.dhis.dataitem.query.shared.UserAccessStatement.READ_ACCESS;
import static org.hisp.dhis.dataitem.query.shared.UserAccessStatement.sharingConditions;

import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.Pair;
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.dataitem.query.shared.OptionalFilterBuilder;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
Expand All @@ -65,12 +68,23 @@
@Component
public class DataSetQuery implements DataItemQuery {
private static final String COMMON_COLUMNS =
"cast (null as text) as program_name, cast (null as text) as program_uid,"
+ " cast (null as text) as program_shortname, dataset.uid as item_uid, dataset.name as item_name,"
+ " dataset.shortname as item_shortname, cast (null as text) as item_valuetype, dataset.code as item_code,"
+ " dataset.sharing as item_sharing, cast (null as text) as item_domaintype,"
+ " cast('REPORTING_RATE' as text) as item_type,"
+ " cast (null as text) as expression";
List.of(
Pair.of("program_name", CAST_NULL_AS_TEXT),
Pair.of("program_uid", CAST_NULL_AS_TEXT),
Pair.of("program_shortname", CAST_NULL_AS_TEXT),
Pair.of("item_uid", "dataset.uid"),
Pair.of("item_name", "dataset.name"),
Pair.of("item_shortname", "dataset.shortname"),
Pair.of("item_valuetype", CAST_NULL_AS_TEXT),
Pair.of("item_code", "dataset.code"),
Pair.of("item_sharing", "dataset.sharing"),
Pair.of("item_domaintype", CAST_NULL_AS_TEXT),
Pair.of("item_type", "cast ('REPORTING_RATE' as text)"),
Pair.of("expression", CAST_NULL_AS_TEXT),
Pair.of("optionset_uid", CAST_NULL_AS_TEXT))
.stream()
.map(pair -> pair.getRight() + " as " + pair.getLeft())
.collect(joining(", "));

@Override
public String getStatement(MapSqlParameterSource paramsMap) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
package org.hisp.dhis.dataitem.query;

import static java.util.stream.Collectors.joining;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.hisp.dhis.dataitem.query.shared.FilteringStatement.always;
import static org.hisp.dhis.dataitem.query.shared.FilteringStatement.displayNameFiltering;
Expand All @@ -51,9 +52,9 @@
import static org.hisp.dhis.dataitem.query.shared.StatementUtil.SPACED_WHERE;
import static org.hisp.dhis.dataitem.query.shared.UserAccessStatement.checkOwnerConditions;

import java.util.ArrayList;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.Pair;
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.dataitem.query.shared.OptionalFilterBuilder;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
Expand All @@ -66,18 +67,24 @@
@Slf4j
@Component
public class ExpressionDimensionItemQuery implements DataItemQuery {
private static final List<String> COMMON_COLUMNS = new ArrayList<>();

static {
COMMON_COLUMNS.add("cast (null as text) as program_name, cast (null as text) as program_uid");
COMMON_COLUMNS.add(
"cast (null as text) as program_shortname, expressiondimensionitem.uid as item_uid, expressiondimensionitem.name as item_name");
COMMON_COLUMNS.add(
"expressiondimensionitem.shortname as item_shortname, cast (null as text) as item_valuetype, expressiondimensionitem.code as item_code");
COMMON_COLUMNS.add(
"expressiondimensionitem.sharing as item_sharing, cast (null as text) as item_domaintype, cast ('EXPRESSION_DIMENSION_ITEM' as text) as item_type");
COMMON_COLUMNS.add("expressiondimensionitem.expression");
}
private static final String COMMON_COLUMNS =
List.of(
Pair.of("program_name", CAST_NULL_AS_TEXT),
Pair.of("program_uid", CAST_NULL_AS_TEXT),
Pair.of("program_shortname", CAST_NULL_AS_TEXT),
Pair.of("item_uid", "expressiondimensionitem.uid"),
Pair.of("item_name", "expressiondimensionitem.name"),
Pair.of("item_shortname", "expressiondimensionitem.shortname"),
Pair.of("item_valuetype", CAST_NULL_AS_TEXT),
Pair.of("item_code", "expressiondimensionitem.code"),
Pair.of("item_sharing", "expressiondimensionitem.sharing"),
Pair.of("item_domaintype", CAST_NULL_AS_TEXT),
Pair.of("item_type", "cast ('EXPRESSION_DIMENSION_ITEM' as text)"),
Pair.of("expression", "expressiondimensionitem.expression"),
Pair.of("optionset_uid", CAST_NULL_AS_TEXT))
.stream()
.map(pair -> pair.getRight() + " as " + pair.getLeft())
.collect(joining(", "));

/**
* Builds and returns the SQL statement required by the implementation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
package org.hisp.dhis.dataitem.query;

import static java.util.stream.Collectors.joining;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.hisp.dhis.common.ValueType.NUMBER;
import static org.hisp.dhis.dataitem.query.shared.FilteringStatement.always;
Expand All @@ -52,7 +53,9 @@
import static org.hisp.dhis.dataitem.query.shared.UserAccessStatement.READ_ACCESS;
import static org.hisp.dhis.dataitem.query.shared.UserAccessStatement.sharingConditions;

import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.tuple.Pair;
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.dataitem.query.shared.OptionalFilterBuilder;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
Expand All @@ -67,11 +70,23 @@
@Component
public class IndicatorQuery implements DataItemQuery {
private static final String COMMON_COLUMNS =
"cast (null as text) as program_name, cast (null as text) as program_uid,"
+ " cast (null as text) as program_shortname, indicator.uid as item_uid, indicator.name as item_name,"
+ " indicator.shortname as item_shortname, cast (null as text) as item_valuetype, indicator.code as item_code,"
+ " indicator.sharing as item_sharing, cast (null as text) as item_domaintype, cast ('INDICATOR' as text) as item_type,"
+ " cast (null as text) as expression";
List.of(
Pair.of("program_name", CAST_NULL_AS_TEXT),
Pair.of("program_uid", CAST_NULL_AS_TEXT),
Pair.of("program_shortname", CAST_NULL_AS_TEXT),
Pair.of("item_uid", "indicator.uid"),
Pair.of("item_name", "indicator.name"),
Pair.of("item_shortname", "indicator.shortname"),
Pair.of("item_valuetype", CAST_NULL_AS_TEXT),
Pair.of("item_code", "indicator.code"),
Pair.of("item_sharing", "indicator.sharing"),
Pair.of("item_domaintype", CAST_NULL_AS_TEXT),
Pair.of("item_type", "cast ('INDICATOR' as text)"),
Pair.of("expression", CAST_NULL_AS_TEXT),
Pair.of("optionset_uid", CAST_NULL_AS_TEXT))
.stream()
.map(pair -> pair.getRight() + " as " + pair.getLeft())
.collect(joining(", "));

@Override
public String getStatement(MapSqlParameterSource paramsMap) {
Expand Down
Loading

0 comments on commit e898458

Please sign in to comment.