use of org.olat.imscp.xml.manifest.ResourceType in project OpenOLAT by OpenOLAT.
the class QTI21ImportProcessor method process.
public List<QuestionItem> process(File file) {
// export zip file
List<QuestionItem> items = new ArrayList<>();
try (FileSystem fs = FileSystems.newFileSystem(file.toPath(), null)) {
Path fPath = fs.getPath("/");
if (fPath != null) {
ImsManifestVisitor visitor = new ImsManifestVisitor();
Files.walkFileTree(fPath, visitor);
List<Path> imsmanifests = visitor.getImsmanifestFiles();
for (Path imsmanifest : imsmanifests) {
InputStream in = Files.newInputStream(imsmanifest);
ManifestBuilder manifestBuilder = ManifestBuilder.read(new ShieldInputStream(in));
List<ResourceType> resources = manifestBuilder.getResourceList();
for (ResourceType resource : resources) {
ManifestMetadataBuilder metadataBuilder = manifestBuilder.getMetadataBuilder(resource, true);
QuestionItem qitem = processResource(resource, imsmanifest, metadataBuilder);
if (qitem != null) {
items.add(qitem);
}
}
}
}
} catch (IOException e) {
log.error("", e);
}
return items;
}
use of org.olat.imscp.xml.manifest.ResourceType in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class ManifestBuilder method getResourceBuilderByHref.
public ManifestMetadataBuilder getResourceBuilderByHref(String href) {
ResourceType resourceType = getResourceTypeByHref(href);
MetadataType metadata = getMetadata(resourceType);
return metadata == null ? null : new ManifestMetadataBuilder(metadata);
}
use of org.olat.imscp.xml.manifest.ResourceType in project OpenOLAT by OpenOLAT.
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 org.olat.imscp.xml.manifest.ResourceType in project OpenOLAT by OpenOLAT.
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