use of de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RResponse in project webanno by webanno.
the class RemoteApiController2 method annotationsDelete.
@ApiOperation(value = "Delete a user's annotations of one document from a project")
@RequestMapping(value = "/" + PROJECTS + "/{" + PARAM_PROJECT_ID + "}/" + DOCUMENTS + "/{" + PARAM_DOCUMENT_ID + "}/" + ANNOTATIONS + "/{" + PARAM_ANNOTATOR_ID + "}", method = RequestMethod.DELETE, produces = APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<RResponse<Void>> annotationsDelete(@PathVariable(PARAM_PROJECT_ID) long aProjectId, @PathVariable(PARAM_DOCUMENT_ID) long aDocumentId, @PathVariable(PARAM_ANNOTATOR_ID) String aAnnotatorId) 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);
AnnotationDocument anno = getAnnotation(doc, aAnnotatorId, false);
documentService.removeAnnotationDocument(anno);
documentService.deleteAnnotationCas(anno);
return ResponseEntity.ok(new RResponse<>(INFO, "Annotations of user [" + aAnnotatorId + "] on 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 annotationsCreate.
@ApiOperation(value = "Create annotations for a document in a project")
@RequestMapping(value = "/" + PROJECTS + "/{" + PARAM_PROJECT_ID + "}/" + DOCUMENTS + "/{" + PARAM_DOCUMENT_ID + "}/" + ANNOTATIONS + "/{" + PARAM_ANNOTATOR_ID + "}", method = RequestMethod.POST, consumes = MULTIPART_FORM_DATA_VALUE, produces = APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<RResponse<RAnnotation>> annotationsCreate(@PathVariable(PARAM_PROJECT_ID) long aProjectId, @PathVariable(PARAM_DOCUMENT_ID) long aDocumentId, @PathVariable(PARAM_ANNOTATOR_ID) String aAnnotatorId, @RequestParam(value = PARAM_CONTENT) MultipartFile aFile, @RequestParam(value = PARAM_FORMAT) Optional<String> aFormat, @RequestParam(value = PARAM_STATE) Optional<String> aState, UriComponentsBuilder aUcb) throws Exception {
User annotator = getUser(aAnnotatorId);
Project project = getProject(aProjectId);
SourceDocument document = getDocument(project, aDocumentId);
AnnotationDocument anno = getAnnotation(document, aAnnotatorId, true);
JCas annotationCas = createCompatibleCas(aProjectId, aDocumentId, aFile, aFormat);
// If they are compatible, then we can store the new annotations
documentService.writeAnnotationCas(annotationCas, document, annotator, false);
// Set state if one was provided
if (aState.isPresent()) {
anno.setState(parseAnnotationDocumentState(aState.get()));
documentService.createAnnotationDocument(anno);
}
RResponse<RAnnotation> response = new RResponse<>(new RAnnotation(anno));
if (aState.isPresent()) {
response.addMessage(INFO, "State of annotations of user [" + aAnnotatorId + "] on document [" + document.getId() + "] set to [" + aState.get() + "]");
}
return ResponseEntity.created(aUcb.path(API_BASE + "/" + PROJECTS + "/{pid}/" + DOCUMENTS + "/{did}/" + ANNOTATIONS + "/{aid}").buildAndExpand(project.getId(), document.getId(), annotator.getUsername()).toUri()).body(response);
}
use of de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RResponse 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)));
}
use of de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RResponse in project webanno by webanno.
the class RemoteApiController2 method documentList.
@ApiOperation(value = "List documents in a project")
@RequestMapping(value = "/" + PROJECTS + "/{" + PARAM_PROJECT_ID + "}/" + DOCUMENTS, method = RequestMethod.GET, produces = APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<RResponse<List<RDocument>>> documentList(@PathVariable(PARAM_PROJECT_ID) long aProjectId) throws Exception {
// Get project (this also ensures that it exists and that the current user can access it
Project project = getProject(aProjectId);
List<SourceDocument> documents = documentService.listSourceDocuments(project);
List<RDocument> documentList = new ArrayList<>();
for (SourceDocument document : documents) {
documentList.add(new RDocument(document));
}
return ResponseEntity.ok(new RResponse<>(documentList));
}
use of de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RResponse in project webanno by webanno.
the class RemoteApiController2 method projectDelete.
@ApiOperation(value = "Delete an existing project")
@RequestMapping(value = ("/" + PROJECTS + "/{" + PARAM_PROJECT_ID + "}"), method = RequestMethod.DELETE, produces = APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<RResponse<Void>> projectDelete(@PathVariable(PARAM_PROJECT_ID) long aProjectId) throws Exception {
// Get project (this also ensures that it exists and that the current user can access it
Project project = getProject(aProjectId);
projectService.removeProject(project);
return ResponseEntity.ok(new RResponse<>(INFO, "Project [" + aProjectId + "] deleted."));
}
Aggregations