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);
}
}
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);
}
}
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);
}
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;
}
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);
}
}
Aggregations