Search in sources :

Example 21 with EventVisualization

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

the class DimensionServiceTest method testMergeAnalyticalEventObjectB.

@Test
void testMergeAnalyticalEventObjectB() {
    // Given
    EventVisualization eventVisualization = new EventVisualization("any");
    BaseDimensionalObject deCDim = new BaseDimensionalObject(deC.getUid(), DimensionType.PROGRAM_DATA_ELEMENT, null, null, null, psA, "EQ:uidA");
    eventVisualization.getColumns().add(deCDim);
    eventVisualization.getRows().add(new BaseDimensionalObject(DimensionalObject.ORGUNIT_DIM_ID, DimensionType.ORGANISATION_UNIT, Lists.newArrayList(ouA, ouB, ouC)));
    eventVisualization.getFilters().add(new BaseDimensionalObject(DimensionalObject.PERIOD_DIM_ID, DimensionType.PERIOD, Lists.newArrayList(peA, peB)));
    // When
    dimensionService.mergeAnalyticalObject(eventVisualization);
    // Then
    assertEquals(1, eventVisualization.getDataElementDimensions().size());
    assertEquals(2, eventVisualization.getPeriods().size());
    assertEquals(3, eventVisualization.getOrganisationUnits().size());
    TrackedEntityDataElementDimension teDeDim = eventVisualization.getDataElementDimensions().get(0);
    assertEquals(deC, teDeDim.getDataElement());
    assertEquals(psA, teDeDim.getProgramStage());
}
Also used : BaseDimensionalObject(org.hisp.dhis.common.BaseDimensionalObject) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) TrackedEntityDataElementDimension(org.hisp.dhis.trackedentity.TrackedEntityDataElementDimension) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 22 with EventVisualization

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

the class DimensionServiceTest method testMergeAnalyticalEventObjectRelativePeriods.

@Test
void testMergeAnalyticalEventObjectRelativePeriods() {
    // 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(peLast12Months)));
    // When
    dimensionService.mergeAnalyticalObject(eventVisualization);
    // Then
    assertEquals(2, eventVisualization.getDataDimensionItems().size());
    assertEquals(0, eventVisualization.getPeriods().size());
    assertTrue(eventVisualization.getRelatives().isLast12Months());
    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 23 with EventVisualization

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

the class AclServiceTest method testUserBCanUpdateEventVisualizationWithAuthority.

@Test
void testUserBCanUpdateEventVisualizationWithAuthority() {
    // Given
    User userA = createUser('A');
    manager.save(userA);
    EventVisualization eventVisualization = new EventVisualization();
    eventVisualization.setAutoFields();
    eventVisualization.setName("FavA");
    eventVisualization.setCreatedBy(userA);
    eventVisualization.getSharing().setOwner(userA);
    eventVisualization.setPublicAccess(AccessStringHelper.DEFAULT);
    eventVisualization.setType(EventVisualizationType.COLUMN);
    assertTrue(aclService.canUpdate(userA, eventVisualization));
    manager.save(eventVisualization);
    // Then
    UserAuthorityGroup userAuthorityGroup = new UserAuthorityGroup();
    userAuthorityGroup.setAutoFields();
    userAuthorityGroup.setName("UR");
    userAuthorityGroup.getAuthorities().add("F_EVENT_VISUALIZATION_PUBLIC_ADD");
    manager.save(userAuthorityGroup);
    User userB = createUser('B');
    userB.getUserAuthorityGroups().add(userAuthorityGroup);
    manager.save(userB);
    eventVisualization.getSharing().addUserAccess(new UserAccess(userB, AccessStringHelper.FULL));
    manager.update(eventVisualization);
    assertTrue(aclService.canUpdate(userB, eventVisualization));
}
Also used : User(org.hisp.dhis.user.User) UserAuthorityGroup(org.hisp.dhis.user.UserAuthorityGroup) UserAccess(org.hisp.dhis.user.sharing.UserAccess) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 24 with EventVisualization

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

the class AclServiceTest method testVerifyEventVisualizationCantExternalize.

@Test
void testVerifyEventVisualizationCantExternalize() {
    // Given
    User user = createAdminUser("F_EVENT_VISUALIZATION_PUBLIC_ADD");
    EventVisualization eventVisualization = new EventVisualization();
    eventVisualization.setAutoFields();
    eventVisualization.setPublicAccess(AccessStringHelper.DEFAULT);
    eventVisualization.setExternalAccess(true);
    eventVisualization.setType(EventVisualizationType.COLUMN);
    // Then
    assertFalse(aclService.verifySharing(eventVisualization, user).isEmpty());
}
Also used : User(org.hisp.dhis.user.User) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 25 with EventVisualization

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

the class AclServiceTest method testUserBCanUpdateEventVisualizationWithoutAuthority.

@Test
void testUserBCanUpdateEventVisualizationWithoutAuthority() {
    // Given
    User userA = createUser('A');
    manager.save(userA);
    EventVisualization eventVisualization = new EventVisualization();
    eventVisualization.setAutoFields();
    eventVisualization.setName("FavA");
    eventVisualization.setCreatedBy(userA);
    eventVisualization.getSharing().setOwner(userA);
    eventVisualization.setPublicAccess(AccessStringHelper.DEFAULT);
    eventVisualization.setType(EventVisualizationType.COLUMN);
    assertTrue(aclService.canUpdate(userA, eventVisualization));
    manager.save(eventVisualization);
    // Then
    User userB = createUser('B');
    manager.save(userB);
    eventVisualization.getSharing().addUserAccess(new UserAccess(userB, AccessStringHelper.FULL));
    manager.update(eventVisualization);
    assertTrue(aclService.canUpdate(userB, eventVisualization));
}
Also used : User(org.hisp.dhis.user.User) UserAccess(org.hisp.dhis.user.sharing.UserAccess) EventVisualization(org.hisp.dhis.eventvisualization.EventVisualization) TransactionalIntegrationTest(org.hisp.dhis.TransactionalIntegrationTest) Test(org.junit.jupiter.api.Test)

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