use of org.olat.modules.qpool.QuestionItem in project OpenOLAT by OpenOLAT.
the class QTI21QPoolServiceProviderTest method importArchive_qpoolQuestionsMetadata.
@Test
public void importArchive_qpoolQuestionsMetadata() throws URISyntaxException {
Identity owner = JunitTestHelper.createAndPersistIdentityAsUser("imp-pool-1");
String filename = "ExportItems_pool_metadata.zip";
URL fileUrl = QTI21QPoolServiceProviderTest.class.getResource(filename);
File questionFile = new File(fileUrl.toURI());
List<QuestionItem> items = poolServiceProvider.importItems(owner, Locale.ENGLISH, filename, questionFile);
dbInstance.commitAndCloseSession();
Assert.assertNotNull(items);
Assert.assertEquals(1, items.size());
QuestionItem item = items.get(0);
Assert.assertEquals("OpenOLAT", item.getEditor());
Assert.assertEquals("10.2.1", item.getEditorVersion());
Assert.assertEquals("IMS QTI 2.1", item.getFormat());
Assert.assertEquals(0.54d, item.getDifficulty().doubleValue(), 0.00001);
Assert.assertEquals(0.5d, item.getDifferentiation().doubleValue(), 0.00001);
Assert.assertEquals(0.33d, item.getStdevDifficulty().doubleValue(), 0.00001);
Assert.assertEquals(2, item.getNumOfAnswerAlternatives());
Assert.assertEquals("Image", item.getKeywords());
}
use of org.olat.modules.qpool.QuestionItem in project OpenOLAT by OpenOLAT.
the class QTI21ImportProcessor method process.
public List<QuestionItem> process(File file) {
// export zip file
List<QuestionItem> items = new ArrayList<>();
try (FileSystem fs = FileSystems.newFileSystem(file.toPath(), null)) {
Path fPath = fs.getPath("/");
if (fPath != null) {
ImsManifestVisitor visitor = new ImsManifestVisitor();
Files.walkFileTree(fPath, visitor);
List<Path> imsmanifests = visitor.getImsmanifestFiles();
for (Path imsmanifest : imsmanifests) {
InputStream in = Files.newInputStream(imsmanifest);
ManifestBuilder manifestBuilder = ManifestBuilder.read(new ShieldInputStream(in));
List<ResourceType> resources = manifestBuilder.getResourceList();
for (ResourceType resource : resources) {
ManifestMetadataBuilder metadataBuilder = manifestBuilder.getMetadataBuilder(resource, true);
QuestionItem qitem = processResource(resource, imsmanifest, metadataBuilder);
if (qitem != null) {
items.add(qitem);
}
}
}
}
} catch (IOException e) {
log.error("", e);
}
return items;
}
use of org.olat.modules.qpool.QuestionItem in project OpenOLAT by OpenOLAT.
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.modules.qpool.QuestionItem in project OpenOLAT by OpenOLAT.
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;
}
use of org.olat.modules.qpool.QuestionItem 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