Search in sources :

Example 16 with EventVisualization

use of org.hisp.dhis.eventvisualization.EventVisualization in project dhis2-core by dhis2.

the class InterpretationController method writeEventVisualizationInterpretation.

@PostMapping(value = "/eventVisualization/{uid}", consumes = { "text/html", "text/plain" })
@ResponseBody
public WebMessage writeEventVisualizationInterpretation(@PathVariable("uid") final String uid, @RequestParam(value = "ou", required = false) final String orgUnitUid, @RequestBody final String text) throws WebMessageException {
    final EventVisualization eventVisualization = idObjectManager.get(EventVisualization.class, uid);
    if (eventVisualization == null) {
        return conflict("EventVisualization does not exist or is not accessible: " + uid);
    }
    final OrganisationUnit orgUnit = getUserOrganisationUnit(orgUnitUid, eventVisualization, currentUserService.getCurrentUser());
    /*
         * This is needed until the deprecated entities (EventChart and
         * EventReport) are completely removed from the code base. Until there
         * all interpretations saved on the new EventVisualization entity should
         * also be available for the deprecated ones.
         */
    switch(eventVisualization.getType()) {
        case LINE_LIST:
        case PIVOT_TABLE:
            final EventReport eventReport = idObjectManager.get(EventReport.class, eventVisualization.getUid());
            return createInterpretation(new Interpretation(eventVisualization, eventReport, orgUnit, text));
        default:
            final EventChart eventChart = idObjectManager.get(EventChart.class, eventVisualization.getUid());
            return createInterpretation(new Interpretation(eventVisualization, eventChart, orgUnit, text));
    }
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) EventChart(org.hisp.dhis.eventchart.EventChart) Interpretation(org.hisp.dhis.interpretation.Interpretation) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) EventReport(org.hisp.dhis.eventreport.EventReport) PostMapping(org.springframework.web.bind.annotation.PostMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 17 with EventVisualization

use of org.hisp.dhis.eventvisualization.EventVisualization in project dhis2-core by dhis2.

the class DashboardCascadeSharingTest method testCascadeShareEventVisualization.

/**
 * Dashboard has sharingUserA and eventVisualizationA
 * <p>
 * eventVisualizationA has dataElementA
 * <p>
 * Expected: eventVisualizationA and dataElementA should be shared to userA
 */
@Test
void testCascadeShareEventVisualization() {
    DataElement dataElementA = createDEWithDefaultSharing('A');
    objectManager.save(dataElementA);
    DataElement dataElementB = createDEWithDefaultSharing('B');
    objectManager.save(dataElementB);
    Program program = createProgram('Y', null, null);
    objectManager.save(program);
    EventVisualization eventVisualizationA = createEventVisualization('A', program);
    eventVisualizationA.addDataDimensionItem(dataElementA);
    eventVisualizationA.addDataDimensionItem(dataElementB);
    eventVisualizationA.setSharing(Sharing.builder().publicAccess(DEFAULT).build());
    objectManager.save(eventVisualizationA, false);
    Dashboard dashboard = createDashboardWithItem("A", sharingReadForUserAB);
    dashboard.getItems().get(0).setEventVisualization(eventVisualizationA);
    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, eventVisualizationA));
    assertTrue(aclService.canRead(userB, eventVisualizationA));
    assertTrue(aclService.canRead(userA, updatedDataElementA));
    assertTrue(aclService.canRead(userB, updatedDataElementB));
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) Program(org.hisp.dhis.program.Program) Dashboard(org.hisp.dhis.dashboard.Dashboard) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) Test(org.junit.jupiter.api.Test)

Example 18 with EventVisualization

use of org.hisp.dhis.eventvisualization.EventVisualization in project dhis2-core by dhis2.

the class DimensionServiceTest method testMergeEventAnalyticalObject.

@Test
void testMergeEventAnalyticalObject() {
    // Given
    EventVisualization eventVisualization = new EventVisualization("any");
    eventVisualization.setValue(deC);
    // When
    dimensionService.mergeEventAnalyticalObject(eventVisualization);
    // Then
    assertNotNull(eventVisualization.getDataElementValueDimension());
    assertNull(eventVisualization.getAttributeValueDimension());
}
Also used : EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 19 with EventVisualization

use of org.hisp.dhis.eventvisualization.EventVisualization in project dhis2-core by dhis2.

the class DimensionServiceTest method testMergeAnalyticalEventObjectA.

@Test
void testMergeAnalyticalEventObjectA() {
    // Given
    EventVisualization eventVisualization = new EventVisualization("any");
    eventVisualization.getColumns().add(new BaseDimensionalObject(DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X, Lists.newArrayList(deA, deB)));
    eventVisualization.getRows().add(new BaseDimensionalObject(DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, Lists.newArrayList(ouA, ouB, ouC, ouD, ouE)));
    eventVisualization.getFilters().add(new BaseDimensionalObject(DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD, Lists.newArrayList(peA, peB)));
    // When
    dimensionService.mergeAnalyticalObject(eventVisualization);
    // Then
    assertEquals(2, eventVisualization.getDataDimensionItems().size());
    assertEquals(2, eventVisualization.getPeriods().size());
    assertEquals(5, eventVisualization.getOrganisationUnits().size());
}
Also used : BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 20 with EventVisualization

use of org.hisp.dhis.eventvisualization.EventVisualization in project dhis2-core by dhis2.

the class DimensionServiceTest method testMergeAnalyticalEventObjectOrgUnitLevel.

@Test
void testMergeAnalyticalEventObjectOrgUnitLevel() {
    // Given
    EventVisualization eventVisualization = new EventVisualization("any");
    eventVisualization.getColumns().add(new BaseDimensionalObject(DimensionalObject.DATA_X_DIM_ID, DimensionType.DATA_X, Lists.newArrayList(deA, deB)));
    eventVisualization.getRows().add(new BaseDimensionalObject(DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, Lists.newArrayList(ouLevel2, ouA)));
    eventVisualization.getFilters().add(new BaseDimensionalObject(DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD, Lists.newArrayList(peA)));
    // When
    dimensionService.mergeAnalyticalObject(eventVisualization);
    // Then
    assertEquals(2, eventVisualization.getDataDimensionItems().size());
    assertEquals(1, eventVisualization.getPeriods().size());
    assertEquals(1, eventVisualization.getOrganisationUnits().size());
    assertEquals(Integer.valueOf(2), eventVisualization.getOrganisationUnitLevels().get(0));
}
Also used : BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

EventVisualization (org.hisp.dhis.eventvisualization.EventVisualization)31 Test (org.junit.jupiter.api.Test)20 DhisSpringTest (org.hisp.dhis.DhisSpringTest)11 TransactionalIntegrationTest (org.hisp.dhis.TransactionalIntegrationTest)7 BaseDimensionalObject (org.hisp.dhis.common.BaseDimensionalObject)7 User (org.hisp.dhis.user.User)7 OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)4 Program (org.hisp.dhis.program.Program)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)3 JpaQueryParameters (org.hisp.dhis.hibernate.JpaQueryParameters)3 Interpretation (org.hisp.dhis.interpretation.Interpretation)3 UserAccess (org.hisp.dhis.user.sharing.UserAccess)3 ArrayList (java.util.ArrayList)2 Function (java.util.function.Function)2 Dashboard (org.hisp.dhis.dashboard.Dashboard)2 DataElement (org.hisp.dhis.dataelement.DataElement)2 EventChart (org.hisp.dhis.eventchart.EventChart)2 EventReport (org.hisp.dhis.eventreport.EventReport)2 UserAuthorityGroup (org.hisp.dhis.user.UserAuthorityGroup)2 PostMapping (org.springframework.web.bind.annotation.PostMapping)2