Search in sources :

Example 1 with RProject

use of de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.aero.model.RProject in project webanno by webanno.

the class AeroRemoteApiController method projectList.

@ApiOperation(value = "List the projects accessible by the authenticated user")
@RequestMapping(value = ("/" + PROJECTS), method = RequestMethod.GET, produces = APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<RResponse<List<RProject>>> projectList() throws Exception {
    // Get current user - this will throw an exception if the current user does not exit
    User user = getCurrentUser();
    // Get projects with permission
    List<Project> accessibleProjects = projectService.listAccessibleProjects(user);
    // Collect all the projects
    List<RProject> projectList = new ArrayList<>();
    for (Project project : accessibleProjects) {
        projectList.add(new RProject(project));
    }
    return ResponseEntity.ok(new RResponse<>(projectList));
}
Also used : RProject(de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.aero.model.RProject) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) User(de.tudarmstadt.ukp.clarin.webanno.security.model.User) ArrayList(java.util.ArrayList) RProject(de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.aero.model.RProject) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with RProject

use of de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.aero.model.RProject in project webanno by webanno.

the class AeroRemoteApiController method projectImport.

@ApiOperation(value = "Import a previously exported project")
@// 
RequestMapping(// 
value = ("/" + PROJECTS + "/" + IMPORT), // 
method = RequestMethod.POST, // 
consumes = MULTIPART_FORM_DATA_VALUE, produces = APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<RResponse<RProject>> projectImport(@RequestPart(PARAM_FILE) MultipartFile aFile) throws Exception {
    // Get current user - this will throw an exception if the current user does not exit
    User user = getCurrentUser();
    // Check for the access
    assertPermission("User [" + user.getUsername() + "] is not allowed to import projects", userRepository.isAdministrator(user));
    Project importedProject;
    File tempFile = File.createTempFile("webanno-training", null);
    try (InputStream is = new BufferedInputStream(aFile.getInputStream());
        OutputStream os = new FileOutputStream(tempFile)) {
        if (!ZipUtils.isZipStream(is)) {
            throw new UnsupportedFormatException("Invalid ZIP file");
        }
        IOUtils.copyLarge(is, os);
        if (!ImportUtil.isZipValidWebanno(tempFile)) {
            throw new UnsupportedFormatException("Incompatible to webanno ZIP file");
        }
        // importedProject = importService.importProject(tempFile, false);
        ProjectImportRequest request = new ProjectImportRequest(false);
        importedProject = exportService.importProject(request, new ZipFile(tempFile));
    } finally {
        tempFile.delete();
    }
    return ResponseEntity.ok(new RResponse<>(new RProject(importedProject)));
}
Also used : RProject(de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.aero.model.RProject) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) User(de.tudarmstadt.ukp.clarin.webanno.security.model.User) UnsupportedFormatException(de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.aero.exception.UnsupportedFormatException) ZipFile(java.util.zip.ZipFile) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) ZipFile(java.util.zip.ZipFile) MultipartFile(org.springframework.web.multipart.MultipartFile) ProjectImportRequest(de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectImportRequest) RProject(de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.aero.model.RProject) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with RProject

use of de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.aero.model.RProject in project webanno by webanno.

the class AeroRemoteApiController method projectCreate.

@ApiOperation(value = "Create a new project")
@ApiImplicitParams({ @ApiImplicitParam(name = PARAM_NAME, paramType = "form", required = true), @ApiImplicitParam(name = PARAM_CREATOR, paramType = "form") })
@// 
RequestMapping(// 
value = ("/" + PROJECTS), // 
method = RequestMethod.POST, // 
consumes = MULTIPART_FORM_DATA_VALUE, produces = APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<RResponse<RProject>> projectCreate(@RequestParam(PARAM_NAME) String aName, @RequestParam(PARAM_CREATOR) Optional<String> aCreator, UriComponentsBuilder aUcb) throws Exception {
    // Get current user - this will throw an exception if the current user does not exit
    User user = getCurrentUser();
    // Check for the access
    assertPermission("User [" + user.getUsername() + "] is not allowed to create projects", userRepository.isProjectCreator(user) || userRepository.isAdministrator(user));
    // Check if the user can create projects for another user
    assertPermission("User [" + user.getUsername() + "] is not allowed to create projects for user [" + aCreator.orElse("<unspecified>") + "]", userRepository.isAdministrator(user) || (aCreator.isPresent() && aCreator.get().equals(user.getUsername())));
    // Existing project
    if (projectService.existsProject(aName)) {
        throw new ObjectExistsException("A project with name [" + aName + "] already exists");
    }
    // Create the project and initialize tags
    LOG.info("Creating project [" + aName + "]");
    Project project = new Project();
    project.setName(aName);
    project.setMode(WebAnnoConst.PROJECT_TYPE_ANNOTATION);
    project.setScriptDirection(ScriptDirection.LTR);
    project.setState(ProjectState.NEW);
    projectService.createProject(project);
    projectService.initializeProject(project);
    // Create permission for the project creator
    String owner = aCreator.isPresent() ? aCreator.get() : user.getUsername();
    projectService.createProjectPermission(new ProjectPermission(project, owner, PermissionLevel.MANAGER));
    projectService.createProjectPermission(new ProjectPermission(project, owner, PermissionLevel.CURATOR));
    projectService.createProjectPermission(new ProjectPermission(project, owner, PermissionLevel.ANNOTATOR));
    RResponse<RProject> response = new RResponse<>(new RProject(project));
    return ResponseEntity.created(aUcb.path(API_BASE + "/" + PROJECTS + "/{id}").buildAndExpand(project.getId()).toUri()).body(response);
}
Also used : RProject(de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.aero.model.RProject) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) User(de.tudarmstadt.ukp.clarin.webanno.security.model.User) ObjectExistsException(de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.aero.exception.ObjectExistsException) ProjectPermission(de.tudarmstadt.ukp.clarin.webanno.model.ProjectPermission) RProject(de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.aero.model.RProject) RResponse(de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.aero.model.RResponse) ApiImplicitParams(io.swagger.annotations.ApiImplicitParams) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)3 User (de.tudarmstadt.ukp.clarin.webanno.security.model.User)3 RProject (de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.aero.model.RProject)3 ApiOperation (io.swagger.annotations.ApiOperation)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ProjectImportRequest (de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectImportRequest)1 ProjectPermission (de.tudarmstadt.ukp.clarin.webanno.model.ProjectPermission)1 ObjectExistsException (de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.aero.exception.ObjectExistsException)1 UnsupportedFormatException (de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.aero.exception.UnsupportedFormatException)1 RResponse (de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.aero.model.RResponse)1 ApiImplicitParams (io.swagger.annotations.ApiImplicitParams)1 BufferedInputStream (java.io.BufferedInputStream)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 ZipFile (java.util.zip.ZipFile)1 MultipartFile (org.springframework.web.multipart.MultipartFile)1