Search in sources :

Example 76 with IdentityEnvironment

use of org.olat.core.id.IdentityEnvironment in project openolat by klemens.

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 77 with IdentityEnvironment

use of org.olat.core.id.IdentityEnvironment in project openolat by klemens.

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 78 with IdentityEnvironment

use of org.olat.core.id.IdentityEnvironment in project openolat by klemens.

the class ConditionTest method getUserDemoCourseEnvironment.

private UserCourseEnvironment getUserDemoCourseEnvironment() {
    Identity author = JunitTestHelper.createAndPersistIdentityAsUser("junit_auth-" + UUID.randomUUID().toString());
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("condition");
    Roles roles = new Roles(false, false, false, false, false, false, false);
    RepositoryEntry re = JunitTestHelper.deployDemoCourse(author);
    ICourse course = CourseFactory.loadCourse(re);
    IdentityEnvironment identityEnv = new IdentityEnvironment(id, roles);
    UserCourseEnvironment uce = new UserCourseEnvironmentImpl(identityEnv, course.getCourseEnvironment());
    return uce;
}
Also used : UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) Roles(org.olat.core.id.Roles) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment)

Example 79 with IdentityEnvironment

use of org.olat.core.id.IdentityEnvironment in project openolat by klemens.

the class PFManagerTest method uploadFileToDropBox.

@Test
public void uploadFileToDropBox() throws URISyntaxException {
    // prepare
    Identity initialAuthor = JunitTestHelper.createAndPersistIdentityAsRndUser("check-17");
    IdentityEnvironment ienv = new IdentityEnvironment();
    ienv.setIdentity(initialAuthor);
    PFCourseNode pfNode = new PFCourseNode();
    pfNode.getModuleConfiguration().setBooleanEntry(PFCourseNode.CONFIG_KEY_COACHBOX, true);
    pfNode.getModuleConfiguration().setBooleanEntry(PFCourseNode.CONFIG_KEY_PARTICIPANTBOX, true);
    // import "Demo course" into the bcroot_junittest
    RepositoryEntry entry = JunitTestHelper.deployDemoCourse(initialAuthor);
    Long resourceableId = entry.getOlatResource().getResourceableId();
    ICourse course = CourseFactory.loadCourse(resourceableId);
    CourseEnvironment courseEnv = course.getCourseEnvironment();
    // create files
    URL portraitUrl = JunitTestHelper.class.getResource("file_resources/IMG_1482.JPG");
    assertNotNull(portraitUrl);
    File portrait = new File(portraitUrl.toURI());
    boolean fileCreated = pfManager.uploadFileToDropBox(portrait, "textfile1", 1, courseEnv, pfNode, initialAuthor);
    boolean fileNotCreated = pfManager.uploadFileToDropBox(portrait, "textfile2", 0, courseEnv, pfNode, initialAuthor);
    Path relPath = Paths.get(PFManager.FILENAME_PARTICIPANTFOLDER, pfNode.getIdent(), pfManager.getIdFolderName(initialAuthor), PFManager.FILENAME_DROPBOX);
    OlatRootFolderImpl baseContainer = courseEnv.getCourseBaseContainer();
    VFSContainer dropboxContainer = VFSManager.resolveOrCreateContainerFromPath(baseContainer, relPath.toString());
    // check
    Assert.assertTrue(fileCreated);
    Assert.assertTrue(!fileNotCreated);
    Assert.assertTrue("textfile1".equals(dropboxContainer.getItems().get(0).getName()));
}
Also used : Path(java.nio.file.Path) PFCourseNode(org.olat.course.nodes.PFCourseNode) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) VFSContainer(org.olat.core.util.vfs.VFSContainer) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) URL(java.net.URL) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) Identity(org.olat.core.id.Identity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) File(java.io.File) Test(org.junit.Test)

Example 80 with IdentityEnvironment

use of org.olat.core.id.IdentityEnvironment in project openolat by klemens.

the class PFManagerTest method uploadFileToAllReturnBoxes.

@Test
public void uploadFileToAllReturnBoxes() throws URISyntaxException {
    // prepare
    Identity initialAuthor = JunitTestHelper.createAndPersistIdentityAsRndUser("check-18");
    IdentityEnvironment ienv = new IdentityEnvironment();
    ienv.setIdentity(initialAuthor);
    PFCourseNode pfNode = new PFCourseNode();
    pfNode.getModuleConfiguration().setBooleanEntry(PFCourseNode.CONFIG_KEY_COACHBOX, true);
    pfNode.getModuleConfiguration().setBooleanEntry(PFCourseNode.CONFIG_KEY_PARTICIPANTBOX, true);
    // import "Demo course" into the bcroot_junittest
    RepositoryEntry entry = JunitTestHelper.deployDemoCourse(initialAuthor);
    Long resourceableId = entry.getOlatResource().getResourceableId();
    ICourse course = CourseFactory.loadCourse(resourceableId);
    CourseEnvironment courseEnv = course.getCourseEnvironment();
    List<Identity> identities = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        identities.add(JunitTestHelper.createAndPersistIdentityAsRndUser("pf-user-" + i));
    }
    URL portraitUrl = JunitTestHelper.class.getResource("file_resources/IMG_1482.JPG");
    assertNotNull(portraitUrl);
    File portrait = new File(portraitUrl.toURI());
    pfManager.uploadFileToAllReturnBoxes(portrait, "textfile3", courseEnv, pfNode, identities);
    // check
    for (Identity identity : identities) {
        Path relPath = Paths.get(PFManager.FILENAME_PARTICIPANTFOLDER, pfNode.getIdent(), pfManager.getIdFolderName(identity), PFManager.FILENAME_RETURNBOX);
        OlatRootFolderImpl baseContainer = courseEnv.getCourseBaseContainer();
        VFSContainer returnboxContainer = VFSManager.resolveOrCreateContainerFromPath(baseContainer, relPath.toString());
        Assert.assertTrue("textfile3".equals(returnboxContainer.getItems().get(0).getName()));
    }
}
Also used : Path(java.nio.file.Path) PFCourseNode(org.olat.course.nodes.PFCourseNode) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) VFSContainer(org.olat.core.util.vfs.VFSContainer) ArrayList(java.util.ArrayList) ICourse(org.olat.course.ICourse) RepositoryEntry(org.olat.repository.RepositoryEntry) URL(java.net.URL) OlatRootFolderImpl(org.olat.core.commons.modules.bc.vfs.OlatRootFolderImpl) Identity(org.olat.core.id.Identity) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) File(java.io.File) Test(org.junit.Test)

Aggregations

IdentityEnvironment (org.olat.core.id.IdentityEnvironment)96 UserCourseEnvironmentImpl (org.olat.course.run.userview.UserCourseEnvironmentImpl)60 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)58 Identity (org.olat.core.id.Identity)56 ICourse (org.olat.course.ICourse)52 RepositoryEntry (org.olat.repository.RepositoryEntry)34 Roles (org.olat.core.id.Roles)30 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)22 ScoreEvaluation (org.olat.course.run.scoring.ScoreEvaluation)22 Test (org.junit.Test)20 VisibleTreeFilter (org.olat.course.run.userview.VisibleTreeFilter)20 CourseNode (org.olat.course.nodes.CourseNode)18 ArrayList (java.util.ArrayList)16 CourseTreeVisitor (org.olat.course.run.userview.CourseTreeVisitor)16 File (java.io.File)14 INode (org.olat.core.util.nodes.INode)12 Visitor (org.olat.core.util.tree.Visitor)12 VFSContainer (org.olat.core.util.vfs.VFSContainer)12 URL (java.net.URL)10 FOCourseNode (org.olat.course.nodes.FOCourseNode)10