Search in sources :

Example 36 with Visualization

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

the class MetadataImportServiceTest method testImportEmbeddedObjectWithSkipSharingIsTrue.

@Test
void testImportEmbeddedObjectWithSkipSharingIsTrue() throws IOException {
    User user = createUser('A');
    manager.save(user);
    UserGroup userGroup = createUserGroup('A', Sets.newHashSet(user));
    manager.save(userGroup);
    userGroup = manager.get(UserGroup.class, "ugabcdefghA");
    assertNotNull(userGroup);
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/favorites/metadata_visualization_with_accesses.json").getInputStream(), RenderFormat.JSON);
    MetadataImportParams params = createParams(ImportStrategy.CREATE, metadata);
    ImportReport report = importService.importMetadata(params);
    assertEquals(Status.OK, report.getStatus());
    Visualization visualization = manager.get(Visualization.class, "gyYXi0rXAIc");
    assertNotNull(visualization);
    assertEquals(1, visualization.getUserGroupAccesses().size());
    assertEquals(1, visualization.getUserAccesses().size());
    assertEquals(user.getUid(), visualization.getUserAccesses().iterator().next().getUserUid());
    assertEquals(userGroup.getUid(), visualization.getUserGroupAccesses().iterator().next().getUserGroupUid());
    Visualization dataElementOperandVisualization = manager.get(Visualization.class, "qD72aBqsHvt");
    assertNotNull(dataElementOperandVisualization);
    assertEquals(2, dataElementOperandVisualization.getDataDimensionItems().size());
    dataElementOperandVisualization.getDataDimensionItems().stream().forEach(item -> assertNotNull(item.getDataElementOperand()));
    metadata = renderService.fromMetadata(new ClassPathResource("dxf2/favorites/metadata_visualization_with_accesses_update.json").getInputStream(), RenderFormat.JSON);
    params = createParams(ImportStrategy.UPDATE, metadata);
    params.setSkipSharing(true);
    dbmsManager.clearSession();
    report = importService.importMetadata(params);
    assertEquals(Status.OK, report.getStatus());
    visualization = manager.get(Visualization.class, "gyYXi0rXAIc");
    assertNotNull(visualization);
    assertEquals(1, visualization.getUserGroupAccesses().size());
    assertEquals(1, visualization.getUserAccesses().size());
    assertEquals(user.getUid(), visualization.getUserAccesses().iterator().next().getUser().getUid());
    assertEquals(userGroup.getUid(), visualization.getUserGroupAccesses().iterator().next().getUserGroup().getUid());
}
Also used : Visualization(org.hisp.dhis.visualization.Visualization) User(org.hisp.dhis.user.User) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) UserGroup(org.hisp.dhis.user.UserGroup) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 37 with Visualization

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

the class MetadataImportServiceTest method testImportEmbeddedObjectWithSkipSharingIsFalse.

@Test
void testImportEmbeddedObjectWithSkipSharingIsFalse() throws IOException {
    User user = createUser('A');
    manager.save(user);
    User userA = manager.get(User.class, user.getUid());
    assertNotNull(userA);
    UserGroup userGroup = createUserGroup('A', Sets.newHashSet(userA));
    manager.save(userGroup);
    userGroup = manager.get(UserGroup.class, "ugabcdefghA");
    assertNotNull(userGroup);
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/favorites/metadata_visualization_with_accesses.json").getInputStream(), RenderFormat.JSON);
    MetadataImportParams params = createParams(ImportStrategy.CREATE, metadata);
    params.setSkipSharing(false);
    ImportReport report = importService.importMetadata(params);
    assertEquals(Status.OK, report.getStatus());
    dbmsManager.clearSession();
    Visualization visualization = manager.get(Visualization.class, "gyYXi0rXAIc");
    assertNotNull(visualization);
    assertEquals(1, visualization.getUserGroupAccesses().size());
    assertEquals(1, visualization.getUserAccesses().size());
    assertEquals(user.getUid(), visualization.getUserAccesses().iterator().next().getUser().getUid());
    assertEquals(userGroup.getUid(), visualization.getUserGroupAccesses().iterator().next().getUserGroup().getUid());
    metadata = renderService.fromMetadata(new ClassPathResource("dxf2/favorites/metadata_visualization_with_accesses_update.json").getInputStream(), RenderFormat.JSON);
    params = createParams(ImportStrategy.UPDATE, metadata);
    params.setSkipSharing(false);
    dbmsManager.clearSession();
    report = importService.importMetadata(params);
    assertEquals(Status.OK, report.getStatus());
    visualization = manager.get(Visualization.class, "gyYXi0rXAIc");
    assertNotNull(visualization);
    assertEquals(0, visualization.getUserGroupAccesses().size());
    assertEquals(0, visualization.getUserAccesses().size());
}
Also used : Visualization(org.hisp.dhis.visualization.Visualization) User(org.hisp.dhis.user.User) ImportReport(org.hisp.dhis.dxf2.metadata.feedback.ImportReport) List(java.util.List) ClassPathResource(org.springframework.core.io.ClassPathResource) UserGroup(org.hisp.dhis.user.UserGroup) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 38 with Visualization

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

the class ObjectBundleServiceFavoritesTest method testCreateMetadataWithVisualization.

@Test
void testCreateMetadataWithVisualization() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/favorites/metadata_with_visualization.json").getInputStream(), RenderFormat.JSON);
    ObjectBundleParams params = new ObjectBundleParams();
    params.setObjectBundleMode(ObjectBundleMode.COMMIT);
    params.setImportStrategy(ImportStrategy.CREATE_AND_UPDATE);
    params.setObjects(metadata);
    ObjectBundle bundle = objectBundleService.create(params);
    ObjectBundleValidationReport validate = objectBundleValidationService.validate(bundle);
    assertFalse(validate.hasErrorReports());
    objectBundleService.commit(bundle);
    List<DataSet> dataSets = manager.getAll(DataSet.class);
    List<OrganisationUnit> organisationUnits = manager.getAll(OrganisationUnit.class);
    List<DataElement> dataElements = manager.getAll(DataElement.class);
    List<Visualization> visualizations = manager.getAll(Visualization.class);
    assertEquals(1, dataSets.size());
    assertEquals(1, organisationUnits.size());
    assertEquals(4, dataElements.size());
    assertEquals(3, visualizations.size());
    assertNotNull(visualizations.get(0).getFontSize());
    assertNotNull(visualizations.get(1).getFontSize());
    assertNotNull(visualizations.get(2).getFontSize());
    assertNotNull(visualizations.get(0).getSeries());
    assertNotNull(visualizations.get(1).getSeries());
    assertNotNull(visualizations.get(2).getSeries());
    assertNotNull(visualizations.get(0).getAxes());
    assertNotNull(visualizations.get(1).getAxes());
    assertNotNull(visualizations.get(2).getAxes());
    assertNotNull(visualizations.get(0).getSeriesKey());
    assertNotNull(visualizations.get(1).getSeriesKey());
    assertNotNull(visualizations.get(2).getSeriesKey());
    assertEquals(2, visualizations.get(0).getSeries().size());
    assertEquals(2, visualizations.get(1).getSeries().size());
    assertEquals(2, visualizations.get(2).getSeries().size());
    assertEquals(2, visualizations.get(0).getAxes().size());
    assertEquals(2, visualizations.get(1).getAxes().size());
    assertEquals(2, visualizations.get(2).getAxes().size());
    assertNotNull(visualizations.get(0).getFontStyle());
    assertNotNull(visualizations.get(1).getFontStyle());
    assertNotNull(visualizations.get(2).getFontStyle());
    assertNotNull(visualizations.get(0).getFontStyle().getVisualizationTitle());
    assertNotNull(visualizations.get(1).getFontStyle().getVisualizationTitle());
    assertNotNull(visualizations.get(2).getFontStyle().getVisualizationTitle());
    assertEquals("color_set_01", visualizations.get(0).getColorSet());
    assertEquals("color_set_01", visualizations.get(1).getColorSet());
    assertEquals("color_set_01", visualizations.get(2).getColorSet());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Visualization(org.hisp.dhis.visualization.Visualization) ObjectBundleValidationReport(org.hisp.dhis.dxf2.metadata.objectbundle.feedback.ObjectBundleValidationReport) DataSet(org.hisp.dhis.dataset.DataSet) ClassPathResource(org.springframework.core.io.ClassPathResource) IdentifiableObject(org.hisp.dhis.common.IdentifiableObject) DataElement(org.hisp.dhis.dataelement.DataElement) List(java.util.List) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 39 with Visualization

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

the class ObjectBundleHooksTest method testMatchingInterfaceBoundIsIncluded.

@Test
void testMatchingInterfaceBoundIsIncluded() {
    assertHasHooksOfType(new OrganisationUnit(), IdentifiableObjectBundleHook.class, VersionedObjectObjectBundleHook.class);
    assertHasHooksOfType(new User(), IdentifiableObjectBundleHook.class, VersionedObjectObjectBundleHook.class);
    assertHasHooksOfType(new Visualization(), IdentifiableObjectBundleHook.class, VersionedObjectObjectBundleHook.class, AnalyticalObjectObjectBundleHook.class);
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Visualization(org.hisp.dhis.visualization.Visualization) User(org.hisp.dhis.user.User) Test(org.junit.jupiter.api.Test)

Example 40 with Visualization

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

the class DefaultChartService method getJFreePeriodChart.

// -------------------------------------------------------------------------
// Specific chart methods
// -------------------------------------------------------------------------
@Override
@Transactional(readOnly = true)
public JFreeChart getJFreePeriodChart(Indicator indicator, OrganisationUnit unit, boolean title, I18nFormat format) {
    List<Period> periods = periodService.reloadPeriods(new RelativePeriods().setLast12Months(true).getRelativePeriods(format, true));
    Visualization visualization = new Visualization();
    if (title) {
        visualization.setName(indicator.getName());
    }
    visualization.setType(VisualizationType.LINE);
    visualization.setColumnDimensions(Arrays.asList(DimensionalObject.DATA_X_DIM_ID));
    visualization.setRowDimensions(Arrays.asList(DimensionalObject.PERIOD_DIM_ID));
    visualization.setFilterDimensions(Arrays.asList(DimensionalObject.ORGUNIT_DIM_ID));
    visualization.setHideLegend(true);
    visualization.addDataDimensionItem(indicator);
    visualization.setPeriods(periods);
    visualization.getOrganisationUnits().add(unit);
    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)

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