Skip to content

Commit 7579a04

Browse files
fix: Correct ignored stats when import validation [DHIS2-15604](2.39)
1 parent 99fe249 commit 7579a04

File tree

3 files changed

+51
-3
lines changed

3 files changed

+51
-3
lines changed

dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/objectbundle/validation/TranslationsCheck.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public <T extends IdentifiableObject> void check(
6868
Schema schema = context.getSchemaService().getDynamicSchema(klass);
6969

7070
for (int i = 0; i < objects.size(); i++) {
71-
run(objects.get(i), klass, addReports, schema, i);
71+
run(objects.get(i), klass, addReports, schema, i, context);
7272
}
7373
}
7474

@@ -77,7 +77,8 @@ public <T extends IdentifiableObject> void run(
7777
Class<T> klass,
7878
Consumer<ObjectReport> addReports,
7979
Schema schema,
80-
int index) {
80+
int index,
81+
ValidationContext context) {
8182
Set<Translation> translations = object.getTranslations();
8283

8384
if (CollectionUtils.isEmpty(translations)) {
@@ -129,6 +130,9 @@ public <T extends IdentifiableObject> void run(
129130

130131
if (objectReport.hasErrorReports()) {
131132
addReports.accept(objectReport);
133+
if (context != null) {
134+
context.markForRemoval(object);
135+
}
132136
}
133137
}
134138
}

dhis-2/dhis-test-web-api/src/test/java/org/hisp/dhis/webapi/controller/DataElementControllerTest.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
*/
2828
package org.hisp.dhis.webapi.controller;
2929

30+
import static org.hisp.dhis.web.HttpStatus.CONFLICT;
3031
import static org.junit.jupiter.api.Assertions.assertEquals;
32+
import static org.junit.jupiter.api.Assertions.assertNotNull;
3133

3234
import java.util.List;
3335
import java.util.Map;
@@ -37,12 +39,15 @@
3739
import org.hisp.dhis.category.CategoryService;
3840
import org.hisp.dhis.dataelement.DataElement;
3941
import org.hisp.dhis.dataelement.DataElementService;
42+
import org.hisp.dhis.feedback.ErrorCode;
4043
import org.hisp.dhis.jsontree.JsonArray;
4144
import org.hisp.dhis.jsontree.JsonObject;
4245
import org.hisp.dhis.jsontree.JsonValue;
4346
import org.hisp.dhis.webapi.DhisControllerConvenienceTest;
4447
import org.hisp.dhis.webapi.json.domain.JsonDataElement;
48+
import org.hisp.dhis.webapi.json.domain.JsonErrorReport;
4549
import org.hisp.dhis.webapi.json.domain.JsonIdentifiableObject;
50+
import org.hisp.dhis.webapi.json.domain.JsonImportSummary;
4651
import org.junit.jupiter.api.BeforeEach;
4752
import org.junit.jupiter.api.DisplayName;
4853
import org.junit.jupiter.api.Test;
@@ -133,4 +138,42 @@ void dataElementsExcludingDefaultCatComboTest() {
133138
.collect(Collectors.toSet()),
134139
"Returned cat combo IDs equal custom cat combos Ids only");
135140
}
141+
142+
@Test
143+
@DisplayName(
144+
"Creating a data element with missing locale should show correct ignored stats value")
145+
void dataElementValidationIgnoredValueTest() {
146+
JsonImportSummary summary =
147+
POST(
148+
"/metadata",
149+
"{"
150+
+ "\"dataElements\": ["
151+
+ "{"
152+
+ "\"id\": \"DeUid000015\","
153+
+ "\"aggregationType\": \"DEFAULT\","
154+
+ "\"domainType\": \"AGGREGATE\","
155+
+ "\"name\": \"test de 1\","
156+
+ "\"shortName\": \"test DE 1\","
157+
+ "\"valueType\": \"NUMBER\","
158+
+ "\"translations\": ["
159+
+ "{"
160+
+ "\"property\": \"name\","
161+
+ "\"value\": \"french name\""
162+
+ "}"
163+
+ "]"
164+
+ "}"
165+
+ "]"
166+
+ "}")
167+
.content(CONFLICT)
168+
.get("response")
169+
.as(JsonImportSummary.class);
170+
171+
assertEquals(1, summary.getStats().getIgnored());
172+
assertEquals(0, summary.getStats().getCreated());
173+
174+
JsonErrorReport errorReport =
175+
summary.find(JsonErrorReport.class, error -> error.getErrorCode() == ErrorCode.E4000);
176+
assertNotNull(errorReport);
177+
assertEquals("Missing required property `locale`", errorReport.getMessage());
178+
}
136179
}

dhis-2/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,8 @@ public WebMessage replaceTranslations(
619619
getEntityClass(),
620620
objectReport -> objectReports.add(objectReport),
621621
getSchema(),
622-
0);
622+
0,
623+
null);
623624

624625
if (objectReports.size() == 0) {
625626
manager.update(persistedObject, currentUser);

0 commit comments

Comments
 (0)