From c4c7bbe765d74aa8ceb670417ad6d0d055cfaefe Mon Sep 17 00:00:00 2001 From: Flaminia Cavallo Date: Wed, 26 Jun 2024 16:36:07 +0200 Subject: [PATCH 1/3] feat(DHIS2-17506): enable configuring a section display options --- .../src/main/java/org/hisp/dhis/dataset/DataSet.java | 12 ++++++++++++ .../org/hisp/dhis/dataset/hibernate/DataSet.hbm.xml | 2 ++ .../V2_42_8__Add_dataset_diplayoptions_field.sql | 1 + 3 files changed, 15 insertions(+) create mode 100644 dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_8__Add_dataset_diplayoptions_field.sql diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java index 877663eb8ad9..a4accba6b933 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java @@ -194,6 +194,8 @@ public class DataSet extends BaseDimensionalItemObject private ObjectStyle style; + private String displayOptions; + // ------------------------------------------------------------------------- // Constructors // ------------------------------------------------------------------------- @@ -778,6 +780,16 @@ public void setStyle(ObjectStyle style) { this.style = style; } + @JsonProperty + @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) + public String getDisplayOptions() { + return displayOptions; + } + + public void setDisplayOptions(String displayOptions) { + this.displayOptions = displayOptions; + } + @Override @JsonProperty @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataset/hibernate/DataSet.hbm.xml b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataset/hibernate/DataSet.hbm.xml index 3144aa89faf9..2dad9217f907 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataset/hibernate/DataSet.hbm.xml +++ b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dataset/hibernate/DataSet.hbm.xml @@ -25,6 +25,8 @@ + + diff --git a/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_8__Add_dataset_diplayoptions_field.sql b/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_8__Add_dataset_diplayoptions_field.sql new file mode 100644 index 000000000000..9abb5e910fef --- /dev/null +++ b/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_8__Add_dataset_diplayoptions_field.sql @@ -0,0 +1 @@ +ALTER TABLE dataset ADD COLUMN IF NOT EXISTS displayoptions jsonb default '{}'::jsonb; From cf7e884fa8983eccc7ed9dc0a3b21d066bfc0f05 Mon Sep 17 00:00:00 2001 From: Flaminia Cavallo Date: Thu, 27 Jun 2024 15:42:56 +0200 Subject: [PATCH 2/3] feat: add openAPi annotation to display options in dataset and section --- .../dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java | 3 +++ .../dhis-api/src/main/java/org/hisp/dhis/dataset/Section.java | 3 +++ 2 files changed, 6 insertions(+) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java index a4accba6b933..ecb62a024e64 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java @@ -33,6 +33,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; @@ -56,6 +57,7 @@ import org.hisp.dhis.common.InterpretableObject; import org.hisp.dhis.common.MetadataObject; import org.hisp.dhis.common.ObjectStyle; +import org.hisp.dhis.common.OpenApi; import org.hisp.dhis.common.VersionedObject; import org.hisp.dhis.common.adapter.JacksonPeriodTypeDeserializer; import org.hisp.dhis.common.adapter.JacksonPeriodTypeSerializer; @@ -782,6 +784,7 @@ public void setStyle(ObjectStyle style) { @JsonProperty @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) + @OpenApi.Property(ObjectNode.class) public String getDisplayOptions() { return displayOptions; } diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/Section.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/Section.java index 3c15f74a9f4d..e9514f3368c8 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/Section.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/Section.java @@ -29,6 +29,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty; import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement; @@ -40,6 +41,7 @@ import org.hisp.dhis.common.BaseIdentifiableObject; import org.hisp.dhis.common.DxfNamespaces; import org.hisp.dhis.common.MetadataObject; +import org.hisp.dhis.common.OpenApi; import org.hisp.dhis.dataelement.DataElement; import org.hisp.dhis.dataelement.DataElementOperand; import org.hisp.dhis.indicator.Indicator; @@ -218,6 +220,7 @@ public void setShowColumnTotals(boolean showColumnTotals) { @JsonProperty @JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0) + @OpenApi.Property(ObjectNode.class) public String getDisplayOptions() { return displayOptions; } From 347926ce64a65b5f98e28fef1256d2bfffbd3329 Mon Sep 17 00:00:00 2001 From: Flaminia Cavallo Date: Mon, 1 Jul 2024 11:50:54 +0200 Subject: [PATCH 3/3] feat: add tests for posting and retrieving datasets display options --- .../DataSetMetadataControllerTest.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/DataSetMetadataControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/DataSetMetadataControllerTest.java index a63fa554c92e..30261e4de245 100644 --- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/DataSetMetadataControllerTest.java +++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/DataSetMetadataControllerTest.java @@ -36,6 +36,7 @@ import org.hisp.dhis.web.WebClient; import org.hisp.dhis.webapi.DhisControllerIntegrationTest; import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -70,6 +71,37 @@ void getDatasetMetadataDefaultCatComboTest( assertEquals(expectedDefaultCatComboCount, count, defaultCatComboCondition); } + @Test + @DisplayName("Dataset display options are correctly saved and retrieved") + void getDatasetMetadataDisplayOptionsTest() { + String expectedDisplayOptions = "{\"aDisplay\": \"option\"}"; + String dataSetsBody = + """ + { + "dataSets": [ + { + "name": "hellobrenda", + "shortName": "hellobrenda", + "periodType": "Daily", + "displayOptions": "{\\"aDisplay\\": \\"option\\"}" + } + ] + } + """; + + // given + POST("/metadata", WebClient.Body(dataSetsBody)).content(HttpStatus.OK); + + // when the data entry metadata is retrieves + JsonObject dataEntryMetadata = GET("/dataEntry/metadata").content(); + JsonArray dataSets = dataEntryMetadata.getArray("dataSets"); + String actualDisplayOptions = dataSets.getObject(0).getString("displayOptions").string(); + + // then + assertEquals(1, dataSets.size()); + assertEquals(expectedDisplayOptions, actualDisplayOptions); + } + private static Stream defaultCatComboData() { return Stream.of( Arguments.of(