Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(DHIS2-17506): enable configuring a section display options #17891

Merged
merged 3 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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() {
jbee marked this conversation as resolved.
Show resolved Hide resolved
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
Loading