use of uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem 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 uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem 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;
}
use of uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem in project openolat by klemens.
the class QTI21EditorController method event.
@Override
protected void event(UserRequest ureq, Controller source, Event event) {
if (source == editorCtrl) {
if (event instanceof AssessmentItemEvent) {
AssessmentItemEvent aie = (AssessmentItemEvent) event;
AssessmentItem assessmentItem = aie.getAssessmentItem();
qtiService.persistAssessmentObject(resourceFile, assessmentItem);
updateQuestionItem(ureq, assessmentItem);
}
}
}
use of uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem in project openolat by klemens.
the class AssessmentItemFactory method createAssessmentItem.
public static AssessmentItem createAssessmentItem(QTI21QuestionType type, String defaultTitle) {
AssessmentItem assessmentItem = new AssessmentItem();
if (type != null) {
assessmentItem.setIdentifier(IdentifierGenerator.newAsString(type.getPrefix()));
} else {
assessmentItem.setIdentifier(IdentifierGenerator.newAsString("item"));
}
assessmentItem.setTitle(defaultTitle);
assessmentItem.setToolName(QTI21Constants.TOOLNAME);
assessmentItem.setToolVersion(Settings.getVersion());
assessmentItem.setAdaptive(Boolean.FALSE);
assessmentItem.setTimeDependent(Boolean.FALSE);
return assessmentItem;
}
use of uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem in project openolat by klemens.
the class QTI21QPoolServiceProvider method importRepositoryEntry.
public List<QuestionItem> importRepositoryEntry(Identity owner, RepositoryEntry repositoryEntry, Locale defaultLocale) {
FileResourceManager frm = FileResourceManager.getInstance();
File unzippedDirRoot = frm.unzipFileResource(repositoryEntry.getOlatResource());
ResolvedAssessmentTest resolvedAssessmentTest = qtiService.loadAndResolveAssessmentTest(unzippedDirRoot, false, true);
ManifestBuilder clonedManifestBuilder = ManifestBuilder.read(new File(unzippedDirRoot, "imsmanifest.xml"));
List<AssessmentItemRef> itemRefs = resolvedAssessmentTest.getAssessmentItemRefs();
List<QuestionItem> importedItems = new ArrayList<>(itemRefs.size());
for (AssessmentItemRef itemRef : itemRefs) {
ResolvedAssessmentItem resolvedAssessmentItem = resolvedAssessmentTest.getResolvedAssessmentItem(itemRef);
RootNodeLookup<AssessmentItem> rootNode = resolvedAssessmentItem.getItemLookup();
URI itemUri = rootNode.getSystemId();
File itemFile = new File(itemUri);
String relativePathToManifest = unzippedDirRoot.toPath().relativize(itemFile.toPath()).toString();
AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
ResourceType resource = clonedManifestBuilder.getResourceTypeByHref(relativePathToManifest);
ManifestMetadataBuilder metadata = clonedManifestBuilder.getMetadataBuilder(resource, true);
QuestionItem qitem = importAssessmentItemRef(owner, assessmentItem, itemFile, metadata, defaultLocale);
importedItems.add(qitem);
}
return importedItems;
}
Aggregations