Search in sources :

Example 41 with Visualization

use of org.hisp.dhis.visualization.Visualization in project dhis2-core by dhis2.

the class DefaultChartService method getJFreeOrganisationUnitChart.

@Override
@Transactional(readOnly = true)
public JFreeChart getJFreeOrganisationUnitChart(Indicator indicator, OrganisationUnit parent, boolean title, I18nFormat format) {
    List<Period> periods = periodService.reloadPeriods(new RelativePeriods().setThisYear(true).getRelativePeriods(format, true));
    Visualization visualization = new Visualization();
    if (title) {
        visualization.setName(indicator.getName());
    }
    visualization.setType(VisualizationType.COLUMN);
    visualization.setColumnDimensions(Arrays.asList(DimensionalObject.DATA_X_DIM_ID));
    visualization.setRowDimensions(Arrays.asList(DimensionalObject.ORGUNIT_DIM_ID));
    visualization.setFilterDimensions(Arrays.asList(DimensionalObject.PERIOD_DIM_ID));
    visualization.setHideLegend(true);
    visualization.addDataDimensionItem(indicator);
    visualization.setPeriods(periods);
    visualization.setOrganisationUnits(parent.getSortedChildren());
    visualization.setHideSubtitle(title);
    visualization.setFormat(format);
    return getJFreeChart(new PlotData(visualization));
}
Also used : PlotData(org.hisp.dhis.visualization.PlotData) Visualization(org.hisp.dhis.visualization.Visualization) RelativePeriods(org.hisp.dhis.period.RelativePeriods) Period(org.hisp.dhis.period.Period) Transactional(org.springframework.transaction.annotation.Transactional)

Example 42 with Visualization

use of org.hisp.dhis.visualization.Visualization in project dhis2-core by dhis2.

the class AnalyticalObjectOrgUnitSplitHandlerTest method testSplitVisualizations.

@Test
void testSplitVisualizations() {
    Visualization vA = createVisualization('A');
    vA.addDataDimensionItem(deA);
    vA.getOrganisationUnits().add(ouA);
    Visualization vB = createVisualization('B');
    vB.addDataDimensionItem(deA);
    vB.getOrganisationUnits().add(ouA);
    idObjectManager.save(vA);
    idObjectManager.save(vB);
    assertEquals(2, getVisualizationCount(ouA));
    assertEquals(0, getVisualizationCount(ouB));
    assertEquals(0, getVisualizationCount(ouC));
    OrgUnitSplitRequest request = new OrgUnitSplitRequest.Builder().withSource(ouA).addTarget(ouB).addTarget(ouC).withPrimaryTarget(ouB).build();
    handler.splitAnalyticalObjects(request);
    idObjectManager.update(ouC);
    assertEquals(0, getVisualizationCount(ouA));
    assertEquals(2, getVisualizationCount(ouB));
    assertEquals(2, getVisualizationCount(ouC));
}
Also used : Visualization(org.hisp.dhis.visualization.Visualization) OrgUnitSplitRequest(org.hisp.dhis.split.orgunit.OrgUnitSplitRequest) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 43 with Visualization

use of org.hisp.dhis.visualization.Visualization in project dhis2-core by dhis2.

the class DashboardServiceTest method createVisualization.

private Visualization createVisualization(String name) {
    Visualization visualization = createVisualization('X');
    visualization.setName(name);
    return visualization;
}
Also used : EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) Visualization(org.hisp.dhis.visualization.Visualization)

Example 44 with Visualization

use of org.hisp.dhis.visualization.Visualization in project dhis2-core by dhis2.

the class DashboardCascadeSharingTest method testCascadeIndicatorAndDataElement.

@Test
void testCascadeIndicatorAndDataElement() {
    IndicatorType indicatorType = createIndicatorType('A');
    objectManager.save(indicatorType);
    Indicator indicatorA = createIndicator('A', indicatorType);
    indicatorA.setSharing(Sharing.builder().publicAccess(DEFAULT).build());
    objectManager.save(indicatorA, false);
    DataElement dataElementA = createDEWithDefaultSharing('A');
    objectManager.save(dataElementA, false);
    Visualization visualizationA = createVisualization('A');
    visualizationA.addDataDimensionItem(dataElementA);
    visualizationA.addDataDimensionItem(indicatorA);
    visualizationA.setSharing(defaultSharing());
    objectManager.save(visualizationA, false);
    Dashboard dashboard = createDashboardWithItem("a", sharingReadForUserA);
    dashboard.getItems().get(0).setVisualization(visualizationA);
    objectManager.save(dashboard, false);
    CascadeSharingReport report = cascadeSharingService.cascadeSharing(dashboard, new CascadeSharingParameters());
    assertEquals(0, report.getErrorReports().size());
    assertEquals(3, report.getUpdateObjects().size());
    assertEquals(1, report.getUpdateObjects().get(DataElementSchemaDescriptor.PLURAL).size());
    assertEquals(1, report.getUpdateObjects().get(IndicatorSchemaDescriptor.PLURAL).size());
    assertEquals(1, report.getUpdateObjects().get(VisualizationSchemaDescriptor.PLURAL).size());
    DataElement updatedDataElementA = objectManager.get(DataElement.class, dataElementA.getUid());
    Indicator updatedIndicatorA = objectManager.get(Indicator.class, indicatorA.getUid());
    assertTrue(aclService.canRead(userA, visualizationA));
    assertTrue(aclService.canRead(userA, updatedDataElementA));
    assertTrue(aclService.canRead(userA, updatedIndicatorA));
    assertFalse(aclService.canRead(userB, visualizationA));
    assertFalse(aclService.canRead(userB, updatedDataElementA));
    assertFalse(aclService.canRead(userB, updatedIndicatorA));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) Visualization(org.hisp.dhis.visualization.Visualization) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) IndicatorType(org.hisp.dhis.indicator.IndicatorType) Dashboard(org.hisp.dhis.dashboard.Dashboard) Indicator(org.hisp.dhis.indicator.Indicator) Test(org.junit.jupiter.api.Test)

Example 45 with Visualization

use of org.hisp.dhis.visualization.Visualization in project dhis2-core by dhis2.

the class DashboardCascadeSharingTest method testCascadeShareVisualizationError.

@Test
void testCascadeShareVisualizationError() {
    DataElement dataElementA = createDataElement('A');
    dataElementA.setSharing(Sharing.builder().publicAccess(DEFAULT).build());
    objectManager.save(dataElementA, false);
    Visualization vzA = createVisualization('A');
    vzA.setSharing(Sharing.builder().publicAccess(DEFAULT).build());
    vzA.addDataDimensionItem(dataElementA);
    objectManager.save(vzA, false);
    Sharing sharing = new Sharing();
    sharing.setPublicAccess(DEFAULT);
    sharing.addUserAccess(new UserAccess(userB, DEFAULT));
    Dashboard dashboard = createDashboardWithItem("A", sharing);
    dashboard.getItems().get(0).setVisualization(vzA);
    objectManager.save(dashboard, false);
    CascadeSharingReport report = cascadeSharingService.cascadeSharing(dashboard, new CascadeSharingParameters());
    assertEquals(0, report.getUpdateObjects().size());
    assertFalse(aclService.canRead(userB, vzA));
    assertFalse(aclService.canRead(userB, dataElementA));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) Visualization(org.hisp.dhis.visualization.Visualization) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) Sharing(org.hisp.dhis.user.sharing.Sharing) UserAccess(org.hisp.dhis.user.sharing.UserAccess) Dashboard(org.hisp.dhis.dashboard.Dashboard) Test(org.junit.jupiter.api.Test)

Aggregations

Visualization (org.hisp.dhis.visualization.Visualization)48 Test (org.junit.jupiter.api.Test)36 EventVisualization (org.hisp.dhis.eventvisualization.EventVisualization)26 DhisSpringTest (org.hisp.dhis.DhisSpringTest)17 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)14 User (org.hisp.dhis.user.User)13 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)8 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)7 DataElement (org.hisp.dhis.dataelement.DataElement)6 List (java.util.List)5 DataQueryParams (org.hisp.dhis.analytics.DataQueryParams)4 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)4 Period (org.hisp.dhis.period.Period)4 Date (java.util.Date)3 Dashboard (org.hisp.dhis.dashboard.Dashboard)3 DataSet (org.hisp.dhis.dataset.DataSet)3 ErrorReport (org.hisp.dhis.feedback.ErrorReport)3 UserAccess (org.hisp.dhis.user.sharing.UserAccess)3 ClassPathResource (org.springframework.core.io.ClassPathResource)3 ArrayList (java.util.ArrayList)2