Skip to content

Commit

Permalink
feat(DHIS2-17506): enable configuring a section display options (#17891)
Browse files Browse the repository at this point in the history
* feat(DHIS2-17506): enable configuring a section display options

* feat: add openAPi annotation to display options in dataset and section

* feat: add tests for posting and retrieving datasets display options
  • Loading branch information
flaminic authored Jul 4, 2024
1 parent c4d4134 commit dd12f02
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 0 deletions.
15 changes: 15 additions & 0 deletions dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/DataSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -194,6 +196,8 @@ public class DataSet extends BaseDimensionalItemObject

private ObjectStyle style;

private String displayOptions;

// -------------------------------------------------------------------------
// Constructors
// -------------------------------------------------------------------------
Expand Down Expand Up @@ -778,6 +782,17 @@ public void setStyle(ObjectStyle style) {
this.style = style;
}

@JsonProperty
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
@OpenApi.Property(ObjectNode.class)
public String getDisplayOptions() {
return displayOptions;
}

public void setDisplayOptions(String displayOptions) {
this.displayOptions = displayOptions;
}

@Override
@JsonProperty
@JacksonXmlProperty(namespace = DxfNamespaces.DXF_2_0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

<property name="style" type="jbObjectStyle" column="style" />

<property name="displayOptions" type="jbPlainString" column="displayoptions" length="50000" />

<many-to-one name="periodType" lazy="false" class="org.hisp.dhis.period.PeriodType" column="periodtypeid"
not-null="true" foreign-key="fk_dataset_periodtypeid" />

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE dataset ADD COLUMN IF NOT EXISTS displayoptions jsonb default '{}'::jsonb;
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Arguments> defaultCatComboData() {
return Stream.of(
Arguments.of(
Expand Down

0 comments on commit dd12f02

Please sign in to comment.