Merge pull request #1735 from gjergjsheldija/test_language_concurrency_bug
Fix for ConcurrentModificationException for language translation
This commit is contained in:
commit
39d747d736
|
@ -300,9 +300,9 @@ public class LanguageUtils {
|
|||
}
|
||||
}
|
||||
}
|
||||
List<Element> cl = new ArrayList<Element>();
|
||||
cl.addAll(element.getChildren());
|
||||
for (Element c : cl) {
|
||||
// Create a copy of the children collection before iterating
|
||||
List<Element> childrenCopy = List.copyOf(element.getChildren());
|
||||
for (Element c : childrenCopy) {
|
||||
if (!c.getName().equals("designation")) {
|
||||
t = t + importFromTranslations(element, c, translations, usedUnits);
|
||||
}
|
||||
|
|
|
@ -1,15 +1,20 @@
|
|||
package org.hl7.fhir.r5.elementmodel;
|
||||
|
||||
import org.hl7.fhir.r5.context.IWorkerContext;
|
||||
import org.hl7.fhir.r5.formats.JsonCreatorDirect;
|
||||
import org.hl7.fhir.r5.test.utils.CompareUtilities;
|
||||
import org.hl7.fhir.r5.test.utils.TestingUtilities;
|
||||
import org.hl7.fhir.utilities.i18n.LanguageFileProducer;
|
||||
import org.hl7.fhir.utilities.i18n.PoGetTextProducer;
|
||||
import org.hl7.fhir.utilities.tests.ResourceLoaderTests;
|
||||
import org.hl7.fhir.utilities.validation.ValidationMessage;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
class LanguageUtilsTest implements ResourceLoaderTests {
|
||||
|
@ -27,11 +32,24 @@ class LanguageUtilsTest implements ResourceLoaderTests {
|
|||
List<LanguageFileProducer.TranslationUnit> res = new ArrayList<>();
|
||||
res.addAll(lp.loadSource(getResourceAsInputStream("languageUtils", "CodeSystem-answer.po")));
|
||||
|
||||
List<ValidationMessage> lvm = new ArrayList<>();
|
||||
lvm.add(new ValidationMessage());
|
||||
LanguageUtils languageUtils = new LanguageUtils(context);
|
||||
int result = languageUtils.importFromTranslations(element, res, null);
|
||||
int result = languageUtils.importFromTranslations(element, res, lvm);
|
||||
|
||||
Writer generatedResource = new StringWriter();
|
||||
jp.compose(element, new JsonCreatorDirect(generatedResource, false, false));
|
||||
|
||||
assert result == 3;
|
||||
|
||||
InputStream translatedResource = getResourceAsInputStream("languageUtils", "CodeSystem-answer-translated.json");
|
||||
String text = new BufferedReader(new InputStreamReader(translatedResource))
|
||||
.lines()
|
||||
.collect(Collectors.joining("\n"));
|
||||
|
||||
String msg = CompareUtilities.checkJsonSrcIsSame("", generatedResource.toString(),text, null);
|
||||
Assertions.assertNull(msg);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"resourceType" : "CodeSystem",
|
||||
"id" : "basic-answer",
|
||||
"language" : "en",
|
||||
"url" : "https://example.com/CodeSystem/basic-answer",
|
||||
"version" : "0.1.0",
|
||||
"name" : "BasicAnswer",
|
||||
"title" : "Administration-Method",
|
||||
"status" : "active",
|
||||
"date" : "2024-04-07",
|
||||
"publisher" : "Sample",
|
||||
"description" : "Basic answers for any kind of questions.",
|
||||
"caseSensitive" : false,
|
||||
"content" : "complete",
|
||||
"count" : 3,
|
||||
"concept" : [ {
|
||||
"code" : "ok",
|
||||
"display" : "OK",
|
||||
"designation" : [ {
|
||||
"language" : "it",
|
||||
"value" : "OK"
|
||||
} ]
|
||||
}, {
|
||||
"code" : "yes",
|
||||
"display" : "Yes",
|
||||
"designation" : [ {
|
||||
"language" : "it",
|
||||
"value" : "Si"
|
||||
} ]
|
||||
}, {
|
||||
"code" : "no",
|
||||
"display" : "No",
|
||||
"designation" : [ {
|
||||
"language" : "it",
|
||||
"value" : "No"
|
||||
} ]
|
||||
} ]
|
||||
}
|
|
@ -10,18 +10,15 @@
|
|||
"concept": [
|
||||
{
|
||||
"code": "ok",
|
||||
"display": "OK",
|
||||
"definition": "KO"
|
||||
"display": "OK"
|
||||
},
|
||||
{
|
||||
"code": "yes",
|
||||
"display": "Yes",
|
||||
"definition": "seY"
|
||||
"display": "Yes"
|
||||
},
|
||||
{
|
||||
"code": "no",
|
||||
"display": "No",
|
||||
"definition": "oN"
|
||||
"display": "No"
|
||||
}
|
||||
],
|
||||
"language": "en",
|
||||
|
|
Loading…
Reference in New Issue