use of uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem in project openolat by klemens.
the class ManifestMetadataBuilder method appendMetadataFrom.
public void appendMetadataFrom(QuestionItem item, ResolvedAssessmentItem resolvedAssessmentItem, Locale locale) {
AssessmentItem assessmentItem = null;
if (resolvedAssessmentItem != null) {
assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
}
appendMetadataFrom(item, assessmentItem, locale);
}
use of uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem in project openolat by klemens.
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;
}
}
use of uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem in project openolat by klemens.
the class CopyAndConvertVisitor method checkAssessmentItem.
private void checkAssessmentItem(Path outputFile) {
QTI21Service qtiService = CoreSpringFactory.getImpl(QTI21Service.class);
QtiXmlReader qtiXmlReader = new QtiXmlReader(qtiService.jqtiExtensionManager());
ResourceLocator fileResourceLocator = new FileResourceLocator();
ResourceLocator inputResourceLocator = ImsQTI21Resource.createResolvingResourceLocator(fileResourceLocator);
URI assessmentObjectSystemId = outputFile.toFile().toURI();
AssessmentObjectXmlLoader assessmentObjectXmlLoader = new AssessmentObjectXmlLoader(qtiXmlReader, inputResourceLocator);
ResolvedAssessmentItem resolvedAssessmentItem = assessmentObjectXmlLoader.loadAndResolveAssessmentItem(assessmentObjectSystemId);
AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
if (!AssessmentItemChecker.checkAndCorrect(assessmentItem)) {
try (FileOutputStream out = new FileOutputStream(outputFile.toFile())) {
qtiService.qtiSerializer().serializeJqtiObject(assessmentItem, out);
} catch (Exception e) {
log.error("", e);
}
}
}
use of uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem in project openolat by klemens.
the class CopyAndConvertVisitor method validate.
private boolean validate(Path inputFile, InputType type, boolean verbose) {
try {
QtiXmlReader qtiXmlReader = new QtiXmlReader(new JqtiExtensionManager());
ResourceLocator fileResourceLocator = new PathResourceLocator(inputFile.getParent());
AssessmentObjectXmlLoader assessmentObjectXmlLoader = new AssessmentObjectXmlLoader(qtiXmlReader, fileResourceLocator);
RootNode rootNode = null;
BadResourceException e = null;
URI uri = new URI("zip", inputFile.getFileName().toString(), null);
if (type == InputType.assessmentItem) {
ItemValidationResult itemResult = assessmentObjectXmlLoader.loadResolveAndValidateItem(uri);
e = itemResult.getResolvedAssessmentItem().getItemLookup().getBadResourceException();
ResolvedAssessmentItem resolvedAssessmentItem = assessmentObjectXmlLoader.loadAndResolveAssessmentItem(uri);
rootNode = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
} else if (type == InputType.assessmentTest) {
TestValidationResult testResult = assessmentObjectXmlLoader.loadResolveAndValidateTest(uri);
e = testResult.getResolvedAssessmentTest().getTestLookup().getBadResourceException();
ResolvedAssessmentTest resolvedAssessmentTest = assessmentObjectXmlLoader.loadAndResolveAssessmentTest(uri);
rootNode = resolvedAssessmentTest.getRootNodeLookup().extractIfSuccessful();
}
if (e != null && verbose) {
StringBuilder err = new StringBuilder();
BadRessourceHelper.extractMessage(e, err);
log.warn(err.toString());
}
return (rootNode != null) && (e == null || (e instanceof QtiXmlInterpretationException && ((QtiXmlInterpretationException) e).getXmlParseResult().getFatalErrors().isEmpty()));
} catch (URISyntaxException e) {
log.error("", e);
return false;
}
}
use of uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem in project openolat by klemens.
the class AssessmentTestComponent method willShowFeedbacks.
/**
* Check if the assessment item will show some
* form of feedback like feedbackElement, modalFeedback
* or message as invalid or bad response.
*
* @param itemNode
* @return
*/
public boolean willShowFeedbacks(TestPlanNode itemNode) {
if (isHideFeedbacks()) {
return false;
}
try {
URI itemSystemId = itemNode.getItemSystemId();
ResolvedAssessmentItem resolvedAssessmentItem = getResolvedAssessmentTest().getResolvedAssessmentItemBySystemIdMap().get(itemSystemId);
AssessmentItem assessmentItem = resolvedAssessmentItem.getRootNodeLookup().extractIfSuccessful();
if (assessmentItem.getAdaptive()) {
return true;
}
ItemSessionState itemSessionState = getItemSessionState(itemNode.getKey());
if (!itemSessionState.isResponded()) {
return true;
}
ItemProcessingContext itemContext = getTestSessionController().getItemProcessingContext(itemNode);
if (itemContext instanceof ItemSessionController) {
ItemSessionController itemSessionController = (ItemSessionController) itemContext;
List<Interaction> interactions = itemSessionController.getInteractions();
for (Interaction interaction : interactions) {
if (AssessmentRenderFunctions.isBadResponse(itemSessionState, interaction.getResponseIdentifier())) {
return true;
}
if (AssessmentRenderFunctions.isInvalidResponse(itemSessionState, interaction.getResponseIdentifier())) {
return true;
}
}
}
if (assessmentItem.getItemBody().willShowFeedback(itemContext)) {
return true;
}
List<ModalFeedback> modalFeedbacks = assessmentItem.getModalFeedbacks();
for (ModalFeedback modalFeedback : modalFeedbacks) {
if (isFeedback(modalFeedback, itemSessionState)) {
return true;
}
}
} catch (Exception e) {
log.error("", e);
}
return false;
}
Aggregations