use of de.tudarmstadt.ukp.clarin.webanno.model.Project in project webanno by webanno.
the class AnnotationSchemaServiceImpl method createLayer.
@Override
@Transactional
public void createLayer(AnnotationLayer aLayer) throws IOException {
if (isNull(aLayer.getId())) {
entityManager.persist(aLayer);
} else {
entityManager.merge(aLayer);
}
try (MDC.MDCCloseable closable = MDC.putCloseable(Logging.KEY_PROJECT_ID, String.valueOf(aLayer.getProject().getId()))) {
Project project = aLayer.getProject();
log.info("Created layer [{}]({}) in project [{}]({})", aLayer.getName(), aLayer.getId(), project.getName(), project.getId());
}
}
use of de.tudarmstadt.ukp.clarin.webanno.model.Project 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());
}
}
use of de.tudarmstadt.ukp.clarin.webanno.model.Project 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());
}
}
use of de.tudarmstadt.ukp.clarin.webanno.model.Project in project webanno by webanno.
the class ProjectServiceImpl method listAccessibleProjects.
@Override
public List<Project> listAccessibleProjects(User user) {
List<Project> allowedProject = new ArrayList<>();
List<Project> allProjects = listProjects();
// if global admin, list all projects
if (SecurityUtil.isSuperAdmin(this, user)) {
return allProjects;
}
// else only list projects where she is admin / user / curator
for (Project project : allProjects) {
if (SecurityUtil.isProjectAdmin(project, this, user) || SecurityUtil.isAnnotator(project, this, user) || SecurityUtil.isCurator(project, this, user)) {
allowedProject.add(project);
}
}
return allowedProject;
}
use of de.tudarmstadt.ukp.clarin.webanno.model.Project in project webanno by webanno.
the class RemoteApiController method projectDelete.
/**
* Delete a project where user has a ADMIN role
*
* To test when running in Eclipse, use the Linux "curl" command.
*
* curl -v -X DELETE
* 'http://USERNAME:PASSOWRD@localhost:8080/webanno-webapp/api/projects/{aProjectId}'
*
* @param aProjectId
* The id of the project.
* @throws Exception
* if there was an error.
*/
@RequestMapping(value = ("/" + PROJECTS + "/{" + PARAM_PROJECT_ID + "}"), method = RequestMethod.DELETE)
public ResponseEntity<String> projectDelete(@PathVariable(PARAM_PROJECT_ID) long aProjectId) throws Exception {
// Get current user
String username = SecurityContextHolder.getContext().getAuthentication().getName();
User user = userRepository.get(username);
if (user == null) {
return ResponseEntity.badRequest().body("User [" + username + "] not found.");
}
// Get project
Project project;
try {
project = projectRepository.getProject(aProjectId);
} catch (NoResultException e) {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Project [" + aProjectId + "] not found.");
}
// Check for the access
boolean hasAccess = SecurityUtil.isProjectAdmin(project, projectRepository, user) || SecurityUtil.isSuperAdmin(projectRepository, user);
if (!hasAccess) {
return ResponseEntity.status(HttpStatus.FORBIDDEN).body("User [" + username + "] is not allowed to access project [" + aProjectId + "]");
}
// remove project is user has admin access
LOG.info("Deleting project [" + aProjectId + "]");
projectRepository.removeProject(project);
LOG.info("Successfully deleted project [" + aProjectId + "]");
return ResponseEntity.ok("Project [" + aProjectId + "] deleted.");
}
Aggregations