Search in sources :

Example 21 with ResourceType

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

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;
}
Also used : ManifestBuilder(org.olat.ims.qti21.model.xml.ManifestBuilder) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) AssessmentItemMetadata(org.olat.ims.qti21.model.xml.AssessmentItemMetadata) ResourceType(org.olat.imscp.xml.manifest.ResourceType) IOException(java.io.IOException) File(java.io.File) ManifestMetadataBuilder(org.olat.ims.qti21.model.xml.ManifestMetadataBuilder)

Example 22 with ResourceType

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

the class ManifestBuilder method getResourceBuilderByIdentifier.

public ManifestMetadataBuilder getResourceBuilderByIdentifier(String resourceId) {
    ResourceType resourceType = getResourceTypeByIdentifier(resourceId);
    MetadataType metadata = getMetadata(resourceType);
    return metadata == null ? null : new ManifestMetadataBuilder(metadata);
}
Also used : ManifestMetadataType(org.olat.imscp.xml.manifest.ManifestMetadataType) MetadataType(org.olat.imscp.xml.manifest.MetadataType) ResourceType(org.olat.imscp.xml.manifest.ResourceType)

Example 23 with ResourceType

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

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

Example 24 with ResourceType

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

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);
}
Also used : ManifestMetadataType(org.olat.imscp.xml.manifest.ManifestMetadataType) MetadataType(org.olat.imscp.xml.manifest.MetadataType) ResourceType(org.olat.imscp.xml.manifest.ResourceType)

Example 25 with ResourceType

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

the class ManifestBuilder method getResourceBuilderByIdentifier.

public ManifestMetadataBuilder getResourceBuilderByIdentifier(String resourceId) {
    ResourceType resourceType = getResourceTypeByIdentifier(resourceId);
    MetadataType metadata = getMetadata(resourceType);
    return metadata == null ? null : new ManifestMetadataBuilder(metadata);
}
Also used : ManifestMetadataType(org.olat.imscp.xml.manifest.ManifestMetadataType) MetadataType(org.olat.imscp.xml.manifest.MetadataType) ResourceType(org.olat.imscp.xml.manifest.ResourceType)

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