Search in sources :

Example 41 with AssessmentEntry

use of org.olat.modules.assessment.AssessmentEntry in project openolat by klemens.

the class AssessmentEntryDAOTest method loadAssessmentEntryBySubIdentWithStatus.

@Test
public void loadAssessmentEntryBySubIdentWithStatus() {
    Identity assessedIdentity1 = JunitTestHelper.createAndPersistIdentityAsRndUser("as-node-22");
    Identity assessedIdentity2 = JunitTestHelper.createAndPersistIdentityAsRndUser("as-node-23");
    Identity assessedIdentity3 = JunitTestHelper.createAndPersistIdentityAsRndUser("as-node-24");
    Identity assessedIdentity4 = JunitTestHelper.createAndPersistIdentityAsRndUser("as-node-25");
    Identity assessedIdentity5 = JunitTestHelper.createAndPersistIdentityAsRndUser("as-node-25");
    RepositoryEntry entry = JunitTestHelper.createAndPersistRepositoryEntry();
    RepositoryEntry refEntry = JunitTestHelper.createAndPersistRepositoryEntry();
    String subIdent = UUID.randomUUID().toString();
    BusinessGroup group = businessGroupDao.createAndPersist(null, "rel-bg-part-1", "rel-bgis-1-desc", -1, -1, false, false, false, false, false);
    businessGroupRelationDao.addRelationToResource(group, entry);
    businessGroupRelationDao.addRelationToResource(group, refEntry);
    businessGroupRelationDao.addRole(assessedIdentity1, group, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(assessedIdentity2, group, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(assessedIdentity3, group, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(assessedIdentity4, group, GroupRoles.participant.name());
    businessGroupRelationDao.addRole(assessedIdentity5, group, GroupRoles.coach.name());
    AssessmentEntry nodeAssessmentId1 = assessmentEntryDao.createAssessmentEntry(assessedIdentity1, null, entry, subIdent, refEntry);
    AssessmentEntry nodeAssessmentId2 = assessmentEntryDao.createAssessmentEntry(assessedIdentity2, null, entry, subIdent, refEntry, 0.0f, Boolean.FALSE, null, null);
    AssessmentEntry nodeAssessmentId3 = assessmentEntryDao.createAssessmentEntry(assessedIdentity2, null, entry, null, entry, 12.0f, Boolean.FALSE, null, null);
    AssessmentEntry nodeAssessmentId4 = assessmentEntryDao.createAssessmentEntry(assessedIdentity2, null, refEntry, subIdent, refEntry, 3.0f, Boolean.FALSE, null, null);
    AssessmentEntry nodeAssessmentId5 = assessmentEntryDao.createAssessmentEntry(assessedIdentity3, null, entry, subIdent, refEntry, 6.0f, Boolean.TRUE, null, null);
    AssessmentEntry nodeAssessmentId6 = assessmentEntryDao.createAssessmentEntry(assessedIdentity4, null, entry, subIdent, refEntry, 1.0f, Boolean.FALSE, null, null);
    AssessmentEntry nodeAssessmentId7 = assessmentEntryDao.createAssessmentEntry(assessedIdentity5, null, entry, subIdent, refEntry, 10.0f, Boolean.TRUE, null, null);
    dbInstance.commitAndCloseSession();
    // load with our subIdent above
    List<AssessmentEntry> assessmentEntries = assessmentEntryDao.loadAssessmentEntryBySubIdentWithStatus(entry, subIdent, null, true);
    Assert.assertNotNull(assessmentEntries);
    Assert.assertEquals(2, assessmentEntries.size());
    Assert.assertFalse(assessmentEntries.contains(nodeAssessmentId1));
    Assert.assertFalse(assessmentEntries.contains(nodeAssessmentId2));
    Assert.assertFalse(assessmentEntries.contains(nodeAssessmentId3));
    Assert.assertFalse(assessmentEntries.contains(nodeAssessmentId4));
    Assert.assertTrue(assessmentEntries.contains(nodeAssessmentId5));
    Assert.assertTrue(assessmentEntries.contains(nodeAssessmentId6));
    Assert.assertFalse(assessmentEntries.contains(nodeAssessmentId7));
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) RepositoryEntry(org.olat.repository.RepositoryEntry) Identity(org.olat.core.id.Identity) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) Test(org.junit.Test)

Example 42 with AssessmentEntry

use of org.olat.modules.assessment.AssessmentEntry in project openolat by klemens.

the class OLATUpgrade_11_0_0 method convertUserEfficiencyStatemen.

private void convertUserEfficiencyStatemen(RepositoryEntry courseEntry) {
    try {
        final ICourse course = CourseFactory.loadCourse(courseEntry);
        CourseNode rootNode = course.getRunStructure().getRootNode();
        Set<Long> identityKeys = new HashSet<>(loadIdentityKeyOfAssessmentEntries(courseEntry, rootNode.getIdent()));
        int count = 0;
        List<UserEfficiencyStatementLight> statements = getUserEfficiencyStatements(courseEntry);
        for (UserEfficiencyStatementLight statement : statements) {
            Identity identity = statement.getIdentity();
            if (!identityKeys.contains(identity.getKey())) {
                AssessmentEntry entry = createAssessmentEntry(identity, null, course, courseEntry, rootNode.getIdent());
                if (statement.getScore() != null) {
                    entry.setScore(new BigDecimal(statement.getScore()));
                }
                if (statement.getPassed() != null) {
                    entry.setPassed(statement.getPassed());
                }
                dbInstance.getCurrentEntityManager().persist(entry);
                if (count++ % 25 == 0) {
                    dbInstance.commitAndCloseSession();
                }
            }
        }
    } catch (Exception e) {
        log.error("Error with " + courseEntry.getKey() + " " + courseEntry, e);
    }
    dbInstance.commitAndCloseSession();
}
Also used : UserEfficiencyStatementLight(org.olat.course.assessment.model.UserEfficiencyStatementLight) ICourse(org.olat.course.ICourse) 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) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) BigDecimal(java.math.BigDecimal) CorruptedCourseException(org.olat.course.CorruptedCourseException) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) HashSet(java.util.HashSet)

Example 43 with AssessmentEntry

use of org.olat.modules.assessment.AssessmentEntry in project openolat by klemens.

the class AssessmentNotificationsHandler method createSubscriptionInfo.

/**
 * @see org.olat.core.commons.services.notifications.NotificationsHandler#createSubscriptionInfo(org.olat.core.commons.services.notifications.Subscriber,
 *      java.util.Locale, java.util.Date)
 */
public SubscriptionInfo createSubscriptionInfo(final Subscriber subscriber, Locale locale, Date compareDate) {
    SubscriptionInfo si = null;
    Publisher p = subscriber.getPublisher();
    if (!NotificationsUpgradeHelper.checkCourse(p)) {
        // course don't exist anymore
        notificationsManager.deactivate(p);
        return notificationsManager.getNoSubscriptionInfo();
    }
    try {
        Date latestNews = p.getLatestNewsDate();
        Identity identity = subscriber.getIdentity();
        // can't be loaded when already deleted
        if (notificationsManager.isPublisherValid(p) && compareDate.before(latestNews)) {
            Long courseId = new Long(p.getData());
            final ICourse course = loadCourseFromId(courseId);
            if (courseStatus(course)) {
                // course admins or users with the course right to have full access to
                // the assessment tool will have full access to user tests
                CourseGroupManager cgm = course.getCourseEnvironment().getCourseGroupManager();
                final boolean hasFullAccess = (cgm.isIdentityCourseAdministrator(identity) ? true : cgm.hasRight(identity, CourseRights.RIGHT_ASSESSMENT));
                final Set<Identity> coachedUsers = new HashSet<Identity>();
                if (!hasFullAccess) {
                    // initialize list of users, only when user has not full access
                    List<BusinessGroup> coachedGroups = cgm.getOwnedBusinessGroups(identity);
                    List<Identity> coachedIdentites = businessGroupService.getMembers(coachedGroups, GroupRoles.participant.name());
                    coachedUsers.addAll(coachedIdentites);
                }
                List<AssessableCourseNode> testNodes = getCourseTestNodes(course);
                Translator translator = Util.createPackageTranslator(AssessmentManager.class, locale);
                for (AssessableCourseNode test : testNodes) {
                    List<AssessmentEntry> assessments = courseNodeAssessmentDao.loadAssessmentEntryBySubIdent(cgm.getCourseEntry(), test.getIdent());
                    for (AssessmentEntry assessment : assessments) {
                        Date modDate = assessment.getLastModified();
                        Identity assessedIdentity = assessment.getIdentity();
                        if (modDate.after(compareDate) && (hasFullAccess || coachedUsers.contains(assessedIdentity))) {
                            BigDecimal score = assessment.getScore();
                            if (test instanceof ScormCourseNode) {
                                ScormCourseNode scormTest = (ScormCourseNode) test;
                                // check if completed or passed
                                String status = ScormAssessmentManager.getInstance().getLastLessonStatus(assessedIdentity.getName(), course.getCourseEnvironment(), scormTest);
                                if (!"passed".equals(status) && !"completed".equals(status)) {
                                    continue;
                                }
                            }
                            String desc;
                            String type = translator.translate("notifications.entry." + test.getType());
                            if (score == null) {
                                desc = translator.translate("notifications.entry.attempt", new String[] { test.getShortTitle(), NotificationHelper.getFormatedName(assessedIdentity), type });
                            } else {
                                String scoreStr = AssessmentHelper.getRoundedScore(score);
                                desc = translator.translate("notifications.entry", new String[] { test.getShortTitle(), NotificationHelper.getFormatedName(assessedIdentity), scoreStr, type });
                            }
                            String urlToSend = null;
                            String businessPath = null;
                            if (p.getBusinessPath() != null) {
                                businessPath = p.getBusinessPath() + "[Users:0][Node:" + test.getIdent() + "][Identity:" + assessedIdentity.getKey() + "]";
                                urlToSend = BusinessControlFactory.getInstance().getURLFromBusinessPathString(businessPath);
                            }
                            SubscriptionListItem subListItem = new SubscriptionListItem(desc, urlToSend, businessPath, modDate, CSS_CLASS_USER_ICON);
                            if (si == null) {
                                String title = translator.translate("notifications.header", new String[] { course.getCourseTitle() });
                                String css = CourseNodeFactory.getInstance().getCourseNodeConfigurationEvenForDisabledBB(test.getType()).getIconCSSClass();
                                si = new SubscriptionInfo(subscriber.getKey(), p.getType(), new TitleItem(title, css), null);
                            }
                            si.addSubscriptionListItem(subListItem);
                        }
                    }
                }
            }
        }
        if (si == null) {
            si = notificationsManager.getNoSubscriptionInfo();
        }
        return si;
    } catch (Exception e) {
        log.error("Error while creating assessment notifications", e);
        checkPublisher(p);
        return notificationsManager.getNoSubscriptionInfo();
    }
}
Also used : CourseGroupManager(org.olat.course.groupsandrights.CourseGroupManager) BusinessGroup(org.olat.group.BusinessGroup) SubscriptionInfo(org.olat.core.commons.services.notifications.SubscriptionInfo) ICourse(org.olat.course.ICourse) Publisher(org.olat.core.commons.services.notifications.Publisher) TitleItem(org.olat.core.commons.services.notifications.model.TitleItem) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry) ScormCourseNode(org.olat.course.nodes.ScormCourseNode) Date(java.util.Date) BigDecimal(java.math.BigDecimal) AssertException(org.olat.core.logging.AssertException) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) SubscriptionListItem(org.olat.core.commons.services.notifications.model.SubscriptionListItem) Translator(org.olat.core.gui.translator.Translator) Identity(org.olat.core.id.Identity) HashSet(java.util.HashSet)

Example 44 with AssessmentEntry

use of org.olat.modules.assessment.AssessmentEntry in project openolat by klemens.

the class CourseAssessmentManagerImpl method incrementNodeAttemptsInBackground.

@Override
public void incrementNodeAttemptsInBackground(CourseNode courseNode, Identity assessedIdentity, UserCourseEnvironment userCourseEnv) {
    ICourse course = CourseFactory.loadCourse(cgm.getCourseEntry());
    AssessmentEntry nodeAssessment = getOrCreate(assessedIdentity, courseNode);
    int attempts = nodeAssessment.getAttempts() == null ? 1 : nodeAssessment.getAttempts().intValue() + 1;
    nodeAssessment.setAttempts(attempts);
    assessmentService.updateAssessmentEntry(nodeAssessment);
    if (courseNode instanceof AssessableCourseNode) {
        // Update users efficiency statement
        efficiencyStatementManager.updateUserEfficiencyStatement(userCourseEnv);
    }
    // notify about changes
    AssessmentChangedEvent ace = new AssessmentChangedEvent(AssessmentChangedEvent.TYPE_ATTEMPTS_CHANGED, assessedIdentity);
    CoordinatorManager.getInstance().getCoordinator().getEventBus().fireEventToListenersOf(ace, course);
}
Also used : AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) AssessmentChangedEvent(org.olat.course.assessment.AssessmentChangedEvent) ICourse(org.olat.course.ICourse) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry)

Example 45 with AssessmentEntry

use of org.olat.modules.assessment.AssessmentEntry in project openolat by klemens.

the class CourseAssessmentManagerImpl method removeIndividualAssessmentDocument.

@Override
public void removeIndividualAssessmentDocument(CourseNode courseNode, Identity identity, Identity assessedIdentity, File document) {
    if (document != null && document.exists()) {
        document.delete();
        // update counter
        File directory = getAssessmentDocumentsDirectory(courseNode, assessedIdentity);
        AssessmentEntry nodeAssessment = getOrCreate(assessedIdentity, courseNode);
        File[] docs = directory.listFiles(new SystemFileFilter(true, false));
        int numOfDocs = docs == null ? 0 : docs.length;
        nodeAssessment.setNumberOfAssessmentDocuments(numOfDocs);
        assessmentService.updateAssessmentEntry(nodeAssessment);
        // node log
        ICourse course = CourseFactory.loadCourse(cgm.getCourseEntry());
        UserNodeAuditManager am = course.getCourseEnvironment().getAuditManager();
        am.appendToUserNodeLog(courseNode, identity, assessedIdentity, "assessment document removed: " + document.getName());
        // user activity logging
        ThreadLocalUserActivityLogger.log(AssessmentLoggingAction.ASSESSMENT_DOCUMENT_REMOVED, getClass(), LoggingResourceable.wrap(assessedIdentity), LoggingResourceable.wrapNonOlatResource(StringResourceableType.assessmentDocument, "", StringHelper.stripLineBreaks(document.getName())));
    }
}
Also used : UserNodeAuditManager(org.olat.course.auditing.UserNodeAuditManager) ICourse(org.olat.course.ICourse) SystemFileFilter(org.olat.core.util.io.SystemFileFilter) File(java.io.File) AssessmentEntry(org.olat.modules.assessment.AssessmentEntry)

Aggregations

AssessmentEntry (org.olat.modules.assessment.AssessmentEntry)150 Identity (org.olat.core.id.Identity)88 RepositoryEntry (org.olat.repository.RepositoryEntry)70 Test (org.junit.Test)50 ICourse (org.olat.course.ICourse)38 AssessmentTestSession (org.olat.ims.qti21.AssessmentTestSession)32 File (java.io.File)26 Date (java.util.Date)26 HashMap (java.util.HashMap)22 BigDecimal (java.math.BigDecimal)20 ArrayList (java.util.ArrayList)20 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)20 UserNodeAuditManager (org.olat.course.auditing.UserNodeAuditManager)16 CourseNode (org.olat.course.nodes.CourseNode)16 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)16 ScoreEvaluation (org.olat.course.run.scoring.ScoreEvaluation)14 AssessmentChangedEvent (org.olat.course.assessment.AssessmentChangedEvent)12 AssessmentManager (org.olat.course.assessment.AssessmentManager)12 BusinessGroup (org.olat.group.BusinessGroup)12 List (java.util.List)10