use of de.tudarmstadt.ukp.clarin.webanno.api.event.AfterDocumentCreatedEvent in project webanno by webanno.
the class DocumentServiceImpl method uploadSourceDocument.
@Override
@Transactional
public void uploadSourceDocument(InputStream aIs, SourceDocument aDocument) throws IOException {
// Create the metadata record - this also assigns the ID to the document
createSourceDocument(aDocument);
// Import the actual content
File targetFile = getSourceDocumentFile(aDocument);
JCas jcas;
try {
FileUtils.forceMkdir(targetFile.getParentFile());
try (OutputStream os = new FileOutputStream(targetFile)) {
copyLarge(aIs, os);
}
// Check if the file has a valid format / can be converted without error
// This requires that the document ID has already been assigned
jcas = createInitialCas(aDocument);
} catch (IOException e) {
FileUtils.forceDelete(targetFile);
removeSourceDocument(aDocument);
throw e;
} catch (Exception e) {
FileUtils.forceDelete(targetFile);
removeSourceDocument(aDocument);
throw new IOException(e.getMessage(), e);
}
applicationEventPublisher.publishEvent(new AfterDocumentCreatedEvent(this, aDocument, jcas));
try (MDC.MDCCloseable closable = MDC.putCloseable(Logging.KEY_PROJECT_ID, String.valueOf(aDocument.getProject().getId()))) {
Project project = aDocument.getProject();
log.info("Imported source document [{}]({}) to project [{}]({})", aDocument.getName(), aDocument.getId(), project.getName(), project.getId());
}
}
Aggregations