Search in sources :

Example 1 with AssessmentContext

use of org.olat.ims.qti.container.AssessmentContext in project OpenOLAT by OpenOLAT.

the class ResultsBuilder method getResDoc.

/**
 * Method getResDoc.
 *
 * @param ai The assessment instance
 * @param locale The users locale
 * @param identity
 * @return Document The XML document
 */
public Document getResDoc(AssessmentInstance ai, Locale locale, Identity identity) {
    AssessmentContext ac = ai.getAssessmentContext();
    DocumentFactory df = DocumentFactory.getInstance();
    Document res_doc = df.createDocument();
    Element root = df.createElement("qti_result_report");
    res_doc.setRootElement(root);
    Element result = root.addElement("result");
    Element extension_result = result.addElement("extension_result");
    String baseUrl = ai.getResolver().getStaticsBaseURI() + "/";
    // extension_result.
    for (int i = 0; i < ac.getSectionContextCount(); i++) {
        SectionContext sectionCtx = ac.getSectionContext(i);
        for (int j = 0; j < sectionCtx.getItemContextCount(); j++) {
            // OO-148
            // on some occasions this did throw an IllegalAddException
            // because el_item had already a parent.
            // make a clone for adding to extension_result
            Element el_item = (Element) sectionCtx.getItemContext(j).getEl_item().clone();
            recurseMattextForMediaURLFiltering(baseUrl, el_item);
            extension_result.add(el_item);
        }
    }
    // add ims cp id for any media references
    addStaticsPath(extension_result, ai);
    // add assessment_result
    // Add User information
    Element context = result.addElement("context");
    User user = identity.getUser();
    String name = user.getProperty(UserConstants.FIRSTNAME, locale) + " " + user.getProperty(UserConstants.LASTNAME, locale);
    String instId = user.getProperty(UserConstants.INSTITUTIONALUSERIDENTIFIER, locale);
    String instName = user.getProperty(UserConstants.INSTITUTIONALNAME, locale);
    if (instId == null)
        instId = "N/A";
    context.addElement("name").addText(name);
    String institution;
    if (instName == null) {
        institution = "N/A";
    } else {
        institution = instName;
    }
    // Add institutional identifier (e.g. Matrikelnummer)
    Element generic_identifier = context.addElement("generic_identifier");
    generic_identifier.addElement("type_label").addText(institution);
    generic_identifier.addElement("identifier_string").addText(instId);
    // Add start and stop date formatted as datetime
    Element beginDate = context.addElement("date");
    beginDate.addElement("type_label").addText("Start");
    beginDate.addElement("datetime").addText(Formatter.formatDatetime(new Date(ac.getTimeOfStart())));
    Element stopDate = context.addElement("date");
    stopDate.addElement("type_label").addText("Stop");
    stopDate.addElement("datetime").addText(Formatter.formatDatetime(new Date(ac.getTimeOfStop())));
    Element ares = result.addElement("assessment_result");
    ares.addAttribute("ident_ref", ac.getIdent());
    if (ac.getTitle() != null) {
        ares.addAttribute("asi_title", ac.getTitle());
    }
    // process assessment score
    Element a_score = ares.addElement("outcomes").addElement("score");
    a_score.addAttribute("varname", "SCORE");
    String strVal = StringHelper.formatFloat(ac.getScore(), 2);
    a_score.addElement("score_value").addText(strVal);
    strVal = ac.getMaxScore() == -1.0f ? "N/A" : StringHelper.formatFloat(ac.getMaxScore(), 2);
    a_score.addElement("score_max").addText(strVal);
    strVal = ac.getCutvalue() == -1.0f ? "N/A" : StringHelper.formatFloat(ac.getCutvalue(), 2);
    a_score.addElement("score_cut").addText(strVal);
    addElementText(ares, "duration", QTIHelper.getISODuration(ac.getDuration()));
    addElementText(ares, "num_sections", "" + ac.getSectionContextCount());
    addElementText(ares, "num_sections_presented", "0");
    addElementText(ares, "num_items", "" + ac.getItemContextCount());
    addElementText(ares, "num_items_presented", "" + ac.getItemsPresentedCount());
    addElementText(ares, "num_items_attempted", "" + ac.getItemsAttemptedCount());
    // add section_result
    int secnt = ac.getSectionContextCount();
    for (int i = 0; i < secnt; i++) {
        SectionContext secc = ac.getSectionContext(i);
        Element secres = ares.addElement("section_result");
        secres.addAttribute("ident_ref", secc.getIdent());
        if (secc.getTitle() != null) {
            secres.addAttribute("asi_title", secc.getTitle());
        }
        addElementText(secres, "duration", QTIHelper.getISODuration(secc.getDuration()));
        addElementText(secres, "num_items", "" + secc.getItemContextCount());
        addElementText(secres, "num_items_presented", "" + secc.getItemsPresentedCount());
        addElementText(secres, "num_items_attempted", "" + secc.getItemsAttemptedCount());
        // process section score
        Element sec_score = secres.addElement("outcomes").addElement("score");
        sec_score.addAttribute("varname", "SCORE");
        strVal = secc.getScore() == -1.0f ? "N/A" : "" + StringHelper.formatFloat(secc.getScore(), 2);
        sec_score.addElement("score_value").addText(strVal);
        strVal = secc.getMaxScore() == -1.0f ? "N/A" : "" + StringHelper.formatFloat(secc.getMaxScore(), 2);
        sec_score.addElement("score_max").addText(strVal);
        strVal = secc.getCutValue() == -1 ? "N/A" : "" + secc.getCutValue();
        sec_score.addElement("score_cut").addText(strVal);
        // iterate over all items in this section context
        List<ItemContext> itemsc = secc.getSectionItemContexts();
        for (Iterator<ItemContext> it_it = itemsc.iterator(); it_it.hasNext(); ) {
            ItemContext itemc = it_it.next();
            Element itres = secres.addElement("item_result");
            itres.addAttribute("ident_ref", itemc.getIdent());
            itres.addAttribute("asi_title", itemc.getEl_item().attributeValue("title"));
            Element it_duration = itres.addElement("duration");
            it_duration.addText(QTIHelper.getISODuration(itemc.getTimeSpent()));
            // process item score
            DecimalVariable scoreVar = (DecimalVariable) (itemc.getVariables().getSCOREVariable());
            Element it_score = itres.addElement("outcomes").addElement("score");
            it_score.addAttribute("varname", "SCORE");
            it_score.addElement("score_value").addText(StringHelper.formatFloat(scoreVar.getTruncatedValue(), 2));
            strVal = scoreVar.hasMinValue() ? "" + scoreVar.getMinValue() : "0.0";
            it_score.addElement("score_min").addText(strVal);
            strVal = scoreVar.hasMaxValue() ? "" + scoreVar.getMaxValue() : "N/A";
            it_score.addElement("score_max").addText(strVal);
            strVal = scoreVar.hasCutValue() ? "" + scoreVar.getCutValue() : "N/A";
            it_score.addElement("score_cut").addText(strVal);
            Element el_item = itemc.getEl_item();
            Map<String, Element> res_responsehash = new HashMap<>(3);
            // iterate over all responses of this item
            List resps = el_item.selectNodes(".//response_lid|.//response_xy|.//response_str|.//response_num|.//response_grp");
            for (Iterator it_resp = resps.iterator(); it_resp.hasNext(); ) {
                Element resp = (Element) it_resp.next();
                String ident = resp.attributeValue("ident");
                String rcardinality = resp.attributeValue("rcardinality");
                String rtiming = resp.attributeValue("rtiming");
                // add new response
                Element res_response = itres.addElement("response");
                res_response.addAttribute("ident_ref", ident);
                // enable lookup of
                res_responsehash.put(ident, res_response);
                // @identref of <response>
                // (needed with <varequal>
                // elements
                // add new response_form
                // <response_lid ident="MR01" rcardinality="Multiple" rtiming="No">
                Element res_responseform = res_response.addElement("response_form");
                res_responseform.addAttribute("cardinality", rcardinality);
                res_responseform.addAttribute("timing", rtiming);
                String respName = resp.getName();
                String type = respName.substring(respName.indexOf("_") + 1);
                res_responseform.addAttribute("response_type", type);
                // add user answer
                ItemInput itemInp = itemc.getItemInput();
                Translator trans = Util.createPackageTranslator(QTIModule.class, locale);
                if (itemInp == null) {
                    // user did not answer this question at all
                    res_response.addElement("response_value").addText(trans.translate("ResBuilder.NoAnswer"));
                } else {
                    List<String> userAnswer = itemInp.getAsList(ident);
                    if (userAnswer == null) {
                        // user did not answer this question at
                        // all
                        res_response.addElement("response_value").addText(trans.translate("ResBuilder.NoAnswer"));
                    } else {
                        // simply click send)
                        for (Iterator<String> it_ans = userAnswer.iterator(); it_ans.hasNext(); ) {
                            res_response.addElement("response_value").addText(it_ans.next());
                        }
                    }
                }
            }
            /*
				 * The simple element correct_response can only list correct elements,
				 * that is, no "or" or "and" elements may be in the conditionvar.
				 * Pragmatic solution: if condition has ors or ands, then put whole
				 * conditionvar into <extension_response> (proprietary), and for easier
				 * cases (just "varequal" "not" elements) use correct_response.
				 */
            // keys: respIdents, values: HashSet
            Map<String, Set<String>> corr_answers = new HashMap<>();
            // of correct answers for this
            // respIdent
            List respconds = el_item.selectNodes(".//respcondition");
            for (Iterator it_respc = respconds.iterator(); it_respc.hasNext(); ) {
                Element el_respc = (Element) it_respc.next();
                // check for add/set in setvar elements (check for single instance
                // only -> spec allows for multiple instances)
                Element el_setvar = (Element) el_respc.selectSingleNode(".//setvar");
                if (el_setvar == null)
                    continue;
                if (el_setvar.attributeValue("action").equals("Add") || el_setvar.attributeValue("action").equals("Set")) {
                    // This resrocessing gives points -> assume correct answer
                    float numPoints = 0;
                    try {
                        numPoints = Float.parseFloat(el_setvar.getTextTrim());
                    } catch (NumberFormatException nfe) {
                    // 
                    }
                    if (numPoints <= 0)
                        continue;
                    Element conditionvar = (Element) el_respc.selectSingleNode(".//conditionvar");
                    // there is an evaluation defined (a "resprocessing" element exists)
                    // if (xpath(count(.//varequal) + count(.//not) = count(.//*)) is
                    // true, then there are only "not" and "varequal" elements
                    XPath xCanHandle = DocumentHelper.createXPath("count(.//varequal) + count(.//not) = count(.//*)");
                    boolean canHandle = xCanHandle.matches(conditionvar);
                    if (!canHandle) {
                        // maybe we have <condvar> <and> <...>, try again
                        Element el_and = (Element) conditionvar.selectSingleNode("and");
                        if (el_and != null) {
                            canHandle = xCanHandle.matches(el_and);
                            if (canHandle) {
                                // simultate the el_and to be the conditionvar
                                conditionvar = el_and;
                            }
                        } else {
                            // and finally, maybe we have an <or> element ..
                            Element el_or = (Element) conditionvar.selectSingleNode("or");
                            if (el_or != null) {
                                canHandle = xCanHandle.matches(el_or);
                                if (canHandle) {
                                    // simultate the el_and to be the conditionvar
                                    conditionvar = el_or;
                                }
                            }
                        }
                    }
                    if (!canHandle) {
                        // qti res 1.2.1 can't handle it
                        Element condcopy = conditionvar.createCopy();
                        itres.addElement("extension_item_result").add(condcopy);
                    } else {
                        /*
							 * easy case: get all varequal directly under the conditionvar
							 * element and assume the "not" elements do not contain "not"
							 * elements again... <!ELEMENT response (qti_comment? ,
							 * response_form? , num_attempts? , response_value* ,
							 * extension_response?)> <!ELEMENT response_form
							 * (correct_response* , extension_responseform?)> <!ELEMENT
							 * correct_response (#PCDATA)>
							 */
                        List vareqs = conditionvar.selectNodes("./varequal");
                        for (Iterator it_vareq = vareqs.iterator(); it_vareq.hasNext(); ) {
                            /*
								 * get the identifier of the response, so that we can attach the
								 * <correct_response> to the right <response> element quote: ims
								 * qti asi xml binding :3.6.23.1 <varequal> Element: respident
								 * (required). The identifier of the corresponding
								 * <response_lid>, <response_xy>, etc. element (this was
								 * assigned using its ident attribute).
								 */
                            Element vareq = (Element) it_vareq.next();
                            String respIdent = vareq.attributeValue("respident");
                            Set<String> respIdent_corr_answers = corr_answers.get(respIdent);
                            if (respIdent_corr_answers == null)
                                respIdent_corr_answers = new HashSet<String>(3);
                            respIdent_corr_answers.add(vareq.getText());
                            corr_answers.put(respIdent, respIdent_corr_answers);
                        }
                    // for varequal
                    }
                // else varequal
                }
            // add/set setvar
            }
            // for resprocessing
            Set<String> resp_ids = corr_answers.keySet();
            for (Iterator<String> idents = resp_ids.iterator(); idents.hasNext(); ) {
                String respIdent = idents.next();
                Set<String> respIdent_corr_answers = corr_answers.get(respIdent);
                Element res_response = res_responsehash.get(respIdent);
                Element res_respform = res_response.element("response_form");
                for (Iterator<String> iter = respIdent_corr_answers.iterator(); iter.hasNext(); ) {
                    String answer = iter.next();
                    res_respform.addElement("correct_response").addText(answer);
                }
            }
        }
    // for response_xy
    }
    return res_doc;
}
Also used : SectionContext(org.olat.ims.qti.container.SectionContext) User(org.olat.core.id.User) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Element(org.dom4j.Element) Document(org.dom4j.Document) ItemInput(org.olat.ims.qti.container.ItemInput) DecimalVariable(org.olat.ims.qti.container.DecimalVariable) Translator(org.olat.core.gui.translator.Translator) Iterator(java.util.Iterator) List(java.util.List) HashSet(java.util.HashSet) XPath(org.dom4j.XPath) Date(java.util.Date) AssessmentContext(org.olat.ims.qti.container.AssessmentContext) ItemContext(org.olat.ims.qti.container.ItemContext) DocumentFactory(org.dom4j.DocumentFactory)

Example 2 with AssessmentContext

use of org.olat.ims.qti.container.AssessmentContext in project OpenOLAT by OpenOLAT.

the class QTI12PullTestsToolController method retrieveTest.

private void retrieveTest(Identity assessedIdentity, ICourse course) {
    ModuleConfiguration modConfig = courseNode.getModuleConfiguration();
    String resourcePathInfo = courseEnv.getCourseResourceableId() + File.separator + courseNode.getIdent();
    AssessmentInstance ai = AssessmentFactory.createAssessmentInstance(assessedIdentity, "", modConfig, false, courseEnv.getCourseResourceableId(), courseNode.getIdent(), 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 = new Float(ac.getScore());
    Boolean passed = new Boolean(ac.isPassed());
    ScoreEvaluation sceval = new ScoreEvaluation(score, passed, Boolean.FALSE, new Long(ai.getAssessID()));
    UserCourseEnvironment userCourseEnv = AssessmentHelper.createAndInitUserCourseEnvironment(assessedIdentity, course);
    courseNode.updateUserScoreEvaluation(sceval, userCourseEnv, assessedIdentity, true, Role.coach);
    // cleanup
    ai.cleanUp();
}
Also used : AssessmentContext(org.olat.ims.qti.container.AssessmentContext) ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) ModuleConfiguration(org.olat.modules.ModuleConfiguration) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) AssessmentInstance(org.olat.ims.qti.process.AssessmentInstance) Document(org.dom4j.Document)

Example 3 with AssessmentContext

use of org.olat.ims.qti.container.AssessmentContext in project OpenOLAT by OpenOLAT.

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();
}
Also used : ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) ModuleConfiguration(org.olat.modules.ModuleConfiguration) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) ICourse(org.olat.course.ICourse) Document(org.dom4j.Document) QTIDocument(org.olat.ims.qti.editor.beecom.objects.QTIDocument) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) AssessmentContext(org.olat.ims.qti.container.AssessmentContext) AssessmentInstance(org.olat.ims.qti.process.AssessmentInstance)

Example 4 with AssessmentContext

use of org.olat.ims.qti.container.AssessmentContext in project OpenOLAT by OpenOLAT.

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);
    }
}
Also used : AssessmentContext(org.olat.ims.qti.container.AssessmentContext) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) PersistentAssessableCourseNode(org.olat.course.nodes.PersistentAssessableCourseNode) SelfAssessableCourseNode(org.olat.course.nodes.SelfAssessableCourseNode) ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) AssessmentManager(org.olat.course.assessment.AssessmentManager) AssessmentEntryStatus(org.olat.modules.assessment.model.AssessmentEntryStatus)

Example 5 with AssessmentContext

use of org.olat.ims.qti.container.AssessmentContext in project OpenOLAT by OpenOLAT.

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);
    }
}
Also used : SectionContext(org.olat.ims.qti.container.SectionContext) ScoreEvaluation(org.olat.course.run.scoring.ScoreEvaluation) HttpItemInput(org.olat.ims.qti.container.HttpItemInput) ItemInput(org.olat.ims.qti.container.ItemInput) ItemsInput(org.olat.ims.qti.container.ItemsInput) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) AssessmentInstance(org.olat.ims.qti.process.AssessmentInstance) CourseNode(org.olat.course.nodes.CourseNode) AssessableCourseNode(org.olat.course.nodes.AssessableCourseNode) IQTESTCourseNode(org.olat.course.nodes.IQTESTCourseNode) IdentityEnvironment(org.olat.core.id.IdentityEnvironment) IQManager(org.olat.modules.iq.IQManager) ModuleConfiguration(org.olat.modules.ModuleConfiguration) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) CourseEnvironment(org.olat.course.run.environment.CourseEnvironment) UserCourseEnvironment(org.olat.course.run.userview.UserCourseEnvironment) Navigator(org.olat.ims.qti.navigator.Navigator) MenuItemNavigator(org.olat.ims.qti.navigator.MenuItemNavigator) Info(org.olat.ims.qti.navigator.Info) WebApplicationException(javax.ws.rs.WebApplicationException) QTIResultSet(org.olat.ims.qti.QTIResultSet) MenuItemNavigator(org.olat.ims.qti.navigator.MenuItemNavigator) AssessmentContext(org.olat.ims.qti.container.AssessmentContext) ItemContext(org.olat.ims.qti.container.ItemContext) UserCourseEnvironmentImpl(org.olat.course.run.userview.UserCourseEnvironmentImpl)

Aggregations

AssessmentContext (org.olat.ims.qti.container.AssessmentContext)44 SectionContext (org.olat.ims.qti.container.SectionContext)28 ItemContext (org.olat.ims.qti.container.ItemContext)20 AssessmentInstance (org.olat.ims.qti.process.AssessmentInstance)12 ItemInput (org.olat.ims.qti.container.ItemInput)10 ScoreEvaluation (org.olat.course.run.scoring.ScoreEvaluation)8 Output (org.olat.ims.qti.container.Output)8 Document (org.dom4j.Document)6 AssessableCourseNode (org.olat.course.nodes.AssessableCourseNode)6 UserCourseEnvironment (org.olat.course.run.userview.UserCourseEnvironment)6 Hint (org.olat.ims.qti.container.qtielements.Hint)6 ModuleConfiguration (org.olat.modules.ModuleConfiguration)6 Date (java.util.Date)4 List (java.util.List)4 StringOutput (org.olat.core.gui.render.StringOutput)4 QTIResultSet (org.olat.ims.qti.QTIResultSet)4 HttpItemInput (org.olat.ims.qti.container.HttpItemInput)4 Info (org.olat.ims.qti.navigator.Info)4 Resolver (org.olat.ims.qti.process.Resolver)4 Navigator (org.olat.ims.qti.navigator.Navigator)3