Search in sources :

Example 1 with OrgUnitMergeRequest

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

the class DataOrgUnitMergeHandlerTest method testMergeDataValues.

@Test
void testMergeDataValues() {
    addDataValues(createDataValue(deA, peA, ouA, cocA, cocA, "10", date(2021, 1, 1), date(2021, 1, 1)), createDataValue(deA, peA, ouB, cocA, cocA, "11", date(2021, 2, 1), date(2021, 2, 1)), createDataValue(deB, peA, ouA, cocA, cocA, "12", date(2021, 3, 1), date(2021, 3, 1)), createDataValue(deB, peA, ouB, cocA, cocA, "13", date(2021, 4, 1), date(2021, 4, 1)));
    assertEquals(2, getDataValueCount(ouA));
    assertEquals(2, getDataValueCount(ouB));
    assertEquals(0, getDataValueCount(ouC));
    OrgUnitMergeRequest request = new OrgUnitMergeRequest.Builder().addSource(ouA).addSource(ouB).withTarget(ouC).withDataValueMergeStrategy(DataMergeStrategy.LAST_UPDATED).build();
    handler.mergeDataValues(request);
    assertEquals(0, getDataValueCount(ouA));
    assertEquals(0, getDataValueCount(ouB));
    assertEquals(2, getDataValueCount(ouC));
}
Also used : OrgUnitMergeRequest(org.hisp.dhis.merge.orgunit.OrgUnitMergeRequest) Test(org.junit.jupiter.api.Test)

Example 2 with OrgUnitMergeRequest

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

the class MetadataOrgUnitMergeHandlerTest method testMergePrograms.

@Test
void testMergePrograms() {
    Program prA = createProgram('A');
    prA.addOrganisationUnit(ouA);
    prA.addOrganisationUnit(ouB);
    Program prB = createProgram('B');
    prB.addOrganisationUnit(ouA);
    OrgUnitMergeRequest request = new OrgUnitMergeRequest.Builder().addSource(ouA).addSource(ouB).withTarget(ouC).build();
    assertEquals(2, ouA.getPrograms().size());
    assertEquals(1, ouB.getPrograms().size());
    assertEquals(0, ouC.getPrograms().size());
    handler.mergePrograms(request);
    assertEquals(0, ouA.getPrograms().size());
    assertEquals(0, ouB.getPrograms().size());
    assertEquals(2, ouC.getPrograms().size());
}
Also used : Program(org.hisp.dhis.program.Program) DhisConvenienceTest.createProgram(org.hisp.dhis.DhisConvenienceTest.createProgram) OrgUnitMergeRequest(org.hisp.dhis.merge.orgunit.OrgUnitMergeRequest) Test(org.junit.jupiter.api.Test)

Example 3 with OrgUnitMergeRequest

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

the class MetadataOrgUnitMergeHandlerTest method testMergeDataSets.

@Test
void testMergeDataSets() {
    DataSet dsA = createDataSet('A');
    dsA.addOrganisationUnit(ouA);
    dsA.addOrganisationUnit(ouB);
    DataSet dsB = createDataSet('B');
    dsB.addOrganisationUnit(ouA);
    OrgUnitMergeRequest request = new OrgUnitMergeRequest.Builder().addSource(ouA).addSource(ouB).withTarget(ouC).build();
    assertEquals(2, ouA.getDataSets().size());
    assertEquals(1, ouB.getDataSets().size());
    assertEquals(0, ouC.getDataSets().size());
    handler.mergeDataSets(request);
    assertEquals(0, ouA.getDataSets().size());
    assertEquals(0, ouB.getDataSets().size());
    assertEquals(2, ouC.getDataSets().size());
}
Also used : DataSet(org.hisp.dhis.dataset.DataSet) DhisConvenienceTest.createDataSet(org.hisp.dhis.DhisConvenienceTest.createDataSet) OrgUnitMergeRequest(org.hisp.dhis.merge.orgunit.OrgUnitMergeRequest) Test(org.junit.jupiter.api.Test)

Example 4 with OrgUnitMergeRequest

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

the class TrackerOrgUnitMergeHandlerTest method testMigrateProgramInstances.

@Test
void testMigrateProgramInstances() {
    assertEquals(2, getProgramInstanceCount(ouA));
    assertEquals(1, getProgramInstanceCount(ouB));
    assertEquals(0, getProgramInstanceCount(ouC));
    OrgUnitMergeRequest request = new OrgUnitMergeRequest.Builder().addSource(ouA).addSource(ouB).withTarget(ouC).build();
    mergeHandler.mergeProgramInstances(request);
    assertEquals(0, getProgramInstanceCount(ouA));
    assertEquals(0, getProgramInstanceCount(ouB));
    assertEquals(3, getProgramInstanceCount(ouC));
}
Also used : OrgUnitMergeRequest(org.hisp.dhis.merge.orgunit.OrgUnitMergeRequest) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

Example 5 with OrgUnitMergeRequest

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

the class AnalyticalObjectOrgUnitMergeHandlerTest method testMergeVisualizations.

@Test
void testMergeVisualizations() {
    Visualization vA = createVisualization('A');
    vA.addDataDimensionItem(deA);
    vA.getOrganisationUnits().add(ouA);
    vA.getOrganisationUnits().add(ouB);
    Visualization vB = createVisualization('B');
    vB.addDataDimensionItem(deA);
    vB.getOrganisationUnits().add(ouA);
    vB.getOrganisationUnits().add(ouB);
    idObjectManager.save(vA);
    idObjectManager.save(vB);
    assertEquals(2, getVisualizationCount(ouA));
    assertEquals(2, getVisualizationCount(ouB));
    assertEquals(0, getVisualizationCount(ouC));
    OrgUnitMergeRequest request = new OrgUnitMergeRequest.Builder().addSource(ouA).addSource(ouB).withTarget(ouC).build();
    handler.mergeAnalyticalObjects(request);
    idObjectManager.update(ouC);
    assertEquals(0, getVisualizationCount(ouA));
    assertEquals(0, getVisualizationCount(ouB));
    assertEquals(2, getVisualizationCount(ouC));
}
Also used : Visualization(org.hisp.dhis.visualization.Visualization) OrgUnitMergeRequest(org.hisp.dhis.merge.orgunit.OrgUnitMergeRequest) Test(org.junit.jupiter.api.Test) DhisSpringTest(org.hisp.dhis.DhisSpringTest)

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