Search in sources :

Example 1 with BeforeDocumentRemovedEvent

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());
    }
}
Also used : Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) BeforeDocumentRemovedEvent(de.tudarmstadt.ukp.clarin.webanno.api.event.BeforeDocumentRemovedEvent) File(java.io.File) MDC(org.slf4j.MDC) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

BeforeDocumentRemovedEvent (de.tudarmstadt.ukp.clarin.webanno.api.event.BeforeDocumentRemovedEvent)1 AnnotationDocument (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument)1 Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)1 File (java.io.File)1 MDC (org.slf4j.MDC)1 Transactional (org.springframework.transaction.annotation.Transactional)1