Search in sources :

Example 11 with OrganisationUnit

use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.

the class DataApprovalServiceTest method testMayUnapproveLowerLevels.

@Test
@Category(IntegrationTest.class)
public void testMayUnapproveLowerLevels() {
    Set<OrganisationUnit> units = newHashSet(organisationUnitB);
    CurrentUserService currentUserService = new MockCurrentUserService(units, null, DataApproval.AUTH_APPROVE_LOWER_LEVELS, AUTH_APPR_LEVEL);
    userService.addUser(currentUserService.getCurrentUser());
    setCurrentUserServiceDependencies(currentUserService);
    Date date = new Date();
    DataApproval dataApprovalA = new DataApproval(level1, workflow1234, periodA, organisationUnitA, defaultOptionCombo, NOT_ACCEPTED, date, userA);
    DataApproval dataApprovalB = new DataApproval(level2, workflow1234, periodA, organisationUnitB, defaultOptionCombo, NOT_ACCEPTED, date, userA);
    DataApproval dataApprovalC = new DataApproval(level3, workflow1234, periodA, organisationUnitC, defaultOptionCombo, NOT_ACCEPTED, date, userA);
    DataApproval dataApprovalD = new DataApproval(level4, workflow1234, periodA, organisationUnitD, defaultOptionCombo, NOT_ACCEPTED, date, userA);
    DataApproval dataApprovalE = new DataApproval(level3, workflow1234, periodA, organisationUnitE, defaultOptionCombo, NOT_ACCEPTED, date, userA);
    DataApproval dataApprovalF = new DataApproval(level4, workflow1234, periodA, organisationUnitF, defaultOptionCombo, NOT_ACCEPTED, date, userA);
    dataApprovalStore.addDataApproval(dataApprovalD);
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitA, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertTrue(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitF, defaultOptionCombo).getPermissions().isMayUnapprove());
    dataApprovalStore.addDataApproval(dataApprovalF);
    dataApprovalStore.addDataApproval(dataApprovalE);
    dataApprovalStore.addDataApproval(dataApprovalC);
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitA, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertTrue(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertTrue(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitF, defaultOptionCombo).getPermissions().isMayUnapprove());
    dataApprovalStore.addDataApproval(dataApprovalB);
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitA, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitF, defaultOptionCombo).getPermissions().isMayUnapprove());
    dataApprovalStore.addDataApproval(dataApprovalA);
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitA, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitF, defaultOptionCombo).getPermissions().isMayUnapprove());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) CurrentUserService(org.hisp.dhis.user.CurrentUserService) Date(java.util.Date) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) Category(org.junit.experimental.categories.Category) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisTest(org.hisp.dhis.DhisTest)

Example 12 with OrganisationUnit

use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.

the class DeletedObjectServiceTest method testDeleteDataElement.

@Test
public void testDeleteDataElement() {
    DataElement dataElementA = createDataElement('A');
    DataElement dataElementB = createDataElement('B');
    DataElement dataElementC = createDataElement('C');
    OrganisationUnit organisationUnitA = createOrganisationUnit('A');
    OrganisationUnit organisationUnitB = createOrganisationUnit('B');
    manager.save(dataElementA);
    manager.save(dataElementB);
    manager.save(dataElementC);
    manager.save(organisationUnitA);
    manager.save(organisationUnitB);
    manager.delete(dataElementA);
    manager.delete(dataElementB);
    manager.delete(dataElementC);
    manager.delete(organisationUnitA);
    manager.delete(organisationUnitB);
    // need to flush to make changes happen within the same tx
    manager.flush();
    assertEquals(5, deletedObjectService.countDeletedObjects());
    assertEquals(3, deletedObjectService.getDeletedObjectsByKlass("DataElement").size());
    assertEquals(2, deletedObjectService.getDeletedObjectsByKlass("OrganisationUnit").size());
}
Also used : DataElement(org.hisp.dhis.dataelement.DataElement) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) DhisSpringTest(org.hisp.dhis.DhisSpringTest) Test(org.junit.Test)

Example 13 with OrganisationUnit

use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.

the class DataApprovalServiceTest method testGetDataApprovalStateAbove.

@Test
@Category(IntegrationTest.class)
public void testGetDataApprovalStateAbove() {
    Set<OrganisationUnit> units = newHashSet(organisationUnitA);
    CurrentUserService currentUserService = new MockCurrentUserService(units, null, DataApproval.AUTH_APPROVE, DataApproval.AUTH_APPROVE_LOWER_LEVELS);
    userService.addUser(currentUserService.getCurrentUser());
    setCurrentUserServiceDependencies(currentUserService);
    Date date = new Date();
    // Approved for organisation unit C
    DataApproval dataApprovalC = new DataApproval(level3, workflow3, periodA, organisationUnitC, defaultOptionCombo, NOT_ACCEPTED, date, userA);
    dataApprovalService.approveData(newArrayList(dataApprovalC));
    assertEquals(DataApprovalState.APPROVED_HERE, dataApprovalService.getDataApprovalStatus(workflow3, periodA, organisationUnitC, defaultOptionCombo).getState());
    assertEquals(DataApprovalState.APPROVED_ABOVE, dataApprovalService.getDataApprovalStatus(workflow3, periodA, organisationUnitD, defaultOptionCombo).getState());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) CurrentUserService(org.hisp.dhis.user.CurrentUserService) Date(java.util.Date) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) Category(org.junit.experimental.categories.Category) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisTest(org.hisp.dhis.DhisTest)

Example 14 with OrganisationUnit

use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.

the class DataApprovalServiceTest method testMayUnapproveSameLevel.

@Test
@Category(IntegrationTest.class)
public void testMayUnapproveSameLevel() {
    Set<OrganisationUnit> units = newHashSet(organisationUnitB);
    CurrentUserService currentUserService = new MockCurrentUserService(units, null, DataApproval.AUTH_APPROVE, AUTH_APPR_LEVEL);
    userService.addUser(currentUserService.getCurrentUser());
    setCurrentUserServiceDependencies(currentUserService);
    Date date = new Date();
    DataApproval dataApprovalA = new DataApproval(level1, workflow1234, periodA, organisationUnitA, defaultOptionCombo, NOT_ACCEPTED, date, userA);
    DataApproval dataApprovalB = new DataApproval(level2, workflow1234, periodA, organisationUnitB, defaultOptionCombo, NOT_ACCEPTED, date, userA);
    DataApproval dataApprovalC = new DataApproval(level3, workflow1234, periodA, organisationUnitC, defaultOptionCombo, NOT_ACCEPTED, date, userA);
    DataApproval dataApprovalD = new DataApproval(level4, workflow1234, periodA, organisationUnitD, defaultOptionCombo, NOT_ACCEPTED, date, userA);
    DataApproval dataApprovalE = new DataApproval(level3, workflow1234, periodA, organisationUnitE, defaultOptionCombo, NOT_ACCEPTED, date, userA);
    DataApproval dataApprovalF = new DataApproval(level4, workflow1234, periodA, organisationUnitF, defaultOptionCombo, NOT_ACCEPTED, date, userA);
    dataApprovalStore.addDataApproval(dataApprovalD);
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitA, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitF, defaultOptionCombo).getPermissions().isMayUnapprove());
    dataApprovalStore.addDataApproval(dataApprovalF);
    dataApprovalStore.addDataApproval(dataApprovalE);
    dataApprovalStore.addDataApproval(dataApprovalC);
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitA, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitF, defaultOptionCombo).getPermissions().isMayUnapprove());
    dataApprovalStore.addDataApproval(dataApprovalB);
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitA, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertTrue(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitF, defaultOptionCombo).getPermissions().isMayUnapprove());
    dataApprovalStore.addDataApproval(dataApprovalA);
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitA, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitB, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitC, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitD, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitE, defaultOptionCombo).getPermissions().isMayUnapprove());
    assertFalse(dataApprovalService.getDataApprovalStatusAndPermissions(workflow1234, periodA, organisationUnitF, defaultOptionCombo).getPermissions().isMayUnapprove());
}
Also used : OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) MockCurrentUserService(org.hisp.dhis.mock.MockCurrentUserService) CurrentUserService(org.hisp.dhis.user.CurrentUserService) Date(java.util.Date) DataElementCategory(org.hisp.dhis.dataelement.DataElementCategory) Category(org.junit.experimental.categories.Category) IntegrationTest(org.hisp.dhis.IntegrationTest) Test(org.junit.Test) DhisTest(org.hisp.dhis.DhisTest)

Example 15 with OrganisationUnit

use of org.hisp.dhis.organisationunit.OrganisationUnit in project dhis2-core by dhis2.

the class MergeServiceTest method mergeOrgUnitGroupSet.

@Test
public void mergeOrgUnitGroupSet() {
    OrganisationUnit organisationUnitA = createOrganisationUnit('A');
    OrganisationUnit organisationUnitB = createOrganisationUnit('B');
    OrganisationUnit organisationUnitC = createOrganisationUnit('C');
    OrganisationUnit organisationUnitD = createOrganisationUnit('D');
    OrganisationUnitGroup organisationUnitGroupA = createOrganisationUnitGroup('A');
    organisationUnitGroupA.getMembers().add(organisationUnitA);
    organisationUnitGroupA.getMembers().add(organisationUnitB);
    organisationUnitGroupA.getMembers().add(organisationUnitC);
    organisationUnitGroupA.getMembers().add(organisationUnitD);
    OrganisationUnitGroupSet organisationUnitGroupSetA = createOrganisationUnitGroupSet('A');
    OrganisationUnitGroupSet organisationUnitGroupSetB = createOrganisationUnitGroupSet('B');
    organisationUnitGroupSetA.addOrganisationUnitGroup(organisationUnitGroupA);
    mergeService.merge(new MergeParams<>(organisationUnitGroupSetA, organisationUnitGroupSetB).setMergeMode(MergeMode.REPLACE));
    assertFalse(organisationUnitGroupSetB.getOrganisationUnitGroups().isEmpty());
    assertEquals(organisationUnitGroupSetA.getName(), organisationUnitGroupSetB.getName());
    assertEquals(organisationUnitGroupSetA.getDescription(), organisationUnitGroupSetB.getDescription());
    assertEquals(organisationUnitGroupSetA.isCompulsory(), organisationUnitGroupSetB.isCompulsory());
    assertEquals(organisationUnitGroupSetA.isIncludeSubhierarchyInAnalytics(), organisationUnitGroupSetB.isIncludeSubhierarchyInAnalytics());
    assertEquals(1, organisationUnitGroupSetB.getOrganisationUnitGroups().size());
}
Also used : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) OrganisationUnit(org.hisp.dhis.organisationunit.OrganisationUnit) MergeParams(org.hisp.dhis.schema.MergeParams) OrganisationUnitGroupSet(org.hisp.dhis.organisationunit.OrganisationUnitGroupSet) Test(org.junit.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Aggregations

OrganisationUnit (org.hisp.dhis.organisationunit.OrganisationUnit)321 Period (org.hisp.dhis.period.Period)74 Test (org.junit.Test)63 ArrayList (java.util.ArrayList)62 User (org.hisp.dhis.user.User)57 Date (java.util.Date)53 HashSet (java.util.HashSet)53 DataSet (org.hisp.dhis.dataset.DataSet)53 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)51 DataElement (org.hisp.dhis.dataelement.DataElement)50 DataElementCategoryOptionCombo (org.hisp.dhis.dataelement.DataElementCategoryOptionCombo)39 DhisSpringTest (org.hisp.dhis.DhisSpringTest)37 List (java.util.List)36 CurrentUserService (org.hisp.dhis.user.CurrentUserService)29 WebMessageException (org.hisp.dhis.dxf2.webmessage.WebMessageException)28 MockCurrentUserService (org.hisp.dhis.mock.MockCurrentUserService)28 IdentifiableObject (org.hisp.dhis.common.IdentifiableObject)23 DataElementCategory (org.hisp.dhis.dataelement.DataElementCategory)23 Program (org.hisp.dhis.program.Program)22 ClassPathResource (org.springframework.core.io.ClassPathResource)20