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);
}
}
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())));
}
}
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()));
}
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()));
}
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())));
}
}
Aggregations