Search in sources :

Example 11 with OlatRootFileImpl

use of org.olat.core.commons.modules.bc.vfs.OlatRootFileImpl in project OpenOLAT by OpenOLAT.

the class FileUploadController method finishSuccessfullUpload.

/**
 * Internal helper to finish the upload and add metadata
 */
private void finishSuccessfullUpload(String filePath, VFSItem item, UserRequest ureq) {
    if (item instanceof OlatRootFileImpl) {
        OlatRootFileImpl relPathItem = (OlatRootFileImpl) item;
        // create meta data
        MetaInfo meta = metaInfoFactory.createMetaInfoFor(relPathItem);
        if (metaDataCtr != null) {
            meta = metaDataCtr.getMetaInfo(meta);
        }
        meta.setAuthor(getIdentity());
        // if overwrite an older file
        meta.clearThumbnails();
        meta.write();
    }
    if (item == null) {
        logError("File cannot be uploaded: " + filePath, null);
    } else {
        ThreadLocalUserActivityLogger.log(FolderLoggingAction.FILE_UPLOADED, getClass(), CoreLoggingResourceable.wrapUploadFile(filePath));
        // Notify listeners about upload
        fireEvent(ureq, new FolderEvent(FolderEvent.UPLOAD_EVENT, item));
    }
}
Also used : MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) OlatRootFileImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFileImpl)

Example 12 with OlatRootFileImpl

use of org.olat.core.commons.modules.bc.vfs.OlatRootFileImpl in project OpenOLAT by OpenOLAT.

the class BulkAssessmentTask method doProcess.

private void doProcess(List<BulkAssessmentFeedback> feedbacks) {
    final DB dbInstance = DBFactory.getInstance();
    final BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
    final Identity coachIdentity = securityManager.loadIdentityByKey(coachedIdentity);
    final ICourse course = CourseFactory.loadCourse(courseRes);
    final AssessableCourseNode courseNode = getCourseNode();
    final Roles studentRoles = new Roles(false, false, false, false, false, false, false, false);
    final boolean hasUserComment = courseNode.hasCommentConfigured();
    final boolean hasScore = courseNode.hasScoreConfigured();
    final boolean hasPassed = courseNode.hasPassedConfigured();
    final boolean hasReturnFiles = (StringHelper.containsNonWhitespace(datas.getReturnFiles()) && (courseNode instanceof TACourseNode || courseNode instanceof GTACourseNode));
    if (hasReturnFiles) {
        try {
            OlatRootFileImpl returnFilesZipped = new OlatRootFileImpl(datas.getReturnFiles(), null);
            String tmp = FolderConfig.getCanonicalTmpDir();
            unzipped = new File(tmp, UUID.randomUUID().toString() + File.separatorChar);
            unzipped.mkdirs();
            ZipUtil.unzip(returnFilesZipped.getBasefile(), unzipped);
        } catch (Exception e) {
            log.error("Cannot unzip the return files during bulk assessment", e);
        }
    }
    Float min = null;
    Float max = null;
    Float cut = null;
    if (hasScore) {
        min = courseNode.getMinScoreConfiguration();
        max = courseNode.getMaxScoreConfiguration();
    }
    if (hasPassed) {
        cut = courseNode.getCutValueConfiguration();
    }
    int count = 0;
    List<BulkAssessmentRow> rows = datas.getRows();
    for (BulkAssessmentRow row : rows) {
        Long identityKey = row.getIdentityKey();
        if (identityKey == null) {
            feedbacks.add(new BulkAssessmentFeedback("bulk.action.no.such.user", row.getAssessedId()));
            // nothing to do
            continue;
        }
        Identity identity = securityManager.loadIdentityByKey(identityKey);
        IdentityEnvironment ienv = new IdentityEnvironment(identity, studentRoles);
        UserCourseEnvironment uce = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
        // update comment, empty string will reset comment
        String userComment = row.getComment();
        if (hasUserComment && userComment != null) {
            // Update userComment in db
            courseNode.updateUserUserComment(userComment, uce, coachIdentity);
        // LD: why do we have to update the efficiency statement?
        // EfficiencyStatementManager esm =	EfficiencyStatementManager.getInstance();
        // esm.updateUserEfficiencyStatement(uce);
        }
        // update score
        Float score = row.getScore();
        if (hasScore && score != null) {
            // score < minimum score
            if ((min != null && score.floatValue() < min.floatValue()) || (score.floatValue() < AssessmentHelper.MIN_SCORE_SUPPORTED)) {
            // "bulk.action.lessThanMin";
            } else // score > maximum score
            if ((max != null && score.floatValue() > max.floatValue()) || (score.floatValue() > AssessmentHelper.MAX_SCORE_SUPPORTED)) {
            // "bulk.action.greaterThanMax";
            } else {
                // score between minimum and maximum score
                ScoreEvaluation se;
                if (hasPassed && cut != null) {
                    Boolean passed = (score.floatValue() >= cut.floatValue()) ? Boolean.TRUE : Boolean.FALSE;
                    se = new ScoreEvaluation(score, passed);
                } else {
                    se = new ScoreEvaluation(score, null);
                }
                // Update score,passed properties in db, and the user's efficiency statement
                courseNode.updateUserScoreEvaluation(se, uce, coachIdentity, false, Role.auto);
            }
        }
        Boolean passed = row.getPassed();
        if (hasPassed && passed != null && cut == null) {
            // Configuration of manual assessment --> Display passed/not passed: yes, Type of display: Manual by tutor
            ScoreEvaluation seOld = courseNode.getUserScoreEvaluation(uce);
            Float oldScore = seOld.getScore();
            ScoreEvaluation se = new ScoreEvaluation(oldScore, passed);
            // Update score,passed properties in db, and the user's efficiency statement
            boolean incrementAttempts = false;
            courseNode.updateUserScoreEvaluation(se, uce, coachIdentity, incrementAttempts, Role.auto);
        }
        boolean identityHasReturnFile = false;
        if (hasReturnFiles && row.getReturnFiles() != null && row.getReturnFiles().size() > 0) {
            String assessedId = row.getAssessedId();
            File assessedFolder = new File(unzipped, assessedId);
            identityHasReturnFile = assessedFolder.exists();
            if (identityHasReturnFile) {
                processReturnFile(courseNode, row, uce, assessedFolder);
            }
        }
        if (courseNode instanceof GTACourseNode) {
            // push the state further
            GTACourseNode gtaNode = (GTACourseNode) courseNode;
            if ((hasScore && score != null) || (hasPassed && passed != null)) {
                // pushed to graded
                updateTasksState(gtaNode, uce, TaskProcess.grading);
            } else if (hasReturnFiles) {
                // push to revised
                updateTasksState(gtaNode, uce, TaskProcess.correction);
            }
        }
        if (count++ % 5 == 0) {
            dbInstance.commitAndCloseSession();
        } else {
            dbInstance.commit();
        }
    }
}
Also used : ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) GTACourseNode(org.olat.course.nodes.GTACourseNode) ICourse(org.olat.course.ICourse) Roles(org.olat.core.id.Roles) TACourseNode(org.olat.course.nodes.TACourseNode) GTACourseNode(org.olat.course.nodes.GTACourseNode) OlatRootFileImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFileImpl) BulkAssessmentRow(org.olat.course.assessment.model.BulkAssessmentRow) FileNotFoundException(java.io.FileNotFoundException) BaseSecurity(org.olat.basesecurity.BaseSecurity) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) BulkAssessmentFeedback(org.olat.course.assessment.model.BulkAssessmentFeedback) Identity(org.olat.core.id.Identity) File(java.io.File) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) DB(org.olat.core.commons.persistence.DB)

Example 13 with OlatRootFileImpl

use of org.olat.core.commons.modules.bc.vfs.OlatRootFileImpl in project OpenOLAT by OpenOLAT.

the class DataStepForm method backupInputDatas.

/**
 * Backup the input field for later editing purpose
 * @param val
 * @param datas
 */
private void backupInputDatas(String val, BulkAssessmentDatas datas, OlatRootFolderImpl tmpDir) {
    OlatRootFileImpl inputFile = null;
    if (StringHelper.containsNonWhitespace(datas.getDataBackupFile())) {
        inputFile = new OlatRootFileImpl(datas.getDataBackupFile(), null);
    }
    if (inputFile == null) {
        String inputFilename = UUID.randomUUID().toString() + ".csv";
        inputFile = tmpDir.createChildLeaf(inputFilename);
    }
    OutputStream out = inputFile.getOutputStream(false);
    try {
        IOUtils.write(val, out, "UTF-8");
        datas.setDataBackupFile(inputFile.getRelPath());
    } catch (IOException e) {
        logError("", e);
    } finally {
        IOUtils.closeQuietly(out);
    }
}
Also used : OutputStream(java.io.OutputStream) OlatRootFileImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFileImpl) IOException(java.io.IOException)

Example 14 with OlatRootFileImpl

use of org.olat.core.commons.modules.bc.vfs.OlatRootFileImpl in project openolat by klemens.

the class FileArtefactHandler method prefillArtefactAccordingToSource.

/**
 * @see org.olat.portfolio.EPAbstractHandler#prefillArtefactAccordingToSource(org.olat.portfolio.model.artefacts.AbstractArtefact,
 *      java.lang.Object)
 */
@Override
public void prefillArtefactAccordingToSource(AbstractArtefact artefact, Object source) {
    super.prefillArtefactAccordingToSource(artefact, source);
    if (source instanceof VFSItem) {
        VFSItem fileSource = (VFSItem) source;
        ((FileArtefact) artefact).setFilename(fileSource.getName());
        MetaInfo meta = null;
        if (fileSource instanceof MetaTagged) {
            meta = ((MetaTagged) fileSource).getMetaInfo();
        }
        if (meta != null && StringHelper.containsNonWhitespace(meta.getTitle())) {
            artefact.setTitle(meta.getTitle());
        } else {
            artefact.setTitle(fileSource.getName());
        }
        if (meta != null && StringHelper.containsNonWhitespace(meta.getComment())) {
            artefact.setDescription(meta.getComment());
        }
        artefact.setSignature(60);
        String path = ((OlatRootFileImpl) fileSource).getRelPath();
        String[] pathElements = path.split("/");
        String finalBusinessPath = null;
        String sourceInfo = null;
        // used to rebuild businessPath and source for a file:
        if (pathElements[1].equals("homes") && meta != null && pathElements[2].equals(meta.getAuthor())) {
            // from users briefcase
            String lastParts = "/";
            for (int i = 4; i < (pathElements.length - 1); i++) {
                lastParts = lastParts + pathElements[i] + "/";
            }
            sourceInfo = "Home -> " + pathElements[3] + " -> " + lastParts + fileSource.getName();
        } else if (pathElements[3].equals("BusinessGroup")) {
            // out of a businessgroup
            String lastParts = "/";
            for (int i = 5; i < (pathElements.length - 1); i++) {
                lastParts = lastParts + pathElements[i] + "/";
            }
            BusinessGroup bGroup = CoreSpringFactory.getImpl(BusinessGroupService.class).loadBusinessGroup(new Long(pathElements[4]));
            if (bGroup != null) {
                sourceInfo = bGroup.getName() + " -> " + lastParts + " -> " + fileSource.getName();
            }
            finalBusinessPath = "[BusinessGroup:" + pathElements[4] + "][toolfolder:0][path=" + lastParts + fileSource.getName() + ":0]";
        } else if (pathElements[4].equals("coursefolder")) {
            // the course folder
            sourceInfo = RepositoryManager.getInstance().lookupDisplayNameByOLATResourceableId(new Long(pathElements[2])) + " -> " + fileSource.getName();
        } else if (pathElements[1].equals("course") && pathElements[3].equals("foldernodes")) {
            // folders inside a course
            sourceInfo = RepositoryManager.getInstance().lookupDisplayNameByOLATResourceableId(new Long(pathElements[2])) + " -> " + pathElements[4] + " -> " + fileSource.getName();
            finalBusinessPath = "[RepositoryEntry:" + pathElements[2] + "][CourseNode:" + pathElements[4] + "]";
        }
        if (sourceInfo == null) {
            // unknown source, keep full path
            sourceInfo = VFSManager.getRealPath(fileSource.getParentContainer()) + "/" + fileSource.getName();
        }
        artefact.setBusinessPath(finalBusinessPath);
        artefact.setSource(sourceInfo);
    }
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) VFSItem(org.olat.core.util.vfs.VFSItem) OlatRootFileImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFileImpl)

Example 15 with OlatRootFileImpl

use of org.olat.core.commons.modules.bc.vfs.OlatRootFileImpl in project openolat by klemens.

the class FileCopyController method finishSuccessfullUpload.

private void finishSuccessfullUpload(String fileName, UserRequest ureq) {
    VFSContainer currentContainer = folderComponent.getCurrentContainer();
    VFSItem item = currentContainer.resolve(fileName);
    if (item instanceof OlatRootFileImpl) {
        OlatRootFileImpl relPathItem = (OlatRootFileImpl) item;
        // create meta data
        MetaInfo meta = CoreSpringFactory.getImpl(MetaInfoFactory.class).createMetaInfoFor(relPathItem);
        meta.setAuthor(ureq.getIdentity());
        // if overwrite an older file
        meta.clearThumbnails();
        meta.write();
    }
    ThreadLocalUserActivityLogger.log(FolderLoggingAction.FILE_COPIED, getClass(), CoreLoggingResourceable.wrapUploadFile(fileName));
    // Notify listeners about upload
    fireEvent(ureq, new FolderEvent(FolderEvent.NEW_FILE_EVENT, newFile.getName()));
    fireEvent(ureq, FolderCommand.FOLDERCOMMAND_FINISHED);
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) VFSItem(org.olat.core.util.vfs.VFSItem) MetaInfoFactory(org.olat.core.commons.modules.bc.meta.MetaInfoFactory) OlatRootFileImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFileImpl)

Aggregations

OlatRootFileImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFileImpl)18 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)6 VFSItem (org.olat.core.util.vfs.VFSItem)6 File (java.io.File)4 IOException (java.io.IOException)4 RevisionListController (org.olat.core.commons.modules.bc.version.RevisionListController)4 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)4 Roles (org.olat.core.id.Roles)4 VFSContainer (org.olat.core.util.vfs.VFSContainer)4 Versionable (org.olat.core.util.vfs.version.Versionable)4 Versions (org.olat.core.util.vfs.version.Versions)4 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStream (java.io.InputStream)2 OutputStream (java.io.OutputStream)2 HashSet (java.util.HashSet)2 ZipInputStream (java.util.zip.ZipInputStream)2 BaseSecurity (org.olat.basesecurity.BaseSecurity)2 FileLinkChooserController (org.olat.core.commons.controllers.linkchooser.FileLinkChooserController)2 URLChoosenEvent (org.olat.core.commons.controllers.linkchooser.URLChoosenEvent)2