Search in sources :

Example 1 with BeforeProjectRemovedEvent

use of de.tudarmstadt.ukp.clarin.webanno.api.event.BeforeProjectRemovedEvent in project webanno by webanno.

the class ProjectServiceImpl method removeProject.

@Override
@Transactional
public void removeProject(Project aProject) throws IOException {
    // remove metadata from DB
    Project project = aProject;
    if (!entityManager.contains(project)) {
        project = entityManager.merge(project);
    }
    applicationEventPublisher.publishEvent(new BeforeProjectRemovedEvent(this, aProject));
    for (ProjectPermission permissions : getProjectPermissions(aProject)) {
        entityManager.remove(permissions);
    }
    entityManager.remove(project);
    // remove the project directory from the file system
    String path = dir.getAbsolutePath() + "/" + PROJECT_FOLDER + "/" + aProject.getId();
    try {
        FileUtils.deleteDirectory(new File(path));
    } catch (FileNotFoundException e) {
        try (MDC.MDCCloseable closable = MDC.putCloseable(Logging.KEY_PROJECT_ID, String.valueOf(aProject.getId()))) {
            log.info("Project directory to be deleted was not found: [{}]. Ignoring.", path);
        }
    }
    try (MDC.MDCCloseable closable = MDC.putCloseable(Logging.KEY_PROJECT_ID, String.valueOf(aProject.getId()))) {
        log.info("Removed project [{}]({})", aProject.getName(), aProject.getId());
    }
}
Also used : Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) ProjectPermission(de.tudarmstadt.ukp.clarin.webanno.model.ProjectPermission) FileNotFoundException(java.io.FileNotFoundException) BeforeProjectRemovedEvent(de.tudarmstadt.ukp.clarin.webanno.api.event.BeforeProjectRemovedEvent) ZipFile(java.util.zip.ZipFile) File(java.io.File) MDC(org.slf4j.MDC) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

BeforeProjectRemovedEvent (de.tudarmstadt.ukp.clarin.webanno.api.event.BeforeProjectRemovedEvent)1 Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)1 ProjectPermission (de.tudarmstadt.ukp.clarin.webanno.model.ProjectPermission)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 ZipFile (java.util.zip.ZipFile)1 MDC (org.slf4j.MDC)1 Transactional (org.springframework.transaction.annotation.Transactional)1