Search in sources :

Example 51 with SingleValue

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

the class AssessmentRenderFunctions method extractRecordFieldValue.

/*
  <xsl:function name="qw:extract-record-field-value" as="xs:string?">
    <xsl:param name="valueHolder" as="element()"/>
    <xsl:param name="fieldName" as="xs:string"/>
    <xsl:choose>
      <xsl:when test="qw:is-record-cardinality-value($valueHolder)">
        <xsl:value-of select="$valueHolder/qw:value[@fieldIdentifier=$fieldName]"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:message terminate="yes">
          Expected value <xsl:copy-of select="$valueHolder"/> to have record
          cardinalty.
        </xsl:message>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:function>
	 */
public static SingleValue extractRecordFieldValue(Value value, Identifier identifier) {
    SingleValue mappedValue = null;
    if (value != null && identifier != null && value.hasCardinality(Cardinality.RECORD)) {
        RecordValue recordValue = (RecordValue) value;
        mappedValue = recordValue.get(identifier);
    }
    return mappedValue;
}
Also used : SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) RecordValue(uk.ac.ed.ph.jqtiplus.value.RecordValue)

Example 52 with SingleValue

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

the class AssessmentObjectComponentRenderer method renderPrintedVariable.

/**
 * The QTI spec says that this variable must have single cardinality.
 *
 * For convenience, we also accept multiple, ordered and record cardinality variables here,
 * printing them out in a hard-coded form that probably won't make sense to test
 * candidates but might be useful for debugging.
 *
 * Our implementation additionally adds support for "printing" MathsContent variables
 * used in MathAssess, outputting an inline Presentation MathML element, as documented
 * in the MathAssses spec.
 */
protected void renderPrintedVariable(AssessmentRenderer renderer, StringOutput sb, PrintedVariable source, VariableDeclaration valueDeclaration, Value valueHolder) {
    if (isNullValue(valueHolder)) {
    // (Spec says to output nothing in this case)
    } else if (isSingleCardinalityValue(valueHolder)) {
        if (valueDeclaration.hasBaseType(BaseType.INTEGER) || valueDeclaration.hasBaseType(BaseType.FLOAT)) {
            renderSingleCardinalityValue(sb, valueHolder);
        } else {
            renderSingleCardinalityValue(sb, valueHolder);
        }
    // math content is a record with special markers
    } else if (isMathsContentValue(valueHolder)) {
        // <xsl:copy-of select="qw:extract-maths-content-pmathml($valueHolder)"/>
        String mathMlContent = extractMathsContentPmathml(valueHolder);
        if (renderer.isMathXsltDisabled()) {
            sb.append(mathMlContent);
        } else {
            transformMathmlAsString(sb, mathMlContent);
        }
    } else if (isMultipleCardinalityValue(valueHolder)) {
        String delimiter = source.getDelimiter();
        if (!StringHelper.containsNonWhitespace(delimiter)) {
            delimiter = ";";
        }
        renderMultipleCardinalityValue(sb, valueHolder, delimiter);
    } else if (isOrderedCardinalityValue(valueHolder)) {
        if (source.getIndex() != null) {
            int index = -1;
            if (source.getIndex().isConstantInteger()) {
                index = source.getIndex().getConstantIntegerValue().intValue();
            } else if (source.getIndex().isVariableRef()) {
            // TODO qti what to do???
            }
            SingleValue indexedValue = extractIterableElement(valueHolder, index);
            renderSingleCardinalityValue(sb, indexedValue);
        } else {
            String delimiter = source.getDelimiter();
            if (!StringHelper.containsNonWhitespace(delimiter)) {
                delimiter = ";";
            }
            renderOrderedCardinalityValue(sb, valueHolder, delimiter);
        }
    } else if (isRecordCardinalityValue(valueHolder)) {
        String field = source.getField();
        if (StringHelper.containsNonWhitespace(field)) {
            Identifier fieldIdentifier = Identifier.assumedLegal(field);
            SingleValue mappedValue = extractRecordFieldValue(valueHolder, fieldIdentifier);
            renderSingleCardinalityValue(sb, mappedValue);
        } else {
            String delimiter = source.getDelimiter();
            String mappingIndicator = source.getMappingIndicator();
            if (!StringHelper.containsNonWhitespace(delimiter)) {
                delimiter = ";";
            }
            if (!StringHelper.containsNonWhitespace(mappingIndicator)) {
                mappingIndicator = "=";
            }
            renderRecordCardinalityValue(sb, valueHolder, delimiter, mappingIndicator);
        }
    } else {
        sb.append("printedVariable may not be applied to value ").append(valueHolder.toString());
    }
}
Also used : SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) AssessmentRenderFunctions.contentAsString(org.olat.ims.qti21.ui.components.AssessmentRenderFunctions.contentAsString)

Aggregations

SingleValue (uk.ac.ed.ph.jqtiplus.value.SingleValue)52 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)30 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)20 FieldValue (uk.ac.ed.ph.jqtiplus.node.shared.FieldValue)18 IdentifierValue (uk.ac.ed.ph.jqtiplus.value.IdentifierValue)18 DirectedPairValue (uk.ac.ed.ph.jqtiplus.value.DirectedPairValue)16 CorrectResponse (uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse)14 MapEntry (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.MapEntry)14 RecordValue (uk.ac.ed.ph.jqtiplus.value.RecordValue)14 ArrayList (java.util.ArrayList)12 BaseValue (uk.ac.ed.ph.jqtiplus.node.expression.general.BaseValue)12 ComplexReferenceIdentifier (uk.ac.ed.ph.jqtiplus.types.ComplexReferenceIdentifier)12 Mapping (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.Mapping)10 Value (uk.ac.ed.ph.jqtiplus.value.Value)10 MultipleValue (uk.ac.ed.ph.jqtiplus.value.MultipleValue)8 Map (java.util.Map)6 Expression (uk.ac.ed.ph.jqtiplus.node.expression.Expression)6 StringValue (uk.ac.ed.ph.jqtiplus.value.StringValue)6 AssessmentItemFactory.appendAssociationMatchResponseDeclaration (org.olat.ims.qti21.model.xml.AssessmentItemFactory.appendAssociationMatchResponseDeclaration)4 AssessmentItemFactory.createMatchResponseDeclaration (org.olat.ims.qti21.model.xml.AssessmentItemFactory.createMatchResponseDeclaration)4