use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection in project openolat by klemens.
the class AssessmentTestHelper method getParentSection.
public static ParentPartItemRefs getParentSection(TestPlanNodeKey itemKey, TestSessionState testSessionState, ResolvedAssessmentTest resolvedAssessmentTest) {
ParentPartItemRefs parentParts = new ParentPartItemRefs();
try {
TestPlanNode currentItem = testSessionState.getTestPlan().getNode(itemKey);
List<AssessmentItemRef> itemRefs = resolvedAssessmentTest.getItemRefsBySystemIdMap().get(currentItem.getItemSystemId());
AssessmentItemRef itemRef = null;
if (itemRefs.size() == 1) {
itemRef = itemRefs.get(0);
} else {
Identifier itemId = itemKey.getIdentifier();
for (AssessmentItemRef ref : itemRefs) {
if (ref.getIdentifier().equals(itemId)) {
itemRef = ref;
break;
}
}
}
if (itemRef != null) {
for (QtiNode parentPart = itemRef.getParent(); parentPart != null; parentPart = parentPart.getParent()) {
if (parentParts.getSectionIdentifier() == null && parentPart instanceof AssessmentSection) {
AssessmentSection section = (AssessmentSection) parentPart;
parentParts.setSectionIdentifier(section.getIdentifier().toString());
} else if (parentParts.getTestPartIdentifier() == null && parentPart instanceof TestPart) {
TestPart testPart = (TestPart) parentPart;
parentParts.setTestPartIdentifier(testPart.getIdentifier().toString());
}
}
}
} catch (Exception e) {
log.error("", e);
}
return parentParts;
}
use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection in project openolat by klemens.
the class AssessmentTestHelper method visit.
/**
* Go through the section part (assessmentSection or assessmentItemRef), visit recursively
* the sections and assessment item refs.
*
* @param sectionPart
* @param visitor
*/
public static void visit(SectionPart sectionPart, AssessmentTestVisitor visitor) {
visitor.visit(sectionPart);
if (sectionPart instanceof AssessmentSection) {
AssessmentSection section = (AssessmentSection) sectionPart;
List<SectionPart> childParts = section.getChildAbstractParts();
if (childParts != null && childParts.size() > 0) {
for (SectionPart childPart : childParts) {
visit(childPart, visitor);
}
}
}
}
use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection in project openolat by klemens.
the class AssessmentTestHelper method needManualCorrection.
public static boolean needManualCorrection(ResolvedAssessmentTest resolvedAssessmentTest) {
AssessmentTest test = resolvedAssessmentTest.getRootNodeLookup().extractIfSuccessful();
boolean needManualCorrection = false;
List<TestPart> parts = test.getChildAbstractParts();
for (TestPart part : parts) {
List<AssessmentSection> sections = part.getAssessmentSections();
for (AssessmentSection section : sections) {
if (needManualCorrection(section, resolvedAssessmentTest)) {
needManualCorrection = true;
break;
}
}
}
return needManualCorrection;
}
use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection in project openolat by klemens.
the class QTI21ExportProcessor method assembleTest.
public void assembleTest(List<QuestionItemFull> fullItems, ZipOutputStream zout) {
try {
QtiSerializer qtiSerializer = qtiService.qtiSerializer();
// imsmanifest
ManifestBuilder manifest = ManifestBuilder.createAssessmentTestBuilder();
// assessment test
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());
String itemFilename = itemFile.getName();
String container = qitem.getKey().toString();
String containedFilename = container + "/" + itemFilename;
ResolvedAssessmentItem resolvedAssessmentItem = qtiService.loadAndResolveAssessmentItemForCopy(itemFile.toURI(), resourceDirectory);
ZipUtil.addFileToZip(containedFilename, itemFile, zout);
AssessmentTestFactory.appendAssessmentItem(section, containedFilename);
manifest.appendAssessmentItem(containedFilename);
ManifestMetadataBuilder metadata = manifest.getResourceBuilderByHref(containedFilename);
metadata.appendMetadataFrom(qitem, resolvedAssessmentItem, locale);
// write materials
try {
Files.walkFileTree(resourceDirectory.toPath(), new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
String filename = file.getFileName().toString();
if (!"imsmanifest.xml".equals(filename) && !filename.startsWith(".") && !itemFilename.equals(filename)) {
String relPath = resourceDirectory.toPath().relativize(file).toString();
ZipUtil.addFileToZip(container + "/" + relPath, file, zout);
}
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
log.error("", e);
}
}
zout.putNextEntry(new ZipEntry(assessmentTestFilename));
qtiSerializer.serializeJqtiObject(assessmentTest, new ShieldOutputStream(zout));
zout.closeEntry();
zout.putNextEntry(new ZipEntry("imsmanifest.xml"));
manifest.write(new ShieldOutputStream(zout));
zout.closeEntry();
} catch (IOException | URISyntaxException e) {
log.error("", e);
}
}
use of uk.ac.ed.ph.jqtiplus.node.test.AssessmentSection in project openolat by klemens.
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);
}
}
Aggregations