Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: import orgUnitGroupMember using csv[DHIS2-18118-39] #18741

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,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 @@ -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;
Expand Down Expand Up @@ -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);
}
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"
Loading