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());
}
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());
}
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());
}
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);
}
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));
}
Aggregations