Search in sources :

Example 36 with Project

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

the class AnnotationPage method handleParameters.

private void handleParameters(AjaxRequestTarget aTarget, StringValue aProjectParameter, StringValue aDocumentParameter, StringValue aFocusParameter, boolean aLockIfPreset) {
    // Get current project from parameters
    Project project = null;
    try {
        project = getProjectFromParameters(aProjectParameter);
    } catch (NoResultException e) {
        error("Project [" + aProjectParameter + "] does not exist");
        return;
    }
    // Get current document from parameters
    SourceDocument document = null;
    if (project != null) {
        try {
            document = getDocumentFromParameters(project, aDocumentParameter);
        } catch (NoResultException e) {
            error("Document [" + aDocumentParameter + "] does not exist in project [" + project.getId() + "]");
        }
    }
    // Get current focus unit from parameters
    int focus = 0;
    if (aFocusParameter != null) {
        focus = aFocusParameter.toInt(0);
    }
    // there is also a document change.
    if (document != null && document.equals(getModelObject().getDocument()) && focus == getModelObject().getFocusUnitIndex()) {
        return;
    }
    // Check access to project
    if (project != null && !isAnnotator(project, projectService, getModelObject().getUser())) {
        error("You have no permission to access project [" + project.getId() + "]");
        return;
    }
    // Check if document is locked for the user
    if (project != null && document != null && documentService.existsAnnotationDocument(document, getModelObject().getUser())) {
        AnnotationDocument adoc = documentService.getAnnotationDocument(document, getModelObject().getUser());
        if (AnnotationDocumentState.IGNORE.equals(adoc.getState())) {
            error("Document [" + document.getId() + "] in project [" + project.getId() + "] is locked for user [" + getModelObject().getUser().getUsername() + "]");
            return;
        }
    }
    // i.e. not only in the case that it was a URL fragment parameter.
    if (project != null) {
        getModelObject().setProject(project);
        if (aLockIfPreset) {
            getModelObject().setProjectLocked(true);
        }
    }
    if (document != null) {
        // or a change of focus (or both)
        if (!document.equals(getModelObject().getDocument())) {
            getModelObject().setDocument(document, getListOfDocs());
            actionLoadDocument(aTarget, focus);
        } else {
            try {
                getModelObject().moveToUnit(getEditorCas(), focus);
                actionRefreshDocument(aTarget);
            } catch (Exception e) {
                aTarget.addChildren(getPage(), IFeedback.class);
                LOG.info("Error reading CAS " + e.getMessage());
                error("Error reading CAS " + e.getMessage());
            }
        }
    }
}
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) NoResultException(javax.persistence.NoResultException) IFeedback(org.apache.wicket.feedback.IFeedback) NoResultException(javax.persistence.NoResultException) IOException(java.io.IOException)

Example 37 with Project

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

the class AnnotationPage method getProjectFromParameters.

private Project getProjectFromParameters(StringValue projectParam) {
    Project project = null;
    if (projectParam != null && !projectParam.isEmpty()) {
        long projectId = projectParam.toLong();
        project = projectService.getProject(projectId);
    }
    return project;
}
Also used : Project(de.tudarmstadt.ukp.clarin.webanno.model.Project)

Example 38 with Project

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

the class AutomationPage 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 (SecurityUtil.isAnnotator(project, projectService, user) && WebAnnoConst.PROJECT_TYPE_AUTOMATION.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 39 with Project

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

the class CopyAnnotationTest method setup.

@Before
public void setup() {
    project = new Project();
    tokenLayer = new AnnotationLayer(Token.class.getName(), "Token", SPAN_TYPE, null, true);
    tokenPosFeature = new AnnotationFeature();
    tokenPosFeature.setName("pos");
    tokenPosFeature.setEnabled(true);
    tokenPosFeature.setType(POS.class.getName());
    tokenPosFeature.setUiName("pos");
    tokenPosFeature.setLayer(tokenLayer);
    tokenPosFeature.setProject(project);
    tokenPosFeature.setVisible(true);
    posLayer = new AnnotationLayer(POS.class.getName(), "POS", SPAN_TYPE, project, true);
    posLayer.setAttachType(tokenLayer);
    posLayer.setAttachFeature(tokenPosFeature);
    posFeature = new AnnotationFeature();
    posFeature.setName("PosValue");
    posFeature.setEnabled(true);
    posFeature.setType(CAS.TYPE_NAME_STRING);
    posFeature.setUiName("PosValue");
    posFeature.setLayer(posLayer);
    posFeature.setProject(project);
    posFeature.setVisible(true);
    slotLayer = new AnnotationLayer(DiffUtils.HOST_TYPE, DiffUtils.HOST_TYPE, SPAN_TYPE, project, false);
    slotFeature = new AnnotationFeature();
    slotFeature.setName("links");
    slotFeature.setEnabled(true);
    slotFeature.setType(Token.class.getName());
    slotFeature.setLinkMode(LinkMode.WITH_ROLE);
    slotFeature.setUiName("f1");
    slotFeature.setLayer(slotLayer);
    slotFeature.setProject(project);
    slotFeature.setVisible(true);
    stringFeature = new AnnotationFeature();
    stringFeature.setName("f1");
    stringFeature.setEnabled(true);
    stringFeature.setType(CAS.TYPE_NAME_STRING);
    stringFeature.setUiName("f1");
    stringFeature.setLayer(slotLayer);
    stringFeature.setProject(project);
    stringFeature.setVisible(true);
    annotationSchemaService = new MockUp<AnnotationSchemaService>() {

        @Mock
        List<AnnotationFeature> listAnnotationFeature(AnnotationLayer type) {
            if (type.getName().equals(POS.class.getName())) {
                return asList(posFeature);
            }
            if (type.getName().equals(DiffUtils.HOST_TYPE)) {
                return asList(slotFeature, stringFeature);
            }
            throw new IllegalStateException("Unknown layer type: " + type.getName());
        }

        @Mock
        TypeAdapter getAdapter(AnnotationLayer aLayer) {
            return AnnotationSchemaServiceImpl.getAdapter(annotationSchemaService, featureSupportRegistry, null, aLayer);
        }
    }.getMockInstance();
    featureSupportRegistry = new FeatureSupportRegistryImpl(asList(new PrimitiveUimaFeatureSupport(), new SlotFeatureSupport()));
    featureSupportRegistry.init();
}
Also used : Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) SlotFeatureSupport(de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.SlotFeatureSupport) POS(de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS) FeatureSupportRegistryImpl(de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.FeatureSupportRegistryImpl) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) MockUp(mockit.MockUp) PrimitiveUimaFeatureSupport(de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.PrimitiveUimaFeatureSupport) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) Before(org.junit.Before)

Example 40 with Project

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

the class ProjectImportPanel method actionImport.

private void actionImport(AjaxRequestTarget aTarget, Form<Preferences> aForm) {
    List<FileUpload> exportedProjects = fileUpload.getFileUploads();
    boolean aGenerateUsers = preferences.getObject().generateUsers;
    // import multiple projects!
    Project importedProject = null;
    for (FileUpload exportedProject : exportedProjects) {
        try {
            // Workaround for WICKET-6425
            File tempFile = File.createTempFile("webanno-training", null);
            try (InputStream is = new BufferedInputStream(exportedProject.getInputStream());
                OutputStream os = new FileOutputStream(tempFile)) {
                if (!ZipUtils.isZipStream(is)) {
                    throw new IOException("Invalid ZIP file");
                }
                IOUtils.copyLarge(is, os);
                if (!ImportUtil.isZipValidWebanno(tempFile)) {
                    throw new IOException("ZIP file is not a WebAnno project archive");
                }
                importedProject = importService.importProject(tempFile, aGenerateUsers);
            } finally {
                tempFile.delete();
            }
        } catch (Exception e) {
            aTarget.addChildren(getPage(), IFeedback.class);
            error("Error importing project: " + ExceptionUtils.getRootCauseMessage(e));
            LOG.error("Error importing project", e);
        }
    }
    if (importedProject != null) {
        selectedModel.setObject(importedProject);
        aTarget.add(getPage());
    }
}
Also used : Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) IFeedback(org.apache.wicket.feedback.IFeedback) FileUpload(org.apache.wicket.markup.html.form.upload.FileUpload) IOException(java.io.IOException)

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