use of org.olat.ims.qti.container.AssessmentContext in project openolat by klemens.
the class CourseAssessmentWebService method importTestItems.
private void importTestItems(ICourse course, String nodeKey, Identity identity, AssessableResultsVO resultsVO) {
try {
IQManager iqManager = CoreSpringFactory.getImpl(IQManager.class);
// load the course and the course node
CourseNode courseNode = getParentNode(course, nodeKey);
ModuleConfiguration modConfig = courseNode.getModuleConfiguration();
// check if the result set is already saved
QTIResultSet set = iqManager.getLastResultSet(identity, course.getResourceableId(), courseNode.getIdent());
if (set == null) {
String resourcePathInfo = course.getResourceableId() + File.separator + courseNode.getIdent();
// The use of these classes AssessmentInstance, AssessmentContext and
// Navigator
// allow the use of the persistence mechanism of OLAT without
// duplicating the code.
// The consequence is that we must loop on section and items and set the
// navigator on
// the right position before submitting the inputs.
AssessmentInstance ai = AssessmentFactory.createAssessmentInstance(identity, "", modConfig, false, course.getResourceableId(), courseNode.getIdent(), resourcePathInfo, null);
Navigator navigator = ai.getNavigator();
navigator.startAssessment();
// The type of the navigator depends on the setting of the course node
boolean perItem = (navigator instanceof MenuItemNavigator);
Map<String, ItemInput> datas = convertToHttpItemInput(resultsVO.getResults());
AssessmentContext ac = ai.getAssessmentContext();
int sectioncnt = ac.getSectionContextCount();
// loop on the sections
for (int i = 0; i < sectioncnt; i++) {
SectionContext sc = ac.getSectionContext(i);
navigator.goToSection(i);
ItemsInput iips = new ItemsInput();
int itemcnt = sc.getItemContextCount();
// loop on the items
for (int j = 0; j < itemcnt; j++) {
ItemContext it = sc.getItemContext(j);
if (datas.containsKey(it.getIdent())) {
if (perItem) {
// save the datas on a per item base
navigator.goToItem(i, j);
// the navigator can give informations on its current status
Info info = navigator.getInfo();
if (info.containsError()) {
// some items cannot processed twice
} else {
iips.addItemInput(datas.get(it.getIdent()));
navigator.submitItems(iips);
iips = new ItemsInput();
}
} else {
// put for a section
iips.addItemInput(datas.get(it.getIdent()));
}
}
}
if (!perItem) {
// save the inputs of the section. In a section based navigation,
// we must saved the inputs of the whole section at once
navigator.submitItems(iips);
}
}
navigator.submitAssessment();
// persist the QTIResultSet (o_qtiresultset and o_qtiresult) on the
// database
// TODO iqManager.persistResults(ai, course.getResourceableId(),
// courseNode.getIdent(), identity, "127.0.0.1");
// write the reporting file on the file system
// The path is <olatdata> / resreporting / <username> / Assessment /
// <assessId>.xml
// TODO Document docResReporting = iqManager.getResultsReporting(ai,
// identity, Locale.getDefault());
// TODO FilePersister.createResultsReporting(docResReporting, identity,
// ai.getFormattedType(), ai.getAssessID());
// prepare all instances needed to save the score at the course node
// level
CourseEnvironment cenv = course.getCourseEnvironment();
IdentityEnvironment identEnv = new IdentityEnvironment();
identEnv.setIdentity(identity);
UserCourseEnvironment userCourseEnv = new UserCourseEnvironmentImpl(identEnv, cenv);
// update scoring overview for the user in the current course
Float score = ac.getScore();
Boolean passed = ac.isPassed();
// perhaps don't pass this key directly
ScoreEvaluation sceval = new ScoreEvaluation(score, passed, passed, new Long(nodeKey));
AssessableCourseNode acn = (AssessableCourseNode) courseNode;
// assessment nodes are assessable
boolean incrementUserAttempts = true;
acn.updateUserScoreEvaluation(sceval, userCourseEnv, identity, incrementUserAttempts, Role.coach);
} else {
log.error("Result set already saved");
}
} catch (Exception e) {
log.error("", e);
}
}
use of org.olat.ims.qti.container.AssessmentContext in project openolat by klemens.
the class IQRunController method submitAssessment.
@Override
public void submitAssessment(AssessmentInstance ai) {
if (type.equals(AssessmentInstance.QMD_ENTRY_TYPE_ASSESS)) {
AssessmentContext ac = ai.getAssessmentContext();
AssessmentManager am = userCourseEnv.getCourseEnvironment().getAssessmentManager();
Boolean fullyAssed = am.getNodeFullyAssessed(courseNode, getIdentity());
String correctionMode = courseNode.getModuleConfiguration().getStringValue(IQEditController.CONFIG_CORRECTION_MODE);
Boolean userVisibility;
AssessmentEntryStatus assessmentStatus;
if (IQEditController.CORRECTION_MANUAL.equals(correctionMode)) {
assessmentStatus = AssessmentEntryStatus.inReview;
userVisibility = Boolean.FALSE;
} else {
assessmentStatus = AssessmentEntryStatus.done;
userVisibility = Boolean.TRUE;
}
ScoreEvaluation sceval = new ScoreEvaluation(ac.getScore(), ac.isPassed(), assessmentStatus, userVisibility, fullyAssed, null, null, ai.getAssessID());
// assessment nodes are assessable
AssessableCourseNode acn = (AssessableCourseNode) courseNode;
acn.updateUserScoreEvaluation(sceval, userCourseEnv, getIdentity(), true, Role.user);
// Mark publisher for notifications
Long courseId = userCourseEnv.getCourseEnvironment().getCourseResourceableId();
assessmentNotificationsHandler.markPublisherNews(getIdentity(), courseId);
if (!assessmentStopped) {
assessmentStopped = true;
AssessmentEvent assessmentStoppedEvent = new AssessmentEvent(AssessmentEvent.TYPE.STOPPED, userSession);
singleUserEventCenter.deregisterFor(this, assessmentInstanceOres);
singleUserEventCenter.fireEventToListenersOf(assessmentStoppedEvent, assessmentEventOres);
}
} else if (type.equals(AssessmentInstance.QMD_ENTRY_TYPE_SURVEY)) {
// save number of attempts
// although this is not an assessable node we still use the assessment
// manager since this one uses caching
AssessmentManager am = userCourseEnv.getCourseEnvironment().getAssessmentManager();
am.incrementNodeAttempts(courseNode, getIdentity(), userCourseEnv, Role.user);
} else if (type.equals(AssessmentInstance.QMD_ENTRY_TYPE_SELF)) {
AssessmentManager am = userCourseEnv.getCourseEnvironment().getAssessmentManager();
am.incrementNodeAttempts(courseNode, getIdentity(), userCourseEnv, Role.user);
}
}
use of org.olat.ims.qti.container.AssessmentContext in project openolat by klemens.
the class QTI12ResultDetailsController method doRetrieveTest.
/**
* Retrieve the test: load the course, close the assessment instamce, persist the QTI
* result set, pass the score to the course node.
* @param ureq
*/
private void doRetrieveTest() {
ICourse course = CourseFactory.loadCourse(courseResourceableId);
AssessableCourseNode testNode = (AssessableCourseNode) course.getRunStructure().getNode(nodeIdent);
ModuleConfiguration modConfig = testNode.getModuleConfiguration();
String resourcePathInfo = courseResourceableId + File.separator + nodeIdent;
AssessmentInstance ai = AssessmentFactory.createAssessmentInstance(assessedIdentity, "", modConfig, false, courseResourceableId, nodeIdent, resourcePathInfo, null);
// close the test
ai.stop();
// persist the results
iqm.persistResults(ai);
// reporting
Document docResReporting = iqm.getResultsReporting(ai, assessedIdentity, I18nModule.getDefaultLocale());
FilePersister.createResultsReporting(docResReporting, assessedIdentity, ai.getFormattedType(), ai.getAssessID());
// olat results
AssessmentContext ac = ai.getAssessmentContext();
Float score = Float.valueOf(ac.getScore());
Boolean passed = Boolean.valueOf(ac.isPassed());
ScoreEvaluation sceval = new ScoreEvaluation(score, passed, Boolean.FALSE, new Long(ai.getAssessID()));
UserCourseEnvironment userCourseEnv = AssessmentHelper.createAndInitUserCourseEnvironment(assessedIdentity, course);
testNode.updateUserScoreEvaluation(sceval, userCourseEnv, assessedIdentity, true, Role.coach);
// cleanup
ai.cleanUp();
List<QTIResultSet> resultSets = qrm.getResultSets(courseResourceableId, nodeIdent, repositoryEntry.getKey(), assessedIdentity);
tableModel.setObjects(resultSets);
tableCtr.modelChanged();
}
use of org.olat.ims.qti.container.AssessmentContext in project openolat by klemens.
the class DefaultNavigator method submitAssessment.
/**
* @see org.olat.qti.process.Navigator#submitAssessment()
*/
public final void submitAssessment() {
Output pendingOutput = null;
boolean pendingFeedback = getInfo().isFeedback();
boolean alreadyClosed = getAssessmentInstance().isClosed();
if (pendingFeedback && getAssessmentInstance().getAssessmentContext().getCurrentSectionContext() != null) {
ItemContext itc = getAssessmentInstance().getAssessmentContext().getCurrentSectionContext().getCurrentItemContext();
pendingOutput = itc.getOutput();
}
getAssessmentInstance().stop();
if (!getAssessmentInstance().isPreview() && !alreadyClosed) {
CoreSpringFactory.getImpl(IQManager.class).persistResults(getAssessmentInstance());
}
AssessmentContext ac = getAssessmentContext();
info.clear();
if (ac.isFeedbackavailable()) {
Output outp = ac.getOutput();
getInfo().setCurrentOutput(outp);
getInfo().setFeedback(true);
} else if (pendingFeedback) {
getInfo().setCurrentOutput(pendingOutput);
getInfo().setFeedback(true);
}
// info.clear();
info.setMessage(QTIConstants.MESSAGE_ASSESSMENT_SUBMITTED);
info.setStatus(QTIConstants.ASSESSMENT_FINISHED);
info.setRenderItems(false);
if (delegate != null && !getAssessmentInstance().isPreview() && !alreadyClosed) {
delegate.submitAssessment(assessmentInstance);
}
getAssessmentInstance().cleanUp();
}
use of org.olat.ims.qti.container.AssessmentContext in project openolat by klemens.
the class MenuItemNavigator method goToSection.
/**
* go to the section (not the item yet): display the objectives of the section
* @see org.olat.qti.process.Navigator#goToSection(int)
*/
public void goToSection(int sectionPos) {
if (getInfo().getStatus() != QTIConstants.ASSESSMENT_RUNNING)
throw new RuntimeException("assessment is NOT running yet or anymore");
clearInfo();
AssessmentContext ac = getAssessmentContext();
ac.setCurrentSectionContextPos(sectionPos);
SectionContext sc = ac.getCurrentSectionContext();
if (!ac.isOpen()) {
getInfo().setError(QTIConstants.ERROR_ASSESSMENT_OUTOFTIME);
getInfo().setRenderItems(false);
} else if (!sc.isOpen()) {
getInfo().setError(QTIConstants.ERROR_SECTION_OUTOFTIME);
getInfo().setRenderItems(false);
} else {
// no current item position, since we display section info only
sc.setCurrentItemContextPos(-1);
sc.start();
getInfo().setStatus(QTIConstants.ASSESSMENT_RUNNING);
// only section info
getInfo().setRenderItems(false);
getInfo().setMessage(QTIConstants.MESSAGE_SECTION_INFODEMANDED);
}
getAssessmentInstance().persist();
}
Aggregations