Search in sources :

Example 6 with RResponse

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 + "]."));
}
Also used : RProject(de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RProject) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with RResponse

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);
}
Also used : RProject(de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RProject) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) RAnnotation(de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RAnnotation) User(de.tudarmstadt.ukp.clarin.webanno.security.model.User) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) JCas(org.apache.uima.jcas.JCas) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) RResponse(de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RResponse) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with RResponse

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)));
}
Also used : RProject(de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.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.v2.exception.UnsupportedFormatException) 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) MultipartFile(org.springframework.web.multipart.MultipartFile) RProject(de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RProject) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with RResponse

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));
}
Also used : RProject(de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RProject) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) ArrayList(java.util.ArrayList) RDocument(de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RDocument) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with RResponse

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."));
}
Also used : RProject(de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RProject) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)12 RProject (de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RProject)12 ApiOperation (io.swagger.annotations.ApiOperation)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 SourceDocument (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)8 User (de.tudarmstadt.ukp.clarin.webanno.security.model.User)4 RResponse (de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RResponse)4 AnnotationDocument (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument)3 RAnnotation (de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RAnnotation)3 ArrayList (java.util.ArrayList)3 SourceDocumentState (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocumentState)2 IllegalObjectStateException (de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.exception.IllegalObjectStateException)2 UnsupportedFormatException (de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.exception.UnsupportedFormatException)2 RDocument (de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RDocument)2 BufferedInputStream (java.io.BufferedInputStream)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 JCas (org.apache.uima.jcas.JCas)2 AnnotationDocumentState (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocumentState)1 ProjectPermission (de.tudarmstadt.ukp.clarin.webanno.model.ProjectPermission)1