From 3529116037311c3e44d7ddfc17b0ccb383fe70f9 Mon Sep 17 00:00:00 2001 From: jason-p-pickering Date: Fri, 1 Dec 2023 07:01:33 +0100 Subject: [PATCH] Replace data element no groups Java check with SQL based check --- .../dataintegrity/DataIntegrityCheckType.java | 1 - .../FlattenedDataIntegrityReport.java | 3 +- .../DefaultDataIntegrityService.java | 5 +-- .../DataIntegrityReportControllerTest.java | 31 +++++++++++++++++++ 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataintegrity/DataIntegrityCheckType.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataintegrity/DataIntegrityCheckType.java index f863bae673a0..de3d6ffd5306 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataintegrity/DataIntegrityCheckType.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataintegrity/DataIntegrityCheckType.java @@ -40,7 +40,6 @@ public enum DataIntegrityCheckType { // DataElements DATA_ELEMENTS_WITHOUT_DATA_SETS, - DATA_ELEMENTS_WITHOUT_GROUPS, DATA_ELEMENTS_ASSIGNED_TO_DATA_SETS_WITH_DIFFERENT_PERIOD_TYPES, DATA_ELEMENTS_VIOLATING_EXCLUSIVE_GROUP_SETS, DATA_ELEMENTS_IN_DATA_SET_NOT_IN_FORM, diff --git a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataintegrity/FlattenedDataIntegrityReport.java b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataintegrity/FlattenedDataIntegrityReport.java index 92c776b4cb5d..856fcc4a781d 100644 --- a/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataintegrity/FlattenedDataIntegrityReport.java +++ b/dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataintegrity/FlattenedDataIntegrityReport.java @@ -122,8 +122,7 @@ public FlattenedDataIntegrityReport(Map detailsByN listOfDisplayNameOrUid( detailsByName.get(DataIntegrityCheckType.DATA_ELEMENTS_WITHOUT_DATA_SETS.getName())); this.dataElementsWithoutGroups = - listOfDisplayNameOrUid( - detailsByName.get(DataIntegrityCheckType.DATA_ELEMENTS_WITHOUT_GROUPS.getName())); + listOfDisplayNameWithUid(detailsByName.get("data_elements_aggregate_no_groups")); this.invalidCategoryCombos = listOfDisplayNameOrUid( detailsByName.get(DataIntegrityCheckType.CATEGORY_COMBOS_BEING_INVALID.getName())); diff --git a/dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataintegrity/DefaultDataIntegrityService.java b/dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataintegrity/DefaultDataIntegrityService.java index fd93a2fc7d09..7f33f3bd5e12 100644 --- a/dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataintegrity/DefaultDataIntegrityService.java +++ b/dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/dataintegrity/DefaultDataIntegrityService.java @@ -546,10 +546,6 @@ public void initIntegrityChecks() { DataIntegrityCheckType.DATA_ELEMENTS_WITHOUT_DATA_SETS, DataElement.class, this::getDataElementsWithoutDataSet); - registerNonDatabaseIntegrityCheck( - DataIntegrityCheckType.DATA_ELEMENTS_WITHOUT_GROUPS, - DataElement.class, - this::getDataElementsWithoutGroups); registerNonDatabaseIntegrityCheck( DataIntegrityCheckType.DATA_ELEMENTS_ASSIGNED_TO_DATA_SETS_WITH_DIFFERENT_PERIOD_TYPES, DataElement.class, @@ -691,6 +687,7 @@ public FlattenedDataIntegrityReport getReport(Set checks, JobProgress pr .collect(Collectors.toSet()); // Add additional SQL based checks here checks.add("organisation_units_without_groups"); + checks.add("data_elements_aggregate_no_groups"); } runDetailsChecks(checks, progress); return new FlattenedDataIntegrityReport(getDetails(checks, -1L)); diff --git a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/dataintegrity/DataIntegrityReportControllerTest.java b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/dataintegrity/DataIntegrityReportControllerTest.java index 5da6e59a4b12..e91b89f006a1 100644 --- a/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/dataintegrity/DataIntegrityReportControllerTest.java +++ b/dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/dataintegrity/DataIntegrityReportControllerTest.java @@ -209,6 +209,37 @@ private String addOrganisationUnitGroupSet(String name, String... groupIds) { + "}")); } + @Test + void testDataElementsNoGroups() { + + String dataElementA = + assertStatus( + HttpStatus.CREATED, + POST( + "/dataElements", + "{ 'name': 'ANC1', 'shortName': 'ANC1', 'valueType' : 'NUMBER'," + + "'domainType' : 'AGGREGATE', 'aggregationType' : 'SUM' }")); + + String dataElementB = + assertStatus( + HttpStatus.CREATED, + POST( + "/dataElements", + "{ 'name': 'ANC2', 'shortName': 'ANC2', 'valueType' : 'NUMBER'," + + "'domainType' : 'AGGREGATE', 'aggregationType' : 'SUM' }")); + + assertStatus( + HttpStatus.CREATED, + POST( + "/dataElementGroups", + "{ 'name': 'ANC', 'shortName': 'ANC' , 'dataElements' : [{'id' : '" + + dataElementA + + "'}]}")); + List results = + getDataIntegrityReport().getDataElementsWithoutGroups().toList(JsonString::string); + assertEquals(singletonList("ANC2" + ":" + dataElementB), results); + } + private JsonDataIntegrityReport getDataIntegrityReport() { return getDataIntegrityReport("/dataIntegrity"); }