Search in sources :

Example 6 with OrgUnitMergeRequest

use of org.hisp.dhis.merge.orgunit.OrgUnitMergeRequest in project dhis2-core by dhis2.

the class UserMetadataOrgUnitMergeHandlerTest method testMergeUsers.

@Test
void testMergeUsers() {
    User userA = createUser('A');
    userA.addOrganisationUnit(ouA);
    userA.getDataViewOrganisationUnits().add(ouA);
    userA.getTeiSearchOrganisationUnits().add(ouA);
    User userB = createUser('B');
    userB.addOrganisationUnit(ouB);
    userB.getDataViewOrganisationUnits().add(ouB);
    userB.getTeiSearchOrganisationUnits().add(ouB);
    userService.addUser(userA);
    userService.addUser(userB);
    assertTrue(ouA.getUsers().contains(userA));
    assertTrue(userA.getOrganisationUnits().contains(ouA));
    assertTrue(ouB.getUsers().contains(userB));
    assertTrue(userB.getOrganisationUnits().contains(ouB));
    OrgUnitMergeRequest request = new OrgUnitMergeRequest.Builder().addSource(ouA).addSource(ouB).withTarget(ouC).build();
    handler.mergeUsers(request);
    assertTrue(ouA.getUsers().isEmpty());
    assertFalse(userA.getOrganisationUnits().contains(ouA));
    assertFalse(userA.getDataViewOrganisationUnits().contains(ouA));
    assertFalse(userA.getTeiSearchOrganisationUnits().contains(ouA));
    assertTrue(ouB.getUsers().isEmpty());
    assertFalse(userB.getOrganisationUnits().contains(ouB));
    assertFalse(userB.getDataViewOrganisationUnits().contains(ouB));
    assertFalse(userB.getTeiSearchOrganisationUnits().contains(ouB));
    assertTrue(ouC.getUsers().contains(userA));
    assertTrue(ouC.getUsers().contains(userB));
    assertContainsOnly(userA.getOrganisationUnits(), ouC);
    assertContainsOnly(userA.getDataViewOrganisationUnits(), ouC);
    assertContainsOnly(userA.getTeiSearchOrganisationUnits(), ouC);
    assertContainsOnly(userB.getOrganisationUnits(), ouC);
    assertContainsOnly(userB.getDataViewOrganisationUnits(), ouC);
    assertContainsOnly(userB.getTeiSearchOrganisationUnits(), ouC);
}
Also used : User(org.hisp.dhis.user.User) OrgUnitMergeRequest(org.hisp.dhis.merge.orgunit.OrgUnitMergeRequest) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 7 with OrgUnitMergeRequest

use of org.hisp.dhis.merge.orgunit.OrgUnitMergeRequest in project dhis2-core by dhis2.

the class InterpretationDataOrgUnitMergeHandlerTest method testMigrate.

@Test
void testMigrate() {
    interpretationService.saveInterpretation(ipA);
    interpretationService.saveInterpretation(ipB);
    interpretationService.saveInterpretation(ipC);
    assertEquals(1, getInterpretationCount(ouA));
    assertEquals(1, getInterpretationCount(ouB));
    assertEquals(1, getInterpretationCount(ouC));
    OrgUnitMergeRequest request = new OrgUnitMergeRequest.Builder().addSource(ouA).addSource(ouB).withTarget(ouC).build();
    mergeHandler.mergeInterpretations(request);
    assertEquals(0, getInterpretationCount(ouA));
    assertEquals(0, getInterpretationCount(ouB));
    assertEquals(3, getInterpretationCount(ouC));
}
Also used : OrgUnitMergeRequest(org.hisp.dhis.merge.orgunit.OrgUnitMergeRequest) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 8 with OrgUnitMergeRequest

use of org.hisp.dhis.merge.orgunit.OrgUnitMergeRequest in project dhis2-core by dhis2.

the class DataOrgUnitMergeHandlerTest method testMergeDataApprovals.

@Test
void testMergeDataApprovals() {
    addDataApprovals(new DataApproval(dlA, dwA, peA, ouA, cocA, false, date(2021, 1, 1), usA), new DataApproval(dlA, dwA, peA, ouB, cocA, false, date(2021, 2, 1), usA), new DataApproval(dlA, dwA, peB, ouA, cocA, false, date(2021, 3, 1), usA), new DataApproval(dlA, dwA, peB, ouB, cocA, false, date(2021, 4, 1), usA));
    assertEquals(2, getDataApprovalCount(ouA));
    assertEquals(2, getDataApprovalCount(ouB));
    assertEquals(0, getDataApprovalCount(ouC));
    OrgUnitMergeRequest request = new OrgUnitMergeRequest.Builder().addSource(ouA).addSource(ouB).withTarget(ouC).withDataApprovalMergeStrategy(DataMergeStrategy.LAST_UPDATED).build();
    handler.mergeDataApprovals(request);
    assertEquals(0, getDataApprovalCount(ouA));
    assertEquals(0, getDataApprovalCount(ouB));
    assertEquals(2, getDataApprovalCount(ouC));
}
Also used : DataApproval(org.hisp.dhis.dataapproval.DataApproval) OrgUnitMergeRequest(org.hisp.dhis.merge.orgunit.OrgUnitMergeRequest) Test(org.junit.jupiter.api.Test)

Example 9 with OrgUnitMergeRequest

use of org.hisp.dhis.merge.orgunit.OrgUnitMergeRequest in project dhis2-core by dhis2.

the class MetadataOrgUnitMergeHandlerTest method testMergeOrgUnitGroups.

@Test
void testMergeOrgUnitGroups() {
    OrganisationUnitGroup ougA = createOrganisationUnitGroup('A');
    ougA.addOrganisationUnit(ouA);
    ougA.addOrganisationUnit(ouB);
    OrganisationUnitGroup ougB = createOrganisationUnitGroup('B');
    ougB.addOrganisationUnit(ouA);
    OrgUnitMergeRequest request = new OrgUnitMergeRequest.Builder().addSource(ouA).addSource(ouB).withTarget(ouC).build();
    assertEquals(2, ouA.getGroups().size());
    assertEquals(1, ouB.getGroups().size());
    assertEquals(0, ouC.getGroups().size());
    handler.mergeOrgUnitGroups(request);
    assertEquals(0, ouA.getGroups().size());
    assertEquals(0, ouB.getGroups().size());
    assertEquals(2, ouC.getGroups().size());
}
Also used : OrganisationUnitGroup(org.hisp.dhis.organisationunit.OrganisationUnitGroup) DhisConvenienceTest.createOrganisationUnitGroup(org.hisp.dhis.DhisConvenienceTest.createOrganisationUnitGroup) OrgUnitMergeRequest(org.hisp.dhis.merge.orgunit.OrgUnitMergeRequest) Test(org.junit.jupiter.api.Test)

Aggregations

OrgUnitMergeRequest (org.hisp.dhis.merge.orgunit.OrgUnitMergeRequest)9 Test (org.junit.jupiter.api.Test)9 DhisSpringTest (org.hisp.dhis.DhisSpringTest)4 DhisConvenienceTest.createDataSet (org.hisp.dhis.DhisConvenienceTest.createDataSet)1 DhisConvenienceTest.createOrganisationUnitGroup (org.hisp.dhis.DhisConvenienceTest.createOrganisationUnitGroup)1 DhisConvenienceTest.createProgram (org.hisp.dhis.DhisConvenienceTest.createProgram)1 DataApproval (org.hisp.dhis.dataapproval.DataApproval)1 DataSet (org.hisp.dhis.dataset.DataSet)1 OrganisationUnitGroup (org.hisp.dhis.organisationunit.OrganisationUnitGroup)1 Program (org.hisp.dhis.program.Program)1 User (org.hisp.dhis.user.User)1 Visualization (org.hisp.dhis.visualization.Visualization)1