Search in sources :

Example 16 with FolderEvent

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);
        }
    }
}
Also used : MailContextImpl(org.olat.core.util.mail.MailContextImpl) AssessmentEvaluation(org.olat.course.run.scoring.AssessmentEvaluation) OLATResourceable(org.olat.core.id.OLATResourceable) MailContext(org.olat.core.util.mail.MailContext) MailerResult(org.olat.core.util.mail.MailerResult) BusinessControl(org.olat.core.id.context.BusinessControl) ContextEntry(org.olat.core.id.context.ContextEntry) UserNodeAuditManager(org.olat.course.auditing.UserNodeAuditManager) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) FolderEvent(org.olat.core.commons.modules.bc.FolderEvent) CourseNode(org.olat.course.nodes.CourseNode) TACourseNode(org.olat.course.nodes.TACourseNode) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) Identity(org.olat.core.id.Identity) MailBundle(org.olat.core.util.mail.MailBundle)

Example 17 with FolderEvent

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);
            }
        }
    }
}
Also used : VFSItem(org.olat.core.util.vfs.VFSItem) FolderEvent(org.olat.core.commons.modules.bc.FolderEvent)

Example 18 with FolderEvent

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);
        }
    }
}
Also used : FolderEvent(org.olat.core.commons.modules.bc.FolderEvent)

Example 19 with FolderEvent

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);
    }
}
Also used : VFSContainer(org.olat.core.util.vfs.VFSContainer) MetaInfo(org.olat.core.commons.modules.bc.meta.MetaInfo) FolderEvent(org.olat.core.commons.modules.bc.FolderEvent)

Example 20 with FolderEvent

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);
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) FolderTreeModel(org.olat.core.gui.control.generic.folder.FolderTreeModel) OlatRelPathImpl(org.olat.core.util.vfs.OlatRelPathImpl) VFSContainer(org.olat.core.util.vfs.VFSContainer) 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) Versionable(org.olat.core.util.vfs.version.Versionable) VFSStatus(org.olat.core.util.vfs.VFSStatus) FolderEvent(org.olat.core.commons.modules.bc.FolderEvent) SubscriptionContext(org.olat.core.commons.services.notifications.SubscriptionContext) VFSSecurityCallback(org.olat.core.util.vfs.callbacks.VFSSecurityCallback)

Aggregations

FolderEvent (org.olat.core.commons.modules.bc.FolderEvent)28 VFSItem (org.olat.core.util.vfs.VFSItem)14 MetaInfo (org.olat.core.commons.modules.bc.meta.MetaInfo)10 VFSContainer (org.olat.core.util.vfs.VFSContainer)8 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)8 MetaTagged (org.olat.core.commons.modules.bc.meta.tagged.MetaTagged)6 ArrayList (java.util.ArrayList)4 Link (org.olat.core.gui.components.link.Link)4 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)4 OlatRelPathImpl (org.olat.core.util.vfs.OlatRelPathImpl)4 FileChoosenEvent (org.olat.core.commons.controllers.filechooser.FileChoosenEvent)2 FolderRunController (org.olat.core.commons.modules.bc.FolderRunController)2 OlatNamedContainerImpl (org.olat.core.commons.modules.bc.vfs.OlatNamedContainerImpl)2 OlatRootFolderImpl (org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl)2 Size (org.olat.core.commons.services.image.Size)2 SubscriptionContext (org.olat.core.commons.services.notifications.SubscriptionContext)2 TableEvent (org.olat.core.gui.components.table.TableEvent)2 TableMultiSelectEvent (org.olat.core.gui.components.table.TableMultiSelectEvent)2 GenericTreeNode (org.olat.core.gui.components.tree.GenericTreeNode)2 TreeEvent (org.olat.core.gui.components.tree.TreeEvent)2