Search in sources :

Example 1 with ResourceType

use of org.olat.imscp.xml.manifest.ResourceType in project OpenOLAT by OpenOLAT.

the class AssessmentTestComposerController method doExportPool.

private void doExportPool(AssessmentItemRef itemRef) {
    ResolvedAssessmentItem resolvedAssessmentItem = resolvedAssessmentTest.getResolvedAssessmentItem(itemRef);
    RootNodeLookup<AssessmentItem> rootNode = resolvedAssessmentItem.getItemLookup();
    AssessmentItem assessmentItem = rootNode.extractIfSuccessful();
    ManifestBuilder clonedManifestBuilder = ManifestBuilder.read(new File(unzippedDirRoot, "imsmanifest.xml"));
    ResourceType resource = getResourceType(clonedManifestBuilder, itemRef);
    ManifestMetadataBuilder metadata = clonedManifestBuilder.getMetadataBuilder(resource, true);
    if (metadata == null) {
        // not in imsmanifest.xml?
        metadata = new ManifestMetadataBuilder();
    }
    File itemFile = new File(rootNode.getSystemId());
    qti21QPoolServiceProvider.importAssessmentItemRef(getIdentity(), assessmentItem, itemFile, metadata, getLocale());
}
Also used : ManifestBuilder(org.olat.ims.qti21.model.xml.ManifestBuilder) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) ResourceType(org.olat.imscp.xml.manifest.ResourceType) File(java.io.File) ManifestMetadataBuilder(org.olat.ims.qti21.model.xml.ManifestMetadataBuilder)

Example 2 with ResourceType

use of org.olat.imscp.xml.manifest.ResourceType in project OpenOLAT by OpenOLAT.

the class AssessmentTestComposerController method doDeleteAssessmentItemRef.

private void doDeleteAssessmentItemRef(UserRequest ureq, AssessmentItemRef itemRef) {
    ResourceType resource = getResourceType(itemRef);
    if (resource != null) {
        manifestBuilder.remove(resource);
    }
    boolean deleted = false;
    boolean removed = itemRef.getParentSection().getSectionParts().remove(itemRef);
    ResolvedAssessmentItem resolvedAssessmentItem = resolvedAssessmentTest.getResolvedAssessmentItem(itemRef);
    if (resolvedAssessmentItem != null) {
        RootNodeLookup<AssessmentItem> rootNode = resolvedAssessmentItem.getItemLookup();
        if (rootNode != null) {
            URI itemUri = rootNode.getSystemId();
            List<AssessmentItemRef> itemRefs = resolvedAssessmentTest.getItemRefsBySystemIdMap().get(itemUri);
            if (itemRefs.size() <= 1) {
                File itemFile = new File(itemUri);
                deleted = itemFile.delete();
            }
        }
    }
    if (deleted) {
        assessmentChanged(ureq);
    }
    logAudit(removed + " " + deleted + " removed item ref", null);
}
Also used : ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItemRef(uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef) ResourceType(org.olat.imscp.xml.manifest.ResourceType) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) URI(java.net.URI) File(java.io.File)

Example 3 with ResourceType

use of org.olat.imscp.xml.manifest.ResourceType in project OpenOLAT by OpenOLAT.

the class ExportBinderAsCPResource method createImsManifest.

private ManifestType createImsManifest(Binder binder, List<Section> sections, List<Page> pages) {
    ManifestType manifest = cpObjectFactory.createManifestType();
    manifest.setIdentifier(UUID.randomUUID().toString());
    // schema
    ManifestMetadataType metadataType = cpObjectFactory.createManifestMetadataType();
    manifest.setMetadata(metadataType);
    // organizations
    OrganizationsType organizations = cpObjectFactory.createOrganizationsType();
    manifest.setOrganizations(organizations);
    OrganizationType organization = cpObjectFactory.createOrganizationType();
    organization.setIdentifier("binder_" + binder.getKey());
    organization.setTitle(binder.getTitle());
    organization.setStructure("hierarchical");
    organizations.getOrganization().add(organization);
    organizations.setDefault(organization);
    ResourcesType resources = cpObjectFactory.createResourcesType();
    manifest.setResources(resources);
    Map<Section, ItemType> sectionToItemMap = new HashMap<>();
    for (Section section : sections) {
        ItemType sectionItem = cpObjectFactory.createItemType();
        String itemIdentifier = "section_" + section.getKey().toString();
        String resourceIdentifier = "res_" + itemIdentifier;
        sectionItem.setTitle(section.getTitle());
        sectionItem.setIdentifier(itemIdentifier);
        sectionItem.setIdentifierref(resourceIdentifier);
        sectionItem.setIsvisible(Boolean.TRUE);
        organization.getItem().add(sectionItem);
        sectionToItemMap.put(section, sectionItem);
        ResourceType resource = cpObjectFactory.createResourceType();
        resource.setIdentifier(resourceIdentifier);
        resource.setType("webcontent");
        resource.setHref(sectionFilename(section));
        resources.getResource().add(resource);
    }
    for (Page page : pages) {
        ItemType sectionItem = sectionToItemMap.get(page.getSection());
        if (sectionItem == null) {
            continue;
        }
        ItemType pageItem = cpObjectFactory.createItemType();
        pageItem.setTitle(page.getTitle());
        String itemIdentifier = "page_" + page.getKey().toString();
        String resourceIdentifier = "res_" + itemIdentifier;
        pageItem.setIdentifier(itemIdentifier);
        pageItem.setIdentifierref(resourceIdentifier);
        pageItem.setIsvisible(Boolean.TRUE);
        sectionItem.getItem().add(pageItem);
        ResourceType resource = cpObjectFactory.createResourceType();
        resource.setIdentifier(resourceIdentifier);
        resource.setType("webcontent");
        resource.setHref(pageFilename(page));
        resources.getResource().add(resource);
    }
    return manifest;
}
Also used : ManifestMetadataType(org.olat.imscp.xml.manifest.ManifestMetadataType) ResourcesType(org.olat.imscp.xml.manifest.ResourcesType) ManifestType(org.olat.imscp.xml.manifest.ManifestType) OrganizationsType(org.olat.imscp.xml.manifest.OrganizationsType) HashMap(java.util.HashMap) ItemType(org.olat.imscp.xml.manifest.ItemType) ResourceType(org.olat.imscp.xml.manifest.ResourceType) Page(org.olat.modules.portfolio.Page) OrganizationType(org.olat.imscp.xml.manifest.OrganizationType) AssessmentSection(org.olat.modules.portfolio.AssessmentSection) Section(org.olat.modules.portfolio.Section)

Example 4 with ResourceType

use of org.olat.imscp.xml.manifest.ResourceType in project OpenOLAT by OpenOLAT.

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);
}
Also used : ResourceType(org.olat.imscp.xml.manifest.ResourceType) ManifestMetadataBuilder(org.olat.ims.qti21.model.xml.ManifestMetadataBuilder)

Example 5 with ResourceType

use of org.olat.imscp.xml.manifest.ResourceType in project OpenOLAT by OpenOLAT.

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;
    }
}
Also used : Path(java.nio.file.Path) AssessmentObjectXmlLoader(uk.ac.ed.ph.jqtiplus.reading.AssessmentObjectXmlLoader) ManifestBuilder(org.olat.ims.qti21.model.xml.ManifestBuilder) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItem(uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem) ResourceType(org.olat.imscp.xml.manifest.ResourceType) URI(java.net.URI) IOException(java.io.IOException) ManifestMetadataBuilder(org.olat.ims.qti21.model.xml.ManifestMetadataBuilder) QtiXmlReader(uk.ac.ed.ph.jqtiplus.reading.QtiXmlReader) QTI21Infos(org.olat.ims.qti21.model.xml.QTI21Infos) FileResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.FileResourceLocator) ResolvedAssessmentItem(uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem) AssessmentItemMetadata(org.olat.ims.qti21.model.xml.AssessmentItemMetadata) File(java.io.File) FileResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.FileResourceLocator) ResourceLocator(uk.ac.ed.ph.jqtiplus.xmlutils.locators.ResourceLocator)

Aggregations

ResourceType (org.olat.imscp.xml.manifest.ResourceType)28 File (java.io.File)14 ManifestMetadataBuilder (org.olat.ims.qti21.model.xml.ManifestMetadataBuilder)14 ManifestBuilder (org.olat.ims.qti21.model.xml.ManifestBuilder)12 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)10 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)10 IOException (java.io.IOException)6 URI (java.net.URI)6 ManifestMetadataType (org.olat.imscp.xml.manifest.ManifestMetadataType)6 QuestionItemImpl (org.olat.modules.qpool.model.QuestionItemImpl)6 Path (java.nio.file.Path)4 ArrayList (java.util.ArrayList)4 AssessmentItemMetadata (org.olat.ims.qti21.model.xml.AssessmentItemMetadata)4 QuestionItem (org.olat.modules.qpool.QuestionItem)4 AssessmentItemRef (uk.ac.ed.ph.jqtiplus.node.test.AssessmentItemRef)4 MetadataType (org.olat.imscp.xml.manifest.MetadataType)3 InputStream (java.io.InputStream)2 FileSystem (java.nio.file.FileSystem)2 HashMap (java.util.HashMap)2 ShieldInputStream (org.olat.core.util.io.ShieldInputStream)2