Search in sources :

Example 41 with Project

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

the class ProjectCasDoctorPanel method actionRepair.

private void actionRepair(AjaxRequestTarget aTarget, Form<?> aForm) throws IOException, UIMAException, ClassNotFoundException {
    casStorageService.disableCache();
    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)) {
        {
            LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [INITIAL]");
            JCas initialCas;
            if (documentService.existsInitialCas(sd)) {
                initialCas = documentService.readInitialCas(sd, false);
            } else {
                messageSet.messages.add(new LogMessage(getClass(), LogLevel.INFO, "Created initial CAS for [" + sd.getName() + "]"));
                initialCas = documentService.createInitialCas(sd, false);
            }
            casDoctor.repair(project, initialCas.getCas(), messageSet.messages);
            CasPersistenceUtils.writeSerializedCas(initialCas, documentService.getCasFile(sd, INITIAL_CAS_PSEUDO_USER));
            noticeIfThereAreNoMessages(messageSet);
            formModel.messageSets.add(messageSet);
        }
        for (AnnotationDocument ad : documentService.listAnnotationDocuments(sd)) {
            if (documentService.existsAnnotationCas(ad)) {
                LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [" + ad.getUser() + "]");
                JCas userCas = documentService.readAnnotationCas(ad, false);
                casDoctor.repair(project, userCas.getCas(), messageSet.messages);
                CasPersistenceUtils.writeSerializedCas(userCas, documentService.getCasFile(ad.getDocument(), ad.getUser()));
                noticeIfThereAreNoMessages(messageSet);
                formModel.messageSets.add(messageSet);
            }
        }
    }
    aTarget.add(this);
}
Also used : Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) LogMessage(de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor.LogMessage) CasDoctor(de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) JCas(org.apache.uima.jcas.JCas) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument)

Example 42 with Project

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

the class ProjectCasDoctorPanel method actionCheck.

private void actionCheck(AjaxRequestTarget aTarget, Form<?> aForm) throws IOException, UIMAException, ClassNotFoundException {
    casStorageService.disableCache();
    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)) {
        {
            LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [INITIAL]");
            JCas initialCas;
            try {
                if (documentService.existsInitialCas(sd)) {
                    initialCas = documentService.readInitialCas(sd, false);
                } else {
                    messageSet.messages.add(new LogMessage(getClass(), LogLevel.INFO, "No initial CAS for [" + sd.getName() + "]"));
                    initialCas = documentService.createInitialCas(sd, false);
                }
                casDoctor.analyze(project, initialCas.getCas(), messageSet.messages);
            } catch (Exception e) {
                messageSet.messages.add(new LogMessage(getClass(), LogLevel.ERROR, "Error reading initial CAS for [" + sd.getName() + "]: " + e.getMessage()));
                LOG.error("Error reading initial CAS for [" + sd.getName() + "]", e);
            }
            noticeIfThereAreNoMessages(messageSet);
            formModel.messageSets.add(messageSet);
        }
        for (AnnotationDocument ad : documentService.listAnnotationDocuments(sd)) {
            if (documentService.existsAnnotationCas(ad)) {
                LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [" + ad.getUser() + "]");
                JCas userCas = documentService.readAnnotationCas(ad, false);
                casDoctor.analyze(project, userCas.getCas(), messageSet.messages);
                noticeIfThereAreNoMessages(messageSet);
                formModel.messageSets.add(messageSet);
            }
        }
    }
    aTarget.add(this);
}
Also used : Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) LogMessage(de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor.LogMessage) CasDoctor(de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) JCas(org.apache.uima.jcas.JCas) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) UIMAException(org.apache.uima.UIMAException) IOException(java.io.IOException)

Example 43 with Project

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

the class ImportDocumentsPanel method actionImport.

private void actionImport(AjaxRequestTarget aTarget, Form<Void> aForm) {
    aTarget.addChildren(getPage(), IFeedback.class);
    List<FileUpload> uploadedFiles = fileUpload.getFileUploads();
    Project project = projectModel.getObject();
    if (isEmpty(uploadedFiles)) {
        error("No document is selected to upload, please select a document first");
        return;
    }
    if (isNull(project.getId())) {
        error("Project not yet created, please save project details!");
        return;
    }
    for (FileUpload documentToUpload : uploadedFiles) {
        String fileName = documentToUpload.getClientFileName();
        if (documentService.existsSourceDocument(project, fileName)) {
            error("Document " + fileName + " already uploaded ! Delete " + "the document if you want to upload again");
            continue;
        }
        try {
            SourceDocument document = new SourceDocument();
            document.setName(fileName);
            document.setProject(project);
            document.setFormat(importExportService.getReadableFormatId(format.getObject()));
            try (InputStream is = documentToUpload.getInputStream()) {
                documentService.uploadSourceDocument(is, document);
            }
            info("File [" + fileName + "] has been imported successfully!");
        } catch (Exception e) {
            error("Error while uploading document " + fileName + ": " + ExceptionUtils.getRootCauseMessage(e));
            LOG.error(fileName + ": " + e.getMessage(), e);
        }
    }
    WicketUtil.refreshPage(aTarget, getPage());
}
Also used : Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) InputStream(java.io.InputStream) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) FileUpload(org.apache.wicket.markup.html.form.upload.FileUpload)

Example 44 with Project

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

the class MonitoringPage method getOverallProjectProgress.

private Map<String, Integer> getOverallProjectProgress() {
    Map<String, Integer> overallProjectProgress = new LinkedHashMap<>();
    String username = SecurityContextHolder.getContext().getAuthentication().getName();
    User user = userRepository.get(username);
    for (Project project : projectService.listProjects()) {
        if (SecurityUtil.isCurator(project, projectService, user) || SecurityUtil.isProjectAdmin(project, projectService, user)) {
            int annoFinished = documentService.listFinishedAnnotationDocuments(project).size();
            int allAnno = documentService.numberOfExpectedAnnotationDocuments(project);
            int progress = (int) Math.round((double) (annoFinished * 100) / (allAnno));
            overallProjectProgress.put(project.getName(), progress);
        }
    }
    return overallProjectProgress;
}
Also used : Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) User(de.tudarmstadt.ukp.clarin.webanno.security.model.User) LinkedHashMap(java.util.LinkedHashMap)

Example 45 with Project

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

the class TagSetImportPanel method actionImport.

private void actionImport(AjaxRequestTarget aTarget, Form<Preferences> aForm) {
    List<FileUpload> uploadedFiles = fileUpload.getFileUploads();
    Project project = selectedProject.getObject();
    if (isEmpty(uploadedFiles)) {
        error("Please choose file with tagset before uploading");
        return;
    } else if (isNull(project.getId())) {
        error("Project not yet created, please save project details!");
        return;
    }
    if (aForm.getModelObject().format.equals(ExportedTagSetConstant.JSON_FORMAT)) {
        for (FileUpload tagFile : uploadedFiles) {
            InputStream tagInputStream;
            try {
                tagInputStream = tagFile.getInputStream();
                if (aForm.getModelObject().overwrite) {
                    JsonImportUtil.importTagSetFromJsonWithOverwrite(project, tagInputStream, annotationService);
                } else {
                    JsonImportUtil.importTagSetFromJson(project, tagInputStream, annotationService);
                }
            } catch (IOException e) {
                error("Error Importing TagSet " + ExceptionUtils.getRootCauseMessage(e));
            }
        }
    } else if (aForm.getModelObject().format.equals(ExportedTagSetConstant.TAB_FORMAT)) {
        for (FileUpload tagFile : uploadedFiles) {
            InputStream tagInputStream;
            try {
                tagInputStream = tagFile.getInputStream();
                String text = IOUtils.toString(tagInputStream, "UTF-8");
                Map<String, String> tabbedTagsetFromFile = ImportUtil.getTagSetFromFile(text);
                Set<String> listOfTagsFromFile = tabbedTagsetFromFile.keySet();
                int i = 0;
                String tagSetName = "";
                String tagSetDescription = "";
                String tagsetLanguage = "";
                de.tudarmstadt.ukp.clarin.webanno.model.TagSet tagSet = null;
                for (String key : listOfTagsFromFile) {
                    // description
                    if (i == 0) {
                        tagSetName = key;
                        tagSetDescription = tabbedTagsetFromFile.get(key);
                    } else // the second key is the tagset language
                    if (i == 1) {
                        tagsetLanguage = key;
                        // exist
                        if (annotationService.existsTagSet(tagSetName, project)) {
                            // If overwrite is enabled
                            if (aForm.getModelObject().overwrite) {
                                tagSet = annotationService.getTagSet(tagSetName, project);
                                annotationService.removeAllTags(tagSet);
                            } else {
                                tagSet = new TagSet();
                                tagSet.setName(JsonImportUtil.copyTagSetName(annotationService, tagSetName, project));
                            }
                        } else {
                            tagSet = new TagSet();
                            tagSet.setName(tagSetName);
                        }
                        tagSet.setDescription(tagSetDescription.replace("\\n", "\n"));
                        tagSet.setLanguage(tagsetLanguage);
                        tagSet.setProject(project);
                        annotationService.createTagSet(tagSet);
                    } else // otherwise it is a tag entry, add the tag
                    // to the tagset
                    {
                        Tag tag = new Tag();
                        tag.setDescription(tabbedTagsetFromFile.get(key).replace("\\n", "\n"));
                        tag.setName(key);
                        tag.setTagSet(tagSet);
                        annotationService.createTag(tag);
                    }
                    i++;
                }
            } catch (Exception e) {
                error("Error importing tag set: " + ExceptionUtils.getRootCauseMessage(e));
                LOG.error("Error importing tag set", e);
            }
        }
    }
    try {
        onImportComplete(aTarget);
    } catch (Exception e) {
        error("Error importing tag set: " + ExceptionUtils.getRootCauseMessage(e));
        LOG.error("Error importing tag set", e);
    }
}
Also used : TagSet(de.tudarmstadt.ukp.clarin.webanno.model.TagSet) Set(java.util.Set) InputStream(java.io.InputStream) IOException(java.io.IOException) IOException(java.io.IOException) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) TagSet(de.tudarmstadt.ukp.clarin.webanno.model.TagSet) Tag(de.tudarmstadt.ukp.clarin.webanno.model.Tag) Map(java.util.Map) FileUpload(org.apache.wicket.markup.html.form.upload.FileUpload)

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