use of de.tudarmstadt.ukp.clarin.webanno.api.event.BeforeDocumentRemovedEvent in project webanno by webanno.
the class DocumentServiceImpl method removeSourceDocument.
@Override
@Transactional
public void removeSourceDocument(SourceDocument aDocument) throws IOException {
// BeforeDocumentRemovedEvent is triggered first, since methods that rely
// on it might need to have access to the associated annotation documents
applicationEventPublisher.publishEvent(new BeforeDocumentRemovedEvent(this, aDocument));
for (AnnotationDocument annotationDocument : listAllAnnotationDocuments(aDocument)) {
removeAnnotationDocument(annotationDocument);
}
entityManager.remove(entityManager.contains(aDocument) ? aDocument : entityManager.merge(aDocument));
String path = dir.getAbsolutePath() + "/" + PROJECT_FOLDER + "/" + aDocument.getProject().getId() + "/" + DOCUMENT_FOLDER + "/" + aDocument.getId();
// remove from file both source and related annotation file
if (new File(path).exists()) {
FileUtils.forceDelete(new File(path));
}
try (MDC.MDCCloseable closable = MDC.putCloseable(Logging.KEY_PROJECT_ID, String.valueOf(aDocument.getProject().getId()))) {
Project project = aDocument.getProject();
log.info("Removed source document [{}]({}) from project [{}]({})", aDocument.getName(), aDocument.getId(), project.getName(), project.getId());
}
}
Aggregations