Skip to content

Commit

Permalink
fix: import orgUnitGroupMember using csv (#18734)
Browse files Browse the repository at this point in the history
  • Loading branch information
vietnguyen authored Oct 3, 2024
1 parent 1ca4b4b commit 0ee87ec
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ private List<OrganisationUnitGroup> orgUnitGroupMembersFromCsv(CsvReader reader)

nonPersistedGroup.setUid(persistedGroup.getUid());
nonPersistedGroup.setName(persistedGroup.getName());
nonPersistedGroup.setShortName(persistedGroup.getShortName());

return nonPersistedGroup;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,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.schema.SchemaService;
import org.hisp.dhis.test.integration.PostgresIntegrationTestBase;
Expand Down Expand Up @@ -180,6 +181,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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name,uid,code,shortName
"group1","a1234567890","G1","Group1"
"group2","b1234567890","G2","Group2"
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
groupid,memberid
a1234567890,c1234567890
a1234567890,d1234567890
b1234567890,e1234567890
b1234567890,f1234567890
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 0ee87ec

Please sign in to comment.