use of org.olat.ims.qti21.model.xml.AssessmentItemBuilder in project openolat by klemens.
the class QTI12To21Converter method convertFIB.
private AssessmentItemBuilder convertFIB(Item item) {
FIBAssessmentItemBuilder itemBuilder = new FIBAssessmentItemBuilder("Gap text", EntryType.text, qtiSerializer);
itemBuilder.setQuestion("");
itemBuilder.clearTextEntries();
convertItemBasics(item, itemBuilder);
Question question = item.getQuestion();
boolean singleCorrect = question.isSingleCorrect();
if (singleCorrect) {
itemBuilder.setScoreEvaluationMode(ScoreEvaluation.allCorrectAnswers);
} else {
itemBuilder.setScoreEvaluationMode(ScoreEvaluation.perAnswer);
}
itemBuilder.getMinScoreBuilder().setScore(new Double(question.getMinValue()));
itemBuilder.getMaxScoreBuilder().setScore(new Double(question.getMaxValue()));
List<Response> responses = question.getResponses();
StringBuilder sb = new StringBuilder();
for (Response response : responses) {
if (response instanceof FIBResponse) {
FIBResponse gap = (FIBResponse) response;
if (FIBResponse.TYPE_BLANK.equals(gap.getType())) {
String responseId = itemBuilder.generateResponseIdentifier();
StringBuilder entryString = new StringBuilder();
entryString.append(" <textentryinteraction responseidentifier=\"").append(responseId).append("\"");
TextEntry entry = itemBuilder.createTextEntry(responseId);
entry.setCaseSensitive("Yes".equals(gap.getCaseSensitive()));
if (gap.getMaxLength() > 0) {
entry.setExpectedLength(gap.getMaxLength());
entryString.append(" expectedlength=\"").append(gap.getMaxLength()).append("\"");
} else if (gap.getSize() > 0) {
entry.setExpectedLength(gap.getSize());
entryString.append(" expectedlength=\"").append(gap.getSize()).append("\"");
}
parseAlternatives(gap.getCorrectBlank(), gap.getPoints(), entry);
entryString.append("></textentryinteraction>");
sb.append(entryString);
} else if (FIBResponse.TYPE_CONTENT.equals(gap.getType())) {
Material text = gap.getContent();
String htmltext = text.renderAsHtmlForEditor();
htmltext = blockedHtml(htmltext);
sb.append(htmltext);
}
}
}
String fib = "<div>" + sb.toString() + "</div>";
itemBuilder.setQuestion(fib);
return itemBuilder;
}
use of org.olat.ims.qti21.model.xml.AssessmentItemBuilder in project openolat by klemens.
the class QTI12To21Converter method convert.
private void convert(Section section, TestPart testPart) throws URISyntaxException {
AssessmentSection assessmentSection = AssessmentTestFactory.appendAssessmentSection("Section", testPart);
assessmentSection.setTitle(section.getTitle());
convertDuration(section.getDuration(), assessmentSection);
RubricBlock rubricBlock = assessmentSection.getRubricBlocks().get(0);
rubricBlock.getBlocks().clear();
String objectives = section.getObjectives();
htmlBuilder.appendHtml(rubricBlock, blockedHtml(objectives));
boolean shuffle = SelectionOrdering.RANDOM.equals(section.getSelection_ordering().getOrderType());
assessmentSection.getOrdering().setShuffle(shuffle);
int selectionNum = section.getSelection_ordering().getSelectionNumber();
if (selectionNum > 0) {
Selection selection = new Selection(assessmentSection);
selection.setSelect(selectionNum);
assessmentSection.setSelection(selection);
}
List<Item> items = section.getItems();
for (Item item : items) {
AssessmentItemBuilder itemBuilder = null;
if (item != null && item.getQuestion() != null) {
int questionType = item.getQuestion().getType();
switch(questionType) {
case Question.TYPE_SC:
itemBuilder = convertSingleChoice(item);
break;
case Question.TYPE_MC:
itemBuilder = convertMultipleChoice(item);
break;
case Question.TYPE_KPRIM:
itemBuilder = convertKPrim(item);
break;
case Question.TYPE_FIB:
itemBuilder = convertFIB(item);
break;
case Question.TYPE_ESSAY:
itemBuilder = convertEssay(item);
break;
}
} else {
errors.add(item.getTitle());
log.error("Item without question: " + item);
}
if (itemBuilder != null) {
itemBuilder.build();
AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
AssessmentItemRef itemRef = new AssessmentItemRef(assessmentSection);
String itemId = IdentifierGenerator.newAsString(itemBuilder.getQuestionType().getPrefix());
itemRef.setIdentifier(Identifier.parseString(itemId));
convertItemBasics(item, itemRef);
File itemFile = new File(unzippedDirRoot, itemId + ".xml");
itemRef.setHref(new URI(itemFile.getName()));
assessmentSection.getSectionParts().add(itemRef);
persistAssessmentObject(itemFile, assessmentItem);
appendResourceAndMetadata(item, itemBuilder, itemFile);
// collect max score
Double maxScore = QtiNodesExtractor.extractMaxScore(assessmentItem);
if (maxScore != null && maxScore.doubleValue() > 0.0d) {
atomicMaxScore.add(maxScore.doubleValue());
}
}
}
}
use of org.olat.ims.qti21.model.xml.AssessmentItemBuilder in project openolat by klemens.
the class QTI12To21Converter method convertKPrim.
private AssessmentItemBuilder convertKPrim(Item item) {
KPrimAssessmentItemBuilder itemBuilder = new KPrimAssessmentItemBuilder("Kprim", "New answer", qtiSerializer);
convertItemBasics(item, itemBuilder);
Question question = item.getQuestion();
itemBuilder.setShuffle(question.isShuffle());
List<Response> responses = question.getResponses();
List<SimpleAssociableChoice> choices = itemBuilder.getKprimChoices();
for (int i = 0; i < 4; i++) {
Response response = responses.get(i);
SimpleAssociableChoice choice = choices.get(i);
String answer = response.getContent().renderAsHtmlForEditor();
answer = blockedHtml(answer);
if (StringHelper.isHtml(answer)) {
htmlBuilder.appendHtml(choice, answer);
} else {
P firstChoiceText = AssessmentItemFactory.getParagraph(choice, answer);
choice.getFlowStatics().clear();
choice.getFlowStatics().add(firstChoiceText);
}
if (response.isCorrect()) {
itemBuilder.setAssociation(choice.getIdentifier(), QTI21Constants.CORRECT_IDENTIFIER);
} else {
itemBuilder.setAssociation(choice.getIdentifier(), QTI21Constants.WRONG_IDENTIFIER);
}
}
double score = question.getMaxValue();
itemBuilder.setMinScore(0.0d);
itemBuilder.setMaxScore(score);
return itemBuilder;
}
use of org.olat.ims.qti21.model.xml.AssessmentItemBuilder in project openolat by klemens.
the class QTI12To21Converter method convertItemBasics.
private void convertItemBasics(Item item, AssessmentItemBuilder itemBuilder) {
AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
if (StringHelper.containsNonWhitespace(item.getTitle())) {
assessmentItem.setTitle(item.getTitle());
}
if (StringHelper.containsNonWhitespace(item.getLabel())) {
assessmentItem.setLabel(item.getLabel());
}
Question question = item.getQuestion();
String questionText = question.getQuestion().renderAsHtmlForEditor();
questionText = blockedHtml(questionText);
if (StringHelper.isHtml(questionText)) {
itemBuilder.setQuestion(questionText);
} else {
itemBuilder.setQuestion("<p>" + questionText + "</p>");
}
String hintText = question.getHintText();
if (StringHelper.containsNonWhitespace(hintText)) {
ModalFeedbackBuilder hint = itemBuilder.createHint();
Translator translator = Util.createPackageTranslator(QTIModule.class, locale);
hint.setTitle(translator.translate("render.hint"));
hint.setText(hintText);
}
String solutionText = question.getSolutionText();
if (StringHelper.containsNonWhitespace(solutionText)) {
ModalFeedbackBuilder solution = itemBuilder.createCorrectSolutionFeedback();
solutionText = blockedHtml(solutionText);
solution.setText(solutionText);
}
String feedbackMastery = QTIEditHelper.getFeedbackMasteryText(item);
if (StringHelper.containsNonWhitespace(feedbackMastery)) {
ModalFeedbackBuilder feedback = itemBuilder.createCorrectFeedback();
feedbackMastery = blockedHtml(feedbackMastery);
feedback.setText(feedbackMastery);
}
String feedbackFail = QTIEditHelper.getFeedbackFailText(item);
if (StringHelper.containsNonWhitespace(feedbackFail)) {
ModalFeedbackBuilder feedback = itemBuilder.createIncorrectFeedback();
feedbackFail = blockedHtml(feedbackFail);
feedback.setText(feedbackFail);
}
}
use of org.olat.ims.qti21.model.xml.AssessmentItemBuilder in project openolat by klemens.
the class QTI12To21Converter method convertItem.
/**
* @param item
* @return The name of the assesssmentItem file
*/
private boolean convertItem(QuestionItemImpl convertedQuestion, Item item) {
QItemTypeDAO qItemTypeDao = CoreSpringFactory.getImpl(QItemTypeDAO.class);
AssessmentItemBuilder itemBuilder = null;
int questionType = item.getQuestion().getType();
switch(questionType) {
case Question.TYPE_SC:
itemBuilder = convertSingleChoice(item);
convertedQuestion.setType(qItemTypeDao.loadByType(QuestionType.SC.name()));
break;
case Question.TYPE_MC:
itemBuilder = convertMultipleChoice(item);
convertedQuestion.setType(qItemTypeDao.loadByType(QuestionType.MC.name()));
break;
case Question.TYPE_KPRIM:
itemBuilder = convertKPrim(item);
convertedQuestion.setType(qItemTypeDao.loadByType(QuestionType.KPRIM.name()));
break;
case Question.TYPE_FIB:
itemBuilder = convertFIB(item);
convertedQuestion.setType(qItemTypeDao.loadByType(QuestionType.FIB.name()));
break;
case Question.TYPE_ESSAY:
itemBuilder = convertEssay(item);
convertedQuestion.setType(qItemTypeDao.loadByType(QuestionType.ESSAY.name()));
break;
}
if (itemBuilder != null) {
itemBuilder.build();
AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
String itemId = IdentifierGenerator.newAsString(itemBuilder.getQuestionType().getPrefix());
File itemFile = new File(unzippedDirRoot, itemId + ".xml");
persistAssessmentObject(itemFile, assessmentItem);
appendResourceAndMetadata(item, itemBuilder, itemFile);
convertedQuestion.setRootFilename(itemFile.getName());
return true;
}
return false;
}
Aggregations