Search in sources :

Example 66 with Project

use of de.tudarmstadt.ukp.clarin.webanno.model.Project in project webanno by webanno.

the class RemoteApiController2 method curationCreate.

@ApiOperation(value = "Create curation for a document in a project")
@RequestMapping(value = "/" + PROJECTS + "/{" + PARAM_PROJECT_ID + "}/" + DOCUMENTS + "/{" + PARAM_DOCUMENT_ID + "}/" + CURATION, method = RequestMethod.POST, consumes = MULTIPART_FORM_DATA_VALUE, produces = APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<RResponse<RAnnotation>> curationCreate(@PathVariable(PARAM_PROJECT_ID) long aProjectId, @PathVariable(PARAM_DOCUMENT_ID) long aDocumentId, @RequestParam(value = PARAM_CONTENT) MultipartFile aFile, @RequestParam(value = PARAM_FORMAT) Optional<String> aFormat, @RequestParam(value = PARAM_STATE) Optional<String> aState, UriComponentsBuilder aUcb) throws Exception {
    Project project = getProject(aProjectId);
    SourceDocument document = getDocument(project, aDocumentId);
    JCas annotationCas = createCompatibleCas(aProjectId, aDocumentId, aFile, aFormat);
    // If they are compatible, then we can store the new annotations
    curationService.writeCurationCas(annotationCas, document, false);
    AnnotationDocumentState resultState = AnnotationDocumentState.IN_PROGRESS;
    if (aState.isPresent()) {
        SourceDocumentState state = parseSourceDocumentState(aState.get());
        switch(state) {
            case CURATION_IN_PROGRESS:
                resultState = AnnotationDocumentState.IN_PROGRESS;
                document.setState(state);
                documentService.createSourceDocument(document);
                break;
            case CURATION_FINISHED:
                resultState = AnnotationDocumentState.FINISHED;
                document.setState(state);
                documentService.createSourceDocument(document);
                break;
            // fallthrough
            case NEW:
            // fallthrough
            case ANNOTATION_IN_PROGRESS:
            // fallthrough
            case ANNOTATION_FINISHED:
            default:
                throw new IllegalObjectStateException("State [%s] not valid when uploading a curation.", aState.get());
        }
    } else {
        document.setState(SourceDocumentState.CURATION_IN_PROGRESS);
        documentService.createSourceDocument(document);
    }
    RResponse<RAnnotation> response = new RResponse<>(new RAnnotation(WebAnnoConst.CURATION_USER, resultState, new Date()));
    return ResponseEntity.created(aUcb.path(API_BASE + "/" + PROJECTS + "/{pid}/" + DOCUMENTS + "/{did}/" + CURATION).buildAndExpand(project.getId(), document.getId()).toUri()).body(response);
}
Also used : RProject(de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RProject) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) IllegalObjectStateException(de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.exception.IllegalObjectStateException) RAnnotation(de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RAnnotation) SourceDocumentState(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocumentState) AnnotationDocumentState(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocumentState) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) JCas(org.apache.uima.jcas.JCas) RResponse(de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RResponse) Date(java.util.Date) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 67 with Project

use of de.tudarmstadt.ukp.clarin.webanno.model.Project in project webanno by webanno.

the class RemoteApiController2 method projectExport.

@ApiOperation(value = "Export a project to a ZIP file")
@RequestMapping(value = ("/" + PROJECTS + "/{" + PARAM_PROJECT_ID + "}/" + EXPORT), method = RequestMethod.GET, produces = { "application/zip", APPLICATION_JSON_UTF8_VALUE })
public ResponseEntity<InputStreamResource> projectExport(@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);
    ProjectExportRequest per = new ProjectExportRequest(Model.of(project), "bin");
    File exportedFile = exportService.generateZipFile(per);
    // Turn the file into a resource and auto-delete the file when the resource closes the
    // stream.
    InputStreamResource result = new InputStreamResource(new FileInputStream(exportedFile) {

        @Override
        public void close() throws IOException {
            super.close();
            FileUtils.forceDelete(exportedFile);
        }
    });
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.setContentType(MediaType.valueOf("application/zip"));
    httpHeaders.setContentLength(exportedFile.length());
    httpHeaders.set("Content-Disposition", "attachment; filename=\"" + exportedFile.getName() + "\"");
    return new ResponseEntity<>(result, httpHeaders, HttpStatus.OK);
}
Also used : RProject(de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RProject) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) ProjectExportRequest(de.tudarmstadt.ukp.clarin.webanno.export.ProjectExportRequest) IOException(java.io.IOException) File(java.io.File) MultipartFile(org.springframework.web.multipart.MultipartFile) FileInputStream(java.io.FileInputStream) InputStreamResource(org.springframework.core.io.InputStreamResource) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 68 with Project

use of de.tudarmstadt.ukp.clarin.webanno.model.Project in project webanno by webanno.

the class RemoteApiController2 method annotationsList.

@ApiOperation(value = "List annotations of a document in a project")
@RequestMapping(value = "/" + PROJECTS + "/{" + PARAM_PROJECT_ID + "}/" + DOCUMENTS + "/{" + PARAM_DOCUMENT_ID + "}/" + ANNOTATIONS, method = RequestMethod.GET, produces = APPLICATION_JSON_UTF8_VALUE)
public ResponseEntity<RResponse<List<RAnnotation>>> annotationsList(@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);
    List<AnnotationDocument> annotations = documentService.listAnnotationDocuments(doc);
    List<RAnnotation> annotationList = new ArrayList<>();
    for (AnnotationDocument annotation : annotations) {
        annotationList.add(new RAnnotation(annotation));
    }
    return ResponseEntity.ok(new RResponse<>(annotationList));
}
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) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) ArrayList(java.util.ArrayList) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)68 SourceDocument (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)23 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)23 User (de.tudarmstadt.ukp.clarin.webanno.security.model.User)22 File (java.io.File)22 RProject (de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RProject)17 IOException (java.io.IOException)15 ApiOperation (io.swagger.annotations.ApiOperation)14 NoResultException (javax.persistence.NoResultException)13 AnnotationDocument (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument)12 ArrayList (java.util.ArrayList)12 MDC (org.slf4j.MDC)12 InputStream (java.io.InputStream)11 JCas (org.apache.uima.jcas.JCas)10 UIMAException (org.apache.uima.UIMAException)8 MultipartFile (org.springframework.web.multipart.MultipartFile)8 BufferedInputStream (java.io.BufferedInputStream)7 FileInputStream (java.io.FileInputStream)7 Transactional (org.springframework.transaction.annotation.Transactional)7 ZipFile (java.util.zip.ZipFile)6