Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat: Add embedded properties to Dashboard [DHIS2-18239] #18843

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
64de358
fix: Update code
larshelge Oct 16, 2024
03682ba
fix: Update code
larshelge Oct 16, 2024
28a46c3
fix: Update code
larshelge Oct 16, 2024
ad03f06
fix: Update code
larshelge Oct 16, 2024
2209fa3
fix: Update code
larshelge Oct 16, 2024
9bf3fda
fix: Update code
larshelge Oct 16, 2024
d594923
fix: Update code
larshelge Oct 16, 2024
5fa38c5
fix: Update code
larshelge Oct 16, 2024
0ad587e
fix: Update code
larshelge Oct 16, 2024
7ca2e31
fix: Update code
larshelge Oct 16, 2024
e1226f1
fix: Update code
larshelge Oct 16, 2024
8e03159
fix: Update code
larshelge Oct 16, 2024
5236fa9
fix: Update code
larshelge Oct 16, 2024
03f15ba
fix: Update code
larshelge Oct 16, 2024
bc18a7a
fix: Update code
larshelge Oct 16, 2024
267e883
fix: Update code
larshelge Oct 16, 2024
5ec16d3
fix: Update code
larshelge Oct 18, 2024
a16b434
Merge branch 'master' into DHIS2-18239
larshelge Oct 18, 2024
3e813c3
Merge branch 'master' into DHIS2-18239
janhenrikoverland Oct 21, 2024
d8a388d
Merge branch 'master' into DHIS2-18239
larshelge Oct 23, 2024
227d5aa
Merge branch 'DHIS2-18239' of github.com:dhis2/dhis2-core into DHIS2-…
larshelge Oct 23, 2024
7f0a2c6
fix: Update code
larshelge Oct 23, 2024
c89bea3
fix: Update code
larshelge Oct 23, 2024
3f4c46c
fix: Update code
larshelge Oct 23, 2024
3d0bf65
fix: Update code
larshelge Oct 23, 2024
7d9b97d
fix: Update code
larshelge Oct 23, 2024
3e30e25
fix: Update code
larshelge Oct 23, 2024
82b14b7
fix: Update code
larshelge Oct 24, 2024
c4a685b
Merge branch 'master' into DHIS2-18239
larshelge Oct 24, 2024
0715fd8
Merge branch 'master' into DHIS2-18239
larshelge Nov 1, 2024
b8843bc
fix: Update code
larshelge Nov 1, 2024
34a490d
fix: Update code
larshelge Nov 1, 2024
230af60
Merge branch 'master' into DHIS2-18239
larshelge Nov 1, 2024
6babdf3
fix: Update code
larshelge Nov 1, 2024
cd018e9
feat: Applied changes from feature branch [DHIS2-18339]
larshelge Nov 1, 2024
65d2c9e
Merge branch 'master' into DHIS2-18239
larshelge Nov 1, 2024
f7ab06c
fix: Update filter
larshelge Nov 1, 2024
3501437
fix: Update code
larshelge Nov 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -67,6 +71,9 @@
/** Allowed filter dimensions (if any) which may be used for the dashboard. */
private List<String> allowedFilters = new ArrayList<>();

/** Optional, only set if this dashboard is embedded and loaded from an external provider. */
private EmbeddedDashboard embedded;

// -------------------------------------------------------------------------
// Constructors
// -------------------------------------------------------------------------
Expand Down Expand Up @@ -98,7 +105,7 @@
@JsonSerialize(contentAs = BaseIdentifiableObject.class)
@JacksonXmlElementWrapper(localName = "dashboardItems", namespace = DxfNamespaces.DXF_2_0)
@JacksonXmlProperty(localName = "dashboardItem", namespace = DxfNamespaces.DXF_2_0)
public List<DashboardItem> getItems() {

Check notice

Code scanning / CodeQL

Exposing internal representation Note

getItems exposes the internal representation stored in field items. The value may be modified
after this call to getItems
.
getItems exposes the internal representation stored in field items. The value may be modified
after this call to getItems
.
getItems exposes the internal representation stored in field items. The value may be modified
after this call to getItems
.
getItems exposes the internal representation stored in field items. The value may be modified
after this call to getItems
.
getItems exposes the internal representation stored in field items. The value may be modified
after this call to getItems
.
getItems exposes the internal representation stored in field items. The value may be modified
after this call to getItems
.
getItems exposes the internal representation stored in field items. The value may be modified
after this call to getItems
.
getItems exposes the internal representation stored in field items. The value may be modified
after this call to getItems
.
getItems exposes the internal representation stored in field items. The value may be modified
after this call to getItems
.
getItems exposes the internal representation stored in field items. The value may be modified
after this call to getItems
.
getItems exposes the internal representation stored in field items. The value may be modified
after this call to getItems
.
getItems exposes the internal representation stored in field items. The value may be modified
after this call to getItems
.
getItems exposes the internal representation stored in field items. The value may be modified
after this call to getItems
.
getItems exposes the internal representation stored in field items. The value may be modified
after this call to getItems
.
getItems exposes the internal representation stored in field items. The value may be modified
after this call to getItems
.
getItems exposes the internal representation stored in field items. The value may be modified
after this call to getItems
.
return items;
}

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

@JsonProperty
@JacksonXmlProperty(namespace = DXF_2_0)
public EmbeddedDashboard getEmbedded() {
return embedded;
}

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

/**
* Encapsulates type of dashboard item.
*
* @author Lars Helge Overland
*/
public enum DashboardItemType {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* 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.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
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;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2004-2024, University of Oslo
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* Neither the name of the HISP project nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.hisp.dhis.dashboard.embedded;

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

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

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

/** Show the filters panel. Applies to Superset. */
@JsonProperty private boolean showFilters;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,7 @@ static boolean isTranslatable(@Nonnull String key) {
return LazySettings.isTranslatable(key);
}

/*
settings used in core
*/

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

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

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

/*

Combinators based on several settings

*/

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

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

<property name="embedded" column="embedded" type="jbEmbeddedDashboard" />

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

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

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

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

<typedef class="org.hisp.dhis.hibernate.jsonb.type.JsonBinaryType" name="jbEmbeddedDashboard">
<param name="clazz">org.hisp.dhis.dashboard.EmbeddedDashboard</param>
</typedef>

<typedef class="org.hisp.dhis.hibernate.jsonb.type.JsonBinaryType" name="jbTextPattern">
<param name="clazz">org.hisp.dhis.textpattern.TextPattern</param>
</typedef>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,15 @@
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.document.Document;
import org.hisp.dhis.document.DocumentService;
import org.hisp.dhis.eventchart.EventChart;
Expand Down Expand Up @@ -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;
Expand All @@ -92,6 +100,8 @@ class DashboardServiceTest extends PostgresIntegrationTestBase {

private DashboardItem diE;

private DashboardItem diF;

private Visualization vzA;

private Visualization vzB;
Expand Down Expand Up @@ -136,28 +146,52 @@ 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, 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
Expand Down
Loading