use of uk.ac.ed.ph.jqtiplus.node.item.interaction.HotspotInteraction in project OpenOLAT by OpenOLAT.
the class AssessmentItemBuilderTest method buildAssessmentItem_hotspot.
@Test
public void buildAssessmentItem_hotspot() throws IOException, URISyntaxException {
QtiSerializer qtiSerializer = new QtiSerializer(new JqtiExtensionManager());
HotspotAssessmentItemBuilder itemBuilder = new HotspotAssessmentItemBuilder("Hotspot", qtiSerializer);
if (build.booleanValue()) {
itemBuilder.build();
}
AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
ItemValidationResult itemResult = serializeAndReload(assessmentItem);
AssessmentItem reloadedItem = itemResult.getResolvedAssessmentItem().getItemLookup().extractIfSuccessful();
List<Interaction> interactions = reloadedItem.getItemBody().findInteractions();
Assert.assertNotNull(interactions);
Assert.assertEquals(1, interactions.size());
Assert.assertTrue(interactions.get(0) instanceof HotspotInteraction);
HotspotInteraction interaction = (HotspotInteraction) interactions.get(0);
Assert.assertNotNull(interaction.getResponseIdentifier());
ResponseDeclaration responseDeclaration = reloadedItem.getResponseDeclaration(interaction.getResponseIdentifier());
Assert.assertNotNull(responseDeclaration);
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.HotspotInteraction in project OpenOLAT by OpenOLAT.
the class HotspotAssessmentItemBuilder method extractHotspotInteraction.
private void extractHotspotInteraction() {
try (StringOutput sb = new StringOutput()) {
List<Block> blocks = assessmentItem.getItemBody().getBlocks();
for (Block block : blocks) {
if (block instanceof HotspotInteraction) {
hotspotInteraction = (HotspotInteraction) block;
responseIdentifier = hotspotInteraction.getResponseIdentifier();
break;
} else {
serializeJqtiObject(block, sb);
}
}
question = sb.toString();
} catch (IOException e) {
log.error("", e);
}
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.HotspotInteraction in project OpenOLAT by OpenOLAT.
the class AssessmentObjectVelocityRenderDecorator method isSingleChoice.
/**
* Check the maxChoices and the cardinality
* @param interaction
* @return
*/
public boolean isSingleChoice(Interaction interaction) {
if (interaction instanceof ChoiceInteraction) {
ChoiceInteraction choiceInteraction = (ChoiceInteraction) interaction;
boolean sc = choiceInteraction.getMaxChoices() == 1;
ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(choiceInteraction.getResponseIdentifier());
if (responseDeclaration != null && responseDeclaration.hasCardinality(Cardinality.MULTIPLE)) {
return false;
}
return sc;
} else if (interaction instanceof HottextInteraction) {
HottextInteraction hottextInteraction = (HottextInteraction) interaction;
boolean sc = hottextInteraction.getMaxChoices() == 1;
ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(hottextInteraction.getResponseIdentifier());
if (responseDeclaration != null && responseDeclaration.hasCardinality(Cardinality.MULTIPLE)) {
return false;
}
return sc;
} else if (interaction instanceof HotspotInteraction) {
HotspotInteraction hotspotInteraction = (HotspotInteraction) interaction;
ResponseDeclaration responseDeclaration = assessmentItem.getResponseDeclaration(hotspotInteraction.getResponseIdentifier());
if (responseDeclaration != null && responseDeclaration.hasCardinality(Cardinality.SINGLE)) {
return true;
}
return false;
}
return false;
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.HotspotInteraction in project openolat by klemens.
the class HotspotAssessmentItemBuilder method extractHotspotInteraction.
private void extractHotspotInteraction() {
try (StringOutput sb = new StringOutput()) {
List<Block> blocks = assessmentItem.getItemBody().getBlocks();
for (Block block : blocks) {
if (block instanceof HotspotInteraction) {
hotspotInteraction = (HotspotInteraction) block;
responseIdentifier = hotspotInteraction.getResponseIdentifier();
break;
} else {
serializeJqtiObject(block, sb);
}
}
question = sb.toString();
} catch (IOException e) {
log.error("", e);
}
}
use of uk.ac.ed.ph.jqtiplus.node.item.interaction.HotspotInteraction in project openolat by klemens.
the class HotspotAssessmentItemBuilder method getQuestionBlocks.
/**
* @return A copy of the list of blocks which make the question.
* The list is a copy and modification will not be persisted.
*/
public List<Block> getQuestionBlocks() {
List<Block> blocks = assessmentItem.getItemBody().getBlocks();
List<Block> questionBlocks = new ArrayList<>(blocks.size());
for (Block block : blocks) {
if (block instanceof HotspotInteraction) {
break;
} else {
questionBlocks.add(block);
}
}
return questionBlocks;
}
Aggregations