Search in sources :

Example 26 with Project

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

the class ImportGuidelinesPanel method actionImport.

private void actionImport(AjaxRequestTarget aTarget, Form<Void> aForm) {
    List<FileUpload> uploadedFiles = fileUpload.getFileUploads();
    Project project = projectModel.getObject();
    if (isNull(project.getId())) {
        aTarget.addChildren(getPage(), IFeedback.class);
        error("Project not yet created, please save project details!");
        return;
    }
    if (isEmpty(uploadedFiles)) {
        aTarget.addChildren(getPage(), IFeedback.class);
        error("No document is selected to upload, please select a document first");
        return;
    }
    for (FileUpload guidelineFile : uploadedFiles) {
        try {
            // Workaround for WICKET-6425
            File tempFile = File.createTempFile("webanno-guidelines", null);
            try (InputStream is = guidelineFile.getInputStream();
                OutputStream os = new FileOutputStream(tempFile)) {
                IOUtils.copyLarge(is, os);
                String fileName = guidelineFile.getClientFileName();
                projectRepository.createGuideline(project, tempFile, fileName);
            } finally {
                tempFile.delete();
            }
        } catch (Exception e) {
            error("Unable to write guideline file " + ExceptionUtils.getRootCauseMessage(e));
        }
    }
    WicketUtil.refreshPage(aTarget, getPage());
}
Also used : Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) FileUpload(org.apache.wicket.markup.html.form.upload.FileUpload)

Example 27 with Project

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

the class CurationPage method getAllowedProjects.

private IModel<List<DecoratedObject<Project>>> getAllowedProjects() {
    return new LoadableDetachableModel<List<DecoratedObject<Project>>>() {

        private static final long serialVersionUID = -2518743298741342852L;

        @Override
        protected List<DecoratedObject<Project>> load() {
            User user = userRepository.get(SecurityContextHolder.getContext().getAuthentication().getName());
            List<DecoratedObject<Project>> allowedProject = new ArrayList<>();
            List<Project> projectsWithFinishedAnnos = projectService.listProjectsWithFinishedAnnos();
            for (Project project : projectService.listProjects()) {
                if (SecurityUtil.isCurator(project, projectService, user)) {
                    DecoratedObject<Project> dp = DecoratedObject.of(project);
                    if (projectsWithFinishedAnnos.contains(project)) {
                        dp.setColor("green");
                    } else {
                        dp.setColor("red");
                    }
                    allowedProject.add(dp);
                }
            }
            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) LoadableDetachableModel(org.apache.wicket.model.LoadableDetachableModel) ArrayList(java.util.ArrayList)

Example 28 with Project

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

the class ProjectDetailPanel method actionSave.

private void actionSave(AjaxRequestTarget aTarget, Form<Project> aForm) {
    aTarget.add(getPage());
    // aTarget.add(((ApplicationPageBase) getPage()).getPageContent());
    // aTarget.addChildren(getPage(), IFeedback.class);
    Project project = aForm.getModelObject();
    if (isNull(project.getId())) {
        try {
            String username = SecurityContextHolder.getContext().getAuthentication().getName();
            projectService.createProject(project);
            projectService.createProjectPermission(new ProjectPermission(project, username, PermissionLevel.ADMIN));
            projectService.createProjectPermission(new ProjectPermission(project, username, PermissionLevel.CURATOR));
            projectService.createProjectPermission(new ProjectPermission(project, username, PermissionLevel.USER));
            annotationService.initializeProject(project);
        } catch (IOException e) {
            error("Project repository path not found " + ":" + ExceptionUtils.getRootCauseMessage(e));
            LOG.error("Project repository path not found " + ":" + ExceptionUtils.getRootCauseMessage(e));
        }
    } else {
        projectService.updateProject(project);
    }
}
Also used : Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) ProjectPermission(de.tudarmstadt.ukp.clarin.webanno.model.ProjectPermission) IOException(java.io.IOException)

Example 29 with Project

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

the class CorrectionPage method getAllowedProjects.

private IModel<List<DecoratedObject<Project>>> getAllowedProjects() {
    return new LoadableDetachableModel<List<DecoratedObject<Project>>>() {

        private static final long serialVersionUID = -2518743298741342852L;

        @Override
        protected List<DecoratedObject<Project>> load() {
            User user = userRepository.get(SecurityContextHolder.getContext().getAuthentication().getName());
            List<DecoratedObject<Project>> allowedProject = new ArrayList<>();
            for (Project project : projectService.listProjects()) {
                if (SecurityUtil.isAnnotator(project, projectService, user) && WebAnnoConst.PROJECT_TYPE_CORRECTION.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) LoadableDetachableModel(org.apache.wicket.model.LoadableDetachableModel) ArrayList(java.util.ArrayList)

Example 30 with Project

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

the class AgreementPage method getJCases.

/**
 * Get the finished CASes used to compute agreement.
 */
private Map<String, List<JCas>> getJCases() {
    // Avoid reloading the CASes when switching features.
    if (cachedCASes != null) {
        return cachedCASes;
    }
    Project project = projectSelectionForm.getModelObject().project;
    List<User> users = projectService.listProjectUsersWithPermissions(project, PermissionLevel.USER);
    List<SourceDocument> sourceDocuments = documentService.listSourceDocuments(project);
    cachedCASes = new LinkedHashMap<>();
    for (User user : users) {
        List<JCas> cases = new ArrayList<>();
        for (SourceDocument document : sourceDocuments) {
            JCas jCas = null;
            // Load the CAS if there is a finished one.
            if (documentService.existsAnnotationDocument(document, user)) {
                AnnotationDocument annotationDocument = documentService.getAnnotationDocument(document, user);
                if (annotationDocument.getState().equals(AnnotationDocumentState.FINISHED)) {
                    try {
                        jCas = documentService.readAnnotationCas(annotationDocument);
                        annotationService.upgradeCas(jCas.getCas(), annotationDocument);
                        // REC: I think there is no need to write the CASes here. We would not
                        // want to interfere with currently active annotator users
                        // Set the CAS name in the DocumentMetaData so that we can pick it
                        // up in the Diff position for the purpose of debugging / transparency.
                        DocumentMetaData documentMetadata = DocumentMetaData.get(jCas);
                        documentMetadata.setDocumentId(annotationDocument.getDocument().getName());
                        documentMetadata.setCollectionId(annotationDocument.getProject().getName());
                    } catch (Exception e) {
                        LOG.error("Unable to load data", e);
                        error("Unable to load data: " + ExceptionUtils.getRootCauseMessage(e));
                    }
                }
            }
            // The next line can enter null values into the list if a user didn't work on this
            // source document yet.
            cases.add(jCas);
        }
        cachedCASes.put(user.getUsername(), cases);
    }
    return cachedCASes;
}
Also used : Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) User(de.tudarmstadt.ukp.clarin.webanno.security.model.User) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) ArrayList(java.util.ArrayList) JCas(org.apache.uima.jcas.JCas) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) DocumentMetaData(de.tudarmstadt.ukp.dkpro.core.api.metadata.type.DocumentMetaData) ResourceStreamNotFoundException(org.apache.wicket.util.resource.ResourceStreamNotFoundException) 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