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