Search in sources :

Example 1 with SnomedLanguageConfig

use of com.b2international.snowowl.snomed.datastore.config.SnomedLanguageConfig in project snow-owl by b2ihealthcare.

the class SnomedRf2ImportRequest method updateCodeSystemSettings.

private void updateCodeSystemSettings(final BranchContext context, final ResourceURI codeSystemUri) throws Exception {
    SnomedReferenceSets languageReferenceSets = SnomedRequests.prepareSearchRefSet().all().filterByType(SnomedRefSetType.LANGUAGE).filterByActive(true).setFields(SnomedConceptDocument.Fields.ID).sortBy(Sort.fieldAsc(SnomedConceptDocument.Fields.ID)).build().execute(context);
    /*
		 * XXX: The default language in locales is always "en", as there is no
		 * machine-readable information about what language code each language type
		 * reference set is associated with.
		 */
    final List<ExtendedLocale> locales = languageReferenceSets.stream().map(refSet -> new ExtendedLocale("en", "", refSet.getId())).collect(Collectors.toList());
    // fetch codesystem again to get the latest settings
    CodeSystem currentSnomedCodeSystem = CodeSystemRequests.prepareGetCodeSystem(codeSystemUri.getResourceId()).buildAsync().get(context);
    Map<String, SnomedLanguageConfig> mergedLanguagesConfiguration = Maps.newLinkedHashMap();
    SnomedDescriptionUtils.getLanguagesConfiguration(context.service(ObjectMapper.class), currentSnomedCodeSystem).forEach(config -> {
        mergedLanguagesConfiguration.put(config.getLanguageTag(), config);
    });
    languageReferenceSets.stream().map(SnomedReferenceSet::getId).filter(SnomedTerminologyComponentConstants.LANG_REFSET_DIALECT_ALIASES::containsKey).forEach(langRefsetId -> {
        final String dialect = SnomedTerminologyComponentConstants.LANG_REFSET_DIALECT_ALIASES.get(langRefsetId);
        // ignore any aliases that are already defined by using computeIfAbsent
        mergedLanguagesConfiguration.computeIfAbsent(dialect, languageTag -> new SnomedLanguageConfig(languageTag, langRefsetId));
    });
    CodeSystemRequests.prepareUpdateCodeSystem(codeSystemUri.getResourceId()).setSettings(Map.of(CodeSystem.CommonSettings.LOCALES, locales, SnomedTerminologyComponentConstants.CODESYSTEM_LANGUAGE_CONFIG_KEY, mergedLanguagesConfiguration.values())).build(context.service(User.class).getUsername(), String.format("Update '%s' settings based on RF2 import", codeSystemUri.getResourceId())).execute(context.service(IEventBus.class)).getSync(2, TimeUnit.MINUTES);
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) Query(com.b2international.index.query.Query) MappingIterator(com.fasterxml.jackson.databind.MappingIterator) LoggerFactory(org.slf4j.LoggerFactory) SnomedReferenceSets(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSets) ObjectReader(com.fasterxml.jackson.databind.ObjectReader) SnomedDescriptionUtils(com.b2international.snowowl.snomed.datastore.SnomedDescriptionUtils) AccessControl(com.b2international.snowowl.core.authorization.AccessControl) Map(java.util.Map) AttachmentRegistry(com.b2international.snowowl.core.attachments.AttachmentRegistry) SnomedLanguageConfig(com.b2international.snowowl.snomed.datastore.config.SnomedLanguageConfig) ZipFile(java.util.zip.ZipFile) Permission(com.b2international.snowowl.core.identity.Permission) ZipEntry(java.util.zip.ZipEntry) ResourceURI(com.b2international.snowowl.core.ResourceURI) Version(com.b2international.snowowl.core.version.Version) Rf2ReleaseType(com.b2international.snowowl.snomed.core.domain.Rf2ReleaseType) ResourceRequests(com.b2international.snowowl.core.request.ResourceRequests) ImmutableSet(com.google.common.collect.ImmutableSet) Rf2ValidationIssueReporter(com.b2international.snowowl.snomed.datastore.request.rf2.validation.Rf2ValidationIssueReporter) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) Request(com.b2international.snowowl.core.events.Request) CsvSchema(com.fasterxml.jackson.dataformat.csv.CsvSchema) Set(java.util.Set) IEventBus(com.b2international.snowowl.eventbus.IEventBus) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) List(java.util.List) DatastoreLockContextDescriptions(com.b2international.snowowl.core.internal.locks.DatastoreLockContextDescriptions) LocalDate(java.time.LocalDate) Sort(com.b2international.snowowl.core.request.SearchResourceRequest.Sort) DBMaker(org.mapdb.DBMaker) CodeSystemRequests(com.b2international.snowowl.core.codesystem.CodeSystemRequests) BranchContext(com.b2international.snowowl.core.domain.BranchContext) com.b2international.snowowl.snomed.datastore.request.rf2.importer(com.b2international.snowowl.snomed.datastore.request.rf2.importer) Maker(org.mapdb.DBMaker.Maker) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) EffectiveTimes(com.b2international.snowowl.core.date.EffectiveTimes) TerminologyResource(com.b2international.snowowl.core.TerminologyResource) Locks(com.b2international.snowowl.core.locks.Locks) ImportResponse(com.b2international.snowowl.core.request.io.ImportResponse) Stopwatch(com.google.common.base.Stopwatch) Strings(com.google.common.base.Strings) ExtendedLocale(com.b2international.commons.http.ExtendedLocale) SnomedRequests(com.b2international.snowowl.snomed.datastore.request.SnomedRequests) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) InternalAttachmentRegistry(com.b2international.snowowl.core.attachments.InternalAttachmentRegistry) com.b2international.snowowl.snomed.datastore.index.entry(com.b2international.snowowl.snomed.datastore.index.entry) Attachment(com.b2international.snowowl.core.attachments.Attachment) ApiException(com.b2international.commons.exceptions.ApiException) BadRequestException(com.b2international.commons.exceptions.BadRequestException) ImportDefectAcceptor(com.b2international.snowowl.core.request.io.ImportDefectAcceptor) Logger(org.slf4j.Logger) DateFormats(com.b2international.snowowl.core.date.DateFormats) CsvParser(com.fasterxml.jackson.dataformat.csv.CsvParser) Files(java.nio.file.Files) CsvMapper(com.fasterxml.jackson.dataformat.csv.CsvMapper) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ComponentURI(com.b2international.snowowl.core.uri.ComponentURI) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) SnomedTerminologyComponentConstants(com.b2international.snowowl.snomed.common.SnomedTerminologyComponentConstants) Maps(com.google.common.collect.Maps) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Paths(java.nio.file.Paths) Rf2GlobalValidator(com.b2international.snowowl.snomed.datastore.request.rf2.validation.Rf2GlobalValidator) User(com.b2international.snowowl.core.identity.User) SnomedReferenceSet(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSet) DB(org.mapdb.DB) Collections(java.util.Collections) ContentAvailabilityInfoProvider(com.b2international.snowowl.core.repository.ContentAvailabilityInfoProvider) InputStream(java.io.InputStream) ImportDefectBuilder(com.b2international.snowowl.core.request.io.ImportDefectAcceptor.ImportDefectBuilder) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType) SnomedReferenceSet(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSet) ExtendedLocale(com.b2international.commons.http.ExtendedLocale) SnomedTerminologyComponentConstants(com.b2international.snowowl.snomed.common.SnomedTerminologyComponentConstants) SnomedReferenceSets(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSets) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) SnomedLanguageConfig(com.b2international.snowowl.snomed.datastore.config.SnomedLanguageConfig)

Aggregations

ApiException (com.b2international.commons.exceptions.ApiException)1 BadRequestException (com.b2international.commons.exceptions.BadRequestException)1 ExtendedLocale (com.b2international.commons.http.ExtendedLocale)1 Query (com.b2international.index.query.Query)1 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)1 ResourceURI (com.b2international.snowowl.core.ResourceURI)1 TerminologyResource (com.b2international.snowowl.core.TerminologyResource)1 SnowowlRuntimeException (com.b2international.snowowl.core.api.SnowowlRuntimeException)1 Attachment (com.b2international.snowowl.core.attachments.Attachment)1 AttachmentRegistry (com.b2international.snowowl.core.attachments.AttachmentRegistry)1 InternalAttachmentRegistry (com.b2international.snowowl.core.attachments.InternalAttachmentRegistry)1 AccessControl (com.b2international.snowowl.core.authorization.AccessControl)1 CodeSystem (com.b2international.snowowl.core.codesystem.CodeSystem)1 CodeSystemRequests (com.b2international.snowowl.core.codesystem.CodeSystemRequests)1 DateFormats (com.b2international.snowowl.core.date.DateFormats)1 EffectiveTimes (com.b2international.snowowl.core.date.EffectiveTimes)1 BranchContext (com.b2international.snowowl.core.domain.BranchContext)1 Request (com.b2international.snowowl.core.events.Request)1 Permission (com.b2international.snowowl.core.identity.Permission)1 User (com.b2international.snowowl.core.identity.User)1