Search in sources :

Example 1 with ImsQTI21Resource

use of org.olat.fileresource.types.ImsQTI21Resource in project OpenOLAT by OpenOLAT.

the class QTI21AssessmentTestHandler method importResource.

@Override
public RepositoryEntry importResource(Identity initialAuthor, String initialAuthorAlt, String displayname, String description, boolean withReferences, Locale locale, File file, String filename) {
    ImsQTI21Resource ores = new ImsQTI21Resource();
    OLATResource resource = OLATResourceManager.getInstance().createAndPersistOLATResourceInstance(ores);
    File fResourceFileroot = FileResourceManager.getInstance().getFileResourceRoot(resource);
    File zipDir = new File(fResourceFileroot, FileResourceManager.ZIPDIR);
    copyResource(file, filename, zipDir);
    File optionsFile = new File(zipDir, QTI21Service.PACKAGE_CONFIG_FILE_NAME);
    if (optionsFile.exists()) {
        try {
            // move the options to the root directory
            File target = new File(fResourceFileroot, QTI21Service.PACKAGE_CONFIG_FILE_NAME);
            Files.move(optionsFile.toPath(), target.toPath(), StandardCopyOption.REPLACE_EXISTING);
        } catch (IOException e) {
            log.error("", e);
        }
    }
    RepositoryEntry re = CoreSpringFactory.getImpl(RepositoryService.class).create(initialAuthor, null, "", displayname, description, resource, RepositoryEntry.ACC_OWNERS);
    DBFactory.getInstance().commit();
    return re;
}
Also used : ImsQTI21Resource(org.olat.fileresource.types.ImsQTI21Resource) OLATResource(org.olat.resource.OLATResource) IOException(java.io.IOException) RepositoryEntry(org.olat.repository.RepositoryEntry) File(java.io.File) RepositoryService(org.olat.repository.RepositoryService)

Example 2 with ImsQTI21Resource

use of org.olat.fileresource.types.ImsQTI21Resource in project OpenOLAT by OpenOLAT.

the class QTI21AssessmentTestHandler method createResource.

@Override
public RepositoryEntry createResource(Identity initialAuthor, String displayname, String description, Object createObject, Locale locale) {
    ImsQTI21Resource ores = new ImsQTI21Resource();
    OLATResource resource = OLATResourceManager.getInstance().findOrPersistResourceable(ores);
    RepositoryEntry re = repositoryService.create(initialAuthor, null, "", displayname, description, resource, RepositoryEntry.ACC_OWNERS);
    dbInstance.commit();
    File repositoryDir = new File(FileResourceManager.getInstance().getFileResourceRoot(re.getOlatResource()), FileResourceManager.ZIPDIR);
    if (!repositoryDir.exists()) {
        repositoryDir.mkdirs();
    }
    if (createObject instanceof QItemList) {
        QItemList itemToImport = (QItemList) createObject;
        qpoolServiceProvider.exportToEditorPackage(repositoryDir, itemToImport.getItems(), locale);
    } else if (createObject instanceof QTIEditorPackage) {
        QTIEditorPackage testToConvert = (QTIEditorPackage) createObject;
        QTI21DeliveryOptions options = qtiService.getDeliveryOptions(re);
        qpoolServiceProvider.convertFromEditorPackage(testToConvert, repositoryDir, locale, options);
        qtiService.setDeliveryOptions(re, options);
    } else if (createObject instanceof OLATResource) {
        // convert a Onyx test in QTI 2.1
        OLATResource onyxResource = (OLATResource) createObject;
        RepositoryEntry onyxRe = CoreSpringFactory.getImpl(RepositoryService.class).loadByResourceKey(onyxResource.getKey());
        if (OnyxModule.isOnyxTest((OLATResource) createObject)) {
            copyOnyxResources(onyxResource, repositoryDir);
        } else {
            QTI21DeliveryOptions options = qtiService.getDeliveryOptions(re);
            QTIEditorPackage testToConvert = TestFileResource.getQTIEditorPackageReader(onyxResource);
            qpoolServiceProvider.convertFromEditorPackage(testToConvert, repositoryDir, locale, options);
            qtiService.setDeliveryOptions(re, options);
        }
        copyMetadata(onyxRe, re, repositoryDir);
    } else {
        createMinimalAssessmentTest(displayname, repositoryDir, locale);
    }
    return re;
}
Also used : QTI21DeliveryOptions(org.olat.ims.qti21.QTI21DeliveryOptions) ImsQTI21Resource(org.olat.fileresource.types.ImsQTI21Resource) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) File(java.io.File) QTIEditorPackage(org.olat.ims.qti.editor.QTIEditorPackage) QItemList(org.olat.modules.qpool.model.QItemList) RepositoryService(org.olat.repository.RepositoryService)

Example 3 with ImsQTI21Resource

use of org.olat.fileresource.types.ImsQTI21Resource in project openolat by klemens.

the class QTI21AssessmentTestHandler method importResource.

@Override
public RepositoryEntry importResource(Identity initialAuthor, String initialAuthorAlt, String displayname, String description, boolean withReferences, Locale locale, File file, String filename) {
    ImsQTI21Resource ores = new ImsQTI21Resource();
    OLATResource resource = OLATResourceManager.getInstance().createAndPersistOLATResourceInstance(ores);
    File fResourceFileroot = FileResourceManager.getInstance().getFileResourceRoot(resource);
    File zipDir = new File(fResourceFileroot, FileResourceManager.ZIPDIR);
    copyResource(file, filename, zipDir);
    File optionsFile = new File(zipDir, QTI21Service.PACKAGE_CONFIG_FILE_NAME);
    if (optionsFile.exists()) {
        try {
            // move the options to the root directory
            File target = new File(fResourceFileroot, QTI21Service.PACKAGE_CONFIG_FILE_NAME);
            Files.move(optionsFile.toPath(), target.toPath(), StandardCopyOption.REPLACE_EXISTING);
        } catch (IOException e) {
            log.error("", e);
        }
    }
    RepositoryEntry re = CoreSpringFactory.getImpl(RepositoryService.class).create(initialAuthor, null, "", displayname, description, resource, RepositoryEntry.ACC_OWNERS);
    DBFactory.getInstance().commit();
    return re;
}
Also used : ImsQTI21Resource(org.olat.fileresource.types.ImsQTI21Resource) OLATResource(org.olat.resource.OLATResource) IOException(java.io.IOException) RepositoryEntry(org.olat.repository.RepositoryEntry) File(java.io.File) RepositoryService(org.olat.repository.RepositoryService)

Example 4 with ImsQTI21Resource

use of org.olat.fileresource.types.ImsQTI21Resource in project openolat by klemens.

the class QTI21AssessmentTestHandler method createResource.

@Override
public RepositoryEntry createResource(Identity initialAuthor, String displayname, String description, Object createObject, Locale locale) {
    ImsQTI21Resource ores = new ImsQTI21Resource();
    OLATResource resource = OLATResourceManager.getInstance().findOrPersistResourceable(ores);
    RepositoryEntry re = repositoryService.create(initialAuthor, null, "", displayname, description, resource, RepositoryEntry.ACC_OWNERS);
    dbInstance.commit();
    File repositoryDir = new File(FileResourceManager.getInstance().getFileResourceRoot(re.getOlatResource()), FileResourceManager.ZIPDIR);
    if (!repositoryDir.exists()) {
        repositoryDir.mkdirs();
    }
    if (createObject instanceof QItemList) {
        QItemList itemToImport = (QItemList) createObject;
        qpoolServiceProvider.exportToEditorPackage(repositoryDir, itemToImport.getItems(), locale);
    } else if (createObject instanceof QTIEditorPackage) {
        QTIEditorPackage testToConvert = (QTIEditorPackage) createObject;
        QTI21DeliveryOptions options = qtiService.getDeliveryOptions(re);
        qpoolServiceProvider.convertFromEditorPackage(testToConvert, repositoryDir, locale, options);
        qtiService.setDeliveryOptions(re, options);
    } else if (createObject instanceof OLATResource) {
        // convert a Onyx test in QTI 2.1
        OLATResource onyxResource = (OLATResource) createObject;
        RepositoryEntry onyxRe = CoreSpringFactory.getImpl(RepositoryService.class).loadByResourceKey(onyxResource.getKey());
        if (OnyxModule.isOnyxTest((OLATResource) createObject)) {
            copyOnyxResources(onyxResource, repositoryDir);
        } else {
            QTI21DeliveryOptions options = qtiService.getDeliveryOptions(re);
            QTIEditorPackage testToConvert = TestFileResource.getQTIEditorPackageReader(onyxResource);
            qpoolServiceProvider.convertFromEditorPackage(testToConvert, repositoryDir, locale, options);
            qtiService.setDeliveryOptions(re, options);
        }
        copyMetadata(onyxRe, re, repositoryDir);
    } else {
        createMinimalAssessmentTest(displayname, repositoryDir, locale);
    }
    return re;
}
Also used : QTI21DeliveryOptions(org.olat.ims.qti21.QTI21DeliveryOptions) ImsQTI21Resource(org.olat.fileresource.types.ImsQTI21Resource) OLATResource(org.olat.resource.OLATResource) RepositoryEntry(org.olat.repository.RepositoryEntry) File(java.io.File) QTIEditorPackage(org.olat.ims.qti.editor.QTIEditorPackage) QItemList(org.olat.modules.qpool.model.QItemList) RepositoryService(org.olat.repository.RepositoryService)

Aggregations

File (java.io.File)4 ImsQTI21Resource (org.olat.fileresource.types.ImsQTI21Resource)4 RepositoryEntry (org.olat.repository.RepositoryEntry)4 RepositoryService (org.olat.repository.RepositoryService)4 OLATResource (org.olat.resource.OLATResource)4 IOException (java.io.IOException)2 QTIEditorPackage (org.olat.ims.qti.editor.QTIEditorPackage)2 QTI21DeliveryOptions (org.olat.ims.qti21.QTI21DeliveryOptions)2 QItemList (org.olat.modules.qpool.model.QItemList)2