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