use of org.olat.modules.qpool.model.QuestionItemImpl in project OpenOLAT by OpenOLAT.
the class RightsMetadataEditController method doOpenAuthorManager.
private void doOpenAuthorManager(UserRequest ureq) {
if (item instanceof QuestionItemImpl) {
QuestionItemImpl itemImpl = (QuestionItemImpl) item;
groupController = new GroupController(ureq, getWindowControl(), true, true, false, true, false, false, itemImpl.getOwnerGroup());
listenTo(groupController);
cmc = new CloseableModalController(getWindowControl(), translate("close"), groupController.getInitialComponent(), true, translate("manage.owners"));
cmc.activate();
listenTo(cmc);
}
}
use of org.olat.modules.qpool.model.QuestionItemImpl in project OpenOLAT by OpenOLAT.
the class QTIImportProcessorTest method testImport_SC.
/**
* This test check every methods of the import process in details
* @throws IOException
* @throws URISyntaxException
*/
@Test
public void testImport_SC() throws IOException, URISyntaxException {
URL itemUrl = QTIImportProcessorTest.class.getResource("mchc_i_002.xml");
Assert.assertNotNull(itemUrl);
File itemFile = new File(itemUrl.toURI());
// get the document informations
QTIImportProcessor proc = new QTIImportProcessor(owner, Locale.ENGLISH, itemFile.getName(), itemFile);
List<DocInfos> docInfoList = proc.getDocInfos();
Assert.assertNotNull(docInfoList);
Assert.assertEquals(1, docInfoList.size());
DocInfos docInfos = docInfoList.get(0);
Assert.assertNotNull(docInfos);
Assert.assertNotNull(docInfos.getFilename());
Assert.assertNotNull(docInfos.getDocument());
Assert.assertEquals("mchc_i_002.xml", docInfos.getFilename());
// get the question DOM's
List<ItemInfos> itemInfos = proc.getItemList(docInfos);
Assert.assertNotNull(itemInfos);
Assert.assertEquals(1, itemInfos.size());
// process item, files...
QuestionItemImpl item = proc.processItem(docInfos, itemInfos.get(0), null);
Assert.assertNotNull(item);
dbInstance.commitAndCloseSession();
proc.processFiles(item, itemInfos.get(0), null);
// reload and check what is saved
QuestionItemFull reloadItem = questionItemDao.loadById(item.getKey());
Assert.assertNotNull(reloadItem);
Assert.assertNotNull(reloadItem.getCreationDate());
Assert.assertNotNull(reloadItem.getLastModified());
Assert.assertEquals(QuestionStatus.draft, reloadItem.getQuestionStatus());
Assert.assertEquals(QTIConstants.QTI_12_FORMAT, reloadItem.getFormat());
// title
Assert.assertEquals("Standard Multiple Choice with Images Item", reloadItem.getTitle());
// description -> qticomment
Assert.assertEquals("This is a multiple-choice example with image content. The rendering is a standard radio button style. No response processing is incorporated.", reloadItem.getDescription());
// question type
Assert.assertNotNull(reloadItem.getType());
Assert.assertEquals(QuestionType.SC.name().toLowerCase(), reloadItem.getType().getType());
// check that the file is storead
VFSContainer itemDir = qpoolFileStorage.getContainer(reloadItem.getDirectory());
Assert.assertNotNull(itemDir);
VFSItem qtiLeaf = itemDir.resolve(reloadItem.getRootFilename());
Assert.assertNotNull(qtiLeaf);
Assert.assertTrue(qtiLeaf instanceof VFSLeaf);
Assert.assertTrue(qtiLeaf.exists());
Assert.assertEquals(itemFile.length(), ((VFSLeaf) qtiLeaf).getSize());
}
use of org.olat.modules.qpool.model.QuestionItemImpl in project OpenOLAT by OpenOLAT.
the class QuestionDAOTest method resetAllStatesToDraft.
@Test
public void resetAllStatesToDraft() {
QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
QuestionItemImpl item1 = questionDao.createAndPersist(null, "RES DRAFT 1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
item1.setQuestionStatus(QuestionStatus.endOfLife);
questionDao.loadForUpdate(item1);
QuestionItemImpl item2 = questionDao.createAndPersist(null, "RES DRAFT 2", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
item2.setQuestionStatus(QuestionStatus.review);
questionDao.loadForUpdate(item2);
QuestionItemImpl item3 = questionDao.createAndPersist(null, "RES DRAFT 3", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
item3.setQuestionStatus(QuestionStatus.revised);
questionDao.loadForUpdate(item3);
questionDao.createAndPersist(null, "RES DRAFT 4", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
dbInstance.commitAndCloseSession();
questionDao.resetAllStatesToDraft();
dbInstance.commitAndCloseSession();
List<QuestionItemFull> allItems = questionDao.getAllItems(0, -1);
for (QuestionItem item : allItems) {
Assert.assertEquals(QuestionStatus.draft, item.getQuestionStatus());
}
}
use of org.olat.modules.qpool.model.QuestionItemImpl in project OpenOLAT by OpenOLAT.
the class QuestionPoolServiceImplTest method shouldGetExportFormatOptions.
@Test
public void shouldGetExportFormatOptions() {
String formatA = "A";
String formatB = "B";
QuestionItemImpl formatAItem = new QuestionItemImpl();
formatAItem.setFormat(formatA);
List<QuestionItemShort> items = Arrays.asList(formatAItem);
ExportFormatOptions exportFormatAR = new DefaultExportFormat(formatA, Outcome.repository, null);
ExportFormatOptions exportFormatAD = new DefaultExportFormat(formatA, Outcome.download, null);
List<ExportFormatOptions> exportFormatsA = Arrays.asList(exportFormatAD, exportFormatAR);
ExportFormatOptions exportFormatBR = new DefaultExportFormat(formatA, Outcome.repository, null);
List<ExportFormatOptions> exportFormatsB = Arrays.asList(exportFormatBR);
QPoolSPI spiA = mock(QPoolSPI.class);
when(spiA.getTestExportFormats()).thenReturn(exportFormatsA);
when(qPoolModuleMock.getQuestionPoolProvider(formatA)).thenReturn(spiA);
QPoolSPI spiB = mock(QPoolSPI.class);
when(spiB.getTestExportFormats()).thenReturn(exportFormatsB);
when(qPoolModuleMock.getQuestionPoolProvider(formatB)).thenReturn(spiB);
Set<ExportFormatOptions> exportFormatOptions = sut.getExportFormatOptions(items, Outcome.repository);
assertThat(exportFormatOptions).hasSize(1).containsExactly(exportFormatAR);
}
use of org.olat.modules.qpool.model.QuestionItemImpl in project OpenOLAT by OpenOLAT.
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;
}
}
Aggregations