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: Add embedded properties to Dashboard [DHIS2-18239] #18843

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
64de358
fix: Update code
larshelge Oct 16, 2024
03682ba
fix: Update code
larshelge Oct 16, 2024
28a46c3
fix: Update code
larshelge Oct 16, 2024
ad03f06
fix: Update code
larshelge Oct 16, 2024
2209fa3
fix: Update code
larshelge Oct 16, 2024
9bf3fda
fix: Update code
larshelge Oct 16, 2024
d594923
fix: Update code
larshelge Oct 16, 2024
5fa38c5
fix: Update code
larshelge Oct 16, 2024
0ad587e
fix: Update code
larshelge Oct 16, 2024
7ca2e31
fix: Update code
larshelge Oct 16, 2024
e1226f1
fix: Update code
larshelge Oct 16, 2024
8e03159
fix: Update code
larshelge Oct 16, 2024
5236fa9
fix: Update code
larshelge Oct 16, 2024
03f15ba
fix: Update code
larshelge Oct 16, 2024
bc18a7a
fix: Update code
larshelge Oct 16, 2024
267e883
fix: Update code
larshelge Oct 16, 2024
5ec16d3
fix: Update code
larshelge Oct 18, 2024
a16b434
Merge branch 'master' into DHIS2-18239
larshelge Oct 18, 2024
3e813c3
Merge branch 'master' into DHIS2-18239
janhenrikoverland Oct 21, 2024
d8a388d
Merge branch 'master' into DHIS2-18239
larshelge Oct 23, 2024
227d5aa
Merge branch 'DHIS2-18239' of github.com:dhis2/dhis2-core into DHIS2-…
larshelge Oct 23, 2024
7f0a2c6
fix: Update code
larshelge Oct 23, 2024
c89bea3
fix: Update code
larshelge Oct 23, 2024
3f4c46c
fix: Update code
larshelge Oct 23, 2024
3d0bf65
fix: Update code
larshelge Oct 23, 2024
7d9b97d
fix: Update code
larshelge Oct 23, 2024
3e30e25
fix: Update code
larshelge Oct 23, 2024
82b14b7
fix: Update code
larshelge Oct 24, 2024
c4a685b
Merge branch 'master' into DHIS2-18239
larshelge Oct 24, 2024
0715fd8
Merge branch 'master' into DHIS2-18239
larshelge Nov 1, 2024
b8843bc
fix: Update code
larshelge Nov 1, 2024
34a490d
fix: Update code
larshelge Nov 1, 2024
230af60
Merge branch 'master' into DHIS2-18239
larshelge Nov 1, 2024
6babdf3
fix: Update code
larshelge Nov 1, 2024
cd018e9
feat: Applied changes from feature branch [DHIS2-18339]
larshelge Nov 1, 2024
65d2c9e
Merge branch 'master' into DHIS2-18239
larshelge Nov 1, 2024
f7ab06c
fix: Update filter
larshelge Nov 1, 2024
3501437
fix: Update code
larshelge Nov 1, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
import java.util.ArrayList;
import java.util.List;
import lombok.NoArgsConstructor;
import org.hisp.dhis.common.BaseIdentifiableObject;
import org.hisp.dhis.common.BaseNameableObject;
import org.hisp.dhis.common.DxfNamespaces;
import org.hisp.dhis.common.MetadataObject;
import org.hisp.dhis.dashboard.design.ItemConfig;
import org.hisp.dhis.dashboard.design.Layout;
import org.hisp.dhis.dashboard.embedded.EmbeddedOptions;
import org.hisp.dhis.dashboard.embedded.EmbeddedProvider;

/**
* @author Lars Helge Overland
*/
@NoArgsConstructor
@JacksonXmlRootElement(localName = "dashboard", namespace = DxfNamespaces.DXF_2_0)
public class Dashboard extends BaseNameableObject implements MetadataObject {
public static final int MAX_ITEMS = 40;
Expand All @@ -67,11 +67,35 @@ public class Dashboard extends BaseNameableObject implements MetadataObject {
/** Allowed filter dimensions (if any) which may be used for the dashboard. */
private List<String> allowedFilters = new ArrayList<>();

/**
* Provider of embedded dashboards, is never <code>null</code>. The default value is {@link
* EmbeddedProvider#NONE} which refers to standard DHIS 2 dashboards. Other values indicate that
* this dashboard is sourced from an external provider and embedded in DHIS 2.
*/
private EmbeddedProvider embeddedProvider;
larshelge marked this conversation as resolved.
Show resolved Hide resolved

/**
* Identifier for external embedded dashboard, is <code>null</code> for DHIS 2 standard
* dashboards.
*/
private String embeddedId;

/**
* Customization options for external embedded options, is <code>null</code> for DHIS 2 standard
* dashboards.
*/
private EmbeddedOptions embeddedOptions;

// -------------------------------------------------------------------------
// Constructors
// -------------------------------------------------------------------------

public Dashboard() {
this.embeddedProvider = EmbeddedProvider.NONE;
}

public Dashboard(String name) {
this();
this.name = name;
}

Expand Down Expand Up @@ -146,4 +170,34 @@ public List<String> getAllowedFilters() {
public void setAllowedFilters(List<String> allowedFilters) {
this.allowedFilters = allowedFilters;
}

@JsonProperty
@JacksonXmlProperty(namespace = DXF_2_0)
public EmbeddedProvider getEmbeddedProvider() {
return embeddedProvider;
}

public void setEmbeddedProvider(EmbeddedProvider embeddedProvider) {
this.embeddedProvider = embeddedProvider;
}

@JsonProperty
@JacksonXmlProperty(namespace = DXF_2_0)
public String getEmbeddedId() {
return embeddedId;
}

public void setEmbeddedId(String embeddedId) {
this.embeddedId = embeddedId;
}

@JsonProperty
@JacksonXmlProperty(namespace = DXF_2_0)
public EmbeddedOptions getEmbeddedOptions() {
return embeddedOptions;
}

public void setEmbeddedOptions(EmbeddedOptions embeddedOptions) {
this.embeddedOptions = embeddedOptions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
package org.hisp.dhis.dashboard;

/**
* Encapsulates type of dashboard item.
*
* @author Lars Helge Overland
*/
public enum DashboardItemType {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2004-2024, 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.dashboard.embedded;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.io.Serializable;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
* Encapsulates customization options for embedded dashboards.
*
* @author Lars Helge Overland
*/
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class EmbeddedOptions implements Serializable {
/** Hide the chart controls. Applies to Superset. */
@JsonProperty private boolean hideChartControls;

/** Expand the filters panel. Applies to Superset. */
@JsonProperty private boolean expandFilters;

/** Show the filters panel. Applies to Superset. */
@JsonProperty private boolean showFilters;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2004-2024, 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.dashboard.embedded;

/**
* Enumeration of providers for embedded dashboards.
*
* @author Lars Helge Overland
*/
public enum EmbeddedProvider {
NONE,
SUPERSET;
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,7 @@ static boolean isTranslatable(@Nonnull String key) {
return LazySettings.isTranslatable(key);
}

/*
settings used in core
*/

/** Settings used in core */
default Locale getUiLocale() {
return asLocale("keyUiLocale", LocaleManager.DEFAULT_LOCALE);
}
Expand Down Expand Up @@ -308,6 +305,10 @@ default boolean getIncludeZeroValuesInAnalytics() {
return asBoolean("keyIncludeZeroValuesInAnalytics", false);
}

default boolean getEmbeddedDashboardsEnabled() {
return asBoolean("keyEmbeddedDashboardsEnabled", false);
}

default int getSqlViewMaxLimit() {
return asInt("keySqlViewMaxLimit", -1);
}
Expand Down Expand Up @@ -720,12 +721,7 @@ default String getGlobalShellAppName() {
return asString("globalShellAppName", "global-app-shell");
}

/*

Combinators based on several settings

*/

/** Combinators based on several settings. */
default boolean isEmailConfigured() {
return !getEmailHostName().isBlank() && getEmailUsername().isBlank();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@

<property name="allowedFilters" column="allowedfilters" type="jbList" />

<property name="embeddedProvider" column="embeddedprovider" length="50" not-null="true">
<type name="org.hibernate.type.EnumType">
<param name="enumClass">org.hisp.dhis.dashboard.embedded.EmbeddedProvider</param>
<param name="useNamed">true</param>
<param name="type">12</param>
</type>
</property>

<property name="embeddedId" column="embeddedid" />

<property name="embeddedOptions" column="embeddedoptions" type="jbEmbeddedOptions" />

<!-- Sharing -->
<property name="sharing" type="jsbObjectSharing"/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;

/** A system setting, for use in store layer only. */
@Slf4j
@Setter
@Getter
@ToString
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ void testIsTranslatable() {
@Test
void testKeysWithDefaults() {
Set<String> keys = SystemSettings.keysWithDefaults();
assertEquals(135, keys.size());
assertEquals(136, keys.size());
// just check some at random
assertTrue(keys.contains("syncSkipSyncForDataChangedBefore"));
assertTrue(keys.contains("keyTrackerDashboardLayout"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

-- Add various embedded dashboard property columns to dashboard table

alter table "dashboard" add column if not exists "embeddedprovider" varchar(50);
update "dashboard" set "embeddedprovider" = 'NONE' where "embeddedprovider" is null;
alter table "dashboard" alter column "embeddedprovider" set not null;

alter table "dashboard" add column if not exists "embeddedid" varchar(255);

alter table "dashboard" add column if not exists "embeddedoptions" jsonb;
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@
<param name="clazz">org.hisp.dhis.dashboard.design.ItemConfig</param>
</typedef>

<typedef class="org.hisp.dhis.hibernate.jsonb.type.JsonBinaryType" name="jbEmbeddedOptions">
<param name="clazz">org.hisp.dhis.dashboard.embedded.EmbeddedOptions</param>
</typedef>

<typedef class="org.hisp.dhis.hibernate.jsonb.type.JsonBinaryType" name="jbTextPattern">
<param name="clazz">org.hisp.dhis.textpattern.TextPattern</param>
</typedef>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.dashboard.embedded.EmbeddedOptions;
import org.hisp.dhis.dashboard.embedded.EmbeddedProvider;
import org.hisp.dhis.document.Document;
import org.hisp.dhis.document.DocumentService;
import org.hisp.dhis.eventchart.EventChart;
Expand Down Expand Up @@ -82,6 +85,8 @@ class DashboardServiceTest extends PostgresIntegrationTestBase {

private Dashboard dbB;

private Dashboard dbC;

private DashboardItem diA;

private DashboardItem diB;
Expand Down Expand Up @@ -136,28 +141,40 @@ void setUp() {
diE = new DashboardItem();
diE.setAutoFields();
diE.setEventVisualization(evzB);

dbA = new Dashboard("A");
dbA.setAutoFields();
dbA.getItems().add(diA);
dbA.getItems().add(diB);
dbA.getItems().add(diC);

dbB = new Dashboard("B");
dbB.setAutoFields();
dbB.setRestrictFilters(true);
dbB.setAllowedFilters(allowedFilters);
dbB.getItems().add(diD);
dbB.getItems().add(diE);

dbC = new Dashboard("C");
dbC.setAutoFields();
dbC.setEmbeddedProvider(EmbeddedProvider.SUPERSET);
dbC.setEmbeddedId("41c52308-1db4-4971-ade4-50c4d12c201d");
dbC.setEmbeddedOptions(new EmbeddedOptions(true, true, true));
}

@Test
void testAddGet() {
void testSaveGet() {
long dAId = dashboardService.saveDashboard(dbA);
long dBId = dashboardService.saveDashboard(dbB);
long dCId = dashboardService.saveDashboard(dbC);
assertEquals(dbA, dashboardService.getDashboard(dAId));
assertEquals(dbB, dashboardService.getDashboard(dBId));
assertEquals(dbC, dashboardService.getDashboard(dCId));
assertEquals(2, dbB.getAllowedFilters().size());
assertEquals(3, dashboardService.getDashboard(dAId).getItems().size());
assertEquals(2, dashboardService.getDashboard(dBId).getItems().size());
assertNotNull(dashboardService.getDashboard(dCId).getEmbeddedId());
assertTrue(dashboardService.getDashboard(dCId).getEmbeddedOptions().isHideChartControls());
}

@Test
Expand Down
Loading