Search in sources :

Example 1 with SystemFileFilter

use of org.olat.core.util.io.SystemFileFilter in project OpenOLAT by OpenOLAT.

the class CourseAssessmentManagerImpl method addIndividualAssessmentDocument.

@Override
public void addIndividualAssessmentDocument(CourseNode courseNode, Identity identity, Identity assessedIdentity, File document, String filename) {
    if (document == null)
        return;
    if (!StringHelper.containsNonWhitespace(filename)) {
        filename = document.getName();
    }
    try {
        File directory = getAssessmentDocumentsDirectory(courseNode, assessedIdentity);
        File targetFile = new File(directory, filename);
        if (targetFile.exists()) {
            String newName = FileUtils.rename(targetFile);
            targetFile = new File(directory, newName);
        }
        Files.copy(document.toPath(), targetFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
        // update counter
        AssessmentEntry nodeAssessment = getOrCreate(assessedIdentity, courseNode);
        File[] docs = directory.listFiles(new SystemFileFilter(true, false));
        int numOfDocs = docs == null ? 0 : docs.length;
        nodeAssessment.setNumberOfAssessmentDocuments(numOfDocs);
        assessmentService.updateAssessmentEntry(nodeAssessment);
        // node log
        ICourse course = CourseFactory.loadCourse(cgm.getCourseEntry());
        UserNodeAuditManager am = course.getCourseEnvironment().getAuditManager();
        am.appendToUserNodeLog(courseNode, identity, assessedIdentity, "assessment document added: " + filename);
        // user activity logging
        ThreadLocalUserActivityLogger.log(AssessmentLoggingAction.ASSESSMENT_DOCUMENT_ADDED, getClass(), LoggingResourceable.wrap(assessedIdentity), LoggingResourceable.wrapNonOlatResource(StringResourceableType.assessmentDocument, "", StringHelper.stripLineBreaks(filename)));
    } catch (IOException e) {
        log.error("", e);
    }
}
Also used : UserNodeAuditManager(org.olat.course.auditing.UserNodeAuditManager) ICourse(org.olat.course.ICourse) IOException(java.io.IOException) SystemFileFilter(org.olat.core.util.io.SystemFileFilter) File(java.io.File) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry)

Example 2 with SystemFileFilter

use of org.olat.core.util.io.SystemFileFilter in project openolat by klemens.

the class CourseAssessmentManagerImpl method removeIndividualAssessmentDocument.

@Override
public void removeIndividualAssessmentDocument(CourseNode courseNode, Identity identity, Identity assessedIdentity, File document) {
    if (document != null && document.exists()) {
        document.delete();
        // update counter
        File directory = getAssessmentDocumentsDirectory(courseNode, assessedIdentity);
        AssessmentEntry nodeAssessment = getOrCreate(assessedIdentity, courseNode);
        File[] docs = directory.listFiles(new SystemFileFilter(true, false));
        int numOfDocs = docs == null ? 0 : docs.length;
        nodeAssessment.setNumberOfAssessmentDocuments(numOfDocs);
        assessmentService.updateAssessmentEntry(nodeAssessment);
        // node log
        ICourse course = CourseFactory.loadCourse(cgm.getCourseEntry());
        UserNodeAuditManager am = course.getCourseEnvironment().getAuditManager();
        am.appendToUserNodeLog(courseNode, identity, assessedIdentity, "assessment document removed: " + document.getName());
        // user activity logging
        ThreadLocalUserActivityLogger.log(AssessmentLoggingAction.ASSESSMENT_DOCUMENT_REMOVED, getClass(), LoggingResourceable.wrap(assessedIdentity), LoggingResourceable.wrapNonOlatResource(StringResourceableType.assessmentDocument, "", StringHelper.stripLineBreaks(document.getName())));
    }
}
Also used : UserNodeAuditManager(org.olat.course.auditing.UserNodeAuditManager) ICourse(org.olat.course.ICourse) SystemFileFilter(org.olat.core.util.io.SystemFileFilter) File(java.io.File) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry)

Example 3 with SystemFileFilter

use of org.olat.core.util.io.SystemFileFilter in project openolat by klemens.

the class SubmitDocumentsController method updateModel.

private void updateModel() {
    File[] documents = documentsDir.listFiles(new SystemFileFilter(true, false));
    List<SubmittedSolution> docList = new ArrayList<>(documents.length);
    for (File document : documents) {
        String filename = document.getName();
        String uploadedBy = null;
        VFSItem item = documentsContainer.resolve(filename);
        if (item instanceof MetaTagged) {
            MetaInfo metaInfo = ((MetaTagged) item).getMetaInfo();
            if (metaInfo != null && metaInfo.getAuthorIdentityKey() != null) {
                uploadedBy = userManager.getUserDisplayName(metaInfo.getAuthorIdentityKey());
            }
        }
        FormItem download;
        if (filename.endsWith(".html")) {
            download = uifactory.addFormLink("view-" + CodeHelper.getRAMUniqueID(), "view", filename, null, flc, Link.LINK | Link.NONTRANSLATED);
            download.setUserObject(filename);
        } else {
            download = uifactory.addDownloadLink("view-" + CodeHelper.getRAMUniqueID(), filename, null, document, tableEl);
        }
        docList.add(new SubmittedSolution(document, uploadedBy, download));
    }
    model.setObjects(docList);
    tableEl.reset();
    if (maxDocs > 0 && docList.size() >= maxDocs) {
        if (uploadDocButton != null) {
            uploadDocButton.setEnabled(false);
        }
        if (createDocButton != null) {
            createDocButton.setEnabled(false);
        }
        String msg = translate("error.max.documents", new String[] { Integer.toString(maxDocs) });
        flc.contextPut("maxDocsWarning", msg);
    } else {
        if (uploadDocButton != null) {
            uploadDocButton.setEnabled(true);
        }
        if (createDocButton != null) {
            createDocButton.setEnabled(true);
        }
        flc.contextPut("maxDocsWarning", Boolean.FALSE);
    }
    flc.contextPut("hasDocuments", Boolean.valueOf(hasUploadDocuments()));
}
Also used : FormItem(org.olat.core.gui.components.form.flexible.FormItem) ArrayList(java.util.ArrayList) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) VFSItem(org.olat.core.util.vfs.VFSItem) SystemFileFilter(org.olat.core.util.io.SystemFileFilter) File(java.io.File)

Example 4 with SystemFileFilter

use of org.olat.core.util.io.SystemFileFilter in project OpenOLAT by OpenOLAT.

the class SubmitDocumentsController method updateModel.

private void updateModel() {
    File[] documents = documentsDir.listFiles(new SystemFileFilter(true, false));
    List<SubmittedSolution> docList = new ArrayList<>(documents.length);
    for (File document : documents) {
        String filename = document.getName();
        String uploadedBy = null;
        VFSItem item = documentsContainer.resolve(filename);
        if (item instanceof MetaTagged) {
            MetaInfo metaInfo = ((MetaTagged) item).getMetaInfo();
            if (metaInfo != null && metaInfo.getAuthorIdentityKey() != null) {
                uploadedBy = userManager.getUserDisplayName(metaInfo.getAuthorIdentityKey());
            }
        }
        FormItem download;
        if (filename.endsWith(".html")) {
            download = uifactory.addFormLink("view-" + CodeHelper.getRAMUniqueID(), "view", filename, null, flc, Link.LINK | Link.NONTRANSLATED);
            download.setUserObject(filename);
        } else {
            download = uifactory.addDownloadLink("view-" + CodeHelper.getRAMUniqueID(), filename, null, document, tableEl);
        }
        docList.add(new SubmittedSolution(document, uploadedBy, download));
    }
    model.setObjects(docList);
    tableEl.reset();
    if (maxDocs > 0 && docList.size() >= maxDocs) {
        if (uploadDocButton != null) {
            uploadDocButton.setEnabled(false);
        }
        if (createDocButton != null) {
            createDocButton.setEnabled(false);
        }
        String msg = translate("error.max.documents", new String[] { Integer.toString(maxDocs) });
        flc.contextPut("maxDocsWarning", msg);
    } else {
        if (uploadDocButton != null) {
            uploadDocButton.setEnabled(true);
        }
        if (createDocButton != null) {
            createDocButton.setEnabled(true);
        }
        flc.contextPut("maxDocsWarning", Boolean.FALSE);
    }
    flc.contextPut("hasDocuments", Boolean.valueOf(hasUploadDocuments()));
}
Also used : FormItem(org.olat.core.gui.components.form.flexible.FormItem) ArrayList(java.util.ArrayList) MetaTagged(org.olat.core.commons.modules.bc.meta.tagged.MetaTagged) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) VFSItem(org.olat.core.util.vfs.VFSItem) SystemFileFilter(org.olat.core.util.io.SystemFileFilter) File(java.io.File)

Example 5 with SystemFileFilter

use of org.olat.core.util.io.SystemFileFilter in project OpenOLAT by OpenOLAT.

the class CourseAssessmentManagerImpl method removeIndividualAssessmentDocument.

@Override
public void removeIndividualAssessmentDocument(CourseNode courseNode, Identity identity, Identity assessedIdentity, File document) {
    if (document != null && document.exists()) {
        document.delete();
        // update counter
        File directory = getAssessmentDocumentsDirectory(courseNode, assessedIdentity);
        AssessmentEntry nodeAssessment = getOrCreate(assessedIdentity, courseNode);
        File[] docs = directory.listFiles(new SystemFileFilter(true, false));
        int numOfDocs = docs == null ? 0 : docs.length;
        nodeAssessment.setNumberOfAssessmentDocuments(numOfDocs);
        assessmentService.updateAssessmentEntry(nodeAssessment);
        // node log
        ICourse course = CourseFactory.loadCourse(cgm.getCourseEntry());
        UserNodeAuditManager am = course.getCourseEnvironment().getAuditManager();
        am.appendToUserNodeLog(courseNode, identity, assessedIdentity, "assessment document removed: " + document.getName());
        // user activity logging
        ThreadLocalUserActivityLogger.log(AssessmentLoggingAction.ASSESSMENT_DOCUMENT_REMOVED, getClass(), LoggingResourceable.wrap(assessedIdentity), LoggingResourceable.wrapNonOlatResource(StringResourceableType.assessmentDocument, "", StringHelper.stripLineBreaks(document.getName())));
    }
}
Also used : UserNodeAuditManager(org.olat.course.auditing.UserNodeAuditManager) ICourse(org.olat.course.ICourse) SystemFileFilter(org.olat.core.util.io.SystemFileFilter) File(java.io.File) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry)

Aggregations

File (java.io.File)8 SystemFileFilter (org.olat.core.util.io.SystemFileFilter)8 ArrayList (java.util.ArrayList)4 ICourse (org.olat.course.ICourse)4 UserNodeAuditManager (org.olat.course.auditing.UserNodeAuditManager)4 AssessmentEntry (org.olat.modules.assessment.AssessmentEntry)4 IOException (java.io.IOException)2 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)2 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)2 FormItem (org.olat.core.gui.components.form.flexible.FormItem)2 VFSItem (org.olat.core.util.vfs.VFSItem)2