Search in sources :

Example 1 with QTIEditorPackage

use of org.olat.ims.qti.editor.QTIEditorPackage in project OpenOLAT by OpenOLAT.

the class OLATUpgrade_11_0_0 method checkEssay.

private boolean checkEssay(RepositoryEntry testEntry) {
    if (qtiEssayMap.containsKey(testEntry.getKey())) {
        return qtiEssayMap.get(testEntry.getKey()).booleanValue();
    }
    TestFileResource fr = new TestFileResource();
    fr.overrideResourceableId(testEntry.getOlatResource().getResourceableId());
    TransientIdentity pseudoIdentity = new TransientIdentity();
    pseudoIdentity.setName("transient");
    Translator translator = Util.createPackageTranslator(QTIModule.class, Locale.ENGLISH);
    try {
        QTIEditorPackage qtiPackage = new QTIEditorPackageImpl(pseudoIdentity, fr, null, translator);
        if (qtiPackage.getQTIDocument() != null && qtiPackage.getQTIDocument().getAssessment() != null) {
            Assessment ass = qtiPackage.getQTIDocument().getAssessment();
            // Sections with their Items
            List<Section> sections = ass.getSections();
            for (Section section : sections) {
                List<Item> items = section.getItems();
                for (Item item : items) {
                    String ident = item.getIdent();
                    if (ident != null && ident.startsWith("QTIEDIT:ESSAY")) {
                        qtiEssayMap.put(testEntry.getKey(), Boolean.TRUE);
                        return true;
                    }
                }
            }
        }
    } catch (OLATRuntimeException e) {
        log.warn("QTI without content in repository entry: " + testEntry.getKey(), e);
    }
    qtiEssayMap.put(testEntry.getKey(), Boolean.FALSE);
    return false;
}
Also used : TransientIdentity(org.olat.admin.user.imp.TransientIdentity) Item(org.olat.ims.qti.editor.beecom.objects.Item) Translator(org.olat.core.gui.translator.Translator) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) QTIEditorPackageImpl(org.olat.ims.qti.editor.QTIEditorPackageImpl) Assessment(org.olat.ims.qti.editor.beecom.objects.Assessment) TestFileResource(org.olat.ims.qti.fileresource.TestFileResource) QTIEditorPackage(org.olat.ims.qti.editor.QTIEditorPackage) Section(org.olat.ims.qti.editor.beecom.objects.Section)

Example 2 with QTIEditorPackage

use of org.olat.ims.qti.editor.QTIEditorPackage 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 QTIEditorPackage

use of org.olat.ims.qti.editor.QTIEditorPackage 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)

Example 4 with QTIEditorPackage

use of org.olat.ims.qti.editor.QTIEditorPackage in project openolat by klemens.

the class OLATUpgrade_11_0_0 method checkEssay.

private boolean checkEssay(RepositoryEntry testEntry) {
    if (qtiEssayMap.containsKey(testEntry.getKey())) {
        return qtiEssayMap.get(testEntry.getKey()).booleanValue();
    }
    TestFileResource fr = new TestFileResource();
    fr.overrideResourceableId(testEntry.getOlatResource().getResourceableId());
    TransientIdentity pseudoIdentity = new TransientIdentity();
    pseudoIdentity.setName("transient");
    Translator translator = Util.createPackageTranslator(QTIModule.class, Locale.ENGLISH);
    try {
        QTIEditorPackage qtiPackage = new QTIEditorPackageImpl(pseudoIdentity, fr, null, translator);
        if (qtiPackage.getQTIDocument() != null && qtiPackage.getQTIDocument().getAssessment() != null) {
            Assessment ass = qtiPackage.getQTIDocument().getAssessment();
            // Sections with their Items
            List<Section> sections = ass.getSections();
            for (Section section : sections) {
                List<Item> items = section.getItems();
                for (Item item : items) {
                    String ident = item.getIdent();
                    if (ident != null && ident.startsWith("QTIEDIT:ESSAY")) {
                        qtiEssayMap.put(testEntry.getKey(), Boolean.TRUE);
                        return true;
                    }
                }
            }
        }
    } catch (OLATRuntimeException e) {
        log.warn("QTI without content in repository entry: " + testEntry.getKey(), e);
    }
    qtiEssayMap.put(testEntry.getKey(), Boolean.FALSE);
    return false;
}
Also used : TransientIdentity(org.olat.admin.user.imp.TransientIdentity) Item(org.olat.ims.qti.editor.beecom.objects.Item) Translator(org.olat.core.gui.translator.Translator) OLATRuntimeException(org.olat.core.logging.OLATRuntimeException) QTIEditorPackageImpl(org.olat.ims.qti.editor.QTIEditorPackageImpl) Assessment(org.olat.ims.qti.editor.beecom.objects.Assessment) TestFileResource(org.olat.ims.qti.fileresource.TestFileResource) QTIEditorPackage(org.olat.ims.qti.editor.QTIEditorPackage) Section(org.olat.ims.qti.editor.beecom.objects.Section)

Aggregations

QTIEditorPackage (org.olat.ims.qti.editor.QTIEditorPackage)4 File (java.io.File)2 TransientIdentity (org.olat.admin.user.imp.TransientIdentity)2 Translator (org.olat.core.gui.translator.Translator)2 OLATRuntimeException (org.olat.core.logging.OLATRuntimeException)2 ImsQTI21Resource (org.olat.fileresource.types.ImsQTI21Resource)2 QTIEditorPackageImpl (org.olat.ims.qti.editor.QTIEditorPackageImpl)2 Assessment (org.olat.ims.qti.editor.beecom.objects.Assessment)2 Item (org.olat.ims.qti.editor.beecom.objects.Item)2 Section (org.olat.ims.qti.editor.beecom.objects.Section)2 TestFileResource (org.olat.ims.qti.fileresource.TestFileResource)2 QTI21DeliveryOptions (org.olat.ims.qti21.QTI21DeliveryOptions)2 QItemList (org.olat.modules.qpool.model.QItemList)2 RepositoryEntry (org.olat.repository.RepositoryEntry)2 RepositoryService (org.olat.repository.RepositoryService)2 OLATResource (org.olat.resource.OLATResource)2