Search in sources :

Example 26 with Visualization

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

the class ObjectBundleServiceFavoritesTest method testCreateMetadataWithVisualizationsWithPeriods.

@Test
void testCreateMetadataWithVisualizationsWithPeriods() throws IOException {
    Map<Class<? extends IdentifiableObject>, List<IdentifiableObject>> metadata = renderService.fromMetadata(new ClassPathResource("dxf2/favorites/metadata_with_visualization_periods.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(4, visualizations.size());
    Visualization visualization = manager.get(Visualization.class, "ziCoxdcXRQz");
    assertNotNull(visualization);
    assertEquals(5, visualization.getPeriods().size());
}
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 27 with Visualization

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

the class InterpretationController method writeVisualizationInterpretation.

// -------------------------------------------------------------------------
// Interpretation create
// -------------------------------------------------------------------------
@PostMapping(value = "/visualization/{uid}", consumes = { "text/html", "text/plain" })
@ResponseBody
public WebMessage writeVisualizationInterpretation(@PathVariable("uid") String uid, @RequestParam(value = "ou", required = false) String orgUnitUid, @CurrentUser User currentUser, @RequestBody String text) throws WebMessageException {
    final Visualization visualization = idObjectManager.get(Visualization.class, uid);
    if (visualization == null) {
        return conflict("Visualization does not exist or is not accessible: " + uid);
    }
    final OrganisationUnit orgUnit = getUserOrganisationUnit(orgUnitUid, visualization, currentUser);
    return createInterpretation(new Interpretation(visualization, orgUnit, text));
}
Also used : Visualization(org.hisp.dhis.visualization.Visualization) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Interpretation(org.hisp.dhis.interpretation.Interpretation) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 28 with Visualization

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

the class DashboardCascadeSharingTest method testCascadeShareVisualization.

/**
 * Dashboard has sharingUserA and visualizationA
 * <p>
 * visualizationA has dataElementA
 * <p>
 * Expected: visualizationA and dataElementA should be shared to userA
 */
@Test
void testCascadeShareVisualization() {
    DataElement dataElementA = createDEWithDefaultSharing('A');
    objectManager.save(dataElementA);
    DataElement dataElementB = createDEWithDefaultSharing('B');
    objectManager.save(dataElementB);
    Visualization visualizationA = createVisualization('A');
    visualizationA.addDataDimensionItem(dataElementA);
    visualizationA.addDataDimensionItem(dataElementB);
    visualizationA.setSharing(Sharing.builder().publicAccess(DEFAULT).build());
    objectManager.save(visualizationA, false);
    Dashboard dashboard = createDashboardWithItem("A", sharingReadForUserAB);
    dashboard.getItems().get(0).setVisualization(visualizationA);
    objectManager.save(dashboard, false);
    CascadeSharingReport report = cascadeSharingService.cascadeSharing(dashboard, new CascadeSharingParameters());
    assertEquals(0, report.getErrorReports().size());
    DataElement updatedDataElementA = objectManager.get(DataElement.class, dataElementA.getUid());
    DataElement updatedDataElementB = objectManager.get(DataElement.class, dataElementB.getUid());
    assertTrue(aclService.canRead(userA, visualizationA));
    assertTrue(aclService.canRead(userB, visualizationA));
    assertTrue(aclService.canRead(userA, updatedDataElementA));
    assertTrue(aclService.canRead(userB, updatedDataElementB));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) Visualization(org.hisp.dhis.visualization.Visualization) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) Dashboard(org.hisp.dhis.dashboard.Dashboard) Test(org.junit.jupiter.api.Test)

Example 29 with Visualization

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

the class InterpretationControllerTest method setUp.

@BeforeEach
void setUp() {
    OrganisationUnit ouA = createOrganisationUnit('A');
    manager.save(ouA);
    Visualization vzA = createVisualization('A');
    visualizationService.save(vzA);
    Interpretation ipA = new Interpretation(vzA, ouA, "Interpration of visualization A");
    interpretationService.saveInterpretation(ipA);
    uid = ipA.getUid();
    ouId = ouA.getUid();
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) Visualization(org.hisp.dhis.visualization.Visualization) Interpretation(org.hisp.dhis.interpretation.Interpretation) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 30 with Visualization

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

the class DimensionServiceTest method testMergeAnalyticalObjectDataElementGroupSet.

@Test
void testMergeAnalyticalObjectDataElementGroupSet() {
    Visualization visualization = new Visualization();
    visualization.getColumns().add(new BaseDimensionalObject(DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X, Lists.newArrayList(deA, deB)));
    visualization.getRows().add(deGroupSetA);
    visualization.getFilters().add(new BaseDimensionalObject(DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD, Lists.newArrayList(peA, peB)));
    dimensionService.mergeAnalyticalObject(visualization);
    assertEquals(2, visualization.getDataDimensionItems().size());
    assertEquals(2, visualization.getPeriods().size());
    assertEquals(1, visualization.getDataElementGroupSetDimensions().size());
    assertEquals(3, visualization.getDataElementGroupSetDimensions().get(0).getItems().size());
}
Also used : Visualization(org.hisp.dhis.visualization.Visualization) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

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