From 64de358ae6ab44d17bd8bebafbd8e65eb00db7ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Wed, 16 Oct 2024 17:17:03 +0200 Subject: [PATCH 01/29] fix: Update code --- .../org/hisp/dhis/dashboard/Dashboard.java | 51 +++++++++++++++++++ .../dhis/dashboard/DashboardItemType.java | 2 + .../dashboard/embedded/EmbeddedOptions.java | 43 ++++++++++++++++ .../dashboard/embedded/EmbeddedProvider.java | 34 +++++++++++++ .../dashboard/hibernate/Dashboard.hbm.xml | 12 +++++ .../org/hisp/dhis/setting/SystemSetting.java | 2 - .../org/hisp/dhis/usertype/UserTypes.hbm.xml | 4 ++ 7 files changed, 146 insertions(+), 2 deletions(-) create mode 100644 dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedOptions.java create mode 100644 dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedProvider.java diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java index b7dbab8bff09..2c286b483ef0 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java @@ -43,6 +43,8 @@ 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 @@ -67,6 +69,25 @@ public class Dashboard extends BaseNameableObject implements MetadataObject { /** Allowed filter dimensions (if any) which may be used for the dashboard. */ private List allowedFilters = new ArrayList<>(); + /** + * Provider of embedded dashboards. The {@link EmbeddedProvider#NATIVE} value refers to + * non-embedded, standard DHIS 2 dashboards. Other values indicate that this dashboard is sourced + * from an external provider and embedded into DHIS 2. + */ + private EmbeddedProvider embeddedProvider; + + /** + * Identifier for external embedded dashboard, is null for DHIS 2 standard + * dashboards. + */ + private String embeddedId; + + /** + * Customization options for external embedded options, is null for DHIS 2 standard + * dashboards. + */ + private EmbeddedOptions embeddedOptions; + // ------------------------------------------------------------------------- // Constructors // ------------------------------------------------------------------------- @@ -146,4 +167,34 @@ public List getAllowedFilters() { public void setAllowedFilters(List 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; + } } diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItemType.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItemType.java index ea804396b2a7..4f1122f41b8d 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItemType.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItemType.java @@ -28,6 +28,8 @@ package org.hisp.dhis.dashboard; /** + * Encapsulates type of dashboard item. + * * @author Lars Helge Overland */ public enum DashboardItemType { diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedOptions.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedOptions.java new file mode 100644 index 000000000000..484cee07a429 --- /dev/null +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedOptions.java @@ -0,0 +1,43 @@ +/* + * 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; + +/** Encapsulates customization options for embedded dashboards. */ +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; +} diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedProvider.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedProvider.java new file mode 100644 index 000000000000..161a7a1e8289 --- /dev/null +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedProvider.java @@ -0,0 +1,34 @@ +/* + * 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. */ +public enum EmbeddedProvider { + NATIVE, + SUPERSET; +} diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dashboard/hibernate/Dashboard.hbm.xml b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dashboard/hibernate/Dashboard.hbm.xml index 705ce90a3e12..c7cc2db171f0 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dashboard/hibernate/Dashboard.hbm.xml +++ b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dashboard/hibernate/Dashboard.hbm.xml @@ -39,6 +39,18 @@ + + + org.hisp.dhis.dashboard.embedded.EmbeddedProvider + true + 12 + + + + + + + diff --git a/dhis-2/dhis-services/dhis-service-setting/src/main/java/org/hisp/dhis/setting/SystemSetting.java b/dhis-2/dhis-services/dhis-service-setting/src/main/java/org/hisp/dhis/setting/SystemSetting.java index e75984454ff0..bc20d2e231c9 100644 --- a/dhis-2/dhis-services/dhis-service-setting/src/main/java/org/hisp/dhis/setting/SystemSetting.java +++ b/dhis-2/dhis-services/dhis-service-setting/src/main/java/org/hisp/dhis/setting/SystemSetting.java @@ -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 diff --git a/dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/org/hisp/dhis/usertype/UserTypes.hbm.xml b/dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/org/hisp/dhis/usertype/UserTypes.hbm.xml index 92f2ab4d29fc..ab4ffd4e5e8c 100644 --- a/dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/org/hisp/dhis/usertype/UserTypes.hbm.xml +++ b/dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/org/hisp/dhis/usertype/UserTypes.hbm.xml @@ -77,6 +77,10 @@ org.hisp.dhis.dashboard.design.ItemConfig + + org.hisp.dhis.dashboard.embedded.EmbeddedOptions + + org.hisp.dhis.textpattern.TextPattern From 03682baa46640788f3632ccc516f2af2de1e9012 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Wed, 16 Oct 2024 17:22:07 +0200 Subject: [PATCH 02/29] fix: Update code --- .../org/hisp/dhis/dashboard/hibernate/Dashboard.hbm.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dashboard/hibernate/Dashboard.hbm.xml b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dashboard/hibernate/Dashboard.hbm.xml index c7cc2db171f0..4370e09031d5 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dashboard/hibernate/Dashboard.hbm.xml +++ b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dashboard/hibernate/Dashboard.hbm.xml @@ -39,7 +39,7 @@ - + org.hisp.dhis.dashboard.embedded.EmbeddedProvider true @@ -49,7 +49,7 @@ - + From 28a46c30e8390fb3270ff9cd614ceabe76b2dad3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Wed, 16 Oct 2024 17:36:12 +0200 Subject: [PATCH 03/29] fix: Update code --- .../org/hisp/dhis/setting/SystemSettings.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettings.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettings.java index 023e0ee47788..f36e7319fcbb 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettings.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettings.java @@ -106,10 +106,7 @@ static boolean isConfidential(@Nonnull String key) { return LazySettings.isConfidential(key); } - /* - settings used in core - */ - + /** Settings used in core. */ default Locale getUiLocale() { return asLocale("keyUiLocale", LocaleManager.DEFAULT_LOCALE); } @@ -294,6 +291,10 @@ default boolean getIncludeZeroValuesInAnalytics() { return asBoolean("keyIncludeZeroValuesInAnalytics", false); } + default boolean getEmbeddedDashboardsEnabled() { + return asBoolean("keyEmbeddedDashboardsEnabled", false); + } + default int getSqlViewMaxLimit() { return asInt("keySqlViewMaxLimit", -1); } @@ -705,12 +706,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(); } From ad03f06bd76e7ccd5c6a046cb6a304ec7e5a6d5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Wed, 16 Oct 2024 17:55:42 +0200 Subject: [PATCH 04/29] fix: Update code --- .../test/java/org/hisp/dhis/setting/SystemSettingsTest.java | 2 +- .../2.42/V2_42_23__Add_embedded_properties_to_dashboard.sql | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_23__Add_embedded_properties_to_dashboard.sql diff --git a/dhis-2/dhis-services/dhis-service-setting/src/test/java/org/hisp/dhis/setting/SystemSettingsTest.java b/dhis-2/dhis-services/dhis-service-setting/src/test/java/org/hisp/dhis/setting/SystemSettingsTest.java index 5ba2d9ea19a7..eeb20ef549fc 100644 --- a/dhis-2/dhis-services/dhis-service-setting/src/test/java/org/hisp/dhis/setting/SystemSettingsTest.java +++ b/dhis-2/dhis-services/dhis-service-setting/src/test/java/org/hisp/dhis/setting/SystemSettingsTest.java @@ -68,7 +68,7 @@ void testIsConfidential() { @Test void testKeysWithDefaults() { Set keys = SystemSettings.keysWithDefaults(); - assertEquals(135, keys.size()); + assertEquals(136, keys.size()); // just check some at random assertTrue(keys.contains("syncSkipSyncForDataChangedBefore")); assertTrue(keys.contains("keyTrackerDashboardLayout")); diff --git a/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_23__Add_embedded_properties_to_dashboard.sql b/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_23__Add_embedded_properties_to_dashboard.sql new file mode 100644 index 000000000000..1dfe36c51e98 --- /dev/null +++ b/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_23__Add_embedded_properties_to_dashboard.sql @@ -0,0 +1,6 @@ + +-- Add various embedded dashboard property columns to dashboard table + +alter table "dashboard" add column if not exists "embeddedprovider" varchar(50); +alter table "dashboard" add column if not exists "embeddedid" text; +alter table "dashboard" add column if not exists "embeddedoptions" jsonb; From 2209fa34ccd7d92aa620972228cc98d9d4301b2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Wed, 16 Oct 2024 17:58:16 +0200 Subject: [PATCH 05/29] fix: Update code --- .../src/main/java/org/hisp/dhis/dashboard/Dashboard.java | 2 +- .../2.42/V2_42_23__Add_embedded_properties_to_dashboard.sql | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java index 2c286b483ef0..859a37e8aa03 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java @@ -72,7 +72,7 @@ public class Dashboard extends BaseNameableObject implements MetadataObject { /** * Provider of embedded dashboards. The {@link EmbeddedProvider#NATIVE} value refers to * non-embedded, standard DHIS 2 dashboards. Other values indicate that this dashboard is sourced - * from an external provider and embedded into DHIS 2. + * from an external provider and embedded into DHIS 2. Not null. */ private EmbeddedProvider embeddedProvider; diff --git a/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_23__Add_embedded_properties_to_dashboard.sql b/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_23__Add_embedded_properties_to_dashboard.sql index 1dfe36c51e98..3071ede3126c 100644 --- a/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_23__Add_embedded_properties_to_dashboard.sql +++ b/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_23__Add_embedded_properties_to_dashboard.sql @@ -2,5 +2,9 @@ -- Add various embedded dashboard property columns to dashboard table alter table "dashboard" add column if not exists "embeddedprovider" varchar(50); +update "dashboard" set "embeddedprovider" = 'NATIVE' where "embeddedprovider" is null; +alter table "dashboard" alter column "embeddedprovider" set not null; + alter table "dashboard" add column if not exists "embeddedid" text; + alter table "dashboard" add column if not exists "embeddedoptions" jsonb; From 9bf3fdab03f76ba89f659dd143102de704eb00f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Wed, 16 Oct 2024 17:59:33 +0200 Subject: [PATCH 06/29] fix: Update code --- .../org/hisp/dhis/dashboard/embedded/EmbeddedOptions.java | 6 +++++- .../org/hisp/dhis/dashboard/embedded/EmbeddedProvider.java | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedOptions.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedOptions.java index 484cee07a429..745250555195 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedOptions.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedOptions.java @@ -30,7 +30,11 @@ import com.fasterxml.jackson.annotation.JsonProperty; import java.io.Serializable; -/** Encapsulates customization options for embedded dashboards. */ +/** + * Encapsulates customization options for embedded dashboards. + * + * @author Lars Helge Overland + */ public class EmbeddedOptions implements Serializable { /** Hide the chart controls. Applies to Superset. */ @JsonProperty private boolean hideChartControls; diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedProvider.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedProvider.java index 161a7a1e8289..880304bdd064 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedProvider.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedProvider.java @@ -27,7 +27,11 @@ */ package org.hisp.dhis.dashboard.embedded; -/** Enumeration of providers for embedded dashboards. */ +/** + * Enumeration of providers for embedded dashboards. + * + * @author Lars Helge Overland + */ public enum EmbeddedProvider { NATIVE, SUPERSET; From d5949230a82eedba10162553f601060c1d0f41d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Wed, 16 Oct 2024 18:34:17 +0200 Subject: [PATCH 07/29] fix: Update code --- .../src/main/java/org/hisp/dhis/dashboard/Dashboard.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java index 859a37e8aa03..920874289457 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java @@ -36,7 +36,6 @@ 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; @@ -49,7 +48,6 @@ /** * @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; @@ -92,7 +90,12 @@ public class Dashboard extends BaseNameableObject implements MetadataObject { // Constructors // ------------------------------------------------------------------------- + public Dashboard() { + this.embeddedProvider = EmbeddedProvider.NATIVE; + } + public Dashboard(String name) { + this(); this.name = name; } From 5fa38c5ccfeab75c713a68f7b71792abd3848221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Wed, 16 Oct 2024 19:51:15 +0200 Subject: [PATCH 08/29] fix: Update code --- .../dashboard/embedded/EmbeddedOptions.java | 8 ++++++++ ...__Add_embedded_properties_to_dashboard.sql | 2 +- .../dhis/dashboard/DashboardServiceTest.java | 20 ++++++++++++++++++- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedOptions.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedOptions.java index 745250555195..03a1a0f997af 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedOptions.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedOptions.java @@ -29,12 +29,20 @@ 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; diff --git a/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_23__Add_embedded_properties_to_dashboard.sql b/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_23__Add_embedded_properties_to_dashboard.sql index 3071ede3126c..2f996b844d1f 100644 --- a/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_23__Add_embedded_properties_to_dashboard.sql +++ b/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_23__Add_embedded_properties_to_dashboard.sql @@ -5,6 +5,6 @@ alter table "dashboard" add column if not exists "embeddedprovider" varchar(50); update "dashboard" set "embeddedprovider" = 'NATIVE' where "embeddedprovider" is null; alter table "dashboard" alter column "embeddedprovider" set not null; -alter table "dashboard" add column if not exists "embeddedid" text; +alter table "dashboard" add column if not exists "embeddedid" varchar(255); alter table "dashboard" add column if not exists "embeddedoptions" jsonb; diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dashboard/DashboardServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dashboard/DashboardServiceTest.java index 29c790d8bbfc..e05ee5226c31 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dashboard/DashboardServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dashboard/DashboardServiceTest.java @@ -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; @@ -82,6 +85,8 @@ class DashboardServiceTest extends PostgresIntegrationTestBase { private Dashboard dbB; + private Dashboard dbC; + private DashboardItem diA; private DashboardItem diB; @@ -136,28 +141,41 @@ 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()); + assertNotNull(dashboardService.getDashboard(dCId).getEmbeddedOptions()); + assertTrue(dashboardService.getDashboard(dCId).getEmbeddedOptions().isHideChartControls()); } @Test From 0ad587e81306dd7dd85c4eb660db547b3b3d7c5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Wed, 16 Oct 2024 19:51:26 +0200 Subject: [PATCH 09/29] fix: Update code --- .../test/java/org/hisp/dhis/dashboard/DashboardServiceTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dashboard/DashboardServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dashboard/DashboardServiceTest.java index e05ee5226c31..3878233be430 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dashboard/DashboardServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dashboard/DashboardServiceTest.java @@ -174,7 +174,6 @@ void testSaveGet() { assertEquals(3, dashboardService.getDashboard(dAId).getItems().size()); assertEquals(2, dashboardService.getDashboard(dBId).getItems().size()); assertNotNull(dashboardService.getDashboard(dCId).getEmbeddedId()); - assertNotNull(dashboardService.getDashboard(dCId).getEmbeddedOptions()); assertTrue(dashboardService.getDashboard(dCId).getEmbeddedOptions().isHideChartControls()); } From 7ca2e319fece0e8de1e25ea99098e3feae177b83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Wed, 16 Oct 2024 20:08:47 +0200 Subject: [PATCH 10/29] fix: Update code --- .../src/main/java/org/hisp/dhis/dashboard/Dashboard.java | 8 ++++---- .../hisp/dhis/dashboard/embedded/EmbeddedProvider.java | 2 +- .../V2_42_23__Add_embedded_properties_to_dashboard.sql | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java index 920874289457..d880b0dc12ec 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java @@ -68,9 +68,9 @@ public class Dashboard extends BaseNameableObject implements MetadataObject { private List allowedFilters = new ArrayList<>(); /** - * Provider of embedded dashboards. The {@link EmbeddedProvider#NATIVE} value refers to - * non-embedded, standard DHIS 2 dashboards. Other values indicate that this dashboard is sourced - * from an external provider and embedded into DHIS 2. Not null. + * Provider of embedded dashboards. The {@link EmbeddedProvider#NONE} value refers to standard + * DHIS 2 dashboards. Other values indicate that this dashboard is sourced from an external + * provider and embedded into DHIS 2. Not null. */ private EmbeddedProvider embeddedProvider; @@ -91,7 +91,7 @@ public class Dashboard extends BaseNameableObject implements MetadataObject { // ------------------------------------------------------------------------- public Dashboard() { - this.embeddedProvider = EmbeddedProvider.NATIVE; + this.embeddedProvider = EmbeddedProvider.NONE; } public Dashboard(String name) { diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedProvider.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedProvider.java index 880304bdd064..4e337cbda9cb 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedProvider.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedProvider.java @@ -33,6 +33,6 @@ * @author Lars Helge Overland */ public enum EmbeddedProvider { - NATIVE, + NONE, SUPERSET; } diff --git a/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_23__Add_embedded_properties_to_dashboard.sql b/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_23__Add_embedded_properties_to_dashboard.sql index 2f996b844d1f..aae41935862f 100644 --- a/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_23__Add_embedded_properties_to_dashboard.sql +++ b/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_23__Add_embedded_properties_to_dashboard.sql @@ -2,7 +2,7 @@ -- Add various embedded dashboard property columns to dashboard table alter table "dashboard" add column if not exists "embeddedprovider" varchar(50); -update "dashboard" set "embeddedprovider" = 'NATIVE' where "embeddedprovider" is null; +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); From e1226f153bf611a0b0652b1285146849711a4491 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Wed, 16 Oct 2024 20:09:06 +0200 Subject: [PATCH 11/29] fix: Update code --- .../src/main/java/org/hisp/dhis/dashboard/Dashboard.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java index d880b0dc12ec..6402e23d061b 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java @@ -70,7 +70,7 @@ public class Dashboard extends BaseNameableObject implements MetadataObject { /** * Provider of embedded dashboards. The {@link EmbeddedProvider#NONE} value refers to standard * DHIS 2 dashboards. Other values indicate that this dashboard is sourced from an external - * provider and embedded into DHIS 2. Not null. + * provider and embedded into DHIS 2. Property value is never null. */ private EmbeddedProvider embeddedProvider; From 8e03159abcf7a666f96dbb835f65a1ea9eb5c163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Wed, 16 Oct 2024 20:09:16 +0200 Subject: [PATCH 12/29] fix: Update code --- .../src/main/java/org/hisp/dhis/dashboard/Dashboard.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java index 6402e23d061b..41aef044657f 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java @@ -70,7 +70,7 @@ public class Dashboard extends BaseNameableObject implements MetadataObject { /** * Provider of embedded dashboards. The {@link EmbeddedProvider#NONE} value refers to standard * DHIS 2 dashboards. Other values indicate that this dashboard is sourced from an external - * provider and embedded into DHIS 2. Property value is never null. + * provider and embedded into DHIS 2. Property value is never null. */ private EmbeddedProvider embeddedProvider; From 5236fa9e05e707afaa1064b288a49f94912ce430 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Wed, 16 Oct 2024 20:09:39 +0200 Subject: [PATCH 13/29] fix: Update code --- .../src/main/java/org/hisp/dhis/dashboard/Dashboard.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java index 41aef044657f..cd21de4b1053 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java @@ -68,9 +68,9 @@ public class Dashboard extends BaseNameableObject implements MetadataObject { private List allowedFilters = new ArrayList<>(); /** - * Provider of embedded dashboards. The {@link EmbeddedProvider#NONE} value refers to standard - * DHIS 2 dashboards. Other values indicate that this dashboard is sourced from an external - * provider and embedded into DHIS 2. Property value is never null. + * Provider of embedded dashboards, is never null. The {@link EmbeddedProvider#NONE} + * value refers to standard DHIS 2 dashboards. Other values indicate that this dashboard is + * sourced from an external provider and embedded into DHIS 2. */ private EmbeddedProvider embeddedProvider; From 03f15badbfbb500a0c904d88b492697a80265c1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Wed, 16 Oct 2024 20:09:56 +0200 Subject: [PATCH 14/29] fix: Update code --- .../src/main/java/org/hisp/dhis/dashboard/Dashboard.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java index cd21de4b1053..e917c31f7971 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java @@ -70,7 +70,7 @@ public class Dashboard extends BaseNameableObject implements MetadataObject { /** * Provider of embedded dashboards, is never null. The {@link EmbeddedProvider#NONE} * value refers to standard DHIS 2 dashboards. Other values indicate that this dashboard is - * sourced from an external provider and embedded into DHIS 2. + * sourced from an external provider and embedded in DHIS 2. */ private EmbeddedProvider embeddedProvider; From bc18a7a0054baa20430b14782d5d5650fb7585c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Wed, 16 Oct 2024 20:10:35 +0200 Subject: [PATCH 15/29] fix: Update code --- .../src/main/java/org/hisp/dhis/dashboard/Dashboard.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java index e917c31f7971..87ac9257481e 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java @@ -68,9 +68,9 @@ public class Dashboard extends BaseNameableObject implements MetadataObject { private List allowedFilters = new ArrayList<>(); /** - * Provider of embedded dashboards, is never null. The {@link EmbeddedProvider#NONE} - * value refers to standard DHIS 2 dashboards. Other values indicate that this dashboard is - * sourced from an external provider and embedded in DHIS 2. + * Provider of embedded dashboards, is never null. The default {@link + * EmbeddedProvider#NONE} value 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; From 267e8839451871e3c45b44564f39b56a8497d4b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Wed, 16 Oct 2024 20:10:52 +0200 Subject: [PATCH 16/29] fix: Update code --- .../src/main/java/org/hisp/dhis/dashboard/Dashboard.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java index 87ac9257481e..c19e378fc862 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java @@ -68,8 +68,8 @@ public class Dashboard extends BaseNameableObject implements MetadataObject { private List allowedFilters = new ArrayList<>(); /** - * Provider of embedded dashboards, is never null. The default {@link - * EmbeddedProvider#NONE} value refers to standard DHIS 2 dashboards. Other values indicate that + * Provider of embedded dashboards, is never null. 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; From 7f0a2c680ef41a486f0f2614d1557c85d2e397cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Wed, 23 Oct 2024 13:04:01 +0200 Subject: [PATCH 17/29] fix: Update code --- .../org/hisp/dhis/dashboard/Dashboard.java | 56 +++---------------- .../dashboard/embedded/EmbeddedDashboard.java | 47 ++++++++++++++++ .../dashboard/embedded/EmbeddedProvider.java | 1 - .../dashboard/hibernate/Dashboard.hbm.xml | 2 + ...> V2_42_23__Add_embedded_to_dashboard.sql} | 0 .../org/hisp/dhis/usertype/UserTypes.hbm.xml | 4 +- 6 files changed, 59 insertions(+), 51 deletions(-) create mode 100644 dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedDashboard.java rename dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/{V2_42_23__Add_embedded_properties_to_dashboard.sql => V2_42_23__Add_embedded_to_dashboard.sql} (100%) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java index c19e378fc862..722bf2eebcf0 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java @@ -42,8 +42,7 @@ 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; +import org.hisp.dhis.dashboard.embedded.EmbeddedDashboard; /** * @author Lars Helge Overland @@ -67,35 +66,16 @@ public class Dashboard extends BaseNameableObject implements MetadataObject { /** Allowed filter dimensions (if any) which may be used for the dashboard. */ private List allowedFilters = new ArrayList<>(); - /** - * Provider of embedded dashboards, is never null. 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; - - /** - * Identifier for external embedded dashboard, is null for DHIS 2 standard - * dashboards. - */ - private String embeddedId; - - /** - * Customization options for external embedded options, is null for DHIS 2 standard - * dashboards. - */ - private EmbeddedOptions embeddedOptions; + /** Optional, only set if this dashboard is embedded and sourced from an external provider. */ + private EmbeddedDashboard embedded; // ------------------------------------------------------------------------- // Constructors // ------------------------------------------------------------------------- - public Dashboard() { - this.embeddedProvider = EmbeddedProvider.NONE; - } + public Dashboard() {} public Dashboard(String name) { - this(); this.name = name; } @@ -173,31 +153,11 @@ public void setAllowedFilters(List 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 EmbeddedDashboard getEmbedded() { + return embedded; } - public void setEmbeddedOptions(EmbeddedOptions embeddedOptions) { - this.embeddedOptions = embeddedOptions; + public void setEmbedded(EmbeddedDashboard embedded) { + this.embedded = embedded; } } diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedDashboard.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedDashboard.java new file mode 100644 index 000000000000..fda843181f23 --- /dev/null +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedDashboard.java @@ -0,0 +1,47 @@ +/* + * 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 java.io.Serializable; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +public class EmbeddedDashboard implements Serializable { + /** Provider of embedded dashboards. */ + private EmbeddedProvider provider; + + /** Identifier for embedded dashboard. */ + private String id; + + /** Customization options for embedded dashboard. */ + private EmbeddedOptions options; +} diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedProvider.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedProvider.java index 4e337cbda9cb..3b7ee0aca75c 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedProvider.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedProvider.java @@ -33,6 +33,5 @@ * @author Lars Helge Overland */ public enum EmbeddedProvider { - NONE, SUPERSET; } diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dashboard/hibernate/Dashboard.hbm.xml b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dashboard/hibernate/Dashboard.hbm.xml index 4370e09031d5..a3f07edf0740 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dashboard/hibernate/Dashboard.hbm.xml +++ b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dashboard/hibernate/Dashboard.hbm.xml @@ -39,6 +39,8 @@ + + org.hisp.dhis.dashboard.embedded.EmbeddedProvider diff --git a/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_23__Add_embedded_properties_to_dashboard.sql b/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_23__Add_embedded_to_dashboard.sql similarity index 100% rename from dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_23__Add_embedded_properties_to_dashboard.sql rename to dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_23__Add_embedded_to_dashboard.sql diff --git a/dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/org/hisp/dhis/usertype/UserTypes.hbm.xml b/dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/org/hisp/dhis/usertype/UserTypes.hbm.xml index ab4ffd4e5e8c..c390656ad0d1 100644 --- a/dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/org/hisp/dhis/usertype/UserTypes.hbm.xml +++ b/dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/org/hisp/dhis/usertype/UserTypes.hbm.xml @@ -77,8 +77,8 @@ org.hisp.dhis.dashboard.design.ItemConfig - - org.hisp.dhis.dashboard.embedded.EmbeddedOptions + + org.hisp.dhis.dashboard.EmbeddedDashboard From c89bea34b1222743b10935fb5045ec6fd0555e43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Wed, 23 Oct 2024 13:05:14 +0200 Subject: [PATCH 18/29] fix: Update code --- .../hisp/dhis/dashboard/hibernate/Dashboard.hbm.xml | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dashboard/hibernate/Dashboard.hbm.xml b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dashboard/hibernate/Dashboard.hbm.xml index a3f07edf0740..59e8c98cbca5 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dashboard/hibernate/Dashboard.hbm.xml +++ b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dashboard/hibernate/Dashboard.hbm.xml @@ -41,18 +41,6 @@ - - - org.hisp.dhis.dashboard.embedded.EmbeddedProvider - true - 12 - - - - - - - From 3f4c46cde82c717a85e8bafbd7998ef4e606028f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Wed, 23 Oct 2024 13:05:55 +0200 Subject: [PATCH 19/29] fix: Update code --- .../src/main/java/org/hisp/dhis/dashboard/Dashboard.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java index 722bf2eebcf0..86a59582adcb 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java @@ -36,6 +36,7 @@ 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; @@ -47,6 +48,7 @@ /** * @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; @@ -73,8 +75,6 @@ public class Dashboard extends BaseNameableObject implements MetadataObject { // Constructors // ------------------------------------------------------------------------- - public Dashboard() {} - public Dashboard(String name) { this.name = name; } From 3d0bf652f380d7b51754720ed7e202771773b550 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Wed, 23 Oct 2024 13:07:25 +0200 Subject: [PATCH 20/29] fix: Update code --- .../src/main/java/org/hisp/dhis/dashboard/Dashboard.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java index 86a59582adcb..96d0d2e8b7c5 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java @@ -46,6 +46,9 @@ import org.hisp.dhis.dashboard.embedded.EmbeddedDashboard; /** + * Encapsulates information about an embedded dashboard. An embedded dashboard is typically loaded + * from an external provider. + * * @author Lars Helge Overland */ @NoArgsConstructor @@ -68,7 +71,7 @@ public class Dashboard extends BaseNameableObject implements MetadataObject { /** Allowed filter dimensions (if any) which may be used for the dashboard. */ private List allowedFilters = new ArrayList<>(); - /** Optional, only set if this dashboard is embedded and sourced from an external provider. */ + /** Optional, only set if this dashboard is embedded and loaded from an external provider. */ private EmbeddedDashboard embedded; // ------------------------------------------------------------------------- From 7d9b97de61488583bc32eea7da25ed5957feb325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Wed, 23 Oct 2024 13:09:57 +0200 Subject: [PATCH 21/29] fix: Update code --- .../2.42/V2_42_23__Add_embedded_to_dashboard.sql | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_23__Add_embedded_to_dashboard.sql b/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_23__Add_embedded_to_dashboard.sql index aae41935862f..fe3aea8d5ab0 100644 --- a/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_23__Add_embedded_to_dashboard.sql +++ b/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_23__Add_embedded_to_dashboard.sql @@ -1,10 +1,2 @@ --- 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; +alter table "dashboard" add column if not exists "embedded" jsonb null; From 3e30e2510e3eb5609215ffaaac9004477fc7b8e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Wed, 23 Oct 2024 13:15:47 +0200 Subject: [PATCH 22/29] fix: Update code --- .../dashboard/embedded/EmbeddedDashboard.java | 2 ++ .../dhis/dashboard/DashboardServiceTest.java | 27 +++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedDashboard.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedDashboard.java index fda843181f23..de0aa9be2f7f 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedDashboard.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedDashboard.java @@ -28,6 +28,7 @@ package org.hisp.dhis.dashboard.embedded; import java.io.Serializable; +import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -35,6 +36,7 @@ @Getter @Setter @NoArgsConstructor +@AllArgsConstructor public class EmbeddedDashboard implements Serializable { /** Provider of embedded dashboards. */ private EmbeddedProvider provider; diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dashboard/DashboardServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dashboard/DashboardServiceTest.java index 3878233be430..bccf3a7e340c 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dashboard/DashboardServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dashboard/DashboardServiceTest.java @@ -46,6 +46,7 @@ import java.util.List; import java.util.Set; import org.hisp.dhis.common.IdentifiableObjectManager; +import org.hisp.dhis.dashboard.embedded.EmbeddedDashboard; import org.hisp.dhis.dashboard.embedded.EmbeddedOptions; import org.hisp.dhis.dashboard.embedded.EmbeddedProvider; import org.hisp.dhis.document.Document; @@ -81,6 +82,8 @@ class DashboardServiceTest extends PostgresIntegrationTestBase { @Autowired private IdentifiableObjectManager objectManager; + private static final String UUID_A = "41c52308-1db4-4971-ade4-50c4d12c201d"; + private Dashboard dbA; private Dashboard dbB; @@ -97,6 +100,8 @@ class DashboardServiceTest extends PostgresIntegrationTestBase { private DashboardItem diE; + private DashboardItem diF; + private Visualization vzA; private Visualization vzB; @@ -141,6 +146,9 @@ void setUp() { diE = new DashboardItem(); diE.setAutoFields(); diE.setEventVisualization(evzB); + diF = new DashboardItem(); + diF.setAutoFields(); + diF.setVisualization(vzA); dbA = new Dashboard("A"); dbA.setAutoFields(); @@ -157,9 +165,10 @@ void setUp() { dbC = new Dashboard("C"); dbC.setAutoFields(); - dbC.setEmbeddedProvider(EmbeddedProvider.SUPERSET); - dbC.setEmbeddedId("41c52308-1db4-4971-ade4-50c4d12c201d"); - dbC.setEmbeddedOptions(new EmbeddedOptions(true, true, true)); + dbC.getItems().add(diF); + dbC.setEmbedded( + new EmbeddedDashboard( + EmbeddedProvider.SUPERSET, UUID_A, new EmbeddedOptions(true, true, true))); } @Test @@ -173,8 +182,16 @@ void testSaveGet() { 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()); + assertEquals(1, dashboardService.getDashboard(dCId).getItems().size()); + + Dashboard rdC = dashboardService.getDashboard(dCId); + assertNotNull(rdC.getEmbedded()); + assertEquals(EmbeddedProvider.SUPERSET, rdC.getEmbedded().getProvider()); + assertEquals(UUID_A, rdC.getEmbedded().getId()); + assertNotNull(rdC.getEmbedded().getOptions()); + assertTrue(rdC.getEmbedded().getOptions().isHideChartControls()); + assertTrue(rdC.getEmbedded().getOptions().isHideChartControls()); + assertTrue(rdC.getEmbedded().getOptions().isShowFilters()); } @Test From 82b14b77c520b49bfdbbf49a7f9b63639c553add Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Thu, 24 Oct 2024 22:32:47 +0200 Subject: [PATCH 23/29] fix: Update code --- .../src/main/resources/org/hisp/dhis/usertype/UserTypes.hbm.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/org/hisp/dhis/usertype/UserTypes.hbm.xml b/dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/org/hisp/dhis/usertype/UserTypes.hbm.xml index c390656ad0d1..5ffc6ca8c9fb 100644 --- a/dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/org/hisp/dhis/usertype/UserTypes.hbm.xml +++ b/dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/org/hisp/dhis/usertype/UserTypes.hbm.xml @@ -78,7 +78,7 @@ - org.hisp.dhis.dashboard.EmbeddedDashboard + org.hisp.dhis.dashboard.embedded.EmbeddedDashboard From b8843bcf0d8beb2451db0163ae7bd043994df5fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Fri, 1 Nov 2024 17:58:05 +0100 Subject: [PATCH 24/29] fix: Update code --- .../dashboard/embedded/EmbeddedDashboard.java | 7 +-- .../dashboard/embedded/EmbeddedOptions.java | 7 ++- .../dashboard/embedded/FilterOptions.java | 46 +++++++++++++++++++ 3 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/FilterOptions.java diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedDashboard.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedDashboard.java index de0aa9be2f7f..8494f923bd9a 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedDashboard.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedDashboard.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.dashboard.embedded; +import com.fasterxml.jackson.annotation.JsonProperty; import java.io.Serializable; import lombok.AllArgsConstructor; import lombok.Getter; @@ -39,11 +40,11 @@ @AllArgsConstructor public class EmbeddedDashboard implements Serializable { /** Provider of embedded dashboards. */ - private EmbeddedProvider provider; + @JsonProperty private EmbeddedProvider provider; /** Identifier for embedded dashboard. */ - private String id; + @JsonProperty private String id; /** Customization options for embedded dashboard. */ - private EmbeddedOptions options; + @JsonProperty private EmbeddedOptions options; } diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedOptions.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedOptions.java index 03a1a0f997af..efb5e28b0350 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedOptions.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedOptions.java @@ -44,11 +44,14 @@ @NoArgsConstructor @AllArgsConstructor public class EmbeddedOptions implements Serializable { + /** Hide tab. Applies to Superset. */ + @JsonProperty private boolean hideTab; + /** Hide the chart controls. Applies to Superset. */ @JsonProperty private boolean hideChartControls; - /** Expand the filters panel. Applies to Superset. */ - @JsonProperty private boolean expandFilters; + /** Filter options. Applies to Superset. */ + @JsonProperty private FilterOptions filters; /** Show the filters panel. Applies to Superset. */ @JsonProperty private boolean showFilters; diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/FilterOptions.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/FilterOptions.java new file mode 100644 index 000000000000..76e2f6da750b --- /dev/null +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/FilterOptions.java @@ -0,0 +1,46 @@ +/* + * 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 lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +public class FilterOptions { + /** Whether filter sidebar should be accessible when opening the dashboard. */ + @JsonProperty private boolean visible; + + /** Whether filter sidebar should be expanded when opening the dashboard. */ + @JsonProperty private boolean expanded; +} From 34a490d6cf5fbf4e301c5c681ee11c574f15a5ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Fri, 1 Nov 2024 17:59:39 +0100 Subject: [PATCH 25/29] fix: Update code --- .../java/org/hisp/dhis/dashboard/embedded/EmbeddedDashboard.java | 1 + 1 file changed, 1 insertion(+) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedDashboard.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedDashboard.java index 8494f923bd9a..d580cb9e46ac 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedDashboard.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedDashboard.java @@ -34,6 +34,7 @@ import lombok.NoArgsConstructor; import lombok.Setter; +/** Encapsulates metadata for an embedded and externally provided dashboard. */ @Getter @Setter @NoArgsConstructor From 6babdf30a74bbbb086af781e9040e6c929d19881 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Fri, 1 Nov 2024 18:56:49 +0100 Subject: [PATCH 26/29] fix: Update code --- .../dhis/dashboard/DashboardServiceTest.java | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dashboard/DashboardServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dashboard/DashboardServiceTest.java index bccf3a7e340c..2be4c5f6586c 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dashboard/DashboardServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dashboard/DashboardServiceTest.java @@ -29,7 +29,6 @@ import static java.util.Arrays.asList; import static java.util.stream.IntStream.range; -import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.hisp.dhis.dashboard.DashboardItemType.EVENT_REPORT; @@ -49,6 +48,7 @@ import org.hisp.dhis.dashboard.embedded.EmbeddedDashboard; import org.hisp.dhis.dashboard.embedded.EmbeddedOptions; import org.hisp.dhis.dashboard.embedded.EmbeddedProvider; +import org.hisp.dhis.dashboard.embedded.FilterOptions; import org.hisp.dhis.document.Document; import org.hisp.dhis.document.DocumentService; import org.hisp.dhis.eventchart.EventChart; @@ -168,7 +168,9 @@ void setUp() { dbC.getItems().add(diF); dbC.setEmbedded( new EmbeddedDashboard( - EmbeddedProvider.SUPERSET, UUID_A, new EmbeddedOptions(true, true, true))); + EmbeddedProvider.SUPERSET, + UUID_A, + new EmbeddedOptions(true, true, new FilterOptions(true, true), true))); } @Test @@ -268,7 +270,7 @@ void testSearchDashboardWithMaxCount() { .forEach( i -> { Visualization visualization = createVisualization('A'); - visualization.setName(randomAlphabetic(5)); + visualization.setName("Visualization" + i); visualizationService.save(visualization); }); @@ -276,18 +278,18 @@ void testSearchDashboardWithMaxCount() { .forEach( i -> { EventVisualization eventVisualization = createEventVisualization("A", prA); - eventVisualization.setName(randomAlphabetic(5)); + eventVisualization.setName("EventVisualization" + i); eventVisualizationService.save(eventVisualization); }); // Non Line List event visualization should be ignored when we search for EVENT_VISUALIZATION: EventVisualization eventVisualization = createEventVisualization("A", prA); - eventVisualization.setName(randomAlphabetic(5)); + eventVisualization.setName("EventVisualizationA"); eventVisualization.setType(COLUMN); eventVisualizationService.save(eventVisualization); - range(1, 30).forEach(i -> eventChartService.saveEventChart(createEventChart(prA))); - range(1, 20).forEach(i -> eventReportService.saveEventReport(createEventReport(prA))); + range(1, 30).forEach(i -> eventChartService.saveEventChart(createEventChart(prA, i))); + range(1, 20).forEach(i -> eventReportService.saveEventReport(createEventReport(prA, i))); DashboardSearchResult result = dashboardService.search(Set.of(VISUALIZATION)); assertThat(result.getVisualizationCount(), is(25)); @@ -326,15 +328,15 @@ private EventVisualization createEventVisualization(String name, Program program return eventVisualization; } - private EventChart createEventChart(Program program) { - EventChart eventChart = new EventChart(randomAlphabetic(5)); + private EventChart createEventChart(Program program, int i) { + EventChart eventChart = new EventChart("EventChart" + i); eventChart.setProgram(program); eventChart.setType(COLUMN); return eventChart; } - private EventReport createEventReport(Program program) { - EventReport eventReport = new EventReport(randomAlphabetic(5)); + private EventReport createEventReport(Program program, int i) { + EventReport eventReport = new EventReport("EventReport" + i); eventReport.setProgram(program); eventReport.setType(PIVOT_TABLE); return eventReport; From cd018e905c0c1a09f9b66d33e128311b4680ea6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Fri, 1 Nov 2024 19:03:41 +0100 Subject: [PATCH 27/29] feat: Applied changes from feature branch [DHIS2-18339] --- .../org/hisp/dhis/dashboard/Dashboard.java | 17 ++++++ .../dhis/dashboard/DashboardItemType.java | 2 + .../dashboard/embedded/EmbeddedDashboard.java | 51 ++++++++++++++++ .../dashboard/embedded/EmbeddedOptions.java | 58 +++++++++++++++++++ .../dashboard/embedded/EmbeddedProvider.java | 37 ++++++++++++ .../dashboard/embedded/FilterOptions.java | 46 +++++++++++++++ .../org/hisp/dhis/setting/SystemSettings.java | 16 ++--- .../dashboard/hibernate/Dashboard.hbm.xml | 2 + .../org/hisp/dhis/setting/SystemSetting.java | 2 - .../hisp/dhis/setting/SystemSettingsTest.java | 2 +- .../V2_42_23__Add_embedded_to_dashboard.sql | 2 + .../org/hisp/dhis/usertype/UserTypes.hbm.xml | 4 ++ .../dhis/dashboard/DashboardServiceTest.java | 58 +++++++++++++++---- 13 files changed, 273 insertions(+), 24 deletions(-) create mode 100644 dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedDashboard.java create mode 100644 dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedOptions.java create mode 100644 dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedProvider.java create mode 100644 dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/FilterOptions.java create mode 100644 dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_23__Add_embedded_to_dashboard.sql diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java index b7dbab8bff09..96d0d2e8b7c5 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/Dashboard.java @@ -43,8 +43,12 @@ 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.EmbeddedDashboard; /** + * Encapsulates information about an embedded dashboard. An embedded dashboard is typically loaded + * from an external provider. + * * @author Lars Helge Overland */ @NoArgsConstructor @@ -67,6 +71,9 @@ public class Dashboard extends BaseNameableObject implements MetadataObject { /** Allowed filter dimensions (if any) which may be used for the dashboard. */ private List allowedFilters = new ArrayList<>(); + /** Optional, only set if this dashboard is embedded and loaded from an external provider. */ + private EmbeddedDashboard embedded; + // ------------------------------------------------------------------------- // Constructors // ------------------------------------------------------------------------- @@ -146,4 +153,14 @@ public List getAllowedFilters() { public void setAllowedFilters(List allowedFilters) { this.allowedFilters = allowedFilters; } + + @JsonProperty + @JacksonXmlProperty(namespace = DXF_2_0) + public EmbeddedDashboard getEmbedded() { + return embedded; + } + + public void setEmbedded(EmbeddedDashboard embedded) { + this.embedded = embedded; + } } diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItemType.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItemType.java index ea804396b2a7..4f1122f41b8d 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItemType.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItemType.java @@ -28,6 +28,8 @@ package org.hisp.dhis.dashboard; /** + * Encapsulates type of dashboard item. + * * @author Lars Helge Overland */ public enum DashboardItemType { diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedDashboard.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedDashboard.java new file mode 100644 index 000000000000..d580cb9e46ac --- /dev/null +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedDashboard.java @@ -0,0 +1,51 @@ +/* + * 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 metadata for an embedded and externally provided dashboard. */ +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +public class EmbeddedDashboard implements Serializable { + /** Provider of embedded dashboards. */ + @JsonProperty private EmbeddedProvider provider; + + /** Identifier for embedded dashboard. */ + @JsonProperty private String id; + + /** Customization options for embedded dashboard. */ + @JsonProperty private EmbeddedOptions options; +} diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedOptions.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedOptions.java new file mode 100644 index 000000000000..efb5e28b0350 --- /dev/null +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedOptions.java @@ -0,0 +1,58 @@ +/* + * 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 tab. Applies to Superset. */ + @JsonProperty private boolean hideTab; + + /** Hide the chart controls. Applies to Superset. */ + @JsonProperty private boolean hideChartControls; + + /** Filter options. Applies to Superset. */ + @JsonProperty private FilterOptions filters; + + /** Show the filters panel. Applies to Superset. */ + @JsonProperty private boolean showFilters; +} diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedProvider.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedProvider.java new file mode 100644 index 000000000000..3b7ee0aca75c --- /dev/null +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/EmbeddedProvider.java @@ -0,0 +1,37 @@ +/* + * 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 { + SUPERSET; +} diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/FilterOptions.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/FilterOptions.java new file mode 100644 index 000000000000..76e2f6da750b --- /dev/null +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/FilterOptions.java @@ -0,0 +1,46 @@ +/* + * 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 lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +public class FilterOptions { + /** Whether filter sidebar should be accessible when opening the dashboard. */ + @JsonProperty private boolean visible; + + /** Whether filter sidebar should be expanded when opening the dashboard. */ + @JsonProperty private boolean expanded; +} diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettings.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettings.java index e211f4f51aea..832fff4601e5 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettings.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettings.java @@ -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); } @@ -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); } @@ -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(); } diff --git a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dashboard/hibernate/Dashboard.hbm.xml b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dashboard/hibernate/Dashboard.hbm.xml index 705ce90a3e12..59e8c98cbca5 100644 --- a/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dashboard/hibernate/Dashboard.hbm.xml +++ b/dhis-2/dhis-services/dhis-service-core/src/main/resources/org/hisp/dhis/dashboard/hibernate/Dashboard.hbm.xml @@ -39,6 +39,8 @@ + + diff --git a/dhis-2/dhis-services/dhis-service-setting/src/main/java/org/hisp/dhis/setting/SystemSetting.java b/dhis-2/dhis-services/dhis-service-setting/src/main/java/org/hisp/dhis/setting/SystemSetting.java index e75984454ff0..bc20d2e231c9 100644 --- a/dhis-2/dhis-services/dhis-service-setting/src/main/java/org/hisp/dhis/setting/SystemSetting.java +++ b/dhis-2/dhis-services/dhis-service-setting/src/main/java/org/hisp/dhis/setting/SystemSetting.java @@ -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 diff --git a/dhis-2/dhis-services/dhis-service-setting/src/test/java/org/hisp/dhis/setting/SystemSettingsTest.java b/dhis-2/dhis-services/dhis-service-setting/src/test/java/org/hisp/dhis/setting/SystemSettingsTest.java index cb0c4fba5ce9..7cbdaa8997d0 100644 --- a/dhis-2/dhis-services/dhis-service-setting/src/test/java/org/hisp/dhis/setting/SystemSettingsTest.java +++ b/dhis-2/dhis-services/dhis-service-setting/src/test/java/org/hisp/dhis/setting/SystemSettingsTest.java @@ -90,7 +90,7 @@ void testIsTranslatable() { @Test void testKeysWithDefaults() { Set keys = SystemSettings.keysWithDefaults(); - assertEquals(135, keys.size()); + assertEquals(136, keys.size()); // just check some at random assertTrue(keys.contains("syncSkipSyncForDataChangedBefore")); assertTrue(keys.contains("keyTrackerDashboardLayout")); diff --git a/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_23__Add_embedded_to_dashboard.sql b/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_23__Add_embedded_to_dashboard.sql new file mode 100644 index 000000000000..fe3aea8d5ab0 --- /dev/null +++ b/dhis-2/dhis-support/dhis-support-db-migration/src/main/resources/org/hisp/dhis/db/migration/2.42/V2_42_23__Add_embedded_to_dashboard.sql @@ -0,0 +1,2 @@ + +alter table "dashboard" add column if not exists "embedded" jsonb null; diff --git a/dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/org/hisp/dhis/usertype/UserTypes.hbm.xml b/dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/org/hisp/dhis/usertype/UserTypes.hbm.xml index 92f2ab4d29fc..5ffc6ca8c9fb 100644 --- a/dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/org/hisp/dhis/usertype/UserTypes.hbm.xml +++ b/dhis-2/dhis-support/dhis-support-hibernate/src/main/resources/org/hisp/dhis/usertype/UserTypes.hbm.xml @@ -77,6 +77,10 @@ org.hisp.dhis.dashboard.design.ItemConfig + + org.hisp.dhis.dashboard.embedded.EmbeddedDashboard + + org.hisp.dhis.textpattern.TextPattern diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dashboard/DashboardServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dashboard/DashboardServiceTest.java index 29c790d8bbfc..2be4c5f6586c 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dashboard/DashboardServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dashboard/DashboardServiceTest.java @@ -29,7 +29,6 @@ import static java.util.Arrays.asList; import static java.util.stream.IntStream.range; -import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; import static org.hisp.dhis.dashboard.DashboardItemType.EVENT_REPORT; @@ -40,11 +39,16 @@ 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.EmbeddedDashboard; +import org.hisp.dhis.dashboard.embedded.EmbeddedOptions; +import org.hisp.dhis.dashboard.embedded.EmbeddedProvider; +import org.hisp.dhis.dashboard.embedded.FilterOptions; import org.hisp.dhis.document.Document; import org.hisp.dhis.document.DocumentService; import org.hisp.dhis.eventchart.EventChart; @@ -78,10 +82,14 @@ class DashboardServiceTest extends PostgresIntegrationTestBase { @Autowired private IdentifiableObjectManager objectManager; + private static final String UUID_A = "41c52308-1db4-4971-ade4-50c4d12c201d"; + private Dashboard dbA; private Dashboard dbB; + private Dashboard dbC; + private DashboardItem diA; private DashboardItem diB; @@ -92,6 +100,8 @@ class DashboardServiceTest extends PostgresIntegrationTestBase { private DashboardItem diE; + private DashboardItem diF; + private Visualization vzA; private Visualization vzB; @@ -136,28 +146,54 @@ void setUp() { diE = new DashboardItem(); diE.setAutoFields(); diE.setEventVisualization(evzB); + diF = new DashboardItem(); + diF.setAutoFields(); + diF.setVisualization(vzA); + 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.getItems().add(diF); + dbC.setEmbedded( + new EmbeddedDashboard( + EmbeddedProvider.SUPERSET, + UUID_A, + new EmbeddedOptions(true, true, new FilterOptions(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()); + assertEquals(1, dashboardService.getDashboard(dCId).getItems().size()); + + Dashboard rdC = dashboardService.getDashboard(dCId); + assertNotNull(rdC.getEmbedded()); + assertEquals(EmbeddedProvider.SUPERSET, rdC.getEmbedded().getProvider()); + assertEquals(UUID_A, rdC.getEmbedded().getId()); + assertNotNull(rdC.getEmbedded().getOptions()); + assertTrue(rdC.getEmbedded().getOptions().isHideChartControls()); + assertTrue(rdC.getEmbedded().getOptions().isHideChartControls()); + assertTrue(rdC.getEmbedded().getOptions().isShowFilters()); } @Test @@ -234,7 +270,7 @@ void testSearchDashboardWithMaxCount() { .forEach( i -> { Visualization visualization = createVisualization('A'); - visualization.setName(randomAlphabetic(5)); + visualization.setName("Visualization" + i); visualizationService.save(visualization); }); @@ -242,18 +278,18 @@ void testSearchDashboardWithMaxCount() { .forEach( i -> { EventVisualization eventVisualization = createEventVisualization("A", prA); - eventVisualization.setName(randomAlphabetic(5)); + eventVisualization.setName("EventVisualization" + i); eventVisualizationService.save(eventVisualization); }); // Non Line List event visualization should be ignored when we search for EVENT_VISUALIZATION: EventVisualization eventVisualization = createEventVisualization("A", prA); - eventVisualization.setName(randomAlphabetic(5)); + eventVisualization.setName("EventVisualizationA"); eventVisualization.setType(COLUMN); eventVisualizationService.save(eventVisualization); - range(1, 30).forEach(i -> eventChartService.saveEventChart(createEventChart(prA))); - range(1, 20).forEach(i -> eventReportService.saveEventReport(createEventReport(prA))); + range(1, 30).forEach(i -> eventChartService.saveEventChart(createEventChart(prA, i))); + range(1, 20).forEach(i -> eventReportService.saveEventReport(createEventReport(prA, i))); DashboardSearchResult result = dashboardService.search(Set.of(VISUALIZATION)); assertThat(result.getVisualizationCount(), is(25)); @@ -292,15 +328,15 @@ private EventVisualization createEventVisualization(String name, Program program return eventVisualization; } - private EventChart createEventChart(Program program) { - EventChart eventChart = new EventChart(randomAlphabetic(5)); + private EventChart createEventChart(Program program, int i) { + EventChart eventChart = new EventChart("EventChart" + i); eventChart.setProgram(program); eventChart.setType(COLUMN); return eventChart; } - private EventReport createEventReport(Program program) { - EventReport eventReport = new EventReport(randomAlphabetic(5)); + private EventReport createEventReport(Program program, int i) { + EventReport eventReport = new EventReport("EventReport" + i); eventReport.setProgram(program); eventReport.setType(PIVOT_TABLE); return eventReport; From f7ab06c9c40b53010e263d79c9bc48d856a28260 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Fri, 1 Nov 2024 19:17:33 +0100 Subject: [PATCH 28/29] fix: Update filter --- .../java/org/hisp/dhis/dashboard/embedded/FilterOptions.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/FilterOptions.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/FilterOptions.java index 76e2f6da750b..c9969e2aa884 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/FilterOptions.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/FilterOptions.java @@ -27,6 +27,7 @@ */ package org.hisp.dhis.dashboard.embedded; +import java.io.Serializable; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.AllArgsConstructor; import lombok.Getter; @@ -37,7 +38,7 @@ @Setter @NoArgsConstructor @AllArgsConstructor -public class FilterOptions { +public class FilterOptions implements Serializable { /** Whether filter sidebar should be accessible when opening the dashboard. */ @JsonProperty private boolean visible; From 3501437dff5fe2703d5c4a5c7cfff9bf8bca2766 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Helge=20=C3=98verland?= Date: Fri, 1 Nov 2024 19:18:59 +0100 Subject: [PATCH 29/29] fix: Update code --- .../java/org/hisp/dhis/dashboard/embedded/FilterOptions.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/FilterOptions.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/FilterOptions.java index c9969e2aa884..fb1f02016c2f 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/FilterOptions.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/embedded/FilterOptions.java @@ -27,8 +27,8 @@ */ package org.hisp.dhis.dashboard.embedded; -import java.io.Serializable; import com.fasterxml.jackson.annotation.JsonProperty; +import java.io.Serializable; import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NoArgsConstructor;