Search in sources :

Example 1 with OLATResourceable

use of org.olat.core.id.OLATResourceable in project OpenOLAT by OpenOLAT.

the class NavigationHandler method doEvaluateJumpTo.

private NodeClickedRef doEvaluateJumpTo(UserRequest ureq, WindowControl wControl, CourseNode courseNode, ControllerEventListener listeningController, String nodecmd, String nodeSubCmd, Controller currentNodeController) {
    NodeClickedRef nclr;
    if (log.isDebug()) {
        log.debug("evaluateJumpTo courseNode = " + courseNode.getIdent() + ", " + courseNode.getShortName());
    }
    // build the new treemodel by evaluating the preconditions
    TreeEvaluation treeEval = new TreeEvaluation();
    GenericTreeModel treeModel = new GenericTreeModel();
    CourseNode rootCn = userCourseEnv.getCourseEnvironment().getRunStructure().getRootNode();
    NodeEvaluation rootNodeEval = rootCn.eval(userCourseEnv.getConditionInterpreter(), treeEval, filter);
    TreeNode treeRoot = rootNodeEval.getTreeNode();
    treeModel.setRootNode(treeRoot);
    // find the treenode that corresponds to the node (!= selectedTreeNode since
    // we built the TreeModel anew in the meantime
    TreeNode newCalledTreeNode = treeEval.getCorrespondingTreeNode(courseNode);
    if (newCalledTreeNode == null) {
        // the clicked node is not visible anymore!
        // if the new calculated model does not contain the selected node anymore
        // (because of visibility changes of at least one of the ancestors
        // -> issue an user infomative msg
        // nclr: the new treemodel, not visible, no selected nodeid, no
        // calledcoursenode, no nodeconstructionresult
        nclr = new NodeClickedRef(treeModel, false, null, null, null, null, false);
    } else {
        // calculate the NodeClickedRef
        // 1. get the correct (new) nodeevaluation
        NodeEvaluation nodeEval = (NodeEvaluation) newCalledTreeNode.getUserObject();
        if (nodeEval.getCourseNode() != courseNode) {
            throw new AssertException("error in structure");
        }
        if (!nodeEval.isVisible()) {
            throw new AssertException("node eval not visible!!");
        }
        // 2. start with the current NodeEvaluation, evaluate overall accessiblity
        // per node bottom-up to see if all ancestors still grant access to the
        // desired node
        boolean mayAccessWholeTreeUp = mayAccessWholeTreeUp(nodeEval);
        String newSelectedNodeId = newCalledTreeNode.getIdent();
        Controller controller;
        AdditionalConditionManager addMan = null;
        if (courseNode instanceof AbstractAccessableCourseNode) {
            Long courseId = userCourseEnv.getCourseEnvironment().getCourseResourceableId();
            CourseNodePasswordManager cnpm = CourseNodePasswordManagerImpl.getInstance();
            Identity identity = userCourseEnv.getIdentityEnvironment().getIdentity();
            AdditionalConditionAnswerContainer answerContainer = cnpm.getAnswerContainer(identity);
            addMan = new AdditionalConditionManager((AbstractAccessableCourseNode) courseNode, courseId, answerContainer);
        }
        if (!mayAccessWholeTreeUp || (addMan != null && !addMan.evaluateConditions())) {
            if (nodeEval.oldStyleConditionsOk()) {
                controller = addMan.nextUserInputController(ureq, wControl, userCourseEnv);
                if (listeningController != null) {
                    controller.addControllerListener(listeningController);
                }
            } else {
                // NOTE: we do not take into account what node caused the non-access by
                // being !isAtLeastOneAccessible, but always state the
                // NoAccessExplanation of the Node originally called by the user
                String explan = courseNode.getNoAccessExplanation();
                String sExplan = (explan == null ? "" : Formatter.formatLatexFormulas(explan));
                controller = MessageUIFactory.createInfoMessage(ureq, wControl, null, sExplan);
                // write log information
                ThreadLocalUserActivityLogger.log(CourseLoggingAction.COURSE_NAVIGATION_NODE_NO_ACCESS, getClass(), LoggingResourceable.wrap(courseNode));
            }
            NodeRunConstructionResult ncr = new NodeRunConstructionResult(controller, null, null, null);
            // nclr: the new treemodel, visible, selected nodeid, calledcoursenode,
            // nodeconstructionresult
            nclr = new NodeClickedRef(treeModel, true, newSelectedNodeId, null, courseNode, ncr, false);
        } else if (!CourseNodeFactory.getInstance().getCourseNodeConfigurationEvenForDisabledBB(courseNode.getType()).isEnabled()) {
            Translator pT = Util.createPackageTranslator(EditorMainController.class, ureq.getLocale());
            controller = MessageUIFactory.createInfoMessage(ureq, wControl, null, pT.translate("course.building.block.disabled.user"));
            NodeRunConstructionResult ncr = new NodeRunConstructionResult(controller, null, null, null);
            nclr = new NodeClickedRef(treeModel, true, newSelectedNodeId, null, courseNode, ncr, false);
        } else {
            if (STCourseNode.isDelegatingSTCourseNode(courseNode) && (courseNode.getChildCount() > 0)) {
                // the clicked node is a STCourse node and is set to "delegate", so
                // delegate to its first visible child; if no child is visible, just skip and do normal eval
                INode child;
                for (int i = 0; i < courseNode.getChildCount(); i++) {
                    child = courseNode.getChildAt(i);
                    if (child instanceof CourseNode) {
                        CourseNode cn = (CourseNode) child;
                        NodeEvaluation cnEval = cn.eval(userCourseEnv.getConditionInterpreter(), treeEval, filter);
                        if (cnEval.isVisible()) {
                            return doEvaluateJumpTo(ureq, wControl, cn, listeningController, nodecmd, nodeSubCmd, currentNodeController);
                        }
                    }
                }
            }
            // access the node, display its result in the right pane
            NodeRunConstructionResult ncr;
            // calculate the new businesscontext for the coursenode being called.
            // type: class of node; key = node.getIdent;
            // don't use the concrete instance since for the course: to jump to a coursenode with a given id is all there is to know
            Class<CourseNode> oresC = CourseNode.class;
            Long oresK = new Long(Long.parseLong(courseNode.getIdent()));
            final OLATResourceable ores = OresHelper.createOLATResourceableInstance(oresC, oresK);
            ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(ores);
            WindowControl bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ce, wControl);
            if (previewMode) {
                ncr = new NodeRunConstructionResult(courseNode.createPreviewController(ureq, bwControl, userCourseEnv, nodeEval));
            } else {
                // cleanup already existing controllers with external models for this node first, never disposed otherwise
                if (externalTreeModels.containsKey(courseNode.getIdent()) && !(TreeEvent.COMMAND_TREENODE_OPEN.equals(nodeSubCmd) || TreeEvent.COMMAND_TREENODE_CLOSE.equals(nodeSubCmd))) {
                    SubTree subTree = externalTreeModels.get(courseNode.getIdent());
                    ControllerEventListener existingSubtreemodelListener = subTree.getTreeModelListener();
                    if (existingSubtreemodelListener != null && currentNodeController != null && !currentNodeController.isDisposed()) {
                        currentNodeController.dispose();
                    }
                }
                ncr = courseNode.createNodeRunConstructionResult(ureq, bwControl, userCourseEnv, nodeEval, nodecmd);
                // remember as instance variable for next click
                ControllerEventListener subtreemodelListener = ncr.getSubTreeListener();
                if (subtreemodelListener != null) {
                    GenericTreeModel subTreeModel = (GenericTreeModel) ncr.getSubTreeModel();
                    externalTreeModels.put(courseNode.getIdent(), new SubTree(ncr.getRunController(), subTreeModel, subtreemodelListener));
                    if (!newSelectedNodeId.equals(ncr.getSelectedTreeNodeId())) {
                        if (ncr.getSelectedTreeNodeId() != null) {
                            TreeNode selectedNode = subTreeModel.getNodeById(ncr.getSelectedTreeNodeId());
                            if (selectedNode != null && selectedNode.getUserObject() instanceof String) {
                                openCourseNodeIds.add((String) selectedNode.getUserObject());
                            }
                        }
                    }
                }
            }
            if (TreeEvent.COMMAND_TREENODE_OPEN.equals(nodeSubCmd)) {
                openCourseNodeIds.add(courseNode.getIdent());
                newSelectedNodeId = convertToTreeNodeId(treeEval, selectedCourseNodeId);
            } else if (TreeEvent.COMMAND_TREENODE_CLOSE.equals(nodeSubCmd)) {
                removeChildrenFromOpenNodes(courseNode);
                newSelectedNodeId = convertToTreeNodeId(treeEval, selectedCourseNodeId);
                if (!isInParentLine(courseNode)) {
                    selectedCourseNodeId = courseNode.getIdent();
                } else {
                    selectedCourseNodeId = null;
                    newSelectedNodeId = null;
                }
            } else {
                // add the selected node to the open one, if not, strange behaviour
                selectedCourseNodeId = courseNode.getIdent();
                openCourseNodeIds.add(selectedCourseNodeId);
                if (ncr != null) {
                    String subNodeId = ncr.getSelectedTreeNodeId();
                    if (subNodeId != null) {
                        openCourseNodeIds.add(subNodeId);
                    }
                }
            }
            openTreeNodeIds = convertToTreeNodeIds(treeEval, openCourseNodeIds);
            reattachExternalTreeModels(treeEval);
            if ((TreeEvent.COMMAND_TREENODE_OPEN.equals(nodeSubCmd) || TreeEvent.COMMAND_TREENODE_CLOSE.equals(nodeSubCmd)) && currentNodeController != null && !currentNodeController.isDisposed()) {
                nclr = new NodeClickedRef(treeModel, true, null, openTreeNodeIds, null, null, false);
            } else {
                // nclr: the new treemodel, visible, selected nodeid, calledcoursenode,
                // nodeconstructionresult
                nclr = new NodeClickedRef(treeModel, true, newSelectedNodeId, openTreeNodeIds, courseNode, ncr, false);
                // attach listener; we know we have a runcontroller here
                if (listeningController != null) {
                    nclr.getRunController().addControllerListener(listeningController);
                }
            }
            // write log information
            ThreadLocalUserActivityLogger.log(CourseLoggingAction.COURSE_NAVIGATION_NODE_ACCESS, getClass(), LoggingResourceable.wrap(courseNode));
        }
    }
    return nclr;
}
Also used : INode(org.olat.core.util.nodes.INode) OLATResourceable(org.olat.core.id.OLATResourceable) AdditionalConditionManager(org.olat.course.condition.additionalconditions.AdditionalConditionManager) WindowControl(org.olat.core.gui.control.WindowControl) ContextEntry(org.olat.core.id.context.ContextEntry) ControllerEventListener(org.olat.core.gui.control.ControllerEventListener) Translator(org.olat.core.gui.translator.Translator) GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode) GenericTreeModel(org.olat.core.gui.components.tree.GenericTreeModel) CourseNode(org.olat.course.nodes.CourseNode) AbstractAccessableCourseNode(org.olat.course.nodes.AbstractAccessableCourseNode) STCourseNode(org.olat.course.nodes.STCourseNode) Identity(org.olat.core.id.Identity) EditorMainController(org.olat.course.editor.EditorMainController) AssertException(org.olat.core.logging.AssertException) EditorMainController(org.olat.course.editor.EditorMainController) TitledWrapperController(org.olat.core.gui.control.generic.title.TitledWrapperController) CPRunController(org.olat.course.nodes.cp.CPRunController) Controller(org.olat.core.gui.control.Controller) CourseNodePasswordManager(de.bps.course.nodes.CourseNodePasswordManager) TreeEvaluation(org.olat.course.run.userview.TreeEvaluation) AbstractAccessableCourseNode(org.olat.course.nodes.AbstractAccessableCourseNode) NodeEvaluation(org.olat.course.run.userview.NodeEvaluation) AdditionalConditionAnswerContainer(org.olat.course.condition.additionalconditions.AdditionalConditionAnswerContainer)

Example 2 with OLATResourceable

use of org.olat.core.id.OLATResourceable in project OpenOLAT by OpenOLAT.

the class CourseSiteContextEntryControllerCreator method createLaunchController.

/**
 * Create a launch controller used to launch the given repo entry.
 * @param re
 * @param initialViewIdentifier if null the default view will be started, otherwise a controllerfactory type dependant view will be activated (subscription subtype)
 * @param ureq
 * @param wControl
 * @return null if no entry was found, a no access message controller if not allowed to launch or the launch
 * controller if successful.
 */
private Controller createLaunchController(RepositoryEntry re, UserRequest ureq, WindowControl wControl) {
    if (re == null) {
        return messageController(ureq, wControl, "repositoryentry.not.existing");
    }
    UserSession usess = ureq.getUserSession();
    if (re.getAccess() == RepositoryEntry.DELETED) {
        Roles roles = usess.getRoles();
        if (!roles.isInstitutionalResourceManager() && !roles.isOLATAdmin()) {
            return messageController(ureq, wControl, "repositoryentry.deleted");
        }
    }
    if (usess.isInAssessmentModeProcess() && !usess.matchLockResource(re.getOlatResource())) {
        return null;
    }
    RepositoryManager rm = RepositoryManager.getInstance();
    RepositoryEntrySecurity reSecurity = rm.isAllowed(ureq, re);
    if (!reSecurity.canLaunch()) {
        return messageController(ureq, wControl, "launch.noaccess");
    }
    RepositoryService rs = CoreSpringFactory.getImpl(RepositoryService.class);
    rs.incrementLaunchCounter(re);
    RepositoryHandler handler = RepositoryHandlerFactory.getInstance().getRepositoryHandler(re);
    WindowControl bwControl;
    OLATResourceable businessOres = re;
    ContextEntry ce = BusinessControlFactory.getInstance().createContextEntry(businessOres);
    if (ce.equals(wControl.getBusinessControl().getCurrentContextEntry())) {
        bwControl = wControl;
    } else {
        bwControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ce, wControl);
    }
    MainLayoutController ctrl = handler.createLaunchController(re, reSecurity, ureq, bwControl);
    if (ctrl == null) {
        throw new AssertException("could not create controller for repositoryEntry " + re);
    }
    return ctrl;
}
Also used : AssertException(org.olat.core.logging.AssertException) OLATResourceable(org.olat.core.id.OLATResourceable) RepositoryEntrySecurity(org.olat.repository.model.RepositoryEntrySecurity) UserSession(org.olat.core.util.UserSession) MainLayoutController(org.olat.core.gui.control.generic.layout.MainLayoutController) Roles(org.olat.core.id.Roles) RepositoryManager(org.olat.repository.RepositoryManager) RepositoryHandler(org.olat.repository.handlers.RepositoryHandler) WindowControl(org.olat.core.gui.control.WindowControl) ContextEntry(org.olat.core.id.context.ContextEntry) RepositoryService(org.olat.repository.RepositoryService)

Example 3 with OLATResourceable

use of org.olat.core.id.OLATResourceable in project OpenOLAT by OpenOLAT.

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 4 with OLATResourceable

use of org.olat.core.id.OLATResourceable in project OpenOLAT by OpenOLAT.

the class QTIQPoolServiceProvider method importRepositoryEntry.

public List<QuestionItem> importRepositoryEntry(Identity owner, RepositoryEntry repositoryEntry, Locale defaultLocale) {
    OLATResourceable ores = repositoryEntry.getOlatResource();
    FileResourceManager frm = FileResourceManager.getInstance();
    File testFile = frm.getFileResource(ores);
    List<QuestionItem> importedItem = importItems(owner, defaultLocale, testFile.getName(), testFile);
    if (importedItem != null && importedItem.size() > 0) {
        dbInstance.getCurrentEntityManager().flush();
    }
    return importedItem;
}
Also used : FileResourceManager(org.olat.fileresource.FileResourceManager) OLATResourceable(org.olat.core.id.OLATResourceable) File(java.io.File) QuestionItem(org.olat.modules.qpool.QuestionItem)

Example 5 with OLATResourceable

use of org.olat.core.id.OLATResourceable in project OpenOLAT by OpenOLAT.

the class BinderController method doOpenAssessment.

private BinderAssessmentController doOpenAssessment(UserRequest ureq) {
    OLATResourceable bindersOres = OresHelper.createOLATResourceableInstance("Assessment", 0l);
    WindowControl swControl = addToHistory(ureq, bindersOres, null);
    assessmentCtrl = new BinderAssessmentController(ureq, swControl, secCallback, binder, config);
    listenTo(assessmentCtrl);
    popUpToBinderController(ureq);
    stackPanel.pushController(translate("portfolio.assessment"), assessmentCtrl);
    segmentButtonsCmp.setSelectedButton(assessmentLink);
    return assessmentCtrl;
}
Also used : OLATResourceable(org.olat.core.id.OLATResourceable) WindowControl(org.olat.core.gui.control.WindowControl)

Aggregations

OLATResourceable (org.olat.core.id.OLATResourceable)924 WindowControl (org.olat.core.gui.control.WindowControl)304 Test (org.junit.Test)158 Identity (org.olat.core.id.Identity)154 RepositoryEntry (org.olat.repository.RepositoryEntry)130 ContextEntry (org.olat.core.id.context.ContextEntry)82 ArrayList (java.util.ArrayList)68 OLATResource (org.olat.resource.OLATResource)60 Controller (org.olat.core.gui.control.Controller)48 Date (java.util.Date)46 AssertException (org.olat.core.logging.AssertException)32 StateSite (org.olat.core.id.context.StateSite)30 SyncerExecutor (org.olat.core.util.coordinate.SyncerExecutor)30 ICourse (org.olat.course.ICourse)30 CourseNode (org.olat.course.nodes.CourseNode)28 DBCheckbox (org.olat.course.nodes.cl.model.DBCheckbox)28 BusinessControl (org.olat.core.id.context.BusinessControl)24 BusinessGroup (org.olat.group.BusinessGroup)24 LayoutMain3ColsController (org.olat.core.commons.fullWebApp.LayoutMain3ColsController)22 BinderSecurityCallback (org.olat.modules.portfolio.BinderSecurityCallback)22