Search in sources :

Example 16 with SnowowlRuntimeException

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

the class SnomedEclEvaluationRequest method executeDescriptionSearch.

private static Expression executeDescriptionSearch(BranchContext context, Expression descriptionExpression) {
    if (descriptionExpression.isMatchAll()) {
        return Expressions.matchAll();
    } else if (descriptionExpression.isMatchNone()) {
        return SnomedDocument.Expressions.ids(Set.of());
    }
    final RevisionSearcher searcher = context.service(RevisionSearcher.class);
    try {
        final Query<String> descriptionIndexQuery = Query.select(String.class).from(SnomedDescriptionIndexEntry.class).fields(SnomedDescriptionIndexEntry.Fields.CONCEPT_ID).where(descriptionExpression).limit(Integer.MAX_VALUE).build();
        final Hits<String> descriptionHits = searcher.search(descriptionIndexQuery);
        final Set<String> conceptIds = Set.copyOf(descriptionHits.getHits());
        return SnomedDocument.Expressions.ids(conceptIds);
    } catch (IOException e) {
        throw new SnowowlRuntimeException(e);
    }
}
Also used : IOException(java.io.IOException) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException)

Example 17 with SnowowlRuntimeException

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

the class SnomedEclRefinementEvaluator method evalAxiomStatements.

static Set<Property> evalAxiomStatements(final BranchContext context, final boolean groupedRelationshipsOnly, final Collection<String> sourceIds, final Collection<String> typeIds, final Collection<String> destinationIds) {
    try {
        // search existing axioms (no values!) defined for the given set of conceptIds
        ExpressionBuilder axiomFilter = Expressions.builder().filter(hasDestinationId());
        if (typeIds != null) {
            axiomFilter.filter(typeIds(typeIds));
        }
        if (destinationIds != null) {
            axiomFilter.filter(destinationIds(destinationIds));
        }
        if (groupedRelationshipsOnly) {
            axiomFilter.filter(relationshipGroup(1, Integer.MAX_VALUE));
        }
        ExpressionBuilder activeOwlAxiomMemberQuery = Expressions.builder().filter(active()).filter(Expressions.nestedMatch(SnomedRefSetMemberIndexEntry.Fields.CLASS_AXIOM_RELATIONSHIP, axiomFilter.build()));
        if (sourceIds != null) {
            activeOwlAxiomMemberQuery.filter(SnomedRefSetMemberIndexEntry.Expressions.referencedComponentIds(sourceIds));
        }
        final Query<SnomedRefSetMemberIndexEntry> activeAxiomStatementsQuery = Query.select(SnomedRefSetMemberIndexEntry.class).where(activeOwlAxiomMemberQuery.build()).limit(Integer.MAX_VALUE).build();
        return context.service(RevisionSearcher.class).search(activeAxiomStatementsQuery).stream().filter(owlMember -> !CompareUtils.isEmpty(owlMember.getClassAxiomRelationships())).flatMap(owlMember -> {
            return owlMember.getClassAxiomRelationships().stream().filter(classAxiom -> {
                return (typeIds == null || typeIds.contains(classAxiom.getTypeId())) && (destinationIds == null || destinationIds.contains(classAxiom.getDestinationId())) && (!groupedRelationshipsOnly || classAxiom.getRelationshipGroup() >= 1);
            }).map(classAxiom -> {
                return new Property(owlMember.getReferencedComponentId(), classAxiom.getTypeId(), classAxiom.getDestinationId(), classAxiom.getRelationshipGroup());
            });
        }).collect(Collectors.toSet());
    } catch (IOException e) {
        throw new SnowowlRuntimeException(e);
    }
}
Also used : SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry) PolymorphicDispatcher(org.eclipse.xtext.util.PolymorphicDispatcher) Query(com.b2international.index.query.Query) SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry) Promise(com.b2international.snowowl.core.events.util.Promise) ID(com.b2international.index.revision.Revision.Fields.ID) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) SnomedDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDocument) SnomedRequests(com.b2international.snowowl.snomed.datastore.request.SnomedRequests) Options(com.b2international.commons.options.Options) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) ExpressionBuilder(com.b2international.index.query.Expressions.ExpressionBuilder) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) com.b2international.snomed.ecl.ecl(com.b2international.snomed.ecl.ecl) RepositoryConfiguration(com.b2international.snowowl.core.config.RepositoryConfiguration) CompareUtils(com.b2international.commons.CompareUtils) com.google.common.collect(com.google.common.collect) ResourceURI(com.b2international.snowowl.core.ResourceURI) BadRequestException(com.b2international.commons.exceptions.BadRequestException) Function(com.google.common.base.Function) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) RelationshipValue(com.b2international.snowowl.snomed.core.domain.RelationshipValue) Collection(java.util.Collection) SnomedRelationshipSearchRequestBuilder(com.b2international.snowowl.snomed.datastore.request.SnomedRelationshipSearchRequestBuilder) DataType(com.b2international.snowowl.snomed.core.domain.refset.DataType) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) BinaryOperator(java.util.function.BinaryOperator) Trees(com.b2international.snowowl.snomed.core.tree.Trees) SearchResourceRequest(com.b2international.snowowl.core.request.SearchResourceRequest) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) Expressions(com.b2international.index.query.Expressions) Expressions.active(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDocument.Expressions.active) Entry(java.util.Map.Entry) Expression(com.b2international.index.query.Expression) SnomedRf2Headers(com.b2international.snowowl.snomed.common.SnomedRf2Headers) BranchContext(com.b2international.snowowl.core.domain.BranchContext) Fields(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry.Fields) Expressions(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry.Expressions) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType) IOException(java.io.IOException) ExpressionBuilder(com.b2international.index.query.Expressions.ExpressionBuilder) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException)

Example 18 with SnowowlRuntimeException

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

the class DatasetBootstrap method init.

@Override
public void init(SnowOwlConfiguration configuration, Environment env) throws Exception {
    final String datasetLocation = System.getProperty(LOC_PARAM_NAME);
    if (Strings.isNullOrEmpty(datasetLocation)) {
        throw new SnowowlRuntimeException(String.format("%s JVM argument is missing", LOC_PARAM_NAME));
    }
    final File datasetFile = new File(datasetLocation);
    if (!datasetFile.canRead()) {
        throw new SnowowlRuntimeException(String.format("Defined dataset location %s does not have a valid dataset archive", datasetLocation));
    }
    // delete resource directory first
    final File resourceDirectory = env.getDataPath().toFile();
    LOG.info("Deleting content of {}", resourceDirectory);
    FileUtils.cleanDirectory(resourceDirectory);
    LOG.info("Extracting dataset from {} to {}", datasetFile, resourceDirectory);
    FileUtils.decompressZipArchive(datasetFile, resourceDirectory);
}
Also used : File(java.io.File) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException)

Example 19 with SnowowlRuntimeException

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

the class Attachment method download.

/**
 * Downloads the file to the specified exportPath. The exportPath argument accepts both directory and file paths. Passing a file path replaces the
 * default file name with the desired one. If the target path is a file path and there is an existing file, it will automatically overwrite the
 * target file.
 *
 * @param context
 *            - the context to use for downloading the file
 * @param target
 *            - either target directory where the file needs to be downloaded or an abolute path to a file which will replace the default file
 *            name included in this attachment
 * @return the absolute file path to the downloaded file
 * @since 7.7
 */
public Path download(ServiceProvider context, Path target) {
    Preconditions.checkNotNull(context, "Context cannot be null");
    Preconditions.checkNotNull(target, "ExportPath cannot be null");
    Path resultFile;
    if (Files.isDirectory(target)) {
        resultFile = target.resolve(getFileName());
    } else {
        resultFile = target;
    }
    try (OutputStream out = Files.newOutputStream(resultFile)) {
        context.service(AttachmentRegistry.class).download(attachmentId, out);
    } catch (IOException e) {
        throw new SnowowlRuntimeException(String.format("Couldn't download file '%s'.", getFileName()), e);
    }
    return resultFile;
}
Also used : Path(java.nio.file.Path) OutputStream(java.io.OutputStream) IOException(java.io.IOException) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException)

Example 20 with SnowowlRuntimeException

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

the class LdapIdentityProvider method searchUsers.

@Override
public Promise<Users> searchUsers(Collection<String> usernames, int limit) {
    final ImmutableList.Builder<User> resultBuilder = ImmutableList.builder();
    final String uidProp = conf.getUserIdProperty();
    InitialLdapContext context = null;
    NamingEnumeration<SearchResult> searchResultEnumeration = null;
    try {
        context = createLdapContext();
        Collection<LdapRole> ldapRoles = getAllLdapRoles(context);
        searchResultEnumeration = context.search(conf.getBaseDn(), conf.getUserFilter(), createSearchControls(ATTRIBUTE_DN, uidProp));
        for (final SearchResult searchResult : ImmutableList.copyOf(Iterators.forEnumeration(searchResultEnumeration))) {
            final Attributes attributes = searchResult.getAttributes();
            if (hasAttribute(attributes, uidProp)) {
                final String userName = (String) attributes.get(uidProp).get();
                final List<Role> userRoles = ldapRoles.stream().filter(role -> role.getUniqueMembers().contains(searchResult.getNameInNamespace())).map(role -> new Role(role.getName(), role.getPermissions())).collect(Collectors.toList());
                resultBuilder.add(new User(userName, userRoles));
            }
        }
        final List<User> users = resultBuilder.build().stream().sorted((u1, u2) -> u1.getUsername().compareTo(u2.getUsername())).filter(user -> usernames.isEmpty() || usernames.contains(user.getUsername())).limit(limit).collect(Collectors.toList());
        return Promise.immediate(new Users(users, limit, users.size()));
    } catch (final NamingException e) {
        LOG.error("Couldn't search users/roles due to LDAP communication error: {}", e.getMessage(), e);
        throw new SnowowlRuntimeException(e);
    } finally {
        closeNamingEnumeration(searchResultEnumeration);
        closeLdapContext(context);
    }
}
Also used : Iterables(com.google.common.collect.Iterables) InitialLdapContext(javax.naming.ldap.InitialLdapContext) Promise(com.b2international.snowowl.core.events.util.Promise) LoggerFactory(org.slf4j.LoggerFactory) NamingException(javax.naming.NamingException) SearchControls(javax.naming.directory.SearchControls) Iterators(com.google.common.collect.Iterators) Attribute(javax.naming.directory.Attribute) Strings(com.google.common.base.Strings) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) Permission(com.b2international.snowowl.core.identity.Permission) Context(javax.naming.Context) NoSuchElementException(java.util.NoSuchElementException) Hashtable(java.util.Hashtable) IdentityProvider(com.b2international.snowowl.core.identity.IdentityProvider) Logger(org.slf4j.Logger) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) Collection(java.util.Collection) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) DirContext(javax.naming.directory.DirContext) Role(com.b2international.snowowl.core.identity.Role) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) TreeMap(java.util.TreeMap) Attributes(javax.naming.directory.Attributes) Users(com.b2international.snowowl.core.identity.Users) NamingEnumeration(javax.naming.NamingEnumeration) User(com.b2international.snowowl.core.identity.User) Preconditions(com.google.common.base.Preconditions) Collections(java.util.Collections) SearchResult(javax.naming.directory.SearchResult) User(com.b2international.snowowl.core.identity.User) ImmutableList(com.google.common.collect.ImmutableList) Attributes(javax.naming.directory.Attributes) SearchResult(javax.naming.directory.SearchResult) Users(com.b2international.snowowl.core.identity.Users) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) Role(com.b2international.snowowl.core.identity.Role) InitialLdapContext(javax.naming.ldap.InitialLdapContext) NamingException(javax.naming.NamingException)

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