|
63 | 63 | import com.b2international.snowowl.core.request.io.ImportResponse;
|
64 | 64 | import com.b2international.snowowl.core.uri.ComponentURI;
|
65 | 65 | import com.b2international.snowowl.eventbus.IEventBus;
|
| 66 | +import com.b2international.snowowl.snomed.common.SnomedTerminologyComponentConstants; |
66 | 67 | import com.b2international.snowowl.snomed.core.domain.Rf2ReleaseType;
|
67 | 68 | import com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType;
|
| 69 | +import com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSet; |
| 70 | +import com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSets; |
| 71 | +import com.b2international.snowowl.snomed.datastore.SnomedDescriptionUtils; |
| 72 | +import com.b2international.snowowl.snomed.datastore.config.SnomedLanguageConfig; |
68 | 73 | import com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument;
|
69 | 74 | import com.b2international.snowowl.snomed.datastore.request.SnomedRequests;
|
70 | 75 | import com.b2international.snowowl.snomed.datastore.request.rf2.importer.*;
|
|
73 | 78 | import com.fasterxml.jackson.annotation.JsonProperty;
|
74 | 79 | import com.fasterxml.jackson.core.JsonProcessingException;
|
75 | 80 | import com.fasterxml.jackson.databind.MappingIterator;
|
| 81 | +import com.fasterxml.jackson.databind.ObjectMapper; |
76 | 82 | import com.fasterxml.jackson.databind.ObjectReader;
|
77 | 83 | import com.fasterxml.jackson.dataformat.csv.CsvMapper;
|
78 | 84 | import com.fasterxml.jackson.dataformat.csv.CsvParser;
|
79 | 85 | import com.fasterxml.jackson.dataformat.csv.CsvSchema;
|
80 | 86 | import com.google.common.base.Stopwatch;
|
81 | 87 | import com.google.common.base.Strings;
|
82 | 88 | import com.google.common.collect.ImmutableSet;
|
| 89 | +import com.google.common.collect.Maps; |
83 | 90 |
|
84 | 91 | /**
|
85 | 92 | * @since 6.0.0
|
@@ -220,7 +227,7 @@ ImportResponse doImport(final BranchContext context, final File rf2Archive, fina
|
220 | 227 | }
|
221 | 228 |
|
222 | 229 | // Update locales registered on the code system
|
223 |
| - updateLocales(context, codeSystemUri); |
| 230 | + updateCodeSystemSettings(context, codeSystemUri); |
224 | 231 | }
|
225 | 232 |
|
226 | 233 | return ImportResponse.success(visitedComponents.build(), reporter.getDefects());
|
@@ -353,27 +360,52 @@ private DB createDb() {
|
353 | 360 | }
|
354 | 361 | }
|
355 | 362 |
|
356 |
| - private void updateLocales(final BranchContext context, final ResourceURI codeSystemUri) throws Exception { |
357 |
| - /* |
358 |
| - * XXX: The default language in locales is always "en", as there is no |
359 |
| - * machine-readable information about what language code each language type |
360 |
| - * reference set is associated with. |
361 |
| - */ |
362 |
| - final List<ExtendedLocale> locales = SnomedRequests.prepareSearchRefSet() |
| 363 | + private void updateCodeSystemSettings(final BranchContext context, final ResourceURI codeSystemUri) throws Exception { |
| 364 | + SnomedReferenceSets languageReferenceSets = SnomedRequests.prepareSearchRefSet() |
363 | 365 | .all()
|
364 | 366 | .filterByType(SnomedRefSetType.LANGUAGE)
|
365 | 367 | .filterByActive(true)
|
366 | 368 | .setFields(SnomedConceptDocument.Fields.ID)
|
367 | 369 | .sortBy(SortField.ascending(SnomedConceptDocument.Fields.ID))
|
368 | 370 | .build()
|
369 |
| - .execute(context) |
| 371 | + .execute(context); |
| 372 | + |
| 373 | + /* |
| 374 | + * XXX: The default language in locales is always "en", as there is no |
| 375 | + * machine-readable information about what language code each language type |
| 376 | + * reference set is associated with. |
| 377 | + */ |
| 378 | + final List<ExtendedLocale> locales = languageReferenceSets |
370 | 379 | .stream()
|
371 | 380 | .map(refSet -> new ExtendedLocale("en", "", refSet.getId()))
|
372 | 381 | .collect(Collectors.toList());
|
373 | 382 |
|
| 383 | + // fetch codesystem again to get the latest settings |
| 384 | + CodeSystem currentSnomedCodeSystem = CodeSystemRequests.prepareGetCodeSystem(codeSystemUri.getResourceId()) |
| 385 | + .buildAsync() |
| 386 | + .get(context); |
| 387 | + |
| 388 | + Map<String, SnomedLanguageConfig> mergedLanguagesConfiguration = Maps.newLinkedHashMap(); |
| 389 | + SnomedDescriptionUtils.getLanguagesConfiguration(context.service(ObjectMapper.class), currentSnomedCodeSystem).forEach(config -> { |
| 390 | + mergedLanguagesConfiguration.put(config.getLanguageTag(), config); |
| 391 | + }); |
| 392 | + |
| 393 | + languageReferenceSets.stream() |
| 394 | + .map(SnomedReferenceSet::getId) |
| 395 | + .filter(SnomedTerminologyComponentConstants.LANG_REFSET_DIALECT_ALIASES::containsKey) |
| 396 | + .forEach(langRefsetId -> { |
| 397 | + final String dialect = SnomedTerminologyComponentConstants.LANG_REFSET_DIALECT_ALIASES.get(langRefsetId); |
| 398 | + // ignore any aliases that are already defined by using computeIfAbsent |
| 399 | + mergedLanguagesConfiguration.computeIfAbsent(dialect, languageTag -> new SnomedLanguageConfig(languageTag, langRefsetId)); |
| 400 | + |
| 401 | + }); |
| 402 | + |
374 | 403 | CodeSystemRequests.prepareUpdateCodeSystem(codeSystemUri.getResourceId())
|
375 |
| - .setSettings(Map.of(CodeSystem.CommonSettings.LOCALES, locales)) |
376 |
| - .build(context.service(User.class).getUsername(), "Update available list of locales on " + codeSystemUri.getResourceId()) |
| 404 | + .setSettings(Map.of( |
| 405 | + CodeSystem.CommonSettings.LOCALES, locales, |
| 406 | + SnomedTerminologyComponentConstants.CODESYSTEM_LANGUAGE_CONFIG_KEY, mergedLanguagesConfiguration.values() |
| 407 | + )) |
| 408 | + .build(context.service(User.class).getUsername(), String.format("Update '%s' settings based on RF2 import", codeSystemUri.getResourceId())) |
377 | 409 | .execute(context.service(IEventBus.class))
|
378 | 410 | .getSync(2, TimeUnit.MINUTES);
|
379 | 411 | }
|
|
0 commit comments