use of uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem in project openolat by klemens.
the class QTI21QPoolServiceProvider method copyItem.
@Override
public void copyItem(QuestionItemFull original, QuestionItemFull copy) {
VFSContainer originalDir = qpoolFileStorage.getContainer(original.getDirectory());
VFSContainer copyDir = qpoolFileStorage.getContainer(copy.getDirectory());
VFSManager.copyContent(originalDir, copyDir);
File file = qpoolService.getRootFile(copy);
File resourceDirectory = qpoolService.getRootDirectory(copy);
URI assessmentItemUri = file.toURI();
File itemFile = qpoolService.getRootFile(copy);
ResolvedAssessmentItem resolvedAssessmentItem = qtiService.loadAndResolveAssessmentItem(assessmentItemUri, resourceDirectory);
AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
assessmentItem.setTitle(copy.getTitle());
qtiService.persistAssessmentObject(itemFile, assessmentItem);
}
use of uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem in project openolat by klemens.
the class QTI21QPoolServiceProvider method exportToQTIEditor.
/**
* Export to QTI editor an item from the pool. The ident of the item
* is always regenerated as an UUID.
* @param qitem
* @param editorContainer
* @return
*/
public AssessmentItem exportToQTIEditor(QuestionItemFull qitem, Locale locale, File editorContainer) throws IOException {
QTI21ExportProcessor processor = new QTI21ExportProcessor(qtiService, qpoolFileStorage, locale);
ResolvedAssessmentItem resolvedAssessmentItem = processor.exportToQTIEditor(qitem, editorContainer);
if (resolvedAssessmentItem != null) {
AssessmentItem assessmentItem = resolvedAssessmentItem.getItemLookup().extractAssumingSuccessful();
assessmentItem.setIdentifier(QTI21QuestionType.generateNewIdentifier(assessmentItem.getIdentifier()));
return assessmentItem;
}
return null;
}
use of uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem in project openolat by klemens.
the class QTI21QPoolServiceProvider method importExcelItem.
public QuestionItemImpl importExcelItem(Identity owner, AssessmentItemAndMetadata itemAndMetadata, Locale defaultLocale) {
QTI21ImportProcessor processor = new QTI21ImportProcessor(owner, defaultLocale);
String editor = itemAndMetadata.getEditor();
String editorVersion = itemAndMetadata.getEditorVersion();
AssessmentItemBuilder itemBuilder = itemAndMetadata.getItemBuilder();
itemBuilder.build();
AssessmentItem assessmentItem = itemBuilder.getAssessmentItem();
QuestionItemImpl qitem = processor.processItem(assessmentItem, null, null, editor, editorVersion, itemAndMetadata);
String originalItemFilename = qitem.getRootFilename();
File itemStorage = qpoolFileStorage.getDirectory(qitem.getDirectory());
File itemFile = new File(itemStorage, originalItemFilename);
qtiService.persistAssessmentObject(itemFile, assessmentItem);
// create manifest
ManifestBuilder manifest = ManifestBuilder.createAssessmentItemBuilder();
ResourceType resource = manifest.appendAssessmentItem(UUID.randomUUID().toString(), originalItemFilename);
ManifestMetadataBuilder metadataBuilder = manifest.getMetadataBuilder(resource, true);
itemAndMetadata.toBuilder(metadataBuilder, defaultLocale);
manifest.write(new File(itemStorage, "imsmanifest.xml"));
return qitem;
}
use of uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem in project openolat by klemens.
the class QTI21AssessmentTestHandler method createMinimalAssessmentTest.
public void createMinimalAssessmentTest(String displayName, File directory, Locale locale) {
ManifestBuilder manifestBuilder = ManifestBuilder.createAssessmentTestBuilder();
Translator translator = Util.createPackageTranslator(AssessmentTestComposerController.class, locale);
// single choice
File itemFile = new File(directory, IdentifierGenerator.newAsString(QTI21QuestionType.sc.getPrefix()) + ".xml");
AssessmentItem assessmentItem = AssessmentItemFactory.createSingleChoice(translator.translate("new.sc"), translator.translate("new.answer"));
QtiSerializer qtiSerializer = qtiService.qtiSerializer();
manifestBuilder.appendAssessmentItem(itemFile.getName());
// test
File testFile = new File(directory, IdentifierGenerator.newAssessmentTestFilename());
AssessmentTest assessmentTest = AssessmentTestFactory.createAssessmentTest(displayName, translator.translate("new.section"));
manifestBuilder.appendAssessmentTest(testFile.getName());
// item -> test
try {
AssessmentSection section = assessmentTest.getTestParts().get(0).getAssessmentSections().get(0);
AssessmentTestFactory.appendAssessmentItem(section, itemFile.getName());
} catch (URISyntaxException e) {
log.error("", e);
}
try (FileOutputStream out = new FileOutputStream(itemFile)) {
qtiSerializer.serializeJqtiObject(assessmentItem, out);
} catch (Exception e) {
log.error("", e);
}
try (FileOutputStream out = new FileOutputStream(testFile)) {
qtiSerializer.serializeJqtiObject(assessmentTest, out);
} catch (Exception e) {
log.error("", e);
}
manifestBuilder.write(new File(directory, "imsmanifest.xml"));
}
use of uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem in project openolat by klemens.
the class DrawingAssessmentItemBuilder method createAssessmentItem.
private static AssessmentItem createAssessmentItem(String title) {
AssessmentItem assessmentItem = AssessmentItemFactory.createAssessmentItem(QTI21QuestionType.drawing, title);
// define the response
Identifier responseDeclarationId = Identifier.assumedLegal("RESPONSE_1");
ResponseDeclaration responseDeclaration = createDrawingResponseDeclaration(assessmentItem, responseDeclarationId);
assessmentItem.getNodeGroups().getResponseDeclarationGroup().getResponseDeclarations().add(responseDeclaration);
// outcomes
appendDefaultOutcomeDeclarations(assessmentItem, 1.0d);
ItemBody itemBody = appendDefaultItemBody(assessmentItem);
appendDrawingInteraction(itemBody, responseDeclarationId);
// response processing
ResponseProcessing responseProcessing = createResponseProcessing(assessmentItem, responseDeclarationId);
assessmentItem.getNodeGroups().getResponseProcessingGroup().setResponseProcessing(responseProcessing);
return assessmentItem;
}
Aggregations