use of de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RProject in project webanno by webanno.
the class RemoteApiController2 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));
}
use of de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RProject in project webanno by webanno.
the class RemoteApiController2 method projectCreate.
@ApiOperation(value = "Create a new project")
@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", isProjectCreator(projectService, user) || isSuperAdmin(projectService, 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>") + "]", isSuperAdmin(projectService, 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);
projectService.createProject(project);
annotationService.initializeProject(project);
// Create permission for the project creator
String owner = aCreator.isPresent() ? aCreator.get() : user.getUsername();
projectService.createProjectPermission(new ProjectPermission(project, owner, PermissionLevel.ADMIN));
projectService.createProjectPermission(new ProjectPermission(project, owner, PermissionLevel.CURATOR));
projectService.createProjectPermission(new ProjectPermission(project, owner, PermissionLevel.USER));
RResponse<RProject> response = new RResponse<>(new RProject(project));
return ResponseEntity.created(aUcb.path(API_BASE + "/" + PROJECTS + "/{id}").buildAndExpand(project.getId()).toUri()).body(response);
}
use of de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RProject in project webanno by webanno.
the class RemoteApiController2 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(@RequestParam(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", isSuperAdmin(projectService, 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);
} finally {
tempFile.delete();
}
return ResponseEntity.ok(new RResponse<>(new RProject(importedProject)));
}
Aggregations