use of org.olat.ims.qti21.model.xml.AssessmentTestBuilder in project OpenOLAT by OpenOLAT.
the class AssessmentTestComposerController method partEditorFactory.
private void partEditorFactory(UserRequest ureq, TreeNode selectedNode) {
// remove old one
if (currentEditorCtrl != null) {
mainVC.remove(currentEditorCtrl.getInitialComponent());
removeAsListenerAndDispose(currentEditorCtrl);
currentEditorCtrl = null;
}
// fill with the new
mainVC.contextPut("cssClass", selectedNode.getIconCssClass());
if (Settings.isDebuging()) {
mainVC.contextPut("identifier", selectedNode.getIdent());
}
mainVC.contextPut("title", selectedNode.getTitle());
mainVC.contextPut("restrictedEdit", restrictedEdit);
Object uobject = selectedNode.getUserObject();
if (uobject instanceof AssessmentTest) {
AssessmentTest test = (AssessmentTest) uobject;
URI testURI = resolvedAssessmentTest.getTestLookup().getSystemId();
File testFile = new File(testURI);
TestPart uniqueTestPart = test.getTestParts().size() == 1 ? test.getTestParts().get(0) : null;
currentEditorCtrl = new AssessmentTestEditorController(ureq, getWindowControl(), assessmentTestBuilder, uniqueTestPart, unzippedDirRoot, unzippedContRoot, testFile, restrictedEdit);
} else if (uobject instanceof TestPart) {
currentEditorCtrl = new AssessmentTestPartEditorController(ureq, getWindowControl(), (TestPart) uobject, restrictedEdit, assessmentTestBuilder.isEditable());
} else if (uobject instanceof AssessmentSection) {
URI testURI = resolvedAssessmentTest.getTestLookup().getSystemId();
File testFile = new File(testURI);
currentEditorCtrl = new AssessmentSectionEditorController(ureq, getWindowControl(), (AssessmentSection) uobject, unzippedDirRoot, unzippedContRoot, testFile, restrictedEdit, assessmentTestBuilder.isEditable());
} else if (uobject instanceof AssessmentItemRef) {
AssessmentItemRef itemRef = (AssessmentItemRef) uobject;
ResolvedAssessmentItem item = resolvedAssessmentTest.getResolvedAssessmentItem(itemRef);
if (item == null || item.getItemLookup() == null) {
currentEditorCtrl = new BadResourceController(ureq, getWindowControl(), null, unzippedDirRoot, itemRef.getHref());
} else if (item.getItemLookup().getBadResourceException() != null) {
currentEditorCtrl = new BadResourceController(ureq, getWindowControl(), item.getItemLookup().getBadResourceException(), unzippedDirRoot, itemRef.getHref());
} else {
URI itemUri = resolvedAssessmentTest.getSystemIdByItemRefMap().get(itemRef);
File itemFile = new File(itemUri);
ManifestMetadataBuilder metadata = getMetadataBuilder(itemRef);
currentEditorCtrl = new AssessmentItemEditorController(ureq, getWindowControl(), testEntry, item, itemRef, metadata, unzippedDirRoot, unzippedContRoot, itemFile, restrictedEdit);
}
}
if (deleteLink != null) {
if (uobject instanceof AssessmentSection || uobject instanceof AssessmentItemRef) {
deleteLink.setEnabled(true);
} else if (uobject instanceof TestPart) {
TestPart testPart = (TestPart) uobject;
deleteLink.setEnabled(testPart.getParent().getTestParts().size() > 1);
} else {
deleteLink.setEnabled(false);
}
}
if (copyLink != null) {
copyLink.setEnabled(uobject instanceof AssessmentItemRef);
}
if (currentEditorCtrl != null) {
listenTo(currentEditorCtrl);
mainVC.put("content", currentEditorCtrl.getInitialComponent());
} else {
mainVC.put("content", new Panel("empty"));
}
}
use of org.olat.ims.qti21.model.xml.AssessmentTestBuilder in project OpenOLAT by OpenOLAT.
the class QTI21ExportProcessor method assembleTest.
public void assembleTest(List<QuestionItemFull> fullItems, File directory) {
try {
QtiSerializer qtiSerializer = qtiService.qtiSerializer();
// imsmanifest
ManifestBuilder manifest = ManifestBuilder.createAssessmentTestBuilder();
// assessment test
DoubleAdder atomicMaxScore = new DoubleAdder();
AssessmentTest assessmentTest = AssessmentTestFactory.createAssessmentTest("Assessment test from pool", "Section");
String assessmentTestFilename = assessmentTest.getIdentifier() + ".xml";
manifest.appendAssessmentTest(assessmentTestFilename);
// make a section
AssessmentSection section = assessmentTest.getTestParts().get(0).getAssessmentSections().get(0);
// assessment items
for (QuestionItemFull qitem : fullItems) {
File resourceDirectory = qpoolFileStorage.getDirectory(qitem.getDirectory());
File itemFile = new File(resourceDirectory, qitem.getRootFilename());
ResolvedAssessmentItem resolvedAssessmentItem = qtiService.loadAndResolveAssessmentItemForCopy(itemFile.toURI(), resourceDirectory);
AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
assessmentItem.setIdentifier(QTI21QuestionType.generateNewIdentifier(assessmentItem.getIdentifier()));
// save the item in its own container
String container = qitem.getKey().toString();
File containerDir = new File(directory, container);
containerDir.mkdirs();
File newItemFile = new File(containerDir, assessmentItem.getIdentifier() + ".xml");
String newItemFilename = container + "/" + newItemFile.getName();
qtiService.persistAssessmentObject(newItemFile, assessmentItem);
AssessmentTestFactory.appendAssessmentItem(section, newItemFilename);
manifest.appendAssessmentItem(newItemFilename);
ManifestMetadataBuilder metadata = manifest.getResourceBuilderByHref(newItemFilename);
metadata.appendMetadataFrom(qitem, resolvedAssessmentItem, locale);
Double maxScore = QtiNodesExtractor.extractMaxScore(assessmentItem);
if (maxScore != null) {
atomicMaxScore.add(maxScore.doubleValue());
}
// write materials
AssessmentItemsAndResources materials = new AssessmentItemsAndResources();
ImportExportHelper.getMaterials(assessmentItem, itemFile, materials);
for (ItemMaterial material : materials.getMaterials()) {
String exportPath = material.getExportUri();
File originalFile = material.getFile();
File exportFile = new File(containerDir, exportPath);
if (!exportFile.getParentFile().exists()) {
exportFile.getParentFile().mkdirs();
}
FileUtils.bcopy(originalFile, exportFile, "Copy material QTI 2.1");
}
}
AssessmentTestBuilder assessmentTestBuilder = new AssessmentTestBuilder(assessmentTest);
double sumMaxScore = atomicMaxScore.sum();
if (sumMaxScore > 0.0d) {
assessmentTestBuilder.setMaxScore(sumMaxScore);
}
assessmentTest = assessmentTestBuilder.build();
try (FileOutputStream out = new FileOutputStream(new File(directory, assessmentTestFilename))) {
qtiSerializer.serializeJqtiObject(assessmentTest, out);
} catch (Exception e) {
log.error("", e);
}
manifest.write(new File(directory, "imsmanifest.xml"));
} catch (Exception e) {
log.error("", e);
}
}
use of org.olat.ims.qti21.model.xml.AssessmentTestBuilder in project openolat by klemens.
the class AssessmentTestComposerController method updateTreeModel.
private void updateTreeModel(boolean forceReload) {
resolvedAssessmentTest = qtiService.loadAndResolveAssessmentTest(unzippedDirRoot, forceReload, true);
menuTree.setTreeModel(new AssessmentTestEditorAndComposerTreeModel(resolvedAssessmentTest));
assessmentTestBuilder = new AssessmentTestBuilder(resolvedAssessmentTest.getRootNodeLookup().extractIfSuccessful());
}
use of org.olat.ims.qti21.model.xml.AssessmentTestBuilder in project OpenOLAT by OpenOLAT.
the class QTI21EditForm method update.
protected void update(RepositoryEntry testEntry) {
Double minValue = null;
Double maxValue = null;
Double cutValue = null;
FileResourceManager frm = FileResourceManager.getInstance();
File unzippedDirRoot = frm.unzipFileResource(testEntry.getOlatResource());
ResolvedAssessmentTest resolvedAssessmentTest = qtiService.loadAndResolveAssessmentTest(unzippedDirRoot, false, false);
AssessmentTest assessmentTest = resolvedAssessmentTest.getRootNodeLookup().extractIfSuccessful();
if (assessmentTest != null) {
AssessmentTestBuilder testBuilder = new AssessmentTestBuilder(assessmentTest);
maxValue = testBuilder.getMaxScore();
cutValue = testBuilder.getCutValue();
if (maxValue != null && "OpenOLAT".equals(assessmentTest.getToolName())) {
minValue = 0d;
}
}
// Put values to module configuration
minScoreEl.setValue(minValue == null ? "" : AssessmentHelper.getRoundedScore(minValue));
minScoreEl.setVisible(minValue != null);
maxScoreEl.setValue(maxValue == null ? "" : AssessmentHelper.getRoundedScore(maxValue));
maxScoreEl.setVisible(maxValue != null);
cutValueEl.setValue(cutValue == null ? "" : AssessmentHelper.getRoundedScore(cutValue));
cutValueEl.setVisible(cutValue != null);
update();
}
use of org.olat.ims.qti21.model.xml.AssessmentTestBuilder in project OpenOLAT by OpenOLAT.
the class AssessmentTestComposerController method updateTreeModel.
private void updateTreeModel(boolean forceReload) {
resolvedAssessmentTest = qtiService.loadAndResolveAssessmentTest(unzippedDirRoot, forceReload, true);
menuTree.setTreeModel(new AssessmentTestEditorAndComposerTreeModel(resolvedAssessmentTest));
assessmentTestBuilder = new AssessmentTestBuilder(resolvedAssessmentTest.getRootNodeLookup().extractIfSuccessful());
}
Aggregations