Search in sources :

Example 51 with UserCourseEnvironmentImpl

use of org.olat.course.run.userview.UserCourseEnvironmentImpl in project OpenOLAT by OpenOLAT.

the class ReminderRuleEngineTest method assessmentData.

private String assessmentData(Identity tutor, Identity student, ScoreEvaluation scoreEval, RepositoryEntry re) {
    // create user course infos
    ICourse course = CourseFactory.loadCourse(re);
    List<CourseNode> assessableNodeList = AssessmentHelper.getAssessableNodes(course.getEditorTreeModel(), null);
    AssessableCourseNode testNode = null;
    for (CourseNode currentNode : assessableNodeList) {
        if (currentNode instanceof AssessableCourseNode) {
            if (currentNode.getType().equalsIgnoreCase("iqtest")) {
                testNode = (AssessableCourseNode) currentNode;
                break;
            }
        }
    }
    Assert.assertNotNull(testNode);
    Assert.assertTrue(testNode.hasScoreConfigured());
    IdentityEnvironment ienv = new IdentityEnvironment();
    ienv.setIdentity(student);
    UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
    course.getCourseEnvironment().getAssessmentManager().saveScoreEvaluation(testNode, tutor, student, scoreEval, userCourseEnv, true, Role.coach);
    dbInstance.commit();
    return testNode.getIdent();
}
Also used : AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) ICourse(org.olat.course.ICourse) CourseNode(org.olat.course.nodes.CourseNode) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) IdentityEnvironment(org.olat.core.id.IdentityEnvironment)

Example 52 with UserCourseEnvironmentImpl

use of org.olat.course.run.userview.UserCourseEnvironmentImpl in project OpenOLAT by OpenOLAT.

the class FeedMediaDispatcher method hasAccess.

/**
 * Verifies the access of an identity to a course node.
 *
 * @param identity
 * @param token
 * @param course
 * @param node
 * @return True if the identity has access to the node in the given course.
 *         False otherwise.
 */
private boolean hasAccess(Identity identity, String token, ICourse course, CourseNode node) {
    boolean hasAccess = false;
    final RepositoryManager resMgr = RepositoryManager.getInstance();
    final RepositoryEntry repoEntry = resMgr.lookupRepositoryEntry(course, false);
    if (allowsGuestAccess(repoEntry)) {
        hasAccess = true;
    } else {
        IdentityEnvironment ienv = new IdentityEnvironment();
        ienv.setIdentity(identity);
        Roles roles = BaseSecurityManager.getInstance().getRoles(identity);
        ienv.setRoles(roles);
        UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
        // Build an evaluation tree
        TreeEvaluation treeEval = new TreeEvaluation();
        NodeEvaluation nodeEval = node.eval(userCourseEnv.getConditionInterpreter(), treeEval, new VisibleTreeFilter());
        if (nodeEval.isVisible() && validAuthentication(identity, token)) {
            hasAccess = true;
        }
    }
    return hasAccess;
}
Also used : UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) TreeEvaluation(org.olat.course.run.userview.TreeEvaluation) RepositoryManager(org.olat.repository.RepositoryManager) Roles(org.olat.core.id.Roles) RepositoryEntry(org.olat.repository.RepositoryEntry) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) NodeEvaluation(org.olat.course.run.userview.NodeEvaluation)

Example 53 with UserCourseEnvironmentImpl

use of org.olat.course.run.userview.UserCourseEnvironmentImpl in project OpenOLAT by OpenOLAT.

the class CourseIndexer method checkAccess.

@Override
public boolean checkAccess(ContextEntry contextEntry, BusinessControl businessControl, Identity identity, Roles roles) {
    ContextEntry bcContextEntry = businessControl.popLauncherContextEntry();
    if (bcContextEntry == null) {
        // not a course node of course we have access to the course metadata
        return true;
    }
    if (isLogDebugEnabled())
        logDebug("Start identity=" + identity + "  roles=" + roles);
    Long repositoryKey = contextEntry.getOLATResourceable().getResourceableId();
    RepositoryEntry repositoryEntry = repositoryManager.lookupRepositoryEntry(repositoryKey);
    if (isLogDebugEnabled())
        logDebug("repositoryEntry=" + repositoryEntry);
    if (roles.isGuestOnly()) {
        if (repositoryEntry.getAccess() != RepositoryEntry.ACC_USERS_GUESTS) {
            return false;
        }
    }
    Long nodeId = bcContextEntry.getOLATResourceable().getResourceableId();
    if (isLogDebugEnabled())
        logDebug("nodeId=" + nodeId);
    ICourse course = CourseFactory.loadCourse(repositoryEntry);
    IdentityEnvironment ienv = new IdentityEnvironment();
    ienv.setIdentity(identity);
    ienv.setRoles(roles);
    UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
    if (isLogDebugEnabled())
        logDebug("userCourseEnv=" + userCourseEnv + "ienv=" + ienv);
    CourseNode rootCn = userCourseEnv.getCourseEnvironment().getRunStructure().getRootNode();
    String nodeIdS = nodeId.toString();
    CourseNode courseNode = course.getRunStructure().getNode(nodeIdS);
    if (isLogDebugEnabled())
        logDebug("courseNode=" + courseNode);
    TreeEvaluation treeEval = new TreeEvaluation();
    NodeEvaluation rootNodeEval = rootCn.eval(userCourseEnv.getConditionInterpreter(), treeEval, new VisibleTreeFilter());
    if (isLogDebugEnabled())
        logDebug("rootNodeEval=" + rootNodeEval);
    TreeNode newCalledTreeNode = treeEval.getCorrespondingTreeNode(courseNode);
    if (newCalledTreeNode == null) {
        // TreeNode no longer visible
        return false;
    }
    // go further
    NodeEvaluation nodeEval = (NodeEvaluation) newCalledTreeNode.getUserObject();
    if (isLogDebugEnabled())
        logDebug("nodeEval=" + nodeEval);
    if (nodeEval.getCourseNode() != courseNode)
        throw new AssertException("error in structure");
    if (!nodeEval.isVisible())
        throw new AssertException("node eval not visible!!");
    if (isLogDebugEnabled())
        logDebug("call mayAccessWholeTreeUp...");
    boolean mayAccessWholeTreeUp = NavigationHandler.mayAccessWholeTreeUp(nodeEval);
    if (isLogDebugEnabled())
        logDebug("call mayAccessWholeTreeUp=" + mayAccessWholeTreeUp);
    if (mayAccessWholeTreeUp) {
        CourseNodeIndexer courseNodeIndexer = getCourseNodeIndexer(courseNode);
        bcContextEntry.setTransientState(new CourseNodeEntry(courseNode));
        return courseNodeIndexer.checkAccess(bcContextEntry, businessControl, identity, roles) && super.checkAccess(bcContextEntry, businessControl, identity, roles);
    } else {
        return false;
    }
}
Also used : AssertException(org.olat.core.logging.AssertException) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) VisibleTreeFilter(org.olat.course.run.userview.VisibleTreeFilter) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) ContextEntry(org.olat.core.id.context.ContextEntry) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) CourseNodeIndexer(org.olat.search.service.indexer.repository.course.CourseNodeIndexer) TreeNode(org.olat.core.gui.components.tree.TreeNode) TreeEvaluation(org.olat.course.run.userview.TreeEvaluation) CourseNodeEntry(org.olat.search.service.indexer.repository.course.CourseNodeEntry) CourseNode(org.olat.course.nodes.CourseNode) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) NodeEvaluation(org.olat.course.run.userview.NodeEvaluation)

Example 54 with UserCourseEnvironmentImpl

use of org.olat.course.run.userview.UserCourseEnvironmentImpl in project OpenOLAT by OpenOLAT.

the class OLATUpgrade_11_0_0 method processCourseAssessmentData.

// select count(*) from o_property where name in ('SCORE','PASSED','ATTEMPTS','COMMENT','COACH_COMMENT','ASSESSMENT_ID','FULLY_ASSESSED');
private boolean processCourseAssessmentData(RepositoryEntry courseEntry) {
    boolean allOk = true;
    try {
        final Long courseResourceId = courseEntry.getOlatResource().getResourceableId();
        final ICourse course = CourseFactory.loadCourse(courseEntry);
        // load all assessable identities
        List<Identity> assessableIdentities = getAllAssessableIdentities(course, courseEntry);
        Map<AssessmentDataKey, AssessmentEntryImpl> curentNodeAssessmentMap = new HashMap<>();
        {
            // load already migrated data
            List<AssessmentEntryImpl> currentNodeAssessmentList = loadAssessmentEntries(courseEntry);
            for (AssessmentEntryImpl currentNodeAssessment : currentNodeAssessmentList) {
                AssessmentDataKey key = new AssessmentDataKey(currentNodeAssessment.getIdentity().getKey(), courseResourceId, currentNodeAssessment.getSubIdent());
                curentNodeAssessmentMap.put(key, currentNodeAssessment);
            }
        }
        Map<AssessmentDataKey, AssessmentEntryImpl> nodeAssessmentMap = new HashMap<>();
        {
            // processed properties
            List<Property> courseProperties = loadAssessmentProperties(courseEntry);
            for (Property property : courseProperties) {
                String propertyCategory = property.getCategory();
                if (StringHelper.containsNonWhitespace(propertyCategory)) {
                    int nodeIdentIndex = propertyCategory.indexOf("::");
                    if (nodeIdentIndex > 0) {
                        String nodeIdent = propertyCategory.substring(propertyCategory.indexOf("::") + 2);
                        AssessmentDataKey key = new AssessmentDataKey(property.getIdentity().getKey(), property.getResourceTypeId(), nodeIdent);
                        if (curentNodeAssessmentMap.containsKey(key)) {
                            continue;
                        }
                        AssessmentEntryImpl nodeAssessment;
                        if (nodeAssessmentMap.containsKey(key)) {
                            nodeAssessment = nodeAssessmentMap.get(key);
                            if (nodeAssessment.getCreationDate().after(property.getCreationDate())) {
                                nodeAssessment.setCreationDate(property.getCreationDate());
                            }
                            if (nodeAssessment.getLastModified().before(property.getLastModified())) {
                                nodeAssessment.setLastModified(property.getLastModified());
                            }
                        } else {
                            nodeAssessment = createAssessmentEntry(property.getIdentity(), property, course, courseEntry, nodeIdent);
                        }
                        copyAssessmentProperty(property, nodeAssessment, course);
                        nodeAssessmentMap.put(key, nodeAssessment);
                    }
                }
            }
        }
        // check the transient qti ser
        CourseNode rootNode = course.getRunStructure().getRootNode();
        new TreeVisitor(new Visitor() {

            @Override
            public void visit(INode node) {
                if (node instanceof AssessableCourseNode) {
                    processNonPropertiesStates(assessableIdentities, (AssessableCourseNode) node, course, courseEntry, nodeAssessmentMap, curentNodeAssessmentMap);
                }
            }
        }, rootNode, true).visitAll();
        dbInstance.commitAndCloseSession();
        int count = 0;
        for (AssessmentEntryImpl courseNodeAssessment : nodeAssessmentMap.values()) {
            dbInstance.getCurrentEntityManager().persist(courseNodeAssessment);
            if (++count % 50 == 0) {
                dbInstance.commit();
            }
        }
        dbInstance.commitAndCloseSession();
        allOk = verifyCourseAssessmentData(assessableIdentities, courseEntry);
        dbInstance.commitAndCloseSession();
        if (allOk) {
            List<STCourseNode> nodes = hasAssessableSTCourseNode(course);
            if (nodes.size() > 0) {
                log.info("Has assessables ST nodes");
                for (Identity identity : assessableIdentities) {
                    IdentityEnvironment identityEnv = new IdentityEnvironment(identity, null);
                    UserCourseEnvironmentImpl userCourseEnv = new UserCourseEnvironmentImpl(identityEnv, course.getCourseEnvironment());
                    userCourseEnv.getScoreAccounting().evaluateAll(true);
                    dbInstance.commit();
                }
            }
        }
    } catch (Exception e) {
        log.error("", e);
    }
    return allOk;
}
Also used : INode(org.olat.core.util.nodes.INode) TreeVisitor(org.olat.core.util.tree.TreeVisitor) Visitor(org.olat.core.util.tree.Visitor) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ICourse(org.olat.course.ICourse) CorruptedCourseException(org.olat.course.CorruptedCourseException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) AssessmentEntryImpl(org.olat.modules.assessment.model.AssessmentEntryImpl) TreeVisitor(org.olat.core.util.tree.TreeVisitor) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) STCourseNode(org.olat.course.nodes.STCourseNode) IQTESTCourseNode(org.olat.course.nodes.IQTESTCourseNode) ArrayList(java.util.ArrayList) List(java.util.List) STCourseNode(org.olat.course.nodes.STCourseNode) GTACourseNode(org.olat.course.nodes.GTACourseNode) MSCourseNode(org.olat.course.nodes.MSCourseNode) ScormCourseNode(org.olat.course.nodes.ScormCourseNode) CourseNode(org.olat.course.nodes.CourseNode) PortfolioCourseNode(org.olat.course.nodes.PortfolioCourseNode) TACourseNode(org.olat.course.nodes.TACourseNode) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) IQTESTCourseNode(org.olat.course.nodes.IQTESTCourseNode) BasicLTICourseNode(org.olat.course.nodes.BasicLTICourseNode) Identity(org.olat.core.id.Identity) TransientIdentity(org.olat.admin.user.imp.TransientIdentity) Property(org.olat.properties.Property) IdentityEnvironment(org.olat.core.id.IdentityEnvironment)

Example 55 with UserCourseEnvironmentImpl

use of org.olat.course.run.userview.UserCourseEnvironmentImpl in project OpenOLAT by OpenOLAT.

the class CourseRuntimeController method processBusinessGroupModifiedEvent.

private void processBusinessGroupModifiedEvent(BusinessGroupModifiedEvent bgme) {
    Identity identity = getIdentity();
    // was adding or removing of the user
    if (bgme.wasMyselfAdded(identity) || bgme.wasMyselfRemoved(identity)) {
        reSecurity = repositoryManager.isAllowed(getIdentity(), roles, getRepositoryEntry());
        reloadGroupMemberships(reSecurity);
        loadRights(reSecurity);
        initToolbar();
    } else if (bgme.getCommand().equals(BusinessGroupModifiedEvent.GROUPRIGHTS_MODIFIED_EVENT)) {
        // check if this affects a right group where the user does participate.
        // if so, we need to rebuild the toolboxes
        UserCourseEnvironmentImpl uce = getUserCourseEnvironment();
        if (uce != null && (PersistenceHelper.listContainsObjectByKey(uce.getParticipatingGroups(), bgme.getModifiedGroupKey()) || PersistenceHelper.listContainsObjectByKey(uce.getCoachedGroups(), bgme.getModifiedGroupKey()))) {
            reSecurity = repositoryManager.isAllowed(getIdentity(), roles, getRepositoryEntry());
            reloadGroupMemberships(reSecurity);
            loadRights(reSecurity);
            initToolbar();
        }
    }
}
Also used : UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) Identity(org.olat.core.id.Identity)

Aggregations

UserCourseEnvironmentImpl (org.olat.course.run.userview.UserCourseEnvironmentImpl)84 IdentityEnvironment (org.olat.core.id.IdentityEnvironment)60 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)58 ICourse (org.olat.course.ICourse)40 Identity (org.olat.core.id.Identity)32 RepositoryEntry (org.olat.repository.RepositoryEntry)28 CourseNode (org.olat.course.nodes.CourseNode)24 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)22 ScoreEvaluation (org.olat.course.run.scoring.ScoreEvaluation)22 Roles (org.olat.core.id.Roles)14 ArrayList (java.util.ArrayList)12 NodeEvaluation (org.olat.course.run.userview.NodeEvaluation)12 VisibleTreeFilter (org.olat.course.run.userview.VisibleTreeFilter)12 IQTESTCourseNode (org.olat.course.nodes.IQTESTCourseNode)10 BusinessGroup (org.olat.group.BusinessGroup)10 VFSContainer (org.olat.core.util.vfs.VFSContainer)8 TreeEvaluation (org.olat.course.run.userview.TreeEvaluation)8 Test (org.junit.Test)7 WebApplicationException (javax.ws.rs.WebApplicationException)6 TreeNode (org.olat.core.gui.components.tree.TreeNode)6