Search in sources :

Example 26 with SnowowlRuntimeException

use of com.b2international.snowowl.core.api.SnowowlRuntimeException in project snow-owl by b2ihealthcare.

the class EclExpression method resolve.

public Promise<Set<String>> resolve(final BranchContext context) {
    if (promise == null) {
        RevisionSearcher searcher = context.service(RevisionSearcher.class);
        boolean cached = context.optionalService(PathWithVersion.class).isPresent();
        promise = resolveToExpression(context).then(expression -> {
            // shortcut to extract IDs from the query itself if possible
            if (SnomedEclEvaluationRequest.canExtractIds(expression)) {
                return SnomedEclEvaluationRequest.extractIds(expression);
            }
            try {
                return newHashSet(searcher.search(Query.select(String.class).from(SnomedConceptDocument.class).fields(SnomedConceptDocument.Fields.ID).where(expression).limit(Integer.MAX_VALUE).cached(cached).build()));
            } catch (IOException e) {
                throw new SnowowlRuntimeException(e);
            }
        });
    }
    return promise;
}
Also used : Query(com.b2international.index.query.Query) SnomedRelationshipIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry) Promise(com.b2international.snowowl.core.events.util.Promise) Multimap(com.google.common.collect.Multimap) Multimaps(com.google.common.collect.Multimaps) SnomedRequests(com.b2international.snowowl.snomed.datastore.request.SnomedRequests) Options(com.b2international.commons.options.Options) NestedExpression(com.b2international.snomed.ecl.ecl.NestedExpression) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) Nullable(javax.annotation.Nullable) ResourceURI(com.b2international.snowowl.core.ResourceURI) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) Lists.newArrayListWithCapacity(com.google.common.collect.Lists.newArrayListWithCapacity) Function(com.google.common.base.Function) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) RevisionDocument(com.b2international.snowowl.core.repository.RevisionDocument) SnomedConcepts(com.b2international.snowowl.snomed.core.domain.SnomedConcepts) Set(java.util.Set) IOException(java.io.IOException) IEventBus(com.b2international.snowowl.eventbus.IEventBus) NotNull(javax.validation.constraints.NotNull) PathWithVersion(com.b2international.snowowl.core.uri.ResourceURIPathResolver.PathWithVersion) SnomedRelationships(com.b2international.snowowl.snomed.core.domain.SnomedRelationships) Any(com.b2international.snomed.ecl.ecl.Any) Trees(com.b2international.snowowl.snomed.core.tree.Trees) SearchResourceRequest(com.b2international.snowowl.core.request.SearchResourceRequest) SnomedRelationship(com.b2international.snowowl.snomed.core.domain.SnomedRelationship) List(java.util.List) Expressions(com.b2international.index.query.Expressions) SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) Expression(com.b2international.index.query.Expression) Preconditions(com.google.common.base.Preconditions) Ecl(com.b2international.snomed.ecl.Ecl) SnomedRf2Headers(com.b2international.snowowl.snomed.common.SnomedRf2Headers) EclConceptReference(com.b2international.snomed.ecl.ecl.EclConceptReference) ExpressionConstraint(com.b2international.snomed.ecl.ecl.ExpressionConstraint) BranchContext(com.b2international.snowowl.core.domain.BranchContext) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType) SnomedCoreConfiguration(com.b2international.snowowl.snomed.datastore.config.SnomedCoreConfiguration) PathWithVersion(com.b2international.snowowl.core.uri.ResourceURIPathResolver.PathWithVersion) IOException(java.io.IOException) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException)

Example 27 with SnowowlRuntimeException

use of com.b2international.snowowl.core.api.SnowowlRuntimeException in project snow-owl by b2ihealthcare.

the class SnomedRf2ExportRequest method createReleaseDirectory.

private Path createReleaseDirectory(final Path exportDirectory, final LocalDateTime archiveEffectiveTime) {
    final String releaseStatus = includePreReleaseContent ? "BETA" : "PRODUCTION";
    final String effectiveDate = DateTimeFormatter.ofPattern(DateFormats.ISO_8601_UTC).format(archiveEffectiveTime);
    final Path releaseDirectory = exportDirectory.resolve(String.format("SNOMEDCT_RF2_%s_%s", releaseStatus, effectiveDate));
    try {
        Files.createDirectories(releaseDirectory);
    } catch (final IOException e) {
        throw new SnowowlRuntimeException("Failed to create RF2 release directory for export.", e);
    }
    return releaseDirectory;
}
Also used : Path(java.nio.file.Path) IOException(java.io.IOException) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException)

Example 28 with SnowowlRuntimeException

use of com.b2international.snowowl.core.api.SnowowlRuntimeException in project snow-owl by b2ihealthcare.

the class SnomedRf2ExportRequest method registerResult.

private void registerResult(final AttachmentRegistry fileRegistry, final UUID exportId, final Path exportDirectory) {
    File archiveFile = null;
    try {
        archiveFile = exportDirectory.resolveSibling(exportDirectory.getFileName() + ".zip").toFile();
        FileUtils.createZipArchive(exportDirectory.toFile(), archiveFile);
        // lgtm[java/input-resource-leak]
        fileRegistry.upload(exportId, new FileInputStream(archiveFile));
    } catch (final IOException e) {
        throw new SnowowlRuntimeException("Failed to register archive file from export directory.", e);
    } finally {
        if (archiveFile != null) {
            archiveFile.delete();
        }
    }
}
Also used : IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException)

Example 29 with SnowowlRuntimeException

use of com.b2international.snowowl.core.api.SnowowlRuntimeException in project snow-owl by b2ihealthcare.

the class SnomedRf2ImportRequest method createDb.

private DB createDb() {
    try {
        Maker dbMaker = DBMaker.fileDB(Files.createTempDirectory(rf2Archive.toString()).resolve("rf2-import.db").toFile()).fileDeleteAfterClose().fileMmapEnable().fileMmapPreclearDisable();
        // for non-delta releases increase the allocation size
        if (releaseType != Rf2ReleaseType.DELTA) {
            dbMaker = dbMaker.allocateStartSize(// 256MB
            256 * 1024 * 1024).allocateIncrement(// 128MB
            128 * 1024 * 1024);
        }
        DB db = dbMaker.make();
        // preload file content into disk cache
        db.getStore().fileLoad();
        return db;
    } catch (IOException e) {
        throw new SnowowlRuntimeException("Couldn't create temporary db", e);
    }
}
Also used : IOException(java.io.IOException) DBMaker(org.mapdb.DBMaker) Maker(org.mapdb.DBMaker.Maker) DB(org.mapdb.DB) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException)

Example 30 with SnowowlRuntimeException

use of com.b2international.snowowl.core.api.SnowowlRuntimeException in project snow-owl by b2ihealthcare.

the class Rf2Exporter method exportBranch.

public final void exportBranch(final Path releaseDirectory, final RepositoryContext context, final String branch, final long effectiveTimeStart, final long effectiveTimeEnd, final Set<String> visitedComponentEffectiveTimes) throws IOException {
    LOG.info("Exporting {} branch to '{}'", branch, getFileName());
    // Ensure that the path leading to the export file exists
    final Path exportFileDirectory = releaseDirectory.resolve(getRelativeDirectory());
    Files.createDirectories(exportFileDirectory);
    final Path exportFile = exportFileDirectory.resolve(getFileName());
    try (RandomAccessFile randomAccessFile = new RandomAccessFile(exportFile.toFile(), "rw")) {
        try (FileChannel fileChannel = randomAccessFile.getChannel()) {
            // Add a header if the file is empty
            if (randomAccessFile.length() == 0L) {
                fileChannel.write(toByteBuffer(TAB_JOINER.join(getHeader())));
                fileChannel.write(toByteBuffer(CR_LF));
            }
            // We want to append rows, if the file already exists, so jump to the end
            fileChannel.position(fileChannel.size());
            /*
				 * XXX: createSearchRequestBuilder() should handle namespace/language code
				 * filtering, if applicable; we will only handle the effective time and module
				 * filters here.
				 * 
				 * An effective time filter is always set, even if not in delta mode, to prevent
				 * exporting unpublished content twice.
				 */
            new BranchRequest<R>(branch, new RevisionIndexReadRequest<>(inner -> {
                createSearchRequestBuilder().filterByModules(// null value will be ignored
                modules).filterByEffectiveTime(effectiveTimeStart, effectiveTimeEnd).setLimit(BATCH_SIZE).setFields(Arrays.asList(getHeader())).stream(inner).flatMap(hits -> getMappedStream(hits, context, branch)).forEachOrdered(row -> {
                    String id = row.get(0);
                    String effectiveTime = row.get(1);
                    if (!visitedComponentEffectiveTimes.add(String.join("_", id, effectiveTime))) {
                        return;
                    }
                    try {
                        fileChannel.write(toByteBuffer(TAB_JOINER.join(row)));
                        fileChannel.write(toByteBuffer(CR_LF));
                    } catch (final IOException e) {
                        throw new SnowowlRuntimeException("Failed to write contents for file '" + exportFile.getFileName() + "'.");
                    }
                });
                return null;
            })).execute(context);
        }
    }
}
Also used : Path(java.nio.file.Path) EffectiveTimes(com.b2international.snowowl.core.date.EffectiveTimes) RandomAccessFile(java.io.RandomAccessFile) BranchRequest(com.b2international.snowowl.core.request.BranchRequest) Arrays(java.util.Arrays) LoggerFactory(org.slf4j.LoggerFactory) SnomedSearchRequestBuilder(com.b2international.snowowl.snomed.datastore.request.SnomedSearchRequestBuilder) ByteBuffer(java.nio.ByteBuffer) BooleanUtils(com.b2international.commons.BooleanUtils) Path(java.nio.file.Path) Rf2ReleaseType(com.b2international.snowowl.snomed.core.domain.Rf2ReleaseType) Charsets(com.google.common.base.Charsets) Logger(org.slf4j.Logger) DateFormats(com.b2international.snowowl.core.date.DateFormats) RepositoryContext(com.b2international.snowowl.core.domain.RepositoryContext) Files(java.nio.file.Files) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) Collection(java.util.Collection) Set(java.util.Set) IOException(java.io.IOException) RevisionIndexReadRequest(com.b2international.snowowl.core.request.RevisionIndexReadRequest) PageableCollectionResource(com.b2international.snowowl.core.domain.PageableCollectionResource) List(java.util.List) Stream(java.util.stream.Stream) LocalDate(java.time.LocalDate) FileChannel(java.nio.channels.FileChannel) SnomedComponent(com.b2international.snowowl.snomed.core.domain.SnomedComponent) Joiner(com.google.common.base.Joiner) RandomAccessFile(java.io.RandomAccessFile) FileChannel(java.nio.channels.FileChannel) RevisionIndexReadRequest(com.b2international.snowowl.core.request.RevisionIndexReadRequest) IOException(java.io.IOException) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException)

Aggregations

SnowowlRuntimeException (com.b2international.snowowl.core.api.SnowowlRuntimeException)39 IOException (java.io.IOException)27 SctId (com.b2international.snowowl.snomed.cis.domain.SctId)7 Collection (java.util.Collection)7 HttpPost (org.apache.http.client.methods.HttpPost)6 BadRequestException (com.b2international.commons.exceptions.BadRequestException)5 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)4 Promise (com.b2international.snowowl.core.events.util.Promise)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 List (java.util.List)4 TimeUnit (java.util.concurrent.TimeUnit)4 File (java.io.File)3 Path (java.nio.file.Path)3 NamingException (javax.naming.NamingException)3 InitialLdapContext (javax.naming.ldap.InitialLdapContext)3 HttpGet (org.apache.http.client.methods.HttpGet)3 Logger (org.slf4j.Logger)3 JwkException (com.auth0.jwk.JwkException)2 JwkProvider (com.auth0.jwk.JwkProvider)2 JwkProviderBuilder (com.auth0.jwk.JwkProviderBuilder)2