Search in sources :

Example 11 with Project

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

Example 12 with Project

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

Example 13 with Project

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

Example 14 with Project

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;
}
Also used : Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) ArrayList(java.util.ArrayList)

Example 15 with Project

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.");
}
Also used : Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) User(de.tudarmstadt.ukp.clarin.webanno.security.model.User) NoResultException(javax.persistence.NoResultException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)68 SourceDocument (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)23 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)23 User (de.tudarmstadt.ukp.clarin.webanno.security.model.User)22 File (java.io.File)22 RProject (de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RProject)17 IOException (java.io.IOException)15 ApiOperation (io.swagger.annotations.ApiOperation)14 NoResultException (javax.persistence.NoResultException)13 AnnotationDocument (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument)12 ArrayList (java.util.ArrayList)12 MDC (org.slf4j.MDC)12 InputStream (java.io.InputStream)11 JCas (org.apache.uima.jcas.JCas)10 UIMAException (org.apache.uima.UIMAException)8 MultipartFile (org.springframework.web.multipart.MultipartFile)8 BufferedInputStream (java.io.BufferedInputStream)7 FileInputStream (java.io.FileInputStream)7 Transactional (org.springframework.transaction.annotation.Transactional)7 ZipFile (java.util.zip.ZipFile)6