use of org.olat.imscp.xml.manifest.ResourceType in project openolat by klemens.
the class ManifestBuilder method appendAssessmentItem.
public ResourceType appendAssessmentItem(String itemId, String itemFileName) {
ResourceType itemResourceType = cpObjectFactory.createResourceType();
itemResourceType.setIdentifier(itemId);
itemResourceType.setType("imsqti_item_xmlv2p1");
itemResourceType.setHref(itemFileName);
getResourceList().add(itemResourceType);
appendFile(itemResourceType, itemFileName);
return itemResourceType;
}
use of org.olat.imscp.xml.manifest.ResourceType in project openolat by klemens.
the class ManifestBuilder method appendAssessmentTest.
private final void appendAssessmentTest(String testId, String testFilename) {
ResourceType testResourceType = cpObjectFactory.createResourceType();
testResourceType.setIdentifier(testId);
testResourceType.setType("imsqti_test_xmlv2p1");
testResourceType.setHref(testFilename);
getResourceList().add(testResourceType);
appendFile(testResourceType, testFilename);
}
use of org.olat.imscp.xml.manifest.ResourceType in project openolat by klemens.
the class QTI21ExportProcessor method enrichWithMetadata.
public void enrichWithMetadata(QuestionItemFull qitem, ResolvedAssessmentItem resolvedAssessmentItem, ManifestBuilder manifestBuilder) {
ResourceType resource = manifestBuilder.getResourceTypeByHref(qitem.getRootFilename());
if (resource == null) {
resource = manifestBuilder.appendAssessmentItem(qitem.getRootFilename());
}
ManifestMetadataBuilder metadataBuilder = manifestBuilder.getMetadataBuilder(resource, true);
metadataBuilder.appendMetadataFrom(qitem, resolvedAssessmentItem, locale);
}
use of org.olat.imscp.xml.manifest.ResourceType 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;
}
use of org.olat.imscp.xml.manifest.ResourceType in project openolat by klemens.
the class QTI21QPoolServiceProvider method importAssessmentItemRef.
/**
* Very important, the ManifestMetadataBuilder will be changed, it need to be a clone
*
* @param owner The future owner of the question
* @param assessmentItem The assessment item to convert
* @param itemFile The file where the assessment item is saved
* @param clonedMetadataBuilder The metadata builder need to be a clone!
* @param fUnzippedDirRoot The directory of the assessment item or the assessment test.
* @param defaultLocale The locale used by some translation
* @return
*/
public QuestionItem importAssessmentItemRef(Identity owner, AssessmentItem assessmentItem, File itemFile, ManifestMetadataBuilder clonedMetadataBuilder, Locale defaultLocale) {
QTI21ImportProcessor processor = new QTI21ImportProcessor(owner, defaultLocale);
AssessmentItemMetadata metadata = new AssessmentItemMetadata(clonedMetadataBuilder);
String editor = null;
String editorVersion = null;
if (StringHelper.containsNonWhitespace(assessmentItem.getToolName())) {
editor = assessmentItem.getToolName();
}
if (StringHelper.containsNonWhitespace(assessmentItem.getToolVersion())) {
editorVersion = assessmentItem.getToolVersion();
}
String originalItemFilename = itemFile.getName();
QuestionItemImpl qitem = processor.processItem(assessmentItem, null, originalItemFilename, editor, editorVersion, metadata);
// storage
File itemStorage = qpoolFileStorage.getDirectory(qitem.getDirectory());
FileUtils.copyDirContentsToDir(itemFile, itemStorage, false, "QTI21 import item xml in pool");
// create manifest
ManifestBuilder manifest = ManifestBuilder.createAssessmentItemBuilder();
ResourceType resource = manifest.appendAssessmentItem(UUID.randomUUID().toString(), originalItemFilename);
ManifestMetadataBuilder exportedMetadataBuilder = manifest.getMetadataBuilder(resource, true);
exportedMetadataBuilder.setMetadata(clonedMetadataBuilder.getMetadata());
manifest.write(new File(itemStorage, "imsmanifest.xml"));
// process material
File materialDirRoot = itemFile.getParentFile();
List<String> materials = ImportExportHelper.getMaterials(assessmentItem);
for (String material : materials) {
if (material.indexOf("://") < 0) {
// material can be an external URL
try {
File materialFile = new File(materialDirRoot, material);
if (materialFile.isFile() && materialFile.exists()) {
File itemMaterialFile = new File(itemStorage, material);
if (!itemMaterialFile.getParentFile().exists()) {
itemMaterialFile.getParentFile().mkdirs();
}
Files.copy(materialFile.toPath(), itemMaterialFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
}
} catch (IOException e) {
log.error("", e);
}
}
}
return qitem;
}
Aggregations