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));
}
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();
}
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();
}
}
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);
}
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())));
}
}
Aggregations