Skip to content

Commit

Permalink
fix: make dataDimensionType not null for catOptionGroup and groupSet
Browse files Browse the repository at this point in the history
  • Loading branch information
vietnguyen committed Dec 11, 2023
1 parent d536a5c commit 8ac2b48
Show file tree
Hide file tree
Showing 13 changed files with 79 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ public CategoryOptionGroup(String name) {
this.name = name;
}

public CategoryOptionGroup(String name, DataDimensionType dataDimensionType) {
this(name);
this.dataDimensionType = dataDimensionType;
}

// -------------------------------------------------------------------------
// DimensionalItemObject
// -------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public CategoryOptionGroupSet(String name) {
this.shortName = name;
}

public CategoryOptionGroupSet(String name, DataDimensionType dataDimensionType) {
this(name);
this.dataDimensionType = dataDimensionType;
}

// -------------------------------------------------------------------------
// Logic
// -------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,9 @@ private List<CategoryOptionGroup> 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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<CategoryOptionGroup> 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name,uid,code,shortname,datadimensiontype
GroupA,,GroupA,,
GroupB,,GroupB,,disaggregation
GroupC,,GroupC,,attribute
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8ac2b48

Please sign in to comment.