Search in sources :

Example 1 with OrderedValue

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

the class CorrectResponsesUtil method getCorrectOrderedIdentifierResponses.

public static final List<Identifier> getCorrectOrderedIdentifierResponses(AssessmentItem assessmentItem, Interaction interaction) {
    List<Identifier> correctAnswers = new ArrayList<>(5);
    ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(interaction.getResponseIdentifier());
    if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
        CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
        if (correctResponse.getCardinality().isOneOf(Cardinality.ORDERED)) {
            List<FieldValue> values = correctResponse.getFieldValues();
            Value value = FieldValue.computeValue(Cardinality.ORDERED, values);
            if (value instanceof OrderedValue) {
                OrderedValue multiValue = (OrderedValue) value;
                multiValue.forEach(oValue -> {
                    if (oValue instanceof IdentifierValue) {
                        IdentifierValue identifierValue = (IdentifierValue) oValue;
                        Identifier correctAnswer = identifierValue.identifierValue();
                        correctAnswers.add(correctAnswer);
                    }
                });
            }
        }
    }
    return correctAnswers;
}
Also used : Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) OrderedValue(uk.ac.ed.ph.jqtiplus.value.OrderedValue) ArrayList(java.util.ArrayList) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) OrderedValue(uk.ac.ed.ph.jqtiplus.value.OrderedValue) MultipleValue(uk.ac.ed.ph.jqtiplus.value.MultipleValue) PointValue(uk.ac.ed.ph.jqtiplus.value.PointValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) IntegerValue(uk.ac.ed.ph.jqtiplus.value.IntegerValue) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue) PairValue(uk.ac.ed.ph.jqtiplus.value.PairValue) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) CorrectResponse(uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Example 2 with OrderedValue

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

the class CorrectResponsesUtil method getCorrectOrderedIdentifierResponses.

public static final List<Identifier> getCorrectOrderedIdentifierResponses(AssessmentItem assessmentItem, Interaction interaction) {
    List<Identifier> correctAnswers = new ArrayList<>(5);
    ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(interaction.getResponseIdentifier());
    if (responseDeclaration != null && responseDeclaration.getCorrectResponse() != null) {
        CorrectResponse correctResponse = responseDeclaration.getCorrectResponse();
        if (correctResponse.getCardinality().isOneOf(Cardinality.ORDERED)) {
            List<FieldValue> values = correctResponse.getFieldValues();
            Value value = FieldValue.computeValue(Cardinality.ORDERED, values);
            if (value instanceof OrderedValue) {
                OrderedValue multiValue = (OrderedValue) value;
                multiValue.forEach(oValue -> {
                    if (oValue instanceof IdentifierValue) {
                        IdentifierValue identifierValue = (IdentifierValue) oValue;
                        Identifier correctAnswer = identifierValue.identifierValue();
                        correctAnswers.add(correctAnswer);
                    }
                });
            }
        }
    }
    return correctAnswers;
}
Also used : Identifier(uk.ac.ed.ph.jqtiplus.types.Identifier) OrderedValue(uk.ac.ed.ph.jqtiplus.value.OrderedValue) ArrayList(java.util.ArrayList) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) OrderedValue(uk.ac.ed.ph.jqtiplus.value.OrderedValue) MultipleValue(uk.ac.ed.ph.jqtiplus.value.MultipleValue) PointValue(uk.ac.ed.ph.jqtiplus.value.PointValue) Value(uk.ac.ed.ph.jqtiplus.value.Value) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) SingleValue(uk.ac.ed.ph.jqtiplus.value.SingleValue) IntegerValue(uk.ac.ed.ph.jqtiplus.value.IntegerValue) DirectedPairValue(uk.ac.ed.ph.jqtiplus.value.DirectedPairValue) PairValue(uk.ac.ed.ph.jqtiplus.value.PairValue) IdentifierValue(uk.ac.ed.ph.jqtiplus.value.IdentifierValue) CorrectResponse(uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse) FieldValue(uk.ac.ed.ph.jqtiplus.node.shared.FieldValue) ResponseDeclaration(uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)

Aggregations

ArrayList (java.util.ArrayList)2 CorrectResponse (uk.ac.ed.ph.jqtiplus.node.item.CorrectResponse)2 ResponseDeclaration (uk.ac.ed.ph.jqtiplus.node.item.response.declaration.ResponseDeclaration)2 FieldValue (uk.ac.ed.ph.jqtiplus.node.shared.FieldValue)2 Identifier (uk.ac.ed.ph.jqtiplus.types.Identifier)2 DirectedPairValue (uk.ac.ed.ph.jqtiplus.value.DirectedPairValue)2 IdentifierValue (uk.ac.ed.ph.jqtiplus.value.IdentifierValue)2 IntegerValue (uk.ac.ed.ph.jqtiplus.value.IntegerValue)2 MultipleValue (uk.ac.ed.ph.jqtiplus.value.MultipleValue)2 OrderedValue (uk.ac.ed.ph.jqtiplus.value.OrderedValue)2 PairValue (uk.ac.ed.ph.jqtiplus.value.PairValue)2 PointValue (uk.ac.ed.ph.jqtiplus.value.PointValue)2 SingleValue (uk.ac.ed.ph.jqtiplus.value.SingleValue)2 Value (uk.ac.ed.ph.jqtiplus.value.Value)2