Search in sources :

Example 6 with CORRECTION_USER

use of de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.CORRECTION_USER in project webanno by webanno.

the class ProjectCasDoctorPanel method actionRepair.

private void actionRepair(AjaxRequestTarget aTarget, Form<?> aForm) throws IOException, UIMAException, ClassNotFoundException {
    CasDoctor casDoctor = new CasDoctor();
    casDoctor.setApplicationContext(ApplicationContextProvider.getApplicationContext());
    casDoctor.setFatalChecks(false);
    casDoctor.setRepairClasses(formModel.repairs);
    Project project = getModelObject();
    formModel.messageSets = new ArrayList<>();
    for (SourceDocument sd : documentService.listSourceDocuments(project)) {
        // Repair INITIAL CAS
        {
            LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [INITIAL]");
            try {
                casStorageService.forceActionOnCas(sd, INITIAL_CAS_PSEUDO_USER, (doc, user) -> createOrReadInitialCasWithoutSaving(doc, messageSet), // 
                (cas) -> casDoctor.repair(project, cas, messageSet.messages), true);
            } catch (Exception e) {
                messageSet.messages.add(new LogMessage(getClass(), LogLevel.ERROR, "Error repairing initial CAS for [" + sd.getName() + "]: " + e.getMessage()));
                LOG.error("Error repairing initial CAS for [{}]", sd.getName(), e);
            }
            noticeIfThereAreNoMessages(messageSet);
            formModel.messageSets.add(messageSet);
        }
        // Repair CORRECTION_USER CAS if necessary
        if (PROJECT_TYPE_CORRECTION.equals(project.getMode())) {
            LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [" + CORRECTION_USER + "]");
            try {
                casStorageService.forceActionOnCas(sd, CORRECTION_USER, (doc, user) -> casStorageService.readCas(doc, user, UNMANAGED_NON_INITIALIZING_ACCESS), // 
                (cas) -> casDoctor.repair(project, cas, messageSet.messages), true);
            } catch (FileNotFoundException e) {
                // If there is no CAS for the correction user, then correction has not started
                // yet. This is not a problem, so we can ignore it. (REC: I wonder if this
                // assumption is correct in curation mode...)
                messageSet.messages.add(LogMessage.info(getClass(), "Correction seems to have not yet started."));
            } catch (Exception e) {
                messageSet.messages.add(new LogMessage(getClass(), LogLevel.ERROR, "Error checking annotations for [" + CORRECTION_USER + "] for [" + sd.getName() + "]: " + e.getMessage()));
                LOG.error("Error checking annotations for [{}] for [{}]", CORRECTION_USER, sd.getName(), e);
            }
            noticeIfThereAreNoMessages(messageSet);
            formModel.messageSets.add(messageSet);
        }
        // Repair CURATION_USER CAS
        {
            LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [" + CURATION_USER + "]");
            try {
                casStorageService.forceActionOnCas(sd, CURATION_USER, (doc, user) -> casStorageService.readCas(doc, user, UNMANAGED_NON_INITIALIZING_ACCESS), // 
                (cas) -> casDoctor.repair(project, cas, messageSet.messages), true);
            } catch (FileNotFoundException e) {
                if (asList(CURATION_IN_PROGRESS, CURATION_FINISHED).contains(sd.getState())) {
                    messageSet.messages.add(LogMessage.error(getClass(), "Curation CAS missing."));
                } else {
                    // If there is no CAS for the curation user, then curation has not started
                    // yet. This is not a problem, so we can ignore it.
                    messageSet.messages.add(LogMessage.info(getClass(), "Curation has not started."));
                }
            } catch (Exception e) {
                messageSet.messages.add(new LogMessage(getClass(), LogLevel.ERROR, "Error checking annotations for [" + CURATION_USER + "] for [" + sd.getName() + "]: " + e.getMessage()));
                LOG.error("Error checking annotations for [{}] for [{}]", CURATION_USER, sd.getName(), e);
            }
            noticeIfThereAreNoMessages(messageSet);
            formModel.messageSets.add(messageSet);
        }
        // Repair regular annotator CASes
        for (AnnotationDocument ad : documentService.listAnnotationDocuments(sd)) {
            if (documentService.existsAnnotationCas(ad)) {
                LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [" + ad.getUser() + "]");
                try {
                    casStorageService.forceActionOnCas(sd, ad.getUser(), (doc, user) -> casStorageService.readCas(doc, user, UNMANAGED_NON_INITIALIZING_ACCESS), // 
                    (cas) -> casDoctor.repair(project, cas, messageSet.messages), true);
                } catch (Exception e) {
                    messageSet.messages.add(new LogMessage(getClass(), LogLevel.ERROR, "Error repairing annotations of user [" + ad.getUser() + "] for [" + sd.getName() + "]: " + e.getMessage()));
                    LOG.error("Error repairing annotations of user [{}] for [{}]", ad.getUser(), sd.getName(), e);
                }
                noticeIfThereAreNoMessages(messageSet);
                formModel.messageSets.add(messageSet);
            }
        }
    }
    aTarget.add(this);
}
Also used : Form(org.apache.wicket.markup.html.form.Form) SpringBean(org.apache.wicket.spring.injection.annot.SpringBean) CORRECTION_USER(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.CORRECTION_USER) Safe(de.tudarmstadt.ukp.clarin.webanno.diag.repairs.Repair.Safe) LogMessage(de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage) LoggerFactory(org.slf4j.LoggerFactory) CasStorageService(de.tudarmstadt.ukp.clarin.webanno.api.CasStorageService) CAS(org.apache.uima.cas.CAS) CURATION_USER(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.CURATION_USER) UNMANAGED_NON_INITIALIZING_ACCESS(de.tudarmstadt.ukp.clarin.webanno.api.casstorage.CasAccessMode.UNMANAGED_NON_INITIALIZING_ACCESS) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) CheckBoxMultipleChoice(org.apache.wicket.markup.html.form.CheckBoxMultipleChoice) Repair(de.tudarmstadt.ukp.clarin.webanno.diag.repairs.Repair) ChoiceRenderer(org.apache.wicket.markup.html.form.ChoiceRenderer) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) INITIAL_CAS_PSEUDO_USER(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.INITIAL_CAS_PSEUDO_USER) IModel(org.apache.wicket.model.IModel) ListView(org.apache.wicket.markup.html.list.ListView) UIMAException(org.apache.uima.UIMAException) Label(org.apache.wicket.markup.html.basic.Label) LabelPosition(org.apache.wicket.markup.html.form.AbstractChoice.LabelPosition) PROJECT_TYPE_CORRECTION(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.PROJECT_TYPE_CORRECTION) DocumentService(de.tudarmstadt.ukp.clarin.webanno.api.DocumentService) LogLevel(de.tudarmstadt.ukp.clarin.webanno.support.logging.LogLevel) Logger(org.slf4j.Logger) CURATION_IN_PROGRESS(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocumentState.CURATION_IN_PROGRESS) ListItem(org.apache.wicket.markup.html.list.ListItem) WebAnnoConst(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst) CurationDocumentService(de.tudarmstadt.ukp.clarin.webanno.curation.storage.CurationDocumentService) ProjectSettingsPanelBase(de.tudarmstadt.ukp.clarin.webanno.ui.core.settings.ProjectSettingsPanelBase) CURATION_FINISHED(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocumentState.CURATION_FINISHED) IOException(java.io.IOException) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) LambdaAjaxButton(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaAjaxButton) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) Serializable(java.io.Serializable) List(java.util.List) PropertyModel(org.apache.wicket.model.PropertyModel) CasDoctor(de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor) ApplicationContextProvider(de.tudarmstadt.ukp.clarin.webanno.support.ApplicationContextProvider) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) ImportExportService(de.tudarmstadt.ukp.clarin.webanno.api.ImportExportService) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) LogMessage(de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage) CasDoctor(de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) FileNotFoundException(java.io.FileNotFoundException) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) UIMAException(org.apache.uima.UIMAException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 7 with CORRECTION_USER

use of de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.CORRECTION_USER in project webanno by webanno.

the class ProjectCasDoctorPanel method actionCheck.

private void actionCheck(AjaxRequestTarget aTarget, Form<?> aForm) throws IOException, UIMAException, ClassNotFoundException {
    CasDoctor casDoctor = new CasDoctor();
    casDoctor.setApplicationContext(ApplicationContextProvider.getApplicationContext());
    casDoctor.setFatalChecks(false);
    casDoctor.setCheckClasses(CasDoctor.scanChecks());
    Project project = getModelObject();
    formModel.messageSets = new ArrayList<>();
    for (SourceDocument sd : documentService.listSourceDocuments(project)) {
        // Check INITIAL CAS
        {
            LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [INITIAL]");
            try {
                casStorageService.forceActionOnCas(sd, INITIAL_CAS_PSEUDO_USER, (doc, user) -> createOrReadInitialCasWithoutSaving(doc, messageSet), // 
                (cas) -> casDoctor.analyze(project, cas, messageSet.messages), false);
            } catch (Exception e) {
                messageSet.messages.add(new LogMessage(getClass(), LogLevel.ERROR, "Error checking initial CAS for [" + sd.getName() + "]: " + e.getMessage()));
                LOG.error("Error checking initial CAS for [{}]", sd.getName(), e);
            }
            noticeIfThereAreNoMessages(messageSet);
            formModel.messageSets.add(messageSet);
        }
        // Check CORRECTION_USER CAS if necessary
        if (WebAnnoConst.PROJECT_TYPE_CORRECTION.equals(project.getMode())) {
            LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [" + CORRECTION_USER + "]");
            try {
                casStorageService.forceActionOnCas(sd, CORRECTION_USER, (doc, user) -> casStorageService.readCas(doc, user, UNMANAGED_NON_INITIALIZING_ACCESS), // 
                (cas) -> casDoctor.analyze(project, cas, messageSet.messages), false);
            } catch (FileNotFoundException e) {
                // If there is no CAS for the correction user, then correction has not started
                // yet. This is not a problem, so we can ignore it. (REC: I wonder if this
                // assumption is correct in curation mode...)
                messageSet.messages.add(LogMessage.info(getClass(), "Correction seems to have not yet started."));
            } catch (Exception e) {
                messageSet.messages.add(new LogMessage(getClass(), LogLevel.ERROR, "Error checking annotations for [" + CORRECTION_USER + "] for [" + sd.getName() + "]: " + e.getMessage()));
                LOG.error("Error checking annotations for [{}] for [{}]", CORRECTION_USER, sd.getName(), e);
            }
            noticeIfThereAreNoMessages(messageSet);
            formModel.messageSets.add(messageSet);
        }
        // Check CURATION_USER CAS
        {
            LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [" + CURATION_USER + "]");
            try {
                casStorageService.forceActionOnCas(sd, CURATION_USER, (doc, user) -> casStorageService.readCas(doc, user, UNMANAGED_NON_INITIALIZING_ACCESS), // 
                (cas) -> casDoctor.analyze(project, cas, messageSet.messages), false);
            } catch (FileNotFoundException e) {
                // If there is no CAS for the curation user, then curation has not started yet.
                // This is not a problem, so we can ignore it.
                messageSet.messages.add(LogMessage.info(getClass(), "Curation seems to have not yet started."));
            } catch (Exception e) {
                messageSet.messages.add(new LogMessage(getClass(), LogLevel.ERROR, "Error checking annotations for [" + CURATION_USER + "] for [" + sd.getName() + "]: " + e.getMessage()));
                LOG.error("Error checking annotations for [{}] for [{}]", CURATION_USER, sd.getName(), e);
            }
            noticeIfThereAreNoMessages(messageSet);
            formModel.messageSets.add(messageSet);
        }
        // Check regular annotator CASes
        for (AnnotationDocument ad : documentService.listAnnotationDocuments(sd)) {
            if (documentService.existsAnnotationCas(ad)) {
                LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [" + ad.getUser() + "]");
                try {
                    casStorageService.forceActionOnCas(ad.getDocument(), ad.getUser(), (doc, user) -> casStorageService.readCas(doc, user, UNMANAGED_NON_INITIALIZING_ACCESS), // 
                    (cas) -> casDoctor.analyze(project, cas, messageSet.messages), false);
                } catch (Exception e) {
                    messageSet.messages.add(new LogMessage(getClass(), LogLevel.ERROR, "Error checking annotations of user [" + ad.getUser() + "] for [" + sd.getName() + "]: " + e.getMessage()));
                    LOG.error("Error checking annotations of user [{}] for [{}]", ad.getUser(), sd.getName(), e);
                }
                noticeIfThereAreNoMessages(messageSet);
                formModel.messageSets.add(messageSet);
            }
        }
    }
    aTarget.add(this);
}
Also used : Form(org.apache.wicket.markup.html.form.Form) SpringBean(org.apache.wicket.spring.injection.annot.SpringBean) CORRECTION_USER(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.CORRECTION_USER) Safe(de.tudarmstadt.ukp.clarin.webanno.diag.repairs.Repair.Safe) LogMessage(de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage) LoggerFactory(org.slf4j.LoggerFactory) CasStorageService(de.tudarmstadt.ukp.clarin.webanno.api.CasStorageService) CAS(org.apache.uima.cas.CAS) CURATION_USER(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.CURATION_USER) UNMANAGED_NON_INITIALIZING_ACCESS(de.tudarmstadt.ukp.clarin.webanno.api.casstorage.CasAccessMode.UNMANAGED_NON_INITIALIZING_ACCESS) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) CheckBoxMultipleChoice(org.apache.wicket.markup.html.form.CheckBoxMultipleChoice) Repair(de.tudarmstadt.ukp.clarin.webanno.diag.repairs.Repair) ChoiceRenderer(org.apache.wicket.markup.html.form.ChoiceRenderer) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) INITIAL_CAS_PSEUDO_USER(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.INITIAL_CAS_PSEUDO_USER) IModel(org.apache.wicket.model.IModel) ListView(org.apache.wicket.markup.html.list.ListView) UIMAException(org.apache.uima.UIMAException) Label(org.apache.wicket.markup.html.basic.Label) LabelPosition(org.apache.wicket.markup.html.form.AbstractChoice.LabelPosition) PROJECT_TYPE_CORRECTION(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.PROJECT_TYPE_CORRECTION) DocumentService(de.tudarmstadt.ukp.clarin.webanno.api.DocumentService) LogLevel(de.tudarmstadt.ukp.clarin.webanno.support.logging.LogLevel) Logger(org.slf4j.Logger) CURATION_IN_PROGRESS(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocumentState.CURATION_IN_PROGRESS) ListItem(org.apache.wicket.markup.html.list.ListItem) WebAnnoConst(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst) CurationDocumentService(de.tudarmstadt.ukp.clarin.webanno.curation.storage.CurationDocumentService) ProjectSettingsPanelBase(de.tudarmstadt.ukp.clarin.webanno.ui.core.settings.ProjectSettingsPanelBase) CURATION_FINISHED(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocumentState.CURATION_FINISHED) IOException(java.io.IOException) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) LambdaAjaxButton(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaAjaxButton) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) Serializable(java.io.Serializable) List(java.util.List) PropertyModel(org.apache.wicket.model.PropertyModel) CasDoctor(de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor) ApplicationContextProvider(de.tudarmstadt.ukp.clarin.webanno.support.ApplicationContextProvider) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) ImportExportService(de.tudarmstadt.ukp.clarin.webanno.api.ImportExportService) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) LogMessage(de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage) CasDoctor(de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) FileNotFoundException(java.io.FileNotFoundException) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) UIMAException(org.apache.uima.UIMAException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

DocumentService (de.tudarmstadt.ukp.clarin.webanno.api.DocumentService)7 ImportExportService (de.tudarmstadt.ukp.clarin.webanno.api.ImportExportService)7 CORRECTION_USER (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.CORRECTION_USER)7 PROJECT_TYPE_CORRECTION (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.PROJECT_TYPE_CORRECTION)7 Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)7 SourceDocument (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)7 ArrayList (java.util.ArrayList)7 Arrays.asList (java.util.Arrays.asList)7 List (java.util.List)7 CasStorageService (de.tudarmstadt.ukp.clarin.webanno.api.CasStorageService)6 RepositoryProperties (de.tudarmstadt.ukp.clarin.webanno.api.RepositoryProperties)5 ProjectImportRequest (de.tudarmstadt.ukp.clarin.webanno.api.export.ProjectImportRequest)5 ExportedProject (de.tudarmstadt.ukp.clarin.webanno.export.model.ExportedProject)5 File (java.io.File)5 AnnotationSchemaService (de.tudarmstadt.ukp.clarin.webanno.api.AnnotationSchemaService)4 CURATION_USER (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.CURATION_USER)4 INITIAL_CAS_PSEUDO_USER (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.INITIAL_CAS_PSEUDO_USER)4 PROJECT_TYPE_ANNOTATION (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.PROJECT_TYPE_ANNOTATION)4 BackupProperties (de.tudarmstadt.ukp.clarin.webanno.api.dao.BackupProperties)4 CasStorageServiceImpl (de.tudarmstadt.ukp.clarin.webanno.api.dao.CasStorageServiceImpl)4