use of org.olat.course.run.userview.UserCourseEnvironment in project openolat by klemens.
the class AssessmentManagerTest method testSaveScoreEvaluation.
/**
* Tests the AssessmentManager methods.
*/
@Test
public void testSaveScoreEvaluation() {
log.info("Start testSaveScoreEvaluation");
assertNotNull(course);
// find an assessableCourseNode
List<CourseNode> assessableNodeList = AssessmentHelper.getAssessableNodes(course.getEditorTreeModel(), null);
Iterator<CourseNode> nodesIterator = assessableNodeList.iterator();
boolean testNodeFound = false;
while (nodesIterator.hasNext()) {
CourseNode currentNode = nodesIterator.next();
if (currentNode instanceof AssessableCourseNode) {
if (currentNode.getType().equalsIgnoreCase("iqtest")) {
log.info("Yes, we found a test node! - currentNode.getType(): " + currentNode.getType());
assessableCourseNode = (AssessableCourseNode) currentNode;
testNodeFound = true;
break;
}
}
}
assertTrue("found no test-node of type 'iqtest' (hint: add one to DemoCourse) ", testNodeFound);
assessmentManager = course.getCourseEnvironment().getAssessmentManager();
Long assessmentID = new Long("123456");
Integer attempts = 1;
String coachComment = "SomeUselessCoachComment";
String userComment = "UselessUserComment";
// store ScoreEvaluation for the assessableCourseNode and student
ScoreEvaluation scoreEvaluation = new ScoreEvaluation(score, passed, fullyAssessed, assessmentID);
IdentityEnvironment ienv = new IdentityEnvironment();
ienv.setIdentity(student);
UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
boolean incrementAttempts = true;
assessmentManager.saveScoreEvaluation(assessableCourseNode, tutor, student, scoreEvaluation, userCourseEnv, incrementAttempts, Role.coach);
DBFactory.getInstance().closeSession();
// the attempts mut have been incremented
assertEquals(attempts, assessmentManager.getNodeAttempts(assessableCourseNode, student));
assessmentManager.saveNodeCoachComment(assessableCourseNode, student, coachComment);
assessmentManager.saveNodeComment(assessableCourseNode, tutor, student, userComment);
attempts++;
assessmentManager.saveNodeAttempts(assessableCourseNode, tutor, student, attempts, Role.coach);
assertEquals(attempts, assessmentManager.getNodeAttempts(assessableCourseNode, student));
assertEquals(score, assessmentManager.getNodeScore(assessableCourseNode, student));
assertEquals(passed, assessmentManager.getNodePassed(assessableCourseNode, student));
assertEquals(assessmentID, assessmentManager.getAssessmentID(assessableCourseNode, student));
assertEquals(coachComment, assessmentManager.getNodeCoachComment(assessableCourseNode, student));
assertEquals(userComment, assessmentManager.getNodeComment(assessableCourseNode, student));
log.info("Finish testing AssessmentManager read/write methods");
checkEfficiencyStatementManager();
assertNotNull("no course at the end of test", course);
try {
course = CourseFactory.loadCourse(course.getResourceableId());
} catch (Exception ex) {
fail("Could not load course at the end of test Exception=" + ex);
}
assertNotNull("no course after loadCourse", course);
}
use of org.olat.course.run.userview.UserCourseEnvironment in project openolat by klemens.
the class BulkAssessmentTask method doProcess.
private void doProcess(List<BulkAssessmentFeedback> feedbacks) {
final DB dbInstance = DBFactory.getInstance();
final BaseSecurity securityManager = CoreSpringFactory.getImpl(BaseSecurity.class);
final Identity coachIdentity = securityManager.loadIdentityByKey(coachedIdentity);
final ICourse course = CourseFactory.loadCourse(courseRes);
final AssessableCourseNode courseNode = getCourseNode();
final Roles studentRoles = new Roles(false, false, false, false, false, false, false, false);
final boolean hasUserComment = courseNode.hasCommentConfigured();
final boolean hasScore = courseNode.hasScoreConfigured();
final boolean hasPassed = courseNode.hasPassedConfigured();
final boolean hasReturnFiles = (StringHelper.containsNonWhitespace(datas.getReturnFiles()) && (courseNode instanceof TACourseNode || courseNode instanceof GTACourseNode));
if (hasReturnFiles) {
try {
OlatRootFileImpl returnFilesZipped = new OlatRootFileImpl(datas.getReturnFiles(), null);
String tmp = FolderConfig.getCanonicalTmpDir();
unzipped = new File(tmp, UUID.randomUUID().toString() + File.separatorChar);
unzipped.mkdirs();
ZipUtil.unzip(returnFilesZipped.getBasefile(), unzipped);
} catch (Exception e) {
log.error("Cannot unzip the return files during bulk assessment", e);
}
}
Float min = null;
Float max = null;
Float cut = null;
if (hasScore) {
min = courseNode.getMinScoreConfiguration();
max = courseNode.getMaxScoreConfiguration();
}
if (hasPassed) {
cut = courseNode.getCutValueConfiguration();
}
int count = 0;
List<BulkAssessmentRow> rows = datas.getRows();
for (BulkAssessmentRow row : rows) {
Long identityKey = row.getIdentityKey();
if (identityKey == null) {
feedbacks.add(new BulkAssessmentFeedback("bulk.action.no.such.user", row.getAssessedId()));
// nothing to do
continue;
}
Identity identity = securityManager.loadIdentityByKey(identityKey);
IdentityEnvironment ienv = new IdentityEnvironment(identity, studentRoles);
UserCourseEnvironment uce = new UserCourseEnvironmentImpl(ienv, course.getCourseEnvironment());
// update comment, empty string will reset comment
String userComment = row.getComment();
if (hasUserComment && userComment != null) {
// Update userComment in db
courseNode.updateUserUserComment(userComment, uce, coachIdentity);
// LD: why do we have to update the efficiency statement?
// EfficiencyStatementManager esm = EfficiencyStatementManager.getInstance();
// esm.updateUserEfficiencyStatement(uce);
}
// update score
Float score = row.getScore();
if (hasScore && score != null) {
// score < minimum score
if ((min != null && score.floatValue() < min.floatValue()) || (score.floatValue() < AssessmentHelper.MIN_SCORE_SUPPORTED)) {
// "bulk.action.lessThanMin";
} else // score > maximum score
if ((max != null && score.floatValue() > max.floatValue()) || (score.floatValue() > AssessmentHelper.MAX_SCORE_SUPPORTED)) {
// "bulk.action.greaterThanMax";
} else {
// score between minimum and maximum score
ScoreEvaluation se;
if (hasPassed && cut != null) {
Boolean passed = (score.floatValue() >= cut.floatValue()) ? Boolean.TRUE : Boolean.FALSE;
se = new ScoreEvaluation(score, passed);
} else {
se = new ScoreEvaluation(score, null);
}
// Update score,passed properties in db, and the user's efficiency statement
courseNode.updateUserScoreEvaluation(se, uce, coachIdentity, false, Role.auto);
}
}
Boolean passed = row.getPassed();
if (hasPassed && passed != null && cut == null) {
// Configuration of manual assessment --> Display passed/not passed: yes, Type of display: Manual by tutor
ScoreEvaluation seOld = courseNode.getUserScoreEvaluation(uce);
Float oldScore = seOld.getScore();
ScoreEvaluation se = new ScoreEvaluation(oldScore, passed);
// Update score,passed properties in db, and the user's efficiency statement
boolean incrementAttempts = false;
courseNode.updateUserScoreEvaluation(se, uce, coachIdentity, incrementAttempts, Role.auto);
}
boolean identityHasReturnFile = false;
if (hasReturnFiles && row.getReturnFiles() != null && row.getReturnFiles().size() > 0) {
String assessedId = row.getAssessedId();
File assessedFolder = new File(unzipped, assessedId);
identityHasReturnFile = assessedFolder.exists();
if (identityHasReturnFile) {
processReturnFile(courseNode, row, uce, assessedFolder);
}
}
if (courseNode instanceof GTACourseNode) {
// push the state further
GTACourseNode gtaNode = (GTACourseNode) courseNode;
if ((hasScore && score != null) || (hasPassed && passed != null)) {
// pushed to graded
updateTasksState(gtaNode, uce, TaskProcess.grading);
} else if (hasReturnFiles) {
// push to revised
updateTasksState(gtaNode, uce, TaskProcess.correction);
}
}
if (count++ % 5 == 0) {
dbInstance.commitAndCloseSession();
} else {
dbInstance.commit();
}
}
}
use of org.olat.course.run.userview.UserCourseEnvironment in project openolat by klemens.
the class BulkAssessmentTask method getReturnBox.
/**
* Return the target folder of the assessed identity. This is a factory method which take care
* of the type of the course node.
*
* @param uce
* @param courseNode
* @param identity
* @return
*/
private VFSContainer getReturnBox(UserCourseEnvironment uce, CourseNode courseNode, Identity identity) {
VFSContainer returnContainer = null;
if (courseNode instanceof GTACourseNode) {
final GTAManager gtaManager = CoreSpringFactory.getImpl(GTAManager.class);
CourseEnvironment courseEnv = uce.getCourseEnvironment();
returnContainer = gtaManager.getCorrectionContainer(courseEnv, (GTACourseNode) courseNode, identity);
} else {
String returnPath = ReturnboxController.getReturnboxPathRelToFolderRoot(uce.getCourseEnvironment(), courseNode);
OlatRootFolderImpl rootFolder = new OlatRootFolderImpl(returnPath, null);
VFSItem assessedItem = rootFolder.resolve(identity.getName());
if (assessedItem == null) {
returnContainer = rootFolder.createChildContainer(identity.getName());
} else if (assessedItem instanceof VFSContainer) {
returnContainer = (VFSContainer) assessedItem;
}
}
return returnContainer;
}
use of org.olat.course.run.userview.UserCourseEnvironment in project openolat by klemens.
the class GTANotifications method createAssessmentItem.
private void createAssessmentItem(Task task, Identity assessedIdentity, boolean coach) {
if (task == null || task.getGraduationDate() == null)
return;
if (task.getGraduationDate().after(compareDate)) {
RepositoryEntry courseEntry = courseEnv.getCourseGroupManager().getCourseEntry();
AssessmentEntry assessment = courseNodeAssessmentDao.loadAssessmentEntry(assessedIdentity, courseEntry, gtaNode.getIdent());
boolean resultsVisible = assessment != null && (assessment.getUserVisibility() == null || assessment.getUserVisibility().booleanValue());
if (resultsVisible) {
String score = null;
String status = null;
if (gtaNode.hasScoreConfigured() && assessment.getScore() != null) {
score = AssessmentHelper.getRoundedScore(assessment.getScore());
}
if (gtaNode.hasPassedConfigured() && assessment.getPassed() != null) {
status = assessment.getPassed().booleanValue() ? translator.translate("notifications.assessment.passed.true") : translator.translate("notifications.assessment.passed.false");
}
Date graduationDate = task.getGraduationDate();
String[] params = new String[] { getTaskName(task), courseEntry.getDisplayname(), score, status };
if (score != null && status != null) {
if (assessment.getPassed().booleanValue()) {
appendSubscriptionItem("notifications.assessment.score.passed", params, assessedIdentity, graduationDate, coach);
} else {
appendSubscriptionItem("notifications.assessment.score.notpassed", params, assessedIdentity, graduationDate, coach);
}
} else if (score != null) {
appendSubscriptionItem("notifications.assessment.score", params, assessedIdentity, graduationDate, coach);
} else if (status != null) {
appendSubscriptionItem("notifications.assessment.passed", params, assessedIdentity, graduationDate, coach);
}
ICourse course = CourseFactory.loadCourse(courseEnv.getCourseGroupManager().getCourseEntry());
UserCourseEnvironment assessedUserCourseEnv = AssessmentHelper.createAndInitUserCourseEnvironment(assessedIdentity, course);
List<File> docs = gtaNode.getIndividualAssessmentDocuments(assessedUserCourseEnv);
for (File doc : docs) {
String[] docParams = new String[] { getTaskName(task), courseEntry.getDisplayname(), doc.getName() };
appendSubscriptionItemForFile("notifications.assessment.doc", docParams, assessedIdentity, "[assessment:0]", doc, graduationDate, coach);
}
}
}
}
use of org.olat.course.run.userview.UserCourseEnvironment in project openolat by klemens.
the class GTACoachController method stepRevision.
@Override
protected Task stepRevision(UserRequest ureq, Task assignedTask) {
assignedTask = super.stepRevision(ureq, assignedTask);
boolean revisions = false;
if (config.getBooleanSafe(GTACourseNode.GTASK_ASSIGNMENT) || config.getBooleanSafe(GTACourseNode.GTASK_SUBMIT) || config.getBooleanSafe(GTACourseNode.GTASK_REVIEW_AND_CORRECTION)) {
if (assignedTask == null || assignedTask.getTaskStatus() == TaskProcess.assignment || assignedTask.getTaskStatus() == TaskProcess.submit || assignedTask.getTaskStatus() == TaskProcess.review) {
mainVC.contextPut("revisionCssClass", "");
} else if (assignedTask.getTaskStatus() == TaskProcess.revision || assignedTask.getTaskStatus() == TaskProcess.correction) {
mainVC.contextPut("revisionCssClass", "o_active");
revisions = true;
} else if (assignedTask.getRevisionLoop() == 0) {
mainVC.contextPut("skipRevisions", Boolean.TRUE);
revisions = false;
} else {
mainVC.contextPut("revisionCssClass", "o_done");
revisions = true;
}
} else if (assignedTask == null || assignedTask.getTaskStatus() == TaskProcess.revision || assignedTask.getTaskStatus() == TaskProcess.correction) {
mainVC.contextPut("revisionCssClass", "o_active");
revisions = true;
} else {
mainVC.contextPut("revisionCssClass", "o_done");
revisions = true;
}
if (revisions) {
if (GTAType.individual.name().equals(config.getStringValue(GTACourseNode.GTASK_TYPE))) {
UserCourseEnvironment assessedUserCourseEnv = getAssessedUserCourseEnvironment();
revisionDocumentsCtrl = new GTACoachRevisionAndCorrectionsController(ureq, getWindowControl(), courseEnv, assignedTask, gtaNode, coachCourseEnv, assessedGroup, assessedIdentity, assessedUserCourseEnv, taskListEventResource);
} else {
revisionDocumentsCtrl = new GTACoachRevisionAndCorrectionsController(ureq, getWindowControl(), courseEnv, assignedTask, gtaNode, coachCourseEnv, assessedGroup, null, null, taskListEventResource);
}
listenTo(revisionDocumentsCtrl);
mainVC.put("revisionDocs", revisionDocumentsCtrl.getInitialComponent());
}
return assignedTask;
}
Aggregations