Search in sources :

Example 1 with Project

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

the class AnnotationPage method getAllowedProjects.

private IModel<List<DecoratedObject<Project>>> getAllowedProjects() {
    return LambdaModel.of(() -> {
        User user = userRepository.getCurrentUser();
        List<DecoratedObject<Project>> allowedProject = new ArrayList<>();
        for (Project project : projectService.listProjects()) {
            if (isAnnotator(project, projectService, user) && WebAnnoConst.PROJECT_TYPE_ANNOTATION.equals(project.getMode())) {
                allowedProject.add(DecoratedObject.of(project));
            }
        }
        return allowedProject;
    });
}
Also used : Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) DecoratedObject(de.tudarmstadt.ukp.clarin.webanno.support.wicket.DecoratedObject) User(de.tudarmstadt.ukp.clarin.webanno.security.model.User) ArrayList(java.util.ArrayList)

Example 2 with Project

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

the class WebhookServiceTest method test.

@Test
public void test() {
    Webhook hook = new Webhook();
    hook.setUrl("http://localhost:" + port + "/test/subscribe");
    hook.setTopics(asList(PROJECT_STATE, ANNOTATION_STATE, DOCUMENT_STATE));
    hook.setEnabled(true);
    webhooksConfiguration.setGlobalHooks(asList(hook));
    Project project = new Project();
    project.setState(ProjectState.NEW);
    project.setId(1l);
    SourceDocument doc = new SourceDocument();
    doc.setProject(project);
    doc.setId(2l);
    doc.setState(SourceDocumentState.ANNOTATION_IN_PROGRESS);
    AnnotationDocument ann = new AnnotationDocument();
    ann.setProject(project);
    ann.setId(3l);
    ann.setDocument(doc);
    ann.setState(AnnotationDocumentState.FINISHED);
    applicationEventPublisher.publishEvent(new ProjectStateChangedEvent(this, project, ProjectState.CURATION_FINISHED));
    applicationEventPublisher.publishEvent(new DocumentStateChangedEvent(this, doc, SourceDocumentState.NEW));
    applicationEventPublisher.publishEvent(new AnnotationStateChangeEvent(this, ann, AnnotationDocumentState.IN_PROGRESS));
    assertEquals(1, testService.projectStateChangeMsgs.size());
    assertEquals(1, testService.docStateChangeMsgs.size());
    assertEquals(1, testService.annStateChangeMsgs.size());
}
Also used : Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) ProjectStateChangedEvent(de.tudarmstadt.ukp.clarin.webanno.api.event.ProjectStateChangedEvent) AnnotationStateChangeEvent(de.tudarmstadt.ukp.clarin.webanno.api.event.AnnotationStateChangeEvent) DocumentStateChangedEvent(de.tudarmstadt.ukp.clarin.webanno.api.event.DocumentStateChangedEvent) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with Project

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

the class MiraAutomationServiceImpl method removeTrainingDocument.

@Override
@Transactional
public void removeTrainingDocument(TrainingDocument aDocument) throws IOException {
    entityManager.remove(aDocument);
    String path = dir.getAbsolutePath() + "/" + PROJECT_FOLDER + "/" + aDocument.getProject().getId() + TRAIN + aDocument.getId();
    // remove from file both source and related annotation file
    if (new File(path).exists()) {
        FileUtils.forceDelete(new File(path));
    }
    try (MDC.MDCCloseable closable = MDC.putCloseable(Logging.KEY_PROJECT_ID, String.valueOf(aDocument.getProject().getId()))) {
        Project project = aDocument.getProject();
        log.info("Removed source document [{}]({}) from project [{}]({})", aDocument.getName(), aDocument.getId(), project.getName(), project.getId());
    }
}
Also used : Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) File(java.io.File) MDC(org.slf4j.MDC) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Project

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

the class MiraAutomationServiceImpl method uploadTrainingDocument.

@Override
@Transactional
public void uploadTrainingDocument(File aFile, TrainingDocument aDocument) throws IOException {
    // Check if the file has a valid format / can be converted without error
    JCas cas = null;
    try {
        if (aDocument.getFormat().equals(WebAnnoConst.TAB_SEP)) {
            if (!isTabSepFileFormatCorrect(aFile)) {
                throw new IOException("This TAB-SEP file is not in correct format. It should have two columns separated by TAB!");
            }
        } else {
            cas = importExportService.importCasFromFile(aFile, aDocument.getProject(), aDocument.getFormat());
            automationCasStorageService.analyzeAndRepair(aDocument, cas.getCas());
        }
    } catch (IOException e) {
        removeTrainingDocument(aDocument);
        throw e;
    } catch (Exception e) {
        removeTrainingDocument(aDocument);
        throw new IOException(e.getMessage(), e);
    }
    // Copy the original file into the repository
    File targetFile = getTrainingDocumentFile(aDocument);
    FileUtils.forceMkdir(targetFile.getParentFile());
    FileUtils.copyFile(aFile, targetFile);
    // Copy the initial conversion of the file into the repository
    if (cas != null) {
        CasPersistenceUtils.writeSerializedCas(cas, getCasFile(aDocument));
    }
    try (MDC.MDCCloseable closable = MDC.putCloseable(Logging.KEY_PROJECT_ID, String.valueOf(aDocument.getProject().getId()))) {
        Project project = aDocument.getProject();
        log.info("Imported training document [{}]({}) to project [{}]({})", aDocument.getName(), aDocument.getId(), project.getName(), project.getId());
    }
}
Also used : Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) JCas(org.apache.uima.jcas.JCas) IOException(java.io.IOException) File(java.io.File) MDC(org.slf4j.MDC) NoResultException(javax.persistence.NoResultException) ResourceInitializationException(org.apache.uima.resource.ResourceInitializationException) CASException(org.apache.uima.cas.CASException) UIMAException(org.apache.uima.UIMAException) IOException(java.io.IOException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with Project

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

the class FixAttachFeature330 method doMigration.

private void doMigration() {
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("migrationRoot");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    TransactionStatus status = null;
    try {
        status = txManager.getTransaction(def);
        for (Project project : projectService.listProjects()) {
            try {
                AnnotationLayer tokenLayer = annotationSchemaService.getLayer(Token.class.getName(), project);
                // Set attach-feature of Dependency layer to Token.pos if necessary
                fix(project, Dependency.class, RELATION_TYPE, tokenLayer, "pos");
                // Set attach-feature of POS layer to Token.pos if necessary
                fix(project, POS.class, SPAN_TYPE, tokenLayer, "pos");
                // Set attach-feature of Lemma layer to Token.lemma if necessary
                fix(project, Lemma.class, SPAN_TYPE, tokenLayer, "lemma");
                // Set attach-feature of MorphologicalFeatures layer to Token.morph if necessary
                fix(project, MorphologicalFeatures.class, SPAN_TYPE, tokenLayer, "morph");
            } catch (NoResultException e) {
                // This only happens if a project is not fully set up. Every project
                // should have a Token layer. However, it is not the responsibility of this
                // migration to enforce this, so we just ignore it.
                log.warn("Project {} does not seem to include a Token layer!", project);
            }
        }
        txManager.commit(status);
    } finally {
        if (status != null && !status.isCompleted()) {
            txManager.rollback(status);
        }
    }
}
Also used : Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) TransactionStatus(org.springframework.transaction.TransactionStatus) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) NoResultException(javax.persistence.NoResultException) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)

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