From 8ac2b4831d908bb53e0001f0f866290487067d12 Mon Sep 17 00:00:00 2001 From: Viet Nguyen Date: Mon, 11 Dec 2023 18:25:33 +0700 Subject: [PATCH] fix: make dataDimensionType not null for catOptionGroup and groupSet --- .../dhis/category/CategoryOptionGroup.java | 5 +++ .../dhis/category/CategoryOptionGroupSet.java | 5 +++ .../dxf2/csv/DefaultCsvImportService.java | 3 ++ .../analytics/data/AnalyticsServiceTest.java | 3 +- .../DataApprovalAuditServiceTest.java | 4 +- .../DataApprovalLevelServiceTest.java | 9 +++-- ...pprovalServiceCategoryOptionGroupTest.java | 5 ++- .../dataapproval/DataApprovalServiceTest.java | 5 ++- .../dhis/dxf2/csv/CsvImportServiceTest.java | 39 +++++++++++++++++++ .../dhis/security/acl/AclServiceTest.java | 2 + .../validation/ValidationResultStoreTest.java | 4 +- .../resources/csv/category_option_group.csv | 4 ++ .../webapi/controller/UserControllerTest.java | 2 + 13 files changed, 79 insertions(+), 11 deletions(-) create mode 100644 dhis-2/dhis-test-integration/src/test/resources/csv/category_option_group.csv diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/category/CategoryOptionGroup.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/category/CategoryOptionGroup.java index a7e7c4107f65..f15116a66b59 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/category/CategoryOptionGroup.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/category/CategoryOptionGroup.java @@ -63,6 +63,11 @@ public CategoryOptionGroup(String name) { this.name = name; } + public CategoryOptionGroup(String name, DataDimensionType dataDimensionType) { + this(name); + this.dataDimensionType = dataDimensionType; + } + // ------------------------------------------------------------------------- // DimensionalItemObject // ------------------------------------------------------------------------- diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/category/CategoryOptionGroupSet.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/category/CategoryOptionGroupSet.java index 1b536a07a9b7..90fff63b1c3e 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/category/CategoryOptionGroupSet.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/category/CategoryOptionGroupSet.java @@ -68,6 +68,11 @@ public CategoryOptionGroupSet(String name) { this.shortName = name; } + public CategoryOptionGroupSet(String name, DataDimensionType dataDimensionType) { + this(name); + this.dataDimensionType = dataDimensionType; + } + // ------------------------------------------------------------------------- // Logic // ------------------------------------------------------------------------- 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 183b58b4a44b..f9bdbf8899e1 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 @@ -430,6 +430,9 @@ private List categoryOptionGroupsFromCsv(CsvReader reader) CategoryOptionGroup object = new CategoryOptionGroup(); setIdentifiableObject(object, values); object.setShortName(getSafe(values, 3, object.getName(), 50)); + object.setDataDimensionType( + DataDimensionType.fromValue( + getSafe(values, 4, DataDimensionType.DISAGGREGATION.getValue(), 50))); list.add(object); } } diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceTest.java index ca10b84684ce..7ec621a4f207 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/analytics/data/AnalyticsServiceTest.java @@ -451,7 +451,8 @@ private void setUpValidation() { categoryService.saveCategoryOptionGroup(optionGroupA); categoryService.saveCategoryOptionGroup(optionGroupB); - CategoryOptionGroupSet optionGroupSetB = new CategoryOptionGroupSet("OptionGroupSetB"); + CategoryOptionGroupSet optionGroupSetB = + new CategoryOptionGroupSet("OptionGroupSetB", DataDimensionType.DISAGGREGATION); categoryService.saveCategoryOptionGroupSet(optionGroupSetB); optionGroupSetB.addCategoryOptionGroup(optionGroupA); optionGroupSetB.addCategoryOptionGroup(optionGroupB); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dataapproval/DataApprovalAuditServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dataapproval/DataApprovalAuditServiceTest.java index 12a07ef83ba8..237183fc7e8f 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dataapproval/DataApprovalAuditServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dataapproval/DataApprovalAuditServiceTest.java @@ -47,6 +47,7 @@ import org.hisp.dhis.category.CategoryOptionGroupSet; import org.hisp.dhis.category.CategoryService; import org.hisp.dhis.common.BaseIdentifiableObject; +import org.hisp.dhis.common.DataDimensionType; import org.hisp.dhis.common.IdentifiableObjectManager; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.organisationunit.OrganisationUnitService; @@ -246,7 +247,8 @@ public void setUpTest() throws Exception { optionGroupB = createCategoryOptionGroup('B', optionB); categoryService.saveCategoryOptionGroup(optionGroupA); categoryService.saveCategoryOptionGroup(optionGroupB); - optionGroupSetB = new CategoryOptionGroupSet("OptionGroupSetB"); + optionGroupSetB = + new CategoryOptionGroupSet("OptionGroupSetB", DataDimensionType.DISAGGREGATION); categoryService.saveCategoryOptionGroupSet(optionGroupSetB); optionGroupSetB.addCategoryOptionGroup(optionGroupA); optionGroupSetB.addCategoryOptionGroup(optionGroupB); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dataapproval/DataApprovalLevelServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dataapproval/DataApprovalLevelServiceTest.java index c6f52a08c5f5..5bccdb7396d2 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dataapproval/DataApprovalLevelServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dataapproval/DataApprovalLevelServiceTest.java @@ -40,6 +40,7 @@ import java.util.Set; import org.hisp.dhis.category.CategoryOptionGroupSet; import org.hisp.dhis.category.CategoryService; +import org.hisp.dhis.common.DataDimensionType; import org.hisp.dhis.organisationunit.OrganisationUnit; import org.hisp.dhis.organisationunit.OrganisationUnitService; import org.hisp.dhis.test.integration.TransactionalIntegrationTest; @@ -144,10 +145,10 @@ public void setUpTest() { // --------------------------------------------------------------------- // Add supporting data // --------------------------------------------------------------------- - setA = new CategoryOptionGroupSet("Set A"); - setB = new CategoryOptionGroupSet("Set B"); - setC = new CategoryOptionGroupSet("Set C"); - setD = new CategoryOptionGroupSet("Set D"); + setA = new CategoryOptionGroupSet("Set A", DataDimensionType.DISAGGREGATION); + setB = new CategoryOptionGroupSet("Set B", DataDimensionType.DISAGGREGATION); + setC = new CategoryOptionGroupSet("Set C", DataDimensionType.DISAGGREGATION); + setD = new CategoryOptionGroupSet("Set D", DataDimensionType.DISAGGREGATION); categoryService.saveCategoryOptionGroupSet(setA); categoryService.saveCategoryOptionGroupSet(setB); categoryService.saveCategoryOptionGroupSet(setC); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceCategoryOptionGroupTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceCategoryOptionGroupTest.java index ddcba9c4a7ca..2cf731817a63 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceCategoryOptionGroupTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceCategoryOptionGroupTest.java @@ -52,6 +52,7 @@ import org.hisp.dhis.category.CategoryOptionGroupSet; import org.hisp.dhis.category.CategoryService; import org.hisp.dhis.common.BaseIdentifiableObject; +import org.hisp.dhis.common.DataDimensionType; import org.hisp.dhis.common.IdentifiableObjectManager; import org.hisp.dhis.dataapproval.exceptions.DataApprovalException; import org.hisp.dhis.dataset.DataSet; @@ -537,8 +538,8 @@ public void setUpTest() throws Exception { setAccess(partner2, globalUsers, chinaInteragencyUsers, chinaAgencyAUsers, chinaPartner2Users); // Agencies and partners category option group sets - agencies = new CategoryOptionGroupSet("Agencies"); - partners = new CategoryOptionGroupSet("Partners"); + agencies = new CategoryOptionGroupSet("Agencies", DataDimensionType.DISAGGREGATION); + partners = new CategoryOptionGroupSet("Partners", DataDimensionType.DISAGGREGATION); categoryService.saveCategoryOptionGroupSet(partners); categoryService.saveCategoryOptionGroupSet(agencies); setAccess( diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceTest.java index 0d363bdfa820..96554e36ae69 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dataapproval/DataApprovalServiceTest.java @@ -50,6 +50,7 @@ import org.hisp.dhis.category.CategoryOptionGroup; import org.hisp.dhis.category.CategoryOptionGroupSet; import org.hisp.dhis.category.CategoryService; +import org.hisp.dhis.common.DataDimensionType; import org.hisp.dhis.dataapproval.exceptions.DataMayNotBeApprovedException; import org.hisp.dhis.dataset.DataSet; import org.hisp.dhis.dataset.DataSetService; @@ -559,8 +560,8 @@ private void setUpCategories() { categoryService.saveCategoryOptionGroup(groupCD); categoryService.saveCategoryOptionGroup(groupEF); categoryService.saveCategoryOptionGroup(groupGH); - groupSetABCD = new CategoryOptionGroupSet("GroupSetABCD"); - groupSetEFGH = new CategoryOptionGroupSet("GroupSetEFGH"); + groupSetABCD = new CategoryOptionGroupSet("GroupSetABCD", DataDimensionType.DISAGGREGATION); + groupSetEFGH = new CategoryOptionGroupSet("GroupSetEFGH", DataDimensionType.DISAGGREGATION); categoryService.saveCategoryOptionGroupSet(groupSetABCD); categoryService.saveCategoryOptionGroupSet(groupSetEFGH); groupSetABCD.addCategoryOptionGroup(groupAB); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dxf2/csv/CsvImportServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dxf2/csv/CsvImportServiceTest.java index 08c9cde3dc94..9f28c35a9280 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dxf2/csv/CsvImportServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/dxf2/csv/CsvImportServiceTest.java @@ -32,9 +32,11 @@ import java.io.IOException; import java.io.InputStream; +import java.util.List; import org.hisp.dhis.category.Category; import org.hisp.dhis.category.CategoryCombo; import org.hisp.dhis.category.CategoryOption; +import org.hisp.dhis.category.CategoryOptionGroup; import org.hisp.dhis.common.DataDimensionType; import org.hisp.dhis.common.IdentifiableObjectManager; import org.hisp.dhis.dxf2.metadata.Metadata; @@ -222,4 +224,41 @@ void testImportIndicator() throws IOException { assertEquals("#{h0xKKjijTdI}", indicatorB.getNumerator()); assertEquals(indicatorType.getUid(), indicatorB.getIndicatorType().getUid()); } + + @Test + void testImportCategoryOptionGroup() throws IOException { + InputStream in = new ClassPathResource("csv/category_option_group.csv").getInputStream(); + Metadata metadata = + csvImportService.fromCsv( + in, + new CsvImportOptions() + .setImportClass(CsvImportClass.CATEGORY_OPTION_GROUP) + .setFirstRowIsHeader(true)); + assertEquals(3, metadata.getCategoryOptionGroups().size()); + // make sure all groups have data dimension type set + for (CategoryOptionGroup group : metadata.getCategoryOptionGroups()) { + assertNotNull(group.getDataDimensionType()); + } + + ImportReport report = + importService.importMetadata( + new MetadataImportParams(), + new MetadataObjects().addMetadata(schemaService.getMetadataSchemas(), metadata)); + + assertEquals(Status.OK, report.getStatus()); + List allGroups = manager.getAll(CategoryOptionGroup.class); + assertEquals(3, allGroups.size()); + CategoryOptionGroup groupA = + allGroups.stream().filter(g -> g.getName().equals("GroupA")).findFirst().orElse(null); + assertNotNull(groupA); + assertEquals(DataDimensionType.DISAGGREGATION, groupA.getDataDimensionType()); + CategoryOptionGroup groupB = + allGroups.stream().filter(g -> g.getName().equals("GroupB")).findFirst().orElse(null); + assertNotNull(groupB); + assertEquals(DataDimensionType.DISAGGREGATION, groupB.getDataDimensionType()); + CategoryOptionGroup groupC = + allGroups.stream().filter(g -> g.getName().equals("GroupC")).findFirst().orElse(null); + assertNotNull(groupC); + assertEquals(DataDimensionType.ATTRIBUTE, groupC.getDataDimensionType()); + } } diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/security/acl/AclServiceTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/security/acl/AclServiceTest.java index 962c1d55b645..760ad67857b3 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/security/acl/AclServiceTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/security/acl/AclServiceTest.java @@ -37,6 +37,7 @@ import org.apache.commons.collections4.MapUtils; import org.hisp.dhis.category.CategoryOption; import org.hisp.dhis.category.CategoryOptionGroupSet; +import org.hisp.dhis.common.DataDimensionType; import org.hisp.dhis.common.IdentifiableObjectManager; import org.hisp.dhis.dashboard.Dashboard; import org.hisp.dhis.dataelement.DataElement; @@ -1075,6 +1076,7 @@ void testCanDataOrMetadataRead() { manager.save(user1); // non data shareable object // CategoryOptionGroupSet categoryOptionGroupSet = new CategoryOptionGroupSet(); + categoryOptionGroupSet.setDataDimensionType(DataDimensionType.DISAGGREGATION); categoryOptionGroupSet.setAutoFields(); categoryOptionGroupSet.setName("cogA"); categoryOptionGroupSet.setShortName("cogA"); diff --git a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/validation/ValidationResultStoreTest.java b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/validation/ValidationResultStoreTest.java index 60c3f8244b70..d06eb6298024 100644 --- a/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/validation/ValidationResultStoreTest.java +++ b/dhis-2/dhis-test-integration/src/test/java/org/hisp/dhis/validation/ValidationResultStoreTest.java @@ -51,6 +51,7 @@ import org.hisp.dhis.category.CategoryOptionGroupSet; import org.hisp.dhis.category.CategoryService; import org.hisp.dhis.common.BaseIdentifiableObject; +import org.hisp.dhis.common.DataDimensionType; import org.hisp.dhis.common.IdentifiableObjectManager; import org.hisp.dhis.expression.Expression; import org.hisp.dhis.organisationunit.OrganisationUnit; @@ -229,7 +230,8 @@ public void setUpTest() throws Exception { optionGroupB = createCategoryOptionGroup('B', optionB); categoryService.saveCategoryOptionGroup(optionGroupA); categoryService.saveCategoryOptionGroup(optionGroupB); - optionGroupSetB = new CategoryOptionGroupSet("OptionGroupSetB"); + optionGroupSetB = + new CategoryOptionGroupSet("OptionGroupSetB", DataDimensionType.DISAGGREGATION); categoryService.saveCategoryOptionGroupSet(optionGroupSetB); optionGroupSetB.addCategoryOptionGroup(optionGroupA); optionGroupSetB.addCategoryOptionGroup(optionGroupB); diff --git a/dhis-2/dhis-test-integration/src/test/resources/csv/category_option_group.csv b/dhis-2/dhis-test-integration/src/test/resources/csv/category_option_group.csv new file mode 100644 index 000000000000..396153b599af --- /dev/null +++ b/dhis-2/dhis-test-integration/src/test/resources/csv/category_option_group.csv @@ -0,0 +1,4 @@ +name,uid,code,shortname,datadimensiontype +GroupA,,GroupA,, +GroupB,,GroupB,,disaggregation +GroupC,,GroupC,,attribute \ No newline at end of file diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/UserControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/UserControllerTest.java index df0ba3105186..fcc9920f8850 100644 --- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/UserControllerTest.java +++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/UserControllerTest.java @@ -50,6 +50,7 @@ import org.hisp.dhis.category.CategoryOption; import org.hisp.dhis.category.CategoryOptionGroupSet; import org.hisp.dhis.common.BaseIdentifiableObject; +import org.hisp.dhis.common.DataDimensionType; import org.hisp.dhis.feedback.ErrorCode; import org.hisp.dhis.jsontree.JsonArray; import org.hisp.dhis.jsontree.JsonBoolean; @@ -973,6 +974,7 @@ void testRemoveCogCatDimFromUserCredentialsLegacyFormat() { CategoryOptionGroupSet categoryOptionGroupSet = new CategoryOptionGroupSet(); categoryOptionGroupSet.setAutoFields(); + categoryOptionGroupSet.setDataDimensionType(DataDimensionType.DISAGGREGATION); categoryOptionGroupSet.setName("cogA"); categoryOptionGroupSet.setShortName("cogA"); manager.save(categoryOptionGroupSet);