Search in sources :

Example 1 with SnomedReferenceSets

use of com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSets in project snow-owl by b2ihealthcare.

the class SnomedRf2ExportRequest method getIdentifierConcepts.

private List<SnomedConcept> getIdentifierConcepts(final RepositoryContext context, final String currentVersion) {
    final Collection<String> refSetsToLoad;
    if (refSets == null) {
        // Retrieve all reference sets if refSets is null
        final Request<BranchContext, SnomedReferenceSets> refSetRequest = SnomedRequests.prepareSearchRefSet().all().build();
        final SnomedReferenceSets allReferenceSets = execute(context, currentVersion, refSetRequest);
        refSetsToLoad = allReferenceSets.stream().map(r -> r.getId()).collect(Collectors.toSet());
    } else {
        refSetsToLoad = refSets;
    }
    final SnomedConceptSearchRequestBuilder refSetRequestBuilder = SnomedRequests.prepareSearchConcept().all().filterByIds(refSetsToLoad).setExpand("pt(),referenceSet()").setLocales(locales());
    final Request<BranchContext, SnomedConcepts> request = refSetRequestBuilder.build();
    final SnomedConcepts referenceSets = execute(context, currentVersion, request);
    // Return only the identifier concepts which have an existing reference set on this branch
    return referenceSets.stream().filter(c -> c.getReferenceSet() != null).collect(Collectors.toList());
}
Also used : JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) SnomedConceptSearchRequestBuilder(com.b2international.snowowl.snomed.datastore.request.SnomedConceptSearchRequestBuilder) SnomedRelationshipIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry) SnomedReferenceSets(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSets) RepositoryRequests(com.b2international.snowowl.core.repository.RepositoryRequests) Sets.newTreeSet(com.google.common.collect.Sets.newTreeSet) Collections.singleton(java.util.Collections.singleton) AccessControl(com.b2international.snowowl.core.authorization.AccessControl) LocalTime(java.time.LocalTime) RevisionIndex(com.b2international.index.revision.RevisionIndex) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) AttachmentRegistry(com.b2international.snowowl.core.attachments.AttachmentRegistry) Branches(com.b2international.snowowl.core.branch.Branches) Permission(com.b2international.snowowl.core.identity.Permission) CompareUtils(com.b2international.commons.CompareUtils) Path(java.nio.file.Path) com.google.common.collect(com.google.common.collect) Collectors.toSet(java.util.stream.Collectors.toSet) ResourceURI(com.b2international.snowowl.core.ResourceURI) com.b2international.snowowl.core.request(com.b2international.snowowl.core.request) Version(com.b2international.snowowl.core.version.Version) RepositoryContext(com.b2international.snowowl.core.domain.RepositoryContext) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) Request(com.b2international.snowowl.core.events.Request) IEventBus(com.b2international.snowowl.eventbus.IEventBus) Instant(java.time.Instant) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) Stream(java.util.stream.Stream) VersionDocument(com.b2international.snowowl.core.version.VersionDocument) LocalDate(java.time.LocalDate) Sort(com.b2international.snowowl.core.request.SearchResourceRequest.Sort) Entry(java.util.Map.Entry) CodeSystemRequests(com.b2international.snowowl.core.codesystem.CodeSystemRequests) SnomedDescriptionIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionIndexEntry) BranchContext(com.b2international.snowowl.core.domain.BranchContext) Builder(com.google.common.collect.ImmutableList.Builder) FileUtils(com.b2international.commons.FileUtils) CodeSystem(com.b2international.snowowl.core.codesystem.CodeSystem) EffectiveTimes(com.b2international.snowowl.core.date.EffectiveTimes) java.util(java.util) TerminologyResource(com.b2international.snowowl.core.TerminologyResource) LocalDateTime(java.time.LocalDateTime) com.b2international.snowowl.snomed.datastore.request.rf2.exporter(com.b2international.snowowl.snomed.datastore.request.rf2.exporter) com.b2international.snowowl.snomed.core.domain(com.b2international.snowowl.snomed.core.domain) Branch(com.b2international.snowowl.core.branch.Branch) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) Strings(com.google.common.base.Strings) SnomedRequests(com.b2international.snowowl.snomed.datastore.request.SnomedRequests) Attachment(com.b2international.snowowl.core.attachments.Attachment) SnomedRefSetMemberSearchRequestBuilder(com.b2international.snowowl.snomed.datastore.request.SnomedRefSetMemberSearchRequestBuilder) BadRequestException(com.b2international.commons.exceptions.BadRequestException) BranchPathUtils(com.b2international.snowowl.core.branch.BranchPathUtils) DateFormats(com.b2international.snowowl.core.date.DateFormats) Files(java.nio.file.Files) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) SnomedTerminologyComponentConstants(com.b2international.snowowl.snomed.common.SnomedTerminologyComponentConstants) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) ChronoUnit(java.time.temporal.ChronoUnit) SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) NotEmpty(org.hibernate.validator.constraints.NotEmpty) DateTimeFormatter(java.time.format.DateTimeFormatter) IComponent(com.b2international.snowowl.core.domain.IComponent) SnomedRf2Headers(com.b2international.snowowl.snomed.common.SnomedRf2Headers) Versions(com.b2international.snowowl.core.version.Versions) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType) BranchContext(com.b2international.snowowl.core.domain.BranchContext) SnomedReferenceSets(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSets) SnomedConceptSearchRequestBuilder(com.b2international.snowowl.snomed.datastore.request.SnomedConceptSearchRequestBuilder)

Example 2 with SnomedReferenceSets

use of com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSets 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

BadRequestException (com.b2international.commons.exceptions.BadRequestException)2 ResourceURI (com.b2international.snowowl.core.ResourceURI)2 TerminologyResource (com.b2international.snowowl.core.TerminologyResource)2 SnowowlRuntimeException (com.b2international.snowowl.core.api.SnowowlRuntimeException)2 Attachment (com.b2international.snowowl.core.attachments.Attachment)2 AttachmentRegistry (com.b2international.snowowl.core.attachments.AttachmentRegistry)2 AccessControl (com.b2international.snowowl.core.authorization.AccessControl)2 CodeSystem (com.b2international.snowowl.core.codesystem.CodeSystem)2 CodeSystemRequests (com.b2international.snowowl.core.codesystem.CodeSystemRequests)2 DateFormats (com.b2international.snowowl.core.date.DateFormats)2 EffectiveTimes (com.b2international.snowowl.core.date.EffectiveTimes)2 BranchContext (com.b2international.snowowl.core.domain.BranchContext)2 Request (com.b2international.snowowl.core.events.Request)2 Permission (com.b2international.snowowl.core.identity.Permission)2 Sort (com.b2international.snowowl.core.request.SearchResourceRequest.Sort)2 Version (com.b2international.snowowl.core.version.Version)2 IEventBus (com.b2international.snowowl.eventbus.IEventBus)2 SnomedTerminologyComponentConstants (com.b2international.snowowl.snomed.common.SnomedTerminologyComponentConstants)2 SnomedRefSetType (com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType)2 SnomedReferenceSets (com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSets)2