diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataitem/DataItem.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataitem/DataItem.java index 964e89c41ef7..693d8b6c89a4 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataitem/DataItem.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataitem/DataItem.java @@ -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; } diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/DataElementQuery.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/DataElementQuery.java index 928b0836cd32..14735f3b322c 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/DataElementQuery.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/DataElementQuery.java @@ -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; @@ -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; @@ -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; @@ -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) { @@ -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. @@ -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 = @@ -180,9 +201,11 @@ public Class 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(); } @@ -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(); } } diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/DataItemQuery.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/DataItemQuery.java index 3c277c13f6df..e821aed51b07 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/DataItemQuery.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/DataItemQuery.java @@ -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. * diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/DataSetQuery.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/DataSetQuery.java index c36cd23f7e85..4aadb4ce8aa2 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/DataSetQuery.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/DataSetQuery.java @@ -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; @@ -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; @@ -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) { diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/ExpressionDimensionItemQuery.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/ExpressionDimensionItemQuery.java index 839517841508..2d43c35ffd34 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/ExpressionDimensionItemQuery.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/ExpressionDimensionItemQuery.java @@ -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; @@ -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; @@ -66,18 +67,24 @@ @Slf4j @Component public class ExpressionDimensionItemQuery implements DataItemQuery { - private static final List 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. diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/IndicatorQuery.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/IndicatorQuery.java index 98350c677d4e..74655b42c231 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/IndicatorQuery.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/IndicatorQuery.java @@ -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; @@ -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; @@ -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) { diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/OptionSetQuery.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/OptionSetQuery.java deleted file mode 100644 index 2d8d88d552af..000000000000 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/OptionSetQuery.java +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Copyright (c) 2004-2022, University of Oslo - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * Redistributions of source code must retain the above copyright notice, this - * list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * Neither the name of the HISP project nor the names of its contributors may - * be used to endorse or promote products derived from this software without - * specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR - * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -package org.hisp.dhis.dataitem.query; - -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; -import static org.hisp.dhis.dataitem.query.shared.FilteringStatement.displayShortNameFiltering; -import static org.hisp.dhis.dataitem.query.shared.FilteringStatement.identifiableTokenFiltering; -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.rootJunction; -import static org.hisp.dhis.dataitem.query.shared.FilteringStatement.shortNameFiltering; -import static org.hisp.dhis.dataitem.query.shared.FilteringStatement.uidFiltering; -import static org.hisp.dhis.dataitem.query.shared.LimitStatement.maxLimit; -import static org.hisp.dhis.dataitem.query.shared.NameTranslationStatement.translationNamesColumnsFor; -import static org.hisp.dhis.dataitem.query.shared.NameTranslationStatement.translationNamesJoinsOn; -import static org.hisp.dhis.dataitem.query.shared.OrderingStatement.ordering; -import static org.hisp.dhis.dataitem.query.shared.ParamPresenceChecker.hasNonBlankStringPresence; -import static org.hisp.dhis.dataitem.query.shared.QueryParam.LOCALE; -import static org.hisp.dhis.dataitem.query.shared.StatementUtil.SPACED_FROM; -import static org.hisp.dhis.dataitem.query.shared.StatementUtil.SPACED_LEFT_PARENTHESIS; -import static org.hisp.dhis.dataitem.query.shared.StatementUtil.SPACED_RIGHT_PARENTHESIS; -import static org.hisp.dhis.dataitem.query.shared.StatementUtil.SPACED_SELECT; -import static org.hisp.dhis.dataitem.query.shared.StatementUtil.SPACED_WHERE; -import static org.hisp.dhis.dataitem.query.shared.UserAccessStatement.checkOwnerConditions; - -import java.util.List; -import java.util.stream.Collectors; -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; -import org.springframework.stereotype.Component; - -/** - * This component is responsible for providing query capabilities on top of ExpressionDimensionItem - * objects. - */ -@Slf4j -@Component -public class OptionSetQuery implements DataItemQuery { - public static final String CAST_NULL_AS_TEXT = "cast (null as text)"; - - 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", "optionset.uid"), - Pair.of("item_name", "optionset.name"), - Pair.of("item_shortname", CAST_NULL_AS_TEXT), - Pair.of("item_valuetype", CAST_NULL_AS_TEXT), - Pair.of("item_code", "optionset.code"), - Pair.of("item_sharing", "optionset.sharing"), - Pair.of("item_domaintype", CAST_NULL_AS_TEXT), - Pair.of("item_type", "cast ('OPTION_SET' as text)"), - Pair.of("expression", CAST_NULL_AS_TEXT)) - .stream() - .map(pair -> pair.getRight() + " as " + pair.getLeft()) - .collect(Collectors.joining(", ")); - - /** - * Builds and returns the SQL statement required by the implementation. - * - * @param paramsMap - * @return the full SQL statement - */ - @Override - public String getStatement(MapSqlParameterSource paramsMap) { - StringBuilder sql = new StringBuilder(); - - sql.append(SPACED_LEFT_PARENTHESIS); - - // Creating a temp translated table to be queried. - sql.append(SPACED_SELECT + "*" + SPACED_FROM + SPACED_LEFT_PARENTHESIS); - - if (hasNonBlankStringPresence(paramsMap, LOCALE)) { - // Selecting translated names. - sql.append(selectRowsContainingTranslatedName()); - } else { - // Retrieving all rows ignoring translation as no locale is defined. - sql.append(selectAllRowsIgnoringAnyTranslation()); - } - - sql.append( - " group by item_name, item_uid, item_code, item_sharing, item_shortname," - + " i18n_first_name, i18n_first_shortname, i18n_second_name, i18n_second_shortname, expression"); - - // Closing the temp table. - sql.append(SPACED_RIGHT_PARENTHESIS + " t"); - - sql.append(SPACED_WHERE); - - // Applying filters, ordering and limits. - - // Mandatory filters. They do not respect the root junction filtering. - sql.append(always(checkOwnerConditions("t.item_sharing"))); - - // Optional filters, based on the current root junction. - OptionalFilterBuilder optionalFilters = new OptionalFilterBuilder(paramsMap); - optionalFilters.append(ifSet(displayNameFiltering("t.i18n_first_name", paramsMap))); - optionalFilters.append(ifSet(displayShortNameFiltering("t.i18n_first_shortname", 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))); - sql.append(ifAny(optionalFilters.toString())); - - String identifiableStatement = - identifiableTokenFiltering( - "t.item_uid", "t.item_code", "t.i18n_first_name", null, paramsMap); - - if (isNotBlank(identifiableStatement)) { - sql.append(rootJunction(paramsMap)); - sql.append(identifiableStatement); - } - - sql.append( - ifSet( - ordering( - "t.i18n_first_name, t.i18n_second_name, t.item_uid", - "t.item_name, t.item_uid", - "t.i18n_first_shortname, t.i18n_second_shortname, t.item_uid", - "t.item_shortname, t.item_uid", - paramsMap))); - sql.append(ifSet(maxLimit(paramsMap))); - sql.append(SPACED_RIGHT_PARENTHESIS); - - String fullStatement = sql.toString(); - - log.trace("Full SQL: " + fullStatement); - - return fullStatement; - } - - /** - * Checks if the query rules match the required conditions so the query can be executed. This - * implementation must return always true. - * - * @param paramsMap - * @return true if matches, false otherwise - */ - @Override - public boolean matchQueryRules(MapSqlParameterSource paramsMap) { - return true; - } - - /** - * Simply returns the entity associated with the respective interface/query implementation. - * - * @return the entity associated to the interface implementation - */ - @Override - public Class getRootEntity() { - return QueryableDataItem.OPTION_SET.getEntity(); - } - - private String selectRowsContainingTranslatedName() { - StringBuilder sql = new StringBuilder(); - - sql.append(SPACED_SELECT) - .append(COMMON_COLUMNS) - .append(translationNamesColumnsFor("optionset", false, false)); - - sql.append(" from optionset ").append(translationNamesJoinsOn("optionset")); - - return sql.toString(); - } - - private String selectAllRowsIgnoringAnyTranslation() { - return new StringBuilder() - .append(SPACED_SELECT + COMMON_COLUMNS) - .append(", optionset.name as i18n_first_name, cast (null as text) as i18n_second_name") - .append( - ", " - + CAST_NULL_AS_TEXT - + " as i18n_first_shortname, cast (null as text) as i18n_second_shortname") - .append(" from optionset ") - .toString(); - } -} diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/ProgramAttributeQuery.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/ProgramAttributeQuery.java index bfd3f19cddbf..e27c918eec94 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/ProgramAttributeQuery.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/ProgramAttributeQuery.java @@ -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; @@ -35,6 +36,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.programIdFiltering; import static org.hisp.dhis.dataitem.query.shared.FilteringStatement.rootJunction; import static org.hisp.dhis.dataitem.query.shared.FilteringStatement.shortNameFiltering; @@ -51,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; @@ -67,19 +71,31 @@ @Component public class ProgramAttributeQuery implements DataItemQuery { private static final String COMMON_COLUMNS = - "program.name as program_name, program.uid as program_uid," - + " program.shortname as program_shortname, trackedentityattribute.uid as item_uid," - + " trackedentityattribute.name as item_name, trackedentityattribute.shortname as item_shortname," - + " trackedentityattribute.valuetype as item_valuetype, trackedentityattribute.code as item_code," - + " trackedentityattribute.sharing as item_sharing, cast (null as text) as item_domaintype," - + " cast ('PROGRAM_ATTRIBUTE' as text) as item_type," - + " cast (null as text) as expression"; - - private static final String COMMON_UIDS = "program.uid, trackedentityattribute.uid"; + List.of( + Pair.of("program_name", "program.name"), + Pair.of("program_uid", "program.uid"), + Pair.of("program_shortname", "program.shortname"), + Pair.of("item_uid", "trackedentityattribute.uid"), + Pair.of("item_name", "trackedentityattribute.name"), + Pair.of("item_shortname", "trackedentityattribute.shortname"), + Pair.of("item_valuetype", "trackedentityattribute.valuetype"), + Pair.of("item_code", "trackedentityattribute.code"), + Pair.of("item_sharing", "trackedentityattribute.sharing"), + Pair.of("item_domaintype", CAST_NULL_AS_TEXT), + Pair.of("item_type", "cast ('PROGRAM_ATTRIBUTE' 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 COMMON_UIDS = + "program.uid, trackedentityattribute.uid, optionset.uid"; private static final String JOINS = " join program_attributes on program_attributes.trackedentityattributeid = trackedentityattribute.trackedentityattributeid" - + " join program on program_attributes.programid = program.programid"; + + " join program on program_attributes.programid = program.programid" + + " left join optionset on trackedentityattribute.optionsetid = optionset.optionsetid"; private static final String SPACED_FROM_TRACKED_ENTITY_ATTRIBUTE = " from trackedentityattribute "; @@ -132,6 +148,7 @@ public String getStatement(MapSqlParameterSource paramsMap) { ifSet(shortNameFiltering("t.program_shortname", "t.item_shortname", paramsMap))); optionalFilters.append(ifSet(programIdFiltering("t.program_uid", paramsMap))); optionalFilters.append(ifSet(uidFiltering("t.item_uid", paramsMap))); + optionalFilters.append(ifSet(optionSetIdFiltering("t.optionset_uid", paramsMap))); sql.append(ifAny(optionalFilters.toString())); String identifiableStatement = diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/ProgramIndicatorQuery.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/ProgramIndicatorQuery.java index 6f1f85d83ac7..efeb9e404a11 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/ProgramIndicatorQuery.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/ProgramIndicatorQuery.java @@ -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; @@ -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; @@ -68,11 +71,23 @@ @Component public class ProgramIndicatorQuery implements DataItemQuery { private static final String COMMON_COLUMNS = - "cast (null as text) as program_name, program.uid as program_uid," - + " cast (null as text) as program_shortname, programindicator.uid as item_uid, programindicator.name as item_name," - + " programindicator.shortname as item_shortname, cast (null as text) as item_valuetype, programindicator.code as item_code," - + " programindicator.sharing as item_sharing, cast (null as text) as item_domaintype, cast ('PROGRAM_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", "program.uid"), + Pair.of("program_shortname", CAST_NULL_AS_TEXT), + Pair.of("item_uid", "programindicator.uid"), + Pair.of("item_name", "programindicator.name"), + Pair.of("item_shortname", "programindicator.shortname"), + Pair.of("item_valuetype", CAST_NULL_AS_TEXT), + Pair.of("item_code", "programindicator.code"), + Pair.of("item_sharing", "programindicator.sharing"), + Pair.of("item_domaintype", CAST_NULL_AS_TEXT), + Pair.of("item_type", "cast ('PROGRAM_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(", ")); private static final String COMMON_UIDS = "program.uid, programindicator.uid"; diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/ProgramStageDataElementQuery.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/ProgramStageDataElementQuery.java index 2c7d2754288e..33acb04c217c 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/ProgramStageDataElementQuery.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/ProgramStageDataElementQuery.java @@ -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; @@ -35,6 +36,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.programIdFiltering; import static org.hisp.dhis.dataitem.query.shared.FilteringStatement.rootJunction; import static org.hisp.dhis.dataitem.query.shared.FilteringStatement.shortNameFiltering; @@ -51,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; @@ -67,18 +71,31 @@ @Component public class ProgramStageDataElementQuery implements DataItemQuery { private static final String COMMON_COLUMNS = - "program.name as program_name, program.uid as program_uid," - + " program.shortname 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, cast (null as text) as item_domaintype, cast ('PROGRAM_DATA_ELEMENT' as text) as item_type," - + " cast (null as text) as expression"; - - private static final String COMMON_UIDS = "program.uid, dataelement.uid"; + List.of( + Pair.of("program_name", "program.name"), + Pair.of("program_uid", "program.uid"), + Pair.of("program_shortname", "program.shortname"), + 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", CAST_NULL_AS_TEXT), + Pair.of("item_type", "cast ('PROGRAM_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 COMMON_UIDS = "program.uid, dataelement.uid, optionset.uid"; private static final String JOINS = "join programstagedataelement on programstagedataelement.dataelementid = dataelement.dataelementid" + " join programstage on programstagedataelement.programstageid = programstage.programstageid" - + " join program on program.programid = programstage.programid"; + + " join program on program.programid = programstage.programid" + + " left join optionset on dataelement.optionsetid = optionset.optionsetid"; private static final String SPACED_FROM_DATA_ELEMENT = " from dataelement "; @@ -130,6 +147,7 @@ public String getStatement(MapSqlParameterSource paramsMap) { ifSet(shortNameFiltering("t.program_shortname", "t.item_shortname", paramsMap))); optionalFilters.append(ifSet(programIdFiltering("t.program_uid", paramsMap))); optionalFilters.append(ifSet(uidFiltering("t.item_uid", paramsMap))); + optionalFilters.append(ifSet(optionSetIdFiltering("t.optionset_uid", paramsMap))); sql.append(ifAny(optionalFilters.toString())); String identifiableStatement = diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/QueryableDataItem.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/QueryableDataItem.java index d8ac362e61f3..cd8077fd1257 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/QueryableDataItem.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/QueryableDataItem.java @@ -36,7 +36,6 @@ import org.hisp.dhis.dataset.DataSet; import org.hisp.dhis.expressiondimensionitem.ExpressionDimensionItem; import org.hisp.dhis.indicator.Indicator; -import org.hisp.dhis.option.OptionSet; import org.hisp.dhis.program.ProgramDataElementDimensionItem; import org.hisp.dhis.program.ProgramIndicator; import org.hisp.dhis.program.ProgramTrackedEntityAttributeDimensionItem; @@ -53,8 +52,7 @@ public enum QueryableDataItem { PROGRAM_INDICATOR(ProgramIndicator.class), PROGRAM_DATA_ELEMENT(ProgramDataElementDimensionItem.class), PROGRAM_ATTRIBUTE(ProgramTrackedEntityAttributeDimensionItem.class), - EXPRESSION_DIMENSION_ITEM(ExpressionDimensionItem.class), - OPTION_SET(OptionSet.class); + EXPRESSION_DIMENSION_ITEM(ExpressionDimensionItem.class); private Class entity; diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/ResultProcessor.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/ResultProcessor.java index 5d7f13145314..b6bf3da1d14d 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/ResultProcessor.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/ResultProcessor.java @@ -52,8 +52,12 @@ class ResultProcessor { private static final String PROGRAM_UID = "program_uid"; + private static final String ITEM_CODE = "item_code"; + private static final String EXPRESSION = "expression"; + private static final String OPTION_SET_UID = "optionset_uid"; + private ResultProcessor() {} /** @@ -74,11 +78,12 @@ static List process(SqlRowSet rowSet) { .id(getUid(rowSet)) .shortName(getShortName(rowSet)) .displayShortName(getDisplayShortName(rowSet)) - .code(rowSet.getString("item_code")) + .code(rowSet.getString(ITEM_CODE)) .dimensionItemType(getItemType(rowSet)) .programId(rowSet.getString(PROGRAM_UID)) .valueType(getValueType(rowSet)) .expression(rowSet.getString(EXPRESSION)) + .optionSetId(rowSet.getString(OPTION_SET_UID)) .build()); } diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/shared/FilteringStatement.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/shared/FilteringStatement.java index fefa11990c1e..938cfd62542f 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/shared/FilteringStatement.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/shared/FilteringStatement.java @@ -38,6 +38,7 @@ import static org.hisp.dhis.dataitem.query.shared.QueryParam.DISPLAY_SHORT_NAME; import static org.hisp.dhis.dataitem.query.shared.QueryParam.IDENTIFIABLE_TOKEN_COMPARISON; import static org.hisp.dhis.dataitem.query.shared.QueryParam.NAME; +import static org.hisp.dhis.dataitem.query.shared.QueryParam.OPTION_SET_ID; import static org.hisp.dhis.dataitem.query.shared.QueryParam.PROGRAM_ID; import static org.hisp.dhis.dataitem.query.shared.QueryParam.ROOT_JUNCTION; import static org.hisp.dhis.dataitem.query.shared.QueryParam.SHORT_NAME; @@ -95,6 +96,22 @@ public static String programIdFiltering(String column, MapSqlParameterSource par return EMPTY; } + /** + * Returns a SQL string related to optionSetId equality to be reused as part of data items + * optionSetId filtering. + * + * @param column the uid column + * @param paramsMap + * @return the uid SQL comparison + */ + public static String optionSetIdFiltering(String column, MapSqlParameterSource paramsMap) { + if (hasNonBlankStringPresence(paramsMap, OPTION_SET_ID)) { + return equalsFiltering(column, OPTION_SET_ID); + } + + return EMPTY; + } + /** * Returns a SQL string related to 'name' "ilike" comparison to be reused as part of data items * 'name' filtering. diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/shared/QueryParam.java b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/shared/QueryParam.java index 4ec6fc3a09a0..43d68a8512db 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/shared/QueryParam.java +++ b/dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/dataitem/query/shared/QueryParam.java @@ -56,6 +56,8 @@ public class QueryParam { public static final String PROGRAM_ID = "programId"; + public static final String OPTION_SET_ID = "optionSetId"; + public static final String MAX_LIMIT = "maxLimit"; public static final String NAME_ORDER = "nameOrder"; diff --git a/dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/analytics/dataitems/DataItemsAnalyticsTest.java b/dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/analytics/dataitems/DataItemsAnalyticsTest.java index be1bbcfba11c..471abfffcbb2 100644 --- a/dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/analytics/dataitems/DataItemsAnalyticsTest.java +++ b/dhis-2/dhis-test-e2e/src/test/java/org/hisp/dhis/analytics/dataitems/DataItemsAnalyticsTest.java @@ -29,6 +29,7 @@ import static org.hamcrest.CoreMatchers.hasItem; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.not; import org.hisp.dhis.helpers.extensions.ConfigurationExtension; import org.hisp.dhis.test.e2e.actions.LoginActions; @@ -59,7 +60,7 @@ public static void beforeAll() { } @Test - void testDataItemsContainsOptionSets() { + void testDataItemsDoesNotContainOptionSets() { // Given QueryParamsBuilder params = new QueryParamsBuilder().add("paging=false").add("order=name:asc"); @@ -72,6 +73,60 @@ void testDataItemsContainsOptionSets() { .statusCode(equalTo(200)) .body("dataItems.dimensionItemType", hasItem("PROGRAM_INDICATOR")) .body("dataItems.dimensionItemType", hasItem("DATA_ELEMENT")) - .body("dataItems.dimensionItemType", hasItem("OPTION_SET")); + .body("dataItems.dimensionItemType", not(hasItem("OPTION_SET"))); + } + + @Test + void testDataItemsContainsOptionSetId() { + // Given + QueryParamsBuilder params = new QueryParamsBuilder().add("paging=false").add("order=name:asc"); + + // When + ApiResponse response = dataItemsActions.get(params); + + // Then + response + .validate() + .statusCode(equalTo(200)) + .body("dataItems.optionSetId", hasItem("SokRAajDrRz")); + } + + @Test + void testDataItemsFiltersNonExistingOptionSetId() { + // Given + QueryParamsBuilder params = + new QueryParamsBuilder() + .add("paging=false") + .add("order=name:asc") + .add("filter=optionSetId:eq:ABCD"); + + // When + ApiResponse response = dataItemsActions.get(params); + + // Then + response + .validate() + .statusCode(equalTo(200)) + .body("dataItems.optionSetId", not(hasItem("SokRAajDrRz"))) + .body("dataItems.optionSetId", not(hasItem("ABCD"))); + } + + @Test + void testDataItemsFiltersExistingOptionSetId() { + // Given + QueryParamsBuilder params = + new QueryParamsBuilder() + .add("paging=false") + .add("order=name:asc") + .add("filter=optionSetId:eq:SokRAajDrRz"); + + // When + ApiResponse response = dataItemsActions.get(params); + + // Then + response + .validate() + .statusCode(equalTo(200)) + .body("dataItems.optionSetId", hasItem("SokRAajDrRz")); } } diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataitem/Filter.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataitem/Filter.java index 69de7cb52f3a..0866a625aa99 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataitem/Filter.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataitem/Filter.java @@ -41,6 +41,7 @@ public enum Attribute { SHORT_NAME("shortName"), DISPLAY_SHORT_NAME("displayShortName"), PROGRAM_ID("programId"), + OPTION_SET_ID("optionSetId"), ID("id"); private String name; @@ -107,6 +108,7 @@ public enum Combination { SHORT_NAME_ILIKE("shortName:ilike:"), DISPLAY_SHORT_NAME_ILIKE("displayShortName:ilike:"), PROGRAM_ID_EQUAL("programId:eq:"), + OPTION_SET_ID_EQUAL("optionSetId:eq:"), ID_EQUAL("id:eq:"), IDENTIFIABLE_TOKEN("identifiable:token:"); diff --git a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataitem/helper/FilteringHelper.java b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataitem/helper/FilteringHelper.java index 65b2d9f6b387..193dcb5b6d59 100644 --- a/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataitem/helper/FilteringHelper.java +++ b/dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/dataitem/helper/FilteringHelper.java @@ -49,6 +49,7 @@ import static org.hisp.dhis.dataitem.query.shared.QueryParam.IDENTIFIABLE_TOKEN_COMPARISON; import static org.hisp.dhis.dataitem.query.shared.QueryParam.LOCALE; import static org.hisp.dhis.dataitem.query.shared.QueryParam.NAME; +import static org.hisp.dhis.dataitem.query.shared.QueryParam.OPTION_SET_ID; import static org.hisp.dhis.dataitem.query.shared.QueryParam.PROGRAM_ID; import static org.hisp.dhis.dataitem.query.shared.QueryParam.ROOT_JUNCTION; import static org.hisp.dhis.dataitem.query.shared.QueryParam.SHORT_NAME; @@ -66,6 +67,7 @@ import static org.hisp.dhis.webapi.controller.dataitem.Filter.Combination.IDENTIFIABLE_TOKEN; import static org.hisp.dhis.webapi.controller.dataitem.Filter.Combination.ID_EQUAL; import static org.hisp.dhis.webapi.controller.dataitem.Filter.Combination.NAME_ILIKE; +import static org.hisp.dhis.webapi.controller.dataitem.Filter.Combination.OPTION_SET_ID_EQUAL; import static org.hisp.dhis.webapi.controller.dataitem.Filter.Combination.PROGRAM_ID_EQUAL; import static org.hisp.dhis.webapi.controller.dataitem.Filter.Combination.SHORT_NAME_ILIKE; import static org.hisp.dhis.webapi.controller.dataitem.Filter.Combination.VALUE_TYPE_EQUAL; @@ -298,6 +300,10 @@ public static void setFilteringParams( String programId = extractValueFromFilter(filters, PROGRAM_ID_EQUAL, true); addIfNotBlank(paramsMap, PROGRAM_ID, programId); + // Add optionSet id filtering id, if present. + String optionSetId = extractValueFromFilter(filters, OPTION_SET_ID_EQUAL, true); + addIfNotBlank(paramsMap, OPTION_SET_ID, optionSetId); + // Add user group filtering, when present. if (currentUser != null && CollectionUtils.isNotEmpty(currentUser.getGroups())) { Set userGroupUids =