Search in sources :

Example 1 with BaseType

use of uk.ac.ed.ph.jqtiplus.value.BaseType in project openolat by klemens.

the class AssessmentItemChecker method checkSetCorrectResponse.

/**
 * responseDeclaration -> float
 *
 * templateVraiable -> integer
 *
 * setCorrectResponse
 *   -> variable -> integer doesn't match float -> issue
 * @param item
 * @return
 */
private static boolean checkSetCorrectResponse(AssessmentItem item) {
    boolean allOk = true;
    List<SetCorrectResponse> setCorrectResponses = QueryUtils.search(SetCorrectResponse.class, item);
    for (SetCorrectResponse setCorrectResponse : setCorrectResponses) {
        Identifier responseIdentifier = setCorrectResponse.getIdentifier();
        ResponseDeclaration responseDeclaration = item.getResponseDeclaration(responseIdentifier);
        BaseType baseType = responseDeclaration.getBaseType();
        Expression expression = setCorrectResponse.getExpression();
        if (expression instanceof Variable) {
            Variable variable = (Variable) expression;
            ComplexReferenceIdentifier cpxVariableIdentifier = variable.getIdentifier();
            Identifier variableIdentifier = Identifier.assumedLegal(cpxVariableIdentifier.toString());
            TemplateDeclaration templateDeclaration = item.getTemplateDeclaration(variableIdentifier);
            if (templateDeclaration != null && !templateDeclaration.hasBaseType(baseType)) {
                templateDeclaration.setBaseType(baseType);
                allOk &= false;
            }
        }
    }
    return allOk;
}
Also used : ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) SetCorrectResponse(uk.ac.ed.ph.jqtiplus.node.item.template.processing.SetCorrectResponse) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) Variable(uk.ac.ed.ph.jqtiplus.node.expression.general.Variable) BaseType(uk.ac.ed.ph.jqtiplus.value.BaseType) Expression(uk.ac.ed.ph.jqtiplus.node.expression.Expression) TemplateDeclaration(uk.ac.ed.ph.jqtiplus.node.item.template.declaration.TemplateDeclaration) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Example 2 with BaseType

use of uk.ac.ed.ph.jqtiplus.value.BaseType in project OpenOLAT by OpenOLAT.

the class AssessmentItemChecker method checkSetCorrectResponse.

/**
 * responseDeclaration -> float
 *
 * templateVraiable -> integer
 *
 * setCorrectResponse
 *   -> variable -> integer doesn't match float -> issue
 * @param item
 * @return
 */
private static boolean checkSetCorrectResponse(AssessmentItem item) {
    boolean allOk = true;
    List<SetCorrectResponse> setCorrectResponses = QueryUtils.search(SetCorrectResponse.class, item);
    for (SetCorrectResponse setCorrectResponse : setCorrectResponses) {
        Identifier responseIdentifier = setCorrectResponse.getIdentifier();
        ResponseDeclaration responseDeclaration = item.getResponseDeclaration(responseIdentifier);
        BaseType baseType = responseDeclaration.getBaseType();
        Expression expression = setCorrectResponse.getExpression();
        if (expression instanceof Variable) {
            Variable variable = (Variable) expression;
            ComplexReferenceIdentifier cpxVariableIdentifier = variable.getIdentifier();
            Identifier variableIdentifier = Identifier.assumedLegal(cpxVariableIdentifier.toString());
            TemplateDeclaration templateDeclaration = item.getTemplateDeclaration(variableIdentifier);
            if (templateDeclaration != null && !templateDeclaration.hasBaseType(baseType)) {
                templateDeclaration.setBaseType(baseType);
                allOk &= false;
            }
        }
    }
    return allOk;
}
Also used : ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) SetCorrectResponse(uk.ac.ed.ph.jqtiplus.node.item.template.processing.SetCorrectResponse) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) ComplexReferenceIdentifier(uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier) Variable(uk.ac.ed.ph.jqtiplus.node.expression.general.Variable) BaseType(uk.ac.ed.ph.jqtiplus.value.BaseType) Expression(uk.ac.ed.ph.jqtiplus.node.expression.Expression) TemplateDeclaration(uk.ac.ed.ph.jqtiplus.node.item.template.declaration.TemplateDeclaration) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Aggregations

Expression (uk.ac.ed.ph.jqtiplus.node.expression.Expression)2 Variable (uk.ac.ed.ph.jqtiplus.node.expression.general.Variable)2 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)2 TemplateDeclaration (uk.ac.ed.ph.jqtiplus.node.item.template.declaration.TemplateDeclaration)2 SetCorrectResponse (uk.ac.ed.ph.jqtiplus.node.item.template.processing.SetCorrectResponse)2 ComplexReferenceIdentifier (uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier)2 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)2 BaseType (uk.ac.ed.ph.jqtiplus.value.BaseType)2