use of uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem in project OpenOLAT by OpenOLAT.
the class CorrectionIdentityAssessmentItemListController method doSelect.
private void doSelect(UserRequest ureq, CorrectionIdentityAssessmentItemRow row) {
removeAsListenerAndDispose(identityItemCtrl);
doUnlock();
AssessmentItemRef itemRef = row.getItemRef();
TestSessionState testSessionState = qtiService.loadTestSessionState(candidateSession);
List<TestPlanNode> nodes = testSessionState.getTestPlan().getNodes(itemRef.getIdentifier());
AssessmentItemSession reloadItemSession = null;
if (nodes.size() == 1) {
TestPlanNode itemNode = nodes.get(0);
String stringuifiedIdentifier = itemNode.getKey().getIdentifier().toString();
ParentPartItemRefs parentParts = AssessmentTestHelper.getParentSection(itemNode.getKey(), testSessionState, model.getResolvedAssessmentTest());
reloadItemSession = qtiService.getOrCreateAssessmentItemSession(candidateSession, parentParts, stringuifiedIdentifier);
}
// lock on item, need to check the lock on identity / test
String lockSubKey = "item-" + reloadItemSession.getKey();
OLATResourceable testOres = OresHelper.clone(model.getTestEntry().getOlatResource());
lockResult = CoordinatorManager.getInstance().getCoordinator().getLocker().acquireLock(testOres, getIdentity(), lockSubKey);
if (lockResult.isSuccess()) {
if (nodes.size() == 1) {
TestPlanNode itemNode = nodes.get(0);
ItemSessionState itemSessionState = testSessionState.getItemSessionStates().get(itemNode.getKey());
AssessmentItemCorrection itemCorrection = new AssessmentItemCorrection(assessedIdentity, candidateSession, testSessionState, reloadItemSession, itemSessionState, itemRef, itemNode);
itemCorrection.setItemSession(reloadItemSession);
ResolvedAssessmentItem resolvedAssessmentItem = model.getResolvedAssessmentTest().getResolvedAssessmentItem(itemRef);
AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
identityItemCtrl = new CorrectionIdentityAssessmentItemNavigationController(ureq, getWindowControl(), model.getTestEntry(), model.getResolvedAssessmentTest(), itemCorrection, row, tableModel.getObjects(), model);
listenTo(identityItemCtrl);
stackPanel.pushController(assessmentItem.getTitle(), identityItemCtrl);
updatePreviousNext();
}
} else {
String lockOwnerName = userManager.getUserDisplayName(lockResult.getOwner());
showWarning("warning.assessment.item.locked", new String[] { lockOwnerName });
}
}
use of uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem in project openolat by klemens.
the class AssessmentResultController method initFormItemResult.
private Results initFormItemResult(FormLayoutContainer layoutCont, TestPlanNode node, Map<Identifier, AssessmentItemRef> identifierToRefs, Map<TestPlanNode, Results> resultsMap) {
TestPlanNodeKey testPlanNodeKey = node.getKey();
Identifier identifier = testPlanNodeKey.getIdentifier();
AssessmentItemRef itemRef = identifierToRefs.get(identifier);
ResolvedAssessmentItem resolvedAssessmentItem = resolvedAssessmentTest.getResolvedAssessmentItem(itemRef);
AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
QTI21QuestionType type = QTI21QuestionType.getType(assessmentItem);
AssessmentItemSession itemSession = identifierToItemSession.get(identifier.toString());
Results r = new Results(false, node.getSectionPartTitle(), type.getCssClass(), options.isQuestionSummary());
// init
r.setSessionStatus(null);
r.setItemIdentifier(node.getIdentifier().toString());
ItemSessionState sessionState = testSessionState.getItemSessionStates().get(testPlanNodeKey);
if (sessionState != null) {
r.setSessionState(sessionState);
SessionStatus sessionStatus = sessionState.getSessionStatus();
if (sessionState != null) {
r.setSessionStatus(sessionStatus);
}
}
ItemResult itemResult = assessmentResult.getItemResult(identifier.toString());
if (itemResult != null) {
extractOutcomeVariable(itemResult.getItemVariables(), r);
}
if (itemSession != null) {
if (itemSession.getManualScore() != null) {
r.setScore(itemSession.getManualScore());
r.setManualScore(itemSession.getManualScore());
}
r.setComment(itemSession.getCoachComment());
}
// update max score of section
if (options.isUserSolutions() || options.isCorrectSolutions()) {
InteractionResults interactionResults = initFormItemInteractions(layoutCont, sessionState, resolvedAssessmentItem);
r.setInteractionResults(interactionResults);
if (options.isCorrectSolutions()) {
String correctSolutionId = "correctSolutionItem" + count++;
FeedbackResultFormItem correctSolutionItem = new FeedbackResultFormItem(correctSolutionId, resolvedAssessmentItem);
initInteractionResultFormItem(correctSolutionItem, sessionState);
layoutCont.add(correctSolutionId, correctSolutionItem);
r.setCorrectSolutionItem(correctSolutionItem);
}
}
updateSectionScoreInformations(node, r, resultsMap);
return r;
}
use of uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem in project openolat by klemens.
the class QTI12And21PoolWordExport method exportItems.
private void exportItems(List<QuestionItemFull> fullItems, OutputStream out, boolean withResponses) {
ZipOutputStream zout = null;
try {
OpenXMLDocument document = new OpenXMLDocument();
document.setDocumentHeader("");
Translator qti12Translator = Util.createPackageTranslator(QTIWordExport.class, locale);
Translator translator = Util.createPackageTranslator(AssessmentTestDisplayController.class, locale, Util.createPackageTranslator(AssessmentTestComposerController.class, locale, qti12Translator));
AssessmentHtmlBuilder htmlBuilder = new AssessmentHtmlBuilder();
for (Iterator<QuestionItemFull> itemIt = fullItems.iterator(); itemIt.hasNext(); ) {
QuestionItemFull fullItem = itemIt.next();
if (QTIConstants.QTI_12_FORMAT.equals(fullItem.getFormat())) {
String dir = fullItem.getDirectory();
VFSContainer container = qpoolFileStorage.getContainer(dir);
document.setMediaContainer(container);
VFSItem rootItem = container.resolve(fullItem.getRootFilename());
Item item = QTIEditHelper.readItemXml((VFSLeaf) rootItem);
if (item.isAlient()) {
QTIWordExport.renderAlienItem(item, document, translator);
} else {
QTIWordExport.renderItem(item, document, withResponses, translator);
}
} else {
File resourceDirectory = qpoolService.getRootDirectory(fullItem);
VFSContainer resourceContainer = qpoolService.getRootContainer(fullItem);
document.setMediaContainer(resourceContainer);
File resourceFile = qpoolService.getRootFile(fullItem);
URI assessmentItemUri = resourceFile.toURI();
ResolvedAssessmentItem resolvedAssessmentItem = qtiService.loadAndResolveAssessmentItem(assessmentItemUri, resourceDirectory);
AssessmentItem item = resolvedAssessmentItem.getItemLookup().extractIfSuccessful();
QTI21WordExport.renderAssessmentItem(item, resourceFile, resourceDirectory, document, withResponses, translator, htmlBuilder);
}
if (itemIt.hasNext()) {
document.appendPageBreak();
}
}
zout = new ZipOutputStream(out);
zout.setLevel(9);
OpenXMLDocumentWriter writer = new OpenXMLDocumentWriter();
writer.createDocument(zout, document);
} catch (Exception e) {
log.error("", e);
} finally {
if (zout != null) {
try {
zout.finish();
} catch (IOException e) {
log.error("", e);
}
}
}
}
use of uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem in project openolat by klemens.
the class QTI21ExportProcessor method process.
public void process(QuestionItemFull qitem, ZipOutputStream zout) {
String dir = qitem.getDirectory();
File rootDirectory = qpoolFileStorage.getDirectory(dir);
String rootDir = "qitem_" + qitem.getKey();
File imsmanifest = new File(rootDirectory, "imsmanifest.xml");
ManifestBuilder manifestBuilder;
if (imsmanifest.exists()) {
manifestBuilder = ManifestBuilder.read(imsmanifest);
} else {
manifestBuilder = new ManifestBuilder();
}
File resourceFile = new File(rootDirectory, qitem.getRootFilename());
URI assessmentItemUri = resourceFile.toURI();
ResolvedAssessmentItem resolvedAssessmentItem = qtiService.loadAndResolveAssessmentItemForCopy(assessmentItemUri, rootDirectory);
enrichWithMetadata(qitem, resolvedAssessmentItem, manifestBuilder);
try {
zout.putNextEntry(new ZipEntry(rootDir + "/imsmanifest.xml"));
manifestBuilder.write(new ShieldOutputStream(zout));
zout.closeEntry();
} catch (Exception e) {
log.error("", e);
}
try {
Files.walkFileTree(rootDirectory.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(".")) {
String relPath = rootDirectory.toPath().relativize(file).toString();
ZipUtil.addFileToZip(rootDir + "/" + relPath, file, zout);
}
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
log.error("", e);
}
}
use of uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem 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