Search in sources :

Example 1 with QTI21QPoolServiceProvider

use of org.olat.ims.qti21.pool.QTI21QPoolServiceProvider in project OpenOLAT by OpenOLAT.

the class QuestionListController method doOpenExcelImportQTI21.

private void doOpenExcelImportQTI21(UserRequest ureq) {
    removeAsListenerAndDispose(excelImportWizard);
    Step additionalStep = null;
    if (getSource().askEditable()) {
        additionalStep = new EditableStep(ureq);
    }
    final AssessmentItemsPackage importPackage = new AssessmentItemsPackage();
    final ImportOptions options = new ImportOptions();
    options.setShuffle(true);
    Step start = new QImport_1_InputStep(ureq, importPackage, options, additionalStep);
    StepRunnerCallback finish = new StepRunnerCallback() {

        @Override
        public Step execute(UserRequest uureq, WindowControl wControl, StepsRunContext runContext) {
            QTI21QPoolServiceProvider spi = CoreSpringFactory.getImpl(QTI21QPoolServiceProvider.class);
            List<AssessmentItemAndMetadata> items = importPackage.getItems();
            List<QuestionItem> importItems = new ArrayList<>();
            for (AssessmentItemAndMetadata item : items) {
                QuestionItem importedItem = spi.importExcelItem(getIdentity(), item, getLocale());
                if (importedItem != null) {
                    importItems.add(importedItem);
                }
            }
            for (QuestionItem item : importItems) {
                QuestionItemAuditLogBuilder builder = qpoolService.createAuditLogBuilder(getIdentity(), Action.CREATE_QUESTION_ITEM_BY_IMPORT);
                builder.withAfter(item);
                qpoolService.persist(builder.create());
            }
            boolean editable = true;
            if (getSource().askEditable()) {
                Object editableCtx = runContext.get("editable");
                editable = (editableCtx instanceof Boolean) ? ((Boolean) editableCtx).booleanValue() : false;
            }
            qpoolService.index(importItems);
            int postImported = getSource().postImport(importItems, editable);
            if (postImported > 0) {
                getItemsTable().reset();
            }
            return StepsMainRunController.DONE_MODIFIED;
        }
    };
    excelImportWizard = new StepsMainRunController(ureq, getWindowControl(), start, finish, null, translate("import.excellike.21"), "o_sel_qpool_excel_import_wizard");
    listenTo(excelImportWizard);
    getWindowControl().pushAsModalDialog(excelImportWizard.getInitialComponent());
}
Also used : ArrayList(java.util.ArrayList) QImport_1_InputStep(org.olat.ims.qti21.questionimport.QImport_1_InputStep) Step(org.olat.core.gui.control.generic.wizard.Step) Export_1_TypeStep(org.olat.modules.qpool.ui.wizard.Export_1_TypeStep) ImportAuthor_1_ChooseMemberStep(org.olat.modules.qpool.ui.wizard.ImportAuthor_1_ChooseMemberStep) WindowControl(org.olat.core.gui.control.WindowControl) StepsRunContext(org.olat.core.gui.control.generic.wizard.StepsRunContext) QImport_1_InputStep(org.olat.ims.qti21.questionimport.QImport_1_InputStep) QuestionItemAuditLogBuilder(org.olat.modules.qpool.QuestionItemAuditLogBuilder) QTI21QPoolServiceProvider(org.olat.ims.qti21.pool.QTI21QPoolServiceProvider) AssessmentItemAndMetadata(org.olat.ims.qti21.questionimport.AssessmentItemAndMetadata) AssessmentItemsPackage(org.olat.ims.qti21.questionimport.AssessmentItemsPackage) StepsMainRunController(org.olat.core.gui.control.generic.wizard.StepsMainRunController) QuestionItem(org.olat.modules.qpool.QuestionItem) ImportOptions(org.olat.ims.qti21.questionimport.ImportOptions) StepRunnerCallback(org.olat.core.gui.control.generic.wizard.StepRunnerCallback) UserRequest(org.olat.core.gui.UserRequest)

Example 2 with QTI21QPoolServiceProvider

use of org.olat.ims.qti21.pool.QTI21QPoolServiceProvider in project openolat by klemens.

the class QuestionListController method doOpenExcelImportQTI21.

private void doOpenExcelImportQTI21(UserRequest ureq) {
    removeAsListenerAndDispose(excelImportWizard);
    Step additionalStep = null;
    if (getSource().askEditable()) {
        additionalStep = new EditableStep(ureq);
    }
    final AssessmentItemsPackage importPackage = new AssessmentItemsPackage();
    final ImportOptions options = new ImportOptions();
    options.setShuffle(true);
    Step start = new QImport_1_InputStep(ureq, importPackage, options, additionalStep);
    StepRunnerCallback finish = new StepRunnerCallback() {

        @Override
        public Step execute(UserRequest uureq, WindowControl wControl, StepsRunContext runContext) {
            QTI21QPoolServiceProvider spi = CoreSpringFactory.getImpl(QTI21QPoolServiceProvider.class);
            List<AssessmentItemAndMetadata> items = importPackage.getItems();
            List<QuestionItem> importItems = new ArrayList<>();
            for (AssessmentItemAndMetadata item : items) {
                QuestionItem importedItem = spi.importExcelItem(getIdentity(), item, getLocale());
                if (importedItem != null) {
                    importItems.add(importedItem);
                }
            }
            for (QuestionItem item : importItems) {
                QuestionItemAuditLogBuilder builder = qpoolService.createAuditLogBuilder(getIdentity(), Action.CREATE_QUESTION_ITEM_BY_IMPORT);
                builder.withAfter(item);
                qpoolService.persist(builder.create());
            }
            boolean editable = true;
            if (getSource().askEditable()) {
                Object editableCtx = runContext.get("editable");
                editable = (editableCtx instanceof Boolean) ? ((Boolean) editableCtx).booleanValue() : false;
            }
            qpoolService.index(importItems);
            int postImported = getSource().postImport(importItems, editable);
            if (postImported > 0) {
                getItemsTable().reset();
            }
            return StepsMainRunController.DONE_MODIFIED;
        }
    };
    excelImportWizard = new StepsMainRunController(ureq, getWindowControl(), start, finish, null, translate("import.excellike.21"), "o_sel_qpool_excel_import_wizard");
    listenTo(excelImportWizard);
    getWindowControl().pushAsModalDialog(excelImportWizard.getInitialComponent());
}
Also used : ArrayList(java.util.ArrayList) QImport_1_InputStep(org.olat.ims.qti21.questionimport.QImport_1_InputStep) Step(org.olat.core.gui.control.generic.wizard.Step) Export_1_TypeStep(org.olat.modules.qpool.ui.wizard.Export_1_TypeStep) ImportAuthor_1_ChooseMemberStep(org.olat.modules.qpool.ui.wizard.ImportAuthor_1_ChooseMemberStep) WindowControl(org.olat.core.gui.control.WindowControl) StepsRunContext(org.olat.core.gui.control.generic.wizard.StepsRunContext) QImport_1_InputStep(org.olat.ims.qti21.questionimport.QImport_1_InputStep) QuestionItemAuditLogBuilder(org.olat.modules.qpool.QuestionItemAuditLogBuilder) QTI21QPoolServiceProvider(org.olat.ims.qti21.pool.QTI21QPoolServiceProvider) AssessmentItemAndMetadata(org.olat.ims.qti21.questionimport.AssessmentItemAndMetadata) AssessmentItemsPackage(org.olat.ims.qti21.questionimport.AssessmentItemsPackage) StepsMainRunController(org.olat.core.gui.control.generic.wizard.StepsMainRunController) QuestionItem(org.olat.modules.qpool.QuestionItem) ImportOptions(org.olat.ims.qti21.questionimport.ImportOptions) StepRunnerCallback(org.olat.core.gui.control.generic.wizard.StepRunnerCallback) UserRequest(org.olat.core.gui.UserRequest)

Example 3 with QTI21QPoolServiceProvider

use of org.olat.ims.qti21.pool.QTI21QPoolServiceProvider in project openolat by klemens.

the class QuestionListController method doImportResource.

private void doImportResource(UserRequest ureq, RepositoryEntry repositoryEntry) {
    List<QuestionItem> importItems = null;
    if (ImsQTI21Resource.TYPE_NAME.equals(repositoryEntry.getOlatResource().getResourceableTypeName())) {
        QTI21QPoolServiceProvider spi = CoreSpringFactory.getImpl(QTI21QPoolServiceProvider.class);
        importItems = spi.importRepositoryEntry(getIdentity(), repositoryEntry, getLocale());
    } else {
        QTIQPoolServiceProvider spi = (QTIQPoolServiceProvider) CoreSpringFactory.getBean("qtiPoolServiceProvider");
        importItems = spi.importRepositoryEntry(getIdentity(), repositoryEntry, getLocale());
    }
    for (QuestionItem item : importItems) {
        QuestionItemAuditLogBuilder builder = qpoolService.createAuditLogBuilder(getIdentity(), Action.CREATE_QUESTION_ITEM_BY_IMPORT);
        builder.withAfter(item);
        qpoolService.persist(builder.create());
    }
    if (getSource().askEditable()) {
        removeAsListenerAndDispose(shareItemsToSourceCtrl);
        shareItemsToSourceCtrl = new ShareItemSourceOptionController(ureq, getWindowControl(), importItems, getSource());
        listenTo(shareItemsToSourceCtrl);
        removeAsListenerAndDispose(cmcShareItemToSource);
        cmcShareItemToSource = new CloseableModalController(getWindowControl(), translate("close"), shareItemsToSourceCtrl.getInitialComponent(), true, translate("import.item"));
        cmcShareItemToSource.activate();
        listenTo(cmcShareItemToSource);
    } else {
        qpoolService.index(importItems);
        int postImported = getSource().postImport(importItems, true);
        if (postImported > 0) {
            getItemsTable().reset();
        }
        if (importItems.isEmpty()) {
            showWarning("import.failed");
        } else {
            showInfo("import.success", Integer.toString(importItems.size()));
            getItemsTable().reset();
        }
    }
}
Also used : QuestionItemAuditLogBuilder(org.olat.modules.qpool.QuestionItemAuditLogBuilder) QTI21QPoolServiceProvider(org.olat.ims.qti21.pool.QTI21QPoolServiceProvider) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) QTIQPoolServiceProvider(org.olat.ims.qti.qpool.QTIQPoolServiceProvider) QuestionItem(org.olat.modules.qpool.QuestionItem)

Example 4 with QTI21QPoolServiceProvider

use of org.olat.ims.qti21.pool.QTI21QPoolServiceProvider in project OpenOLAT by OpenOLAT.

the class QuestionListController method doImportResource.

private void doImportResource(UserRequest ureq, RepositoryEntry repositoryEntry) {
    List<QuestionItem> importItems = null;
    if (ImsQTI21Resource.TYPE_NAME.equals(repositoryEntry.getOlatResource().getResourceableTypeName())) {
        QTI21QPoolServiceProvider spi = CoreSpringFactory.getImpl(QTI21QPoolServiceProvider.class);
        importItems = spi.importRepositoryEntry(getIdentity(), repositoryEntry, getLocale());
    } else {
        QTIQPoolServiceProvider spi = (QTIQPoolServiceProvider) CoreSpringFactory.getBean("qtiPoolServiceProvider");
        importItems = spi.importRepositoryEntry(getIdentity(), repositoryEntry, getLocale());
    }
    for (QuestionItem item : importItems) {
        QuestionItemAuditLogBuilder builder = qpoolService.createAuditLogBuilder(getIdentity(), Action.CREATE_QUESTION_ITEM_BY_IMPORT);
        builder.withAfter(item);
        qpoolService.persist(builder.create());
    }
    if (getSource().askEditable()) {
        removeAsListenerAndDispose(shareItemsToSourceCtrl);
        shareItemsToSourceCtrl = new ShareItemSourceOptionController(ureq, getWindowControl(), importItems, getSource());
        listenTo(shareItemsToSourceCtrl);
        removeAsListenerAndDispose(cmcShareItemToSource);
        cmcShareItemToSource = new CloseableModalController(getWindowControl(), translate("close"), shareItemsToSourceCtrl.getInitialComponent(), true, translate("import.item"));
        cmcShareItemToSource.activate();
        listenTo(cmcShareItemToSource);
    } else {
        qpoolService.index(importItems);
        int postImported = getSource().postImport(importItems, true);
        if (postImported > 0) {
            getItemsTable().reset();
        }
        if (importItems.isEmpty()) {
            showWarning("import.failed");
        } else {
            showInfo("import.success", Integer.toString(importItems.size()));
            getItemsTable().reset();
        }
    }
}
Also used : QuestionItemAuditLogBuilder(org.olat.modules.qpool.QuestionItemAuditLogBuilder) QTI21QPoolServiceProvider(org.olat.ims.qti21.pool.QTI21QPoolServiceProvider) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) QTIQPoolServiceProvider(org.olat.ims.qti.qpool.QTIQPoolServiceProvider) QuestionItem(org.olat.modules.qpool.QuestionItem)

Aggregations

QTI21QPoolServiceProvider (org.olat.ims.qti21.pool.QTI21QPoolServiceProvider)4 QuestionItem (org.olat.modules.qpool.QuestionItem)4 QuestionItemAuditLogBuilder (org.olat.modules.qpool.QuestionItemAuditLogBuilder)4 ArrayList (java.util.ArrayList)2 UserRequest (org.olat.core.gui.UserRequest)2 WindowControl (org.olat.core.gui.control.WindowControl)2 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)2 Step (org.olat.core.gui.control.generic.wizard.Step)2 StepRunnerCallback (org.olat.core.gui.control.generic.wizard.StepRunnerCallback)2 StepsMainRunController (org.olat.core.gui.control.generic.wizard.StepsMainRunController)2 StepsRunContext (org.olat.core.gui.control.generic.wizard.StepsRunContext)2 QTIQPoolServiceProvider (org.olat.ims.qti.qpool.QTIQPoolServiceProvider)2 AssessmentItemAndMetadata (org.olat.ims.qti21.questionimport.AssessmentItemAndMetadata)2 AssessmentItemsPackage (org.olat.ims.qti21.questionimport.AssessmentItemsPackage)2 ImportOptions (org.olat.ims.qti21.questionimport.ImportOptions)2 QImport_1_InputStep (org.olat.ims.qti21.questionimport.QImport_1_InputStep)2 Export_1_TypeStep (org.olat.modules.qpool.ui.wizard.Export_1_TypeStep)2 ImportAuthor_1_ChooseMemberStep (org.olat.modules.qpool.ui.wizard.ImportAuthor_1_ChooseMemberStep)2