use of org.olat.core.commons.modules.bc.FolderEvent in project openolat by klemens.
the class ReturnboxFullAccessCallback method event.
/**
* @see org.olat.core.gui.control.DefaultController#event(org.olat.core.gui.UserRequest, org.olat.core.gui.control.Controller, org.olat.core.gui.control.Event)
*/
@Override
public void event(UserRequest ureq, Controller source, Event event) {
if (source == dropboxFolderRunController) {
if (event instanceof FolderEvent) {
FolderEvent folderEvent = (FolderEvent) event;
if (folderEvent.getCommand().equals(FolderEvent.DELETE_EVENT)) {
UserNodeAuditManager am = userCourseEnv.getCourseEnvironment().getAuditManager();
// log entry for this file
Identity coach = ureq.getIdentity();
Identity student = userCourseEnv.getIdentityEnvironment().getIdentity();
am.appendToUserNodeLog(node, coach, student, "FILE DELETED: " + folderEvent.getFilename());
}
}
} else if (source == returnboxFolderRunController) {
if (event instanceof FolderEvent) {
FolderEvent folderEvent = (FolderEvent) event;
if (folderEvent.getCommand().equals(FolderEvent.UPLOAD_EVENT) || folderEvent.getCommand().equals(FolderEvent.NEW_FILE_EVENT)) {
UserNodeAuditManager am = userCourseEnv.getCourseEnvironment().getAuditManager();
// log entry for this file
Identity coach = ureq.getIdentity();
Identity student = userCourseEnv.getIdentityEnvironment().getIdentity();
if (node instanceof AssessableCourseNode) {
AssessableCourseNode acn = (AssessableCourseNode) node;
AssessmentEvaluation eval = acn.getUserScoreEvaluation(userCourseEnv);
if (eval.getAssessmentStatus() == null || eval.getAssessmentStatus() == AssessmentEntryStatus.notStarted) {
eval = new AssessmentEvaluation(eval, AssessmentEntryStatus.inProgress);
acn.updateUserScoreEvaluation(eval, userCourseEnv, coach, false, Role.coach);
}
}
am.appendToUserNodeLog(node, coach, student, "FILE UPLOADED: " + folderEvent.getFilename());
String toMail = UserManager.getInstance().getUserDisplayEmail(student, ureq.getLocale());
OLATResourceable ores = OresHelper.createOLATResourceableInstance(CourseNode.class, Long.valueOf(node.getIdent()));
ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(ores);
BusinessControl bc = BusinessControlFactory.getInstance().createBusinessControl(ce, getWindowControl().getBusinessControl());
String link = BusinessControlFactory.getInstance().getAsURIString(bc, true);
log.debug("DEBUG : Returnbox notification email with link=" + link);
String subject = translate("returnbox.email.subject");
String body = translate("returnbox.email.body", new String[] { userCourseEnv.getCourseEnvironment().getCourseTitle(), node.getShortTitle(), folderEvent.getFilename(), link });
MailContext context = new MailContextImpl(getWindowControl().getBusinessControl().getAsString());
MailBundle bundle = new MailBundle();
bundle.setContext(context);
bundle.setToId(student);
bundle.setContent(subject, body);
MailerResult result = CoreSpringFactory.getImpl(MailManager.class).sendMessage(bundle);
if (result.getReturnCode() > 0) {
am.appendToUserNodeLog(node, coach, student, "MAIL SEND FAILED TO:" + toMail + "; MailReturnCode: " + result.getReturnCode());
log.warn("Could not send email 'returnbox notification' to " + student + "with email=" + toMail);
} else {
log.info("Send email 'returnbox notification' to " + student + "with email=" + toMail);
}
}
} else if (FolderCommand.FOLDERCOMMAND_FINISHED == event) {
if (node instanceof AssessableCourseNode) {
AssessableCourseNode acn = (AssessableCourseNode) node;
AssessmentEvaluation eval = acn.getUserScoreEvaluation(userCourseEnv);
if (eval == null) {
eval = AssessmentEvaluation.EMPTY_EVAL;
}
if (eval.getAssessmentStatus() == null || eval.getAssessmentStatus() == AssessmentEntryStatus.notStarted) {
eval = new AssessmentEvaluation(eval, AssessmentEntryStatus.inProgress);
acn.updateUserScoreEvaluation(eval, userCourseEnv, getIdentity(), false, Role.coach);
fireEvent(ureq, Event.CHANGED_EVENT);
}
}
}
} else if (source == statusForm) {
if (event == Event.DONE_EVENT) {
// get identity not from request (this would be an author)
StatusManager.getInstance().saveStatusFormData(statusForm, node, userCourseEnv);
}
} else if (source == dialogBoxController) {
if (DialogBoxUIFactory.isYesEvent(event) && assignedTask != null) {
// cancel task assignment, and show "no task assigned to user"
removeAssignedTask(userCourseEnv, userCourseEnv.getIdentityEnvironment().getIdentity());
// update UI
myContent.contextPut("assignedtask", null);
}
}
}
use of org.olat.core.commons.modules.bc.FolderEvent in project OpenOLAT by OpenOLAT.
the class CmdUpload method event.
public void event(UserRequest ureq, Controller source, Event event) {
if (source == fileUploadCtr) {
// catch upload event
if (event instanceof FolderEvent && event.getCommand().equals(FolderEvent.UPLOAD_EVENT)) {
FolderEvent folderEvent = (FolderEvent) event;
// Get file from temp folder location
uploadFileName = folderEvent.getFilename();
VFSItem vfsNewFile = currentContainer.resolve(uploadFileName);
overwritten = fileUploadCtr.isExistingFileOverwritten();
if (vfsNewFile != null) {
notifyFinished(ureq);
} else {
showError("file.element.error.general");
}
} else if (event.equals(Event.CANCELLED_EVENT)) {
if (cancelResetsForm) {
fileUploadCtr.reset();
} else {
status = FolderCommandStatus.STATUS_CANCELED;
fireEvent(ureq, FOLDERCOMMAND_FINISHED);
}
}
}
}
use of org.olat.core.commons.modules.bc.FolderEvent in project OpenOLAT by OpenOLAT.
the class CmdCreateFile method event.
public void event(UserRequest ureq, Controller source, Event event) {
if (source == editorCtr) {
if (event == Event.DONE_EVENT) {
// we're done, notify listerers
fireEvent(ureq, new FolderEvent(FolderEvent.NEW_FILE_EVENT, fileName));
notifyFinished(ureq);
} else if (event == Event.CANCELLED_EVENT) {
fireEvent(ureq, FOLDERCOMMAND_FINISHED);
}
}
}
use of org.olat.core.commons.modules.bc.FolderEvent in project OpenOLAT by OpenOLAT.
the class CmdEditMeta method event.
@Override
public void event(UserRequest ureq, Controller source, Event event) {
if (source == metaInfoCtr && event == Event.DONE_EVENT) {
MetaInfo meta = metaInfoCtr.getMetaInfo();
String fileName = metaInfoCtr.getFilename();
if (meta != null) {
meta.write();
if (metaInfoCtr.isFileRenamed()) {
// IMPORTANT: First rename the meta data because underlying file
// has to exist in order to work properly on it's meta data.
VFSContainer container = currentItem.getParentContainer();
if (container.resolve(fileName) != null) {
getWindowControl().setError(translator.translate("TargetNameAlreadyUsed"));
status = FolderCommandStatus.STATUS_FAILED;
} else {
meta.rename(fileName);
if (VFSConstants.NO.equals(currentItem.rename(fileName))) {
getWindowControl().setError(translator.translate("FileRenameFailed", new String[] { fileName }));
status = FolderCommandStatus.STATUS_FAILED;
}
}
}
}
fireEvent(ureq, new FolderEvent(FolderEvent.EDIT_EVENT, fileName));
notifyFinished(ureq);
} else if (event == Event.CANCELLED_EVENT) {
fireEvent(ureq, FOLDERCOMMAND_FINISHED);
}
}
use of org.olat.core.commons.modules.bc.FolderEvent in project OpenOLAT by OpenOLAT.
the class CmdMoveCopy method doMove.
private void doMove(UserRequest ureq) {
FolderTreeModel ftm = (FolderTreeModel) selTree.getTreeModel();
String selectedPath = ftm.getSelectedPath(selTree.getSelectedNode());
if (selectedPath == null) {
abortFailed(ureq, "failed");
return;
}
VFSStatus vfsStatus = VFSConstants.SUCCESS;
VFSContainer rootContainer = folderComponent.getRootContainer();
VFSItem vfsItem = rootContainer.resolve(selectedPath);
if (vfsItem == null || (vfsItem.canWrite() != VFSConstants.YES)) {
abortFailed(ureq, "failed");
return;
}
// copy the files
VFSContainer target = (VFSContainer) vfsItem;
List<VFSItem> sources = getSanityCheckedSourceItems(target, ureq);
if (sources == null)
return;
boolean targetIsRelPath = (target instanceof OlatRelPathImpl);
for (VFSItem vfsSource : sources) {
if (targetIsRelPath && (target instanceof OlatRelPathImpl) && (vfsSource instanceof MetaTagged)) {
// copy the metainfo first
MetaInfo meta = ((MetaTagged) vfsSource).getMetaInfo();
if (meta != null) {
meta.moveCopyToDir((OlatRelPathImpl) target, move);
}
}
VFSItem targetFile = target.resolve(vfsSource.getName());
if (vfsSource instanceof VFSLeaf && targetFile != null && targetFile instanceof Versionable && ((Versionable) targetFile).getVersions().isVersioned()) {
// add a new version to the file
((Versionable) targetFile).getVersions().addVersion(null, "", ((VFSLeaf) vfsSource).getInputStream());
} else {
vfsStatus = target.copyFrom(vfsSource);
}
if (vfsStatus != VFSConstants.SUCCESS) {
String errorKey = "failed";
if (vfsStatus == VFSConstants.ERROR_QUOTA_EXCEEDED)
errorKey = "QuotaExceeded";
abortFailed(ureq, errorKey);
return;
}
if (move) {
// if move, delete the source. Note that meta source
// has already been delete (i.e. moved)
vfsSource.delete();
}
}
// after a copy or a move, notify the subscribers
VFSSecurityCallback secCallback = VFSManager.findInheritedSecurityCallback(folderComponent.getCurrentContainer());
if (secCallback != null) {
SubscriptionContext subsContext = secCallback.getSubscriptionContext();
if (subsContext != null) {
NotificationsManager.getInstance().markPublisherNews(subsContext, ureq.getIdentity(), true);
}
}
fireEvent(ureq, new FolderEvent(move ? FolderEvent.MOVE_EVENT : FolderEvent.COPY_EVENT, fileSelection.renderAsHtml()));
notifyFinished(ureq);
}
Aggregations