From b1646b1474a80c958d7ce04d871bfcc8a73f37d9 Mon Sep 17 00:00:00 2001 From: Viet Nguyen Date: Thu, 3 Oct 2024 17:42:03 +0700 Subject: [PATCH] fix: import orgUnitGroupMember using csv --- .../dxf2/csv/DefaultCsvImportService.java | 1 + .../dxf2/metadata/CsvMetadataImportTest.java | 30 +++++++++++++++++++ .../metadata/organisationUnitGroup.csv | 3 ++ .../organisationUnitGroup_members.csv | 5 ++++ .../metadata/organisationUnitMembers.csv | 5 ++++ 5 files changed, 44 insertions(+) create mode 100644 dhis-2/dhis-test-integration/src/test/resources/metadata/organisationUnitGroup.csv create mode 100644 dhis-2/dhis-test-integration/src/test/resources/metadata/organisationUnitGroup_members.csv create mode 100644 dhis-2/dhis-test-integration/src/test/resources/metadata/organisationUnitMembers.csv diff --git a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/csv/DefaultCsvImportService.java b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/csv/DefaultCsvImportService.java index b5479744a45d..b2a0b9c2a30a 100644 --- a/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/csv/DefaultCsvImportService.java +++ b/dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/csv/DefaultCsvImportService.java @@ -532,6 +532,7 @@ private List orgUnitGroupMembersFromCsv(CsvReader reader) nonPersistedGroup.setUid(persistedGroup.getUid()); nonPersistedGroup.setName(persistedGroup.getName()); + nonPersistedGroup.setShortName(persistedGroup.getShortName()); return nonPersistedGroup; }); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dxf2/metadata/CsvMetadataImportTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dxf2/metadata/CsvMetadataImportTest.java index c7e6470712ee..724550e49a67 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dxf2/metadata/CsvMetadataImportTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dxf2/metadata/CsvMetadataImportTest.java @@ -47,6 +47,7 @@ import org.hisp.dhis.option.OptionGroupSet; import org.hisp.dhis.option.OptionService; import org.hisp.dhis.option.OptionSet; +import org.hisp.dhis.organisationunit.OrganisationUnitGroup; import org.hisp.dhis.organisationunit.OrganisationUnitService; import org.hisp.dhis.preheat.PreheatIdentifier; import org.hisp.dhis.schema.SchemaService; @@ -228,6 +229,35 @@ void testImportOptionGroupSet() throws IOException { assertEquals(2, ogsA.getMembers().get(0).getMembers().size()); } + @Test + void testImportOrganisationUnitGroupMembers() throws IOException { + ImportReport importReport = + runImport( + "metadata/organisationUnitMembers.csv", + CsvImportClass.ORGANISATION_UNIT, + metadata -> assertEquals(4, metadata.getOrganisationUnits().size())); + assertEquals(4, importReport.getStats().getCreated()); + assertEquals(4, organisationUnitService.getAllOrganisationUnits().size()); + + importReport = + runImport( + "metadata/organisationUnitGroup.csv", + CsvImportClass.ORGANISATION_UNIT_GROUP, + metadata -> assertEquals(2, metadata.getOrganisationUnitGroups().size())); + assertEquals(2, importReport.getStats().getCreated()); + + importReport = + runImport( + "metadata/organisationUnitGroup_members.csv", + CsvImportClass.ORGANISATION_UNIT_GROUP_MEMBERSHIP, + metadata -> assertEquals(2, metadata.getOrganisationUnitGroups().size())); + assertEquals(2, importReport.getStats().getUpdated()); + OrganisationUnitGroup orgUnitA = manager.get(OrganisationUnitGroup.class, "a1234567890"); + assertEquals(2, orgUnitA.getMembers().size()); + OrganisationUnitGroup orgUnitB = manager.get(OrganisationUnitGroup.class, "b1234567890"); + assertEquals(2, orgUnitB.getMembers().size()); + } + private ImportReport runImport(String csvFile, CsvImportClass importClass) throws IOException { return runImport(csvFile, importClass, null); } diff --git a/dhis-2/dhis-test-integration/src/test/resources/metadata/organisationUnitGroup.csv b/dhis-2/dhis-test-integration/src/test/resources/metadata/organisationUnitGroup.csv new file mode 100644 index 000000000000..4441ca438aa9 --- /dev/null +++ b/dhis-2/dhis-test-integration/src/test/resources/metadata/organisationUnitGroup.csv @@ -0,0 +1,3 @@ +name,uid,code,shortName +"group1","a1234567890","G1","Group1" +"group2","b1234567890","G2","Group2" \ No newline at end of file diff --git a/dhis-2/dhis-test-integration/src/test/resources/metadata/organisationUnitGroup_members.csv b/dhis-2/dhis-test-integration/src/test/resources/metadata/organisationUnitGroup_members.csv new file mode 100644 index 000000000000..c68a32f4935e --- /dev/null +++ b/dhis-2/dhis-test-integration/src/test/resources/metadata/organisationUnitGroup_members.csv @@ -0,0 +1,5 @@ +groupid,memberid +a1234567890,c1234567890 +a1234567890,d1234567890 +b1234567890,e1234567890 +b1234567890,f1234567890 \ No newline at end of file diff --git a/dhis-2/dhis-test-integration/src/test/resources/metadata/organisationUnitMembers.csv b/dhis-2/dhis-test-integration/src/test/resources/metadata/organisationUnitMembers.csv new file mode 100644 index 000000000000..17de1a5c8212 --- /dev/null +++ b/dhis-2/dhis-test-integration/src/test/resources/metadata/organisationUnitMembers.csv @@ -0,0 +1,5 @@ +name,uid,code,parent,shortName +"Level 2a","c1234567890","L2a","","L2a" +"Level 2b","d1234567890","L2b","c1234567890","L2b" +"Level 3","e1234567890","L3","","L3" +"Level 4","f1234567890","L4","e1234567890","L4" \ No newline at end of file