use of de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RResponse in project webanno by webanno.
the class RemoteApiController2 method curationDelete.
@ApiOperation(value = "Delete a user's annotations of one document from a project")
@RequestMapping(value = "/" + PROJECTS + "/{" + PARAM_PROJECT_ID + "}/" + DOCUMENTS + "/{" + PARAM_DOCUMENT_ID + "}/" + CURATION, method = RequestMethod.DELETE, produces = APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<RResponse<Void>> curationDelete(@PathVariable(PARAM_PROJECT_ID) long aProjectId, @PathVariable(PARAM_DOCUMENT_ID) long aDocumentId) throws Exception {
// Get project (this also ensures that it exists and that the current user can access it
Project project = getProject(aProjectId);
SourceDocument doc = getDocument(project, aDocumentId);
curationService.deleteCurationCas(doc);
// guess is that we set the state back to annotation-in-progress.
switch(doc.getState()) {
// Fall-through
case CURATION_IN_PROGRESS:
case CURATION_FINISHED:
doc.setState(SourceDocumentState.ANNOTATION_IN_PROGRESS);
documentService.createSourceDocument(doc);
break;
default:
}
return ResponseEntity.ok(new RResponse<>(INFO, "Curated annotations for document [" + aDocumentId + "] deleted from project [" + aProjectId + "]."));
}
use of de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RResponse 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.RResponse in project webanno by webanno.
the class RemoteApiController2 method documentDelete.
@ApiOperation(value = "Delete a document from a project")
@RequestMapping(value = "/" + PROJECTS + "/{" + PARAM_PROJECT_ID + "}/" + DOCUMENTS + "/{" + PARAM_DOCUMENT_ID + "}", method = RequestMethod.DELETE, produces = APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<RResponse<Void>> documentDelete(@PathVariable(PARAM_PROJECT_ID) long aProjectId, @PathVariable(PARAM_DOCUMENT_ID) long aDocumentId) throws Exception {
// Get project (this also ensures that it exists and that the current user can access it
Project project = getProject(aProjectId);
SourceDocument doc = getDocument(project, aDocumentId);
documentService.removeSourceDocument(doc);
return ResponseEntity.ok(new RResponse<>(INFO, "Document [" + aDocumentId + "] deleted from project [" + aProjectId + "]."));
}
use of de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RResponse in project webanno by webanno.
the class RemoteApiController2 method documentCreate.
@ApiOperation(value = "Create a new document in a project")
@RequestMapping(value = "/" + PROJECTS + "/{" + PARAM_PROJECT_ID + "}/" + DOCUMENTS, method = RequestMethod.POST, consumes = MULTIPART_FORM_DATA_VALUE, produces = APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<RResponse<RDocument>> documentCreate(@PathVariable(PARAM_PROJECT_ID) long aProjectId, @RequestParam(value = PARAM_CONTENT) MultipartFile aFile, @RequestParam(value = PARAM_NAME) String aName, @RequestParam(value = PARAM_FORMAT) String aFormat, @RequestParam(value = PARAM_STATE) Optional<String> aState, UriComponentsBuilder aUcb) throws Exception {
// Get project (this also ensures that it exists and that the current user can access it
Project project = getProject(aProjectId);
// Check if the format is supported
Map<String, Class<CollectionReader>> readableFormats = importExportService.getReadableFormats();
if (readableFormats.get(aFormat) == null) {
throw new UnsupportedFormatException("Format [%s] not supported. Acceptable formats are %s.", aFormat, readableFormats.keySet());
}
// Meta data entry to the database
SourceDocument document = new SourceDocument();
document.setProject(project);
document.setName(aName);
document.setFormat(aFormat);
// Set state if one was provided
if (aState.isPresent()) {
SourceDocumentState state = parseSourceDocumentState(aState.get());
switch(state) {
// fallthrough
case NEW:
// fallthrough
case ANNOTATION_IN_PROGRESS:
case // fallthrough
ANNOTATION_FINISHED:
document.setState(state);
documentService.createSourceDocument(document);
break;
// fallthrough
case CURATION_IN_PROGRESS:
case CURATION_FINISHED:
default:
throw new IllegalObjectStateException("State [%s] not valid when uploading a document.", aState.get());
}
}
// Import source document to the project repository folder
try (InputStream is = aFile.getInputStream()) {
documentService.uploadSourceDocument(is, document);
}
RResponse<RDocument> rDocument = new RResponse<>(new RDocument(document));
if (aState.isPresent()) {
rDocument.addMessage(INFO, "State of document [" + document.getId() + "] set to [" + aState.get() + "]");
}
return ResponseEntity.created(aUcb.path(API_BASE + "/" + PROJECTS + "/{pid}/" + DOCUMENTS + "/{did}").buildAndExpand(project.getId(), document.getId()).toUri()).body(rDocument);
}
use of de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RResponse 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);
}
Aggregations