use of org.olat.ims.qti.editor.beecom.objects.Item 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.qti.editor.beecom.objects.Item in project openolat by klemens.
the class QTI21QPoolServiceProvider method convert.
@Override
public QuestionItem convert(Identity owner, QuestionItemShort itemToConvert, Locale locale) {
if (QTIConstants.QTI_12_FORMAT.equals(itemToConvert.getFormat())) {
VFSLeaf leaf = qpoolService.getRootLeaf(itemToConvert);
if (leaf == null) {
return null;
} else {
Item qtiItem = QTIEditHelper.readItemXml(leaf);
if (qtiItem != null && !qtiItem.isAlient()) {
QuestionItemImpl original = questionItemDao.loadById(itemToConvert.getKey());
QuestionItemImpl copy = questionItemDao.copy(original);
copy.setTitle(original.getTitle());
copy.setFormat(getFormat());
VFSContainer originalDir = qpoolFileStorage.getContainer(original.getDirectory());
File copyDir = qpoolFileStorage.getDirectory(copy.getDirectory());
QTI12To21Converter converter = new QTI12To21Converter(copyDir, locale);
if (converter.convert(copy, qtiItem, originalDir)) {
questionItemDao.persist(owner, copy);
return copy;
}
}
}
}
return null;
}
use of org.olat.ims.qti.editor.beecom.objects.Item in project openolat by klemens.
the class OLATUpgrade_11_0_0 method checkEssay.
private boolean checkEssay(RepositoryEntry testEntry) {
if (qtiEssayMap.containsKey(testEntry.getKey())) {
return qtiEssayMap.get(testEntry.getKey()).booleanValue();
}
TestFileResource fr = new TestFileResource();
fr.overrideResourceableId(testEntry.getOlatResource().getResourceableId());
TransientIdentity pseudoIdentity = new TransientIdentity();
pseudoIdentity.setName("transient");
Translator translator = Util.createPackageTranslator(QTIModule.class, Locale.ENGLISH);
try {
QTIEditorPackage qtiPackage = new QTIEditorPackageImpl(pseudoIdentity, fr, null, translator);
if (qtiPackage.getQTIDocument() != null && qtiPackage.getQTIDocument().getAssessment() != null) {
Assessment ass = qtiPackage.getQTIDocument().getAssessment();
// Sections with their Items
List<Section> sections = ass.getSections();
for (Section section : sections) {
List<Item> items = section.getItems();
for (Item item : items) {
String ident = item.getIdent();
if (ident != null && ident.startsWith("QTIEDIT:ESSAY")) {
qtiEssayMap.put(testEntry.getKey(), Boolean.TRUE);
return true;
}
}
}
}
} catch (OLATRuntimeException e) {
log.warn("QTI without content in repository entry: " + testEntry.getKey(), e);
}
qtiEssayMap.put(testEntry.getKey(), Boolean.FALSE);
return false;
}
use of org.olat.ims.qti.editor.beecom.objects.Item in project openolat by klemens.
the class OLATUpgrade_12_3_0 method getTitleQTI12.
private String getTitleQTI12(QuestionItemImpl item) {
try {
VFSLeaf leaf = qpoolService.getRootLeaf(item);
Item xmlItem = QTIEditHelper.readItemXml(leaf);
return xmlItem.getTitle();
} catch (NullPointerException e) {
log.warn("Cannot read files from dir: " + item.getDirectory());
}
return null;
}
use of org.olat.ims.qti.editor.beecom.objects.Item in project openolat by klemens.
the class QTI12AssessmentStatisticsController method initItemsOverview.
private void initItemsOverview(List<Item> items) {
List<StatisticSurveyItem> surveyItems = qtiStatisticsManager.getStatisticAnswerOptions(resourceResult.getSearchParams(), items);
int count = 0;
List<String> overviewList = new ArrayList<>();
for (StatisticSurveyItem surveyItem : surveyItems) {
Item item = surveyItem.getItem();
Series series = seriesfactory.getSeries(item, null);
if (series != null) {
// essay hasn't a series
String name = "overview_" + count++;
VelocityContainer vc = createVelocityContainer(name, "hbar_item_overview");
vc.contextPut("series", series);
vc.contextPut("question", item.getQuestion().getQuestion().renderAsHtml(mediaBaseURL));
vc.contextPut("questionType", item.getQuestion().getType());
vc.contextPut("title", item.getTitle());
mainVC.put(vc.getDispatchID(), vc);
overviewList.add(vc.getDispatchID());
}
}
mainVC.contextPut("overviewList", overviewList);
}
Aggregations