use of org.olat.ims.qti21.model.xml.AssessmentItemMetadata in project openolat by klemens.
the class QTI21ImportProcessor method processItemMetadata.
// additionalInformations, assessmentType
protected void processItemMetadata(QuestionItemImpl poolItem, AssessmentItemMetadata metadata) {
// non heuristic set of question type
String typeStr = null;
QTI21QuestionType questionType = metadata.getQuestionType();
if (questionType != null && questionType.getPoolQuestionType() != null) {
typeStr = questionType.getPoolQuestionType().name();
}
if (typeStr != null) {
QItemType type = qItemTypeDao.loadByType(typeStr);
if (type != null) {
poolItem.setType(type);
}
}
String coverage = metadata.getCoverage();
if (StringHelper.containsNonWhitespace(coverage)) {
poolItem.setCoverage(coverage);
}
String language = metadata.getLanguage();
if (StringHelper.containsNonWhitespace(language)) {
poolItem.setLanguage(language);
}
String keywords = metadata.getKeywords();
if (StringHelper.containsNonWhitespace(keywords)) {
poolItem.setKeywords(keywords);
}
String taxonomyPath = metadata.getTaxonomyPath();
if (StringHelper.containsNonWhitespace(taxonomyPath)) {
QTIMetadataConverter converter = new QTIMetadataConverter(qItemTypeDao, qEduContextDao, qpoolService);
TaxonomyLevel taxonomyLevel = converter.toTaxonomy(taxonomyPath);
poolItem.setTaxonomyLevel(taxonomyLevel);
}
// educational
String level = metadata.getLevel();
if (StringHelper.containsNonWhitespace(level)) {
QTIMetadataConverter converter = new QTIMetadataConverter(qItemTypeDao, qEduContextDao, qpoolService);
QEducationalContext educationalContext = converter.toEducationalContext(level);
poolItem.setEducationalContext(educationalContext);
}
String time = metadata.getTypicalLearningTime();
if (StringHelper.containsNonWhitespace(time)) {
poolItem.setEducationalLearningTime(time);
}
String editor = metadata.getEditor();
if (StringHelper.containsNonWhitespace(editor)) {
poolItem.setEditor(editor);
}
String editorVersion = metadata.getEditorVersion();
if (StringHelper.containsNonWhitespace(editorVersion)) {
poolItem.setEditorVersion(editorVersion);
}
// OpenOLAT
poolItem.setDifficulty(metadata.getDifficulty());
poolItem.setDifferentiation(metadata.getDifferentiation());
poolItem.setStdevDifficulty(metadata.getStdevDifficulty());
int numOfAnswerAlternatives = metadata.getNumOfAnswerAlternatives();
if (numOfAnswerAlternatives > 0) {
poolItem.setNumOfAnswerAlternatives(numOfAnswerAlternatives);
}
poolItem.setTopic(metadata.getTopic());
poolItem.setAssessmentType(metadata.getAssessmentType());
poolItem.setAdditionalInformations(metadata.getAdditionalInformations());
}
use of org.olat.ims.qti21.model.xml.AssessmentItemMetadata in project openolat by klemens.
the class QTI21ImportProcessor method processResource.
private QuestionItem processResource(ResourceType resource, Path imsmanifestPath, ManifestMetadataBuilder metadataBuilder) {
try {
String href = resource.getHref();
Path parentPath = imsmanifestPath.getParent();
Path assessmentItemPath = parentPath.resolve(href);
if (Files.notExists(assessmentItemPath)) {
return null;
}
String dir = qpoolFileStorage.generateDir();
// storage
File itemStorage = qpoolFileStorage.getDirectory(dir);
File outputFile = new File(itemStorage, href);
if (!outputFile.getParentFile().exists()) {
outputFile.getParentFile().mkdirs();
}
QTI21Infos infos = getInfos(imsmanifestPath);
convertXmlFile(assessmentItemPath, outputFile.toPath(), infos);
QtiXmlReader qtiXmlReader = new QtiXmlReader(qtiService.jqtiExtensionManager());
ResourceLocator fileResourceLocator = new FileResourceLocator();
ResourceLocator inputResourceLocator = ImsQTI21Resource.createResolvingResourceLocator(fileResourceLocator);
URI assessmentObjectSystemId = outputFile.toURI();
AssessmentObjectXmlLoader assessmentObjectXmlLoader = new AssessmentObjectXmlLoader(qtiXmlReader, inputResourceLocator);
ResolvedAssessmentItem resolvedAssessmentItem = assessmentObjectXmlLoader.loadAndResolveAssessmentItem(assessmentObjectSystemId);
AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
if (!AssessmentItemChecker.checkAndCorrect(assessmentItem)) {
qtiService.persistAssessmentObject(outputFile, assessmentItem);
}
AssessmentItemMetadata metadata = new AssessmentItemMetadata(metadataBuilder);
String editor = null;
String editorVersion = null;
if (StringHelper.containsNonWhitespace(assessmentItem.getToolName())) {
editor = assessmentItem.getToolName();
}
if (StringHelper.containsNonWhitespace(assessmentItem.getToolVersion())) {
editorVersion = assessmentItem.getToolVersion();
}
QuestionItemImpl qitem = processItem(assessmentItem, null, href, editor, editorVersion, dir, metadata);
// create manifest
ManifestBuilder manifest = ManifestBuilder.createAssessmentItemBuilder();
String itemId = IdentifierGenerator.newAsIdentifier("item").toString();
ResourceType importedResource = manifest.appendAssessmentItem(itemId, href);
ManifestMetadataBuilder importedMetadataBuilder = manifest.getMetadataBuilder(importedResource, true);
importedMetadataBuilder.setMetadata(metadataBuilder.getMetadata());
manifest.write(new File(itemStorage, "imsmanifest.xml"));
// process material
List<String> materials = ImportExportHelper.getMaterials(assessmentItem);
for (String material : materials) {
if (material.indexOf("://") < 0) {
// material can be an external URL
Path materialFile = assessmentItemPath.getParent().resolve(material);
PathUtils.copyFileToDir(materialFile, outputFile.getParentFile(), material);
}
}
return qitem;
} catch (Exception e) {
log.error("", e);
return null;
}
}
use of org.olat.ims.qti21.model.xml.AssessmentItemMetadata in project openolat by klemens.
the class QTI21QPoolServiceProvider method createItem.
public QuestionItem createItem(Identity identity, QTI21QuestionType type, String title, Locale locale) {
AssessmentItemBuilder itemBuilder = null;
Translator translator = Util.createPackageTranslator(AssessmentTestComposerController.class, locale);
switch(type) {
case sc:
itemBuilder = new SingleChoiceAssessmentItemBuilder(translator.translate("new.sc"), translator.translate("new.answer"), qtiService.qtiSerializer());
break;
case mc:
itemBuilder = new MultipleChoiceAssessmentItemBuilder(translator.translate("new.mc"), translator.translate("new.answer"), qtiService.qtiSerializer());
break;
case kprim:
itemBuilder = new KPrimAssessmentItemBuilder(translator.translate("new.kprim"), translator.translate("new.answer"), qtiService.qtiSerializer());
break;
case match:
itemBuilder = new MatchAssessmentItemBuilder(translator.translate("new.match"), QTI21Constants.CSS_MATCH_MATRIX, qtiService.qtiSerializer());
break;
case matchdraganddrop:
itemBuilder = new MatchAssessmentItemBuilder(translator.translate("new.match"), QTI21Constants.CSS_MATCH_DRAG_AND_DROP, qtiService.qtiSerializer());
break;
case matchtruefalse:
itemBuilder = new MatchAssessmentItemBuilder(translator.translate("new.match"), QTI21Constants.CSS_MATCH_TRUE_FALSE, translator.translate("match.unanswered"), translator.translate("match.true"), translator.translate("match.false"), qtiService.qtiSerializer());
break;
case fib:
itemBuilder = new FIBAssessmentItemBuilder(translator.translate("new.fib"), EntryType.text, qtiService.qtiSerializer());
break;
case numerical:
itemBuilder = new FIBAssessmentItemBuilder(translator.translate("new.fib.numerical"), EntryType.numerical, qtiService.qtiSerializer());
break;
case essay:
itemBuilder = new EssayAssessmentItemBuilder(translator.translate("new.essay"), qtiService.qtiSerializer());
break;
case upload:
itemBuilder = new UploadAssessmentItemBuilder(translator.translate("new.upload"), qtiService.qtiSerializer());
break;
case drawing:
itemBuilder = new DrawingAssessmentItemBuilder(translator.translate("new.drawing"), qtiService.qtiSerializer());
break;
case hotspot:
itemBuilder = new HotspotAssessmentItemBuilder(translator.translate("new.hotspot"), qtiService.qtiSerializer());
break;
case hottext:
itemBuilder = new HottextAssessmentItemBuilder(translator.translate("new.hottext"), translator.translate("new.hottext.start"), translator.translate("new.hottext.text"), qtiService.qtiSerializer());
break;
default:
return null;
}
AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
assessmentItem.setLabel(title);
assessmentItem.setTitle(title);
AssessmentItemMetadata itemMetadata = new AssessmentItemMetadata();
itemMetadata.setQuestionType(type);
QTI21ImportProcessor processor = new QTI21ImportProcessor(identity, locale);
QuestionItemImpl qitem = processor.processItem(assessmentItem, "", null, "OpenOLAT", Settings.getVersion(), itemMetadata);
VFSContainer baseDir = qpoolFileStorage.getContainer(qitem.getDirectory());
VFSLeaf leaf = baseDir.createChildLeaf(qitem.getRootFilename());
File itemFile = ((LocalImpl) leaf).getBasefile();
qtiService.persistAssessmentObject(itemFile, assessmentItem);
// create imsmanifest
ManifestBuilder manifest = ManifestBuilder.createAssessmentItemBuilder();
manifest.appendAssessmentItem(itemFile.getName());
manifest.write(new File(itemFile.getParentFile(), "imsmanifest.xml"));
return qitem;
}
Aggregations