Search in sources :

Example 1 with AnnotationDocumentState

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

the class DocumentServiceImpl method setAnnotationDocumentState.

@Override
@Transactional
public AnnotationDocumentState setAnnotationDocumentState(AnnotationDocument aDocument, AnnotationDocumentState aState) {
    AnnotationDocumentState oldState = aDocument.getState();
    aDocument.setState(aState);
    createAnnotationDocument(aDocument);
    if (!Objects.equals(oldState, aDocument.getState())) {
        applicationEventPublisher.publishEvent(new AnnotationStateChangeEvent(this, aDocument, oldState));
    }
    return oldState;
}
Also used : AnnotationDocumentState(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocumentState) AnnotationStateChangeEvent(de.tudarmstadt.ukp.clarin.webanno.api.event.AnnotationStateChangeEvent) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with AnnotationDocumentState

use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocumentState 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)

Aggregations

AnnotationDocumentState (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocumentState)2 AnnotationStateChangeEvent (de.tudarmstadt.ukp.clarin.webanno.api.event.AnnotationStateChangeEvent)1 Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)1 SourceDocument (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)1 SourceDocumentState (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocumentState)1 IllegalObjectStateException (de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.exception.IllegalObjectStateException)1 RAnnotation (de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RAnnotation)1 RProject (de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RProject)1 RResponse (de.tudarmstadt.ukp.clarin.webanno.webapp.remoteapi.v2.model.RResponse)1 ApiOperation (io.swagger.annotations.ApiOperation)1 Date (java.util.Date)1 JCas (org.apache.uima.jcas.JCas)1 Transactional (org.springframework.transaction.annotation.Transactional)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1