Search in sources :

Example 51 with QuestionItemImpl

use of org.olat.modules.qpool.model.QuestionItemImpl in project openolat by klemens.

the class QuestionPoolServiceImpl method updateItem.

@Override
public QuestionItem updateItem(QuestionItem item) {
    QuestionItem previousItem = loadItemById(item.getKey());
    QuestionStatus previousStatus = previousItem != null ? previousItem.getQuestionStatus() : null;
    QuestionStatus newStatus = item.getQuestionStatus();
    if (statusChanged(previousStatus, newStatus)) {
        if (item instanceof QuestionItemImpl) {
            QuestionItemImpl itemImpl = (QuestionItemImpl) item;
            itemImpl.setQuestionStatusLastModified(new Date());
        }
        if (reviewService.isReviewStarting(previousStatus, newStatus)) {
            reviewService.startReview(item);
        }
    }
    QuestionItem mergedItem = questionItemDao.merge(item);
    dbInstance.commit();
    lifeIndexer.indexDocument(QItemDocument.TYPE, mergedItem.getKey());
    return mergedItem;
}
Also used : QuestionStatus(org.olat.modules.qpool.QuestionStatus) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) QuestionItem(org.olat.modules.qpool.QuestionItem) Date(java.util.Date)

Example 52 with QuestionItemImpl

use of org.olat.modules.qpool.model.QuestionItemImpl in project openolat by klemens.

the class QuestionPoolServiceImpl method getRootLeaf.

@Override
public VFSLeaf getRootLeaf(QuestionItemShort item) {
    QuestionItemImpl reloadedItem = questionItemDao.loadById(item.getKey());
    if (reloadedItem == null) {
        return null;
    }
    VFSContainer root = qpoolModule.getRootContainer();
    VFSItem dir = root.resolve(reloadedItem.getDirectory());
    if (dir instanceof VFSContainer) {
        VFSContainer itemContainer = (VFSContainer) dir;
        VFSItem rootLeaf = itemContainer.resolve(reloadedItem.getRootFilename());
        if (rootLeaf instanceof VFSLeaf) {
            return (VFSLeaf) rootLeaf;
        }
    }
    return null;
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem)

Example 53 with QuestionItemImpl

use of org.olat.modules.qpool.model.QuestionItemImpl in project openolat by klemens.

the class QuestionPoolServiceImpl method deleteItems.

@Override
public void deleteItems(List<? extends QuestionItemShort> items) {
    if (items == null || items.isEmpty()) {
        // nothing to do
        return;
    }
    List<SecurityGroup> secGroups = new ArrayList<>();
    for (QuestionItemShort item : items) {
        markManager.deleteMarks(item);
        commentAndRatingService.deleteAllIgnoringSubPath(item);
        licenseService.delete(item);
        QuestionItem loadedItem = loadItemById(item.getKey());
        if (loadedItem instanceof QuestionItemImpl) {
            QuestionItemImpl itemImpl = (QuestionItemImpl) loadedItem;
            qpoolFileStorage.deleteDir(itemImpl.getDirectory());
            secGroups.add(itemImpl.getOwnerGroup());
        }
        dbInstance.intermediateCommit();
    }
    poolDao.removeFromPools(items);
    questionItemDao.removeFromShares(items);
    collectionDao.deleteItemFromCollections(items);
    questionItemDao.delete(items);
    // Delete SecurityGroup after the item to avoid foreign key constraint violation.
    for (SecurityGroup secGroup : secGroups) {
        securityManager.deleteSecurityGroup(secGroup);
    }
    for (QuestionItemShort item : items) {
        lifeIndexer.deleteDocument(QItemDocument.TYPE, item.getKey());
    }
    // allow reload of data
    dbInstance.getCurrentEntityManager().flush();
}
Also used : QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) ArrayList(java.util.ArrayList) SecurityGroup(org.olat.basesecurity.SecurityGroup) QuestionItem(org.olat.modules.qpool.QuestionItem)

Example 54 with QuestionItemImpl

use of org.olat.modules.qpool.model.QuestionItemImpl in project openolat by klemens.

the class ReviewStartController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    setFormDescription("process.start.review.description", new String[] { item.getTitle() });
    qpoolTaxonomyTreeBuilder.loadTaxonomyLevelsSelection(getIdentity(), false, ignoreCompetences);
    taxonomyLevelEl = uifactory.addDropdownSingleselect("process.start.review.taxonomy.level", formLayout, qpoolTaxonomyTreeBuilder.getSelectableKeys(), qpoolTaxonomyTreeBuilder.getSelectableValues(), null);
    taxonomyLevelEl.setMandatory(true);
    if (item instanceof QuestionItemImpl) {
        QuestionItemImpl itemImpl = (QuestionItemImpl) item;
        TaxonomyLevel selectedTaxonomyLevel = itemImpl.getTaxonomyLevel();
        if (selectedTaxonomyLevel != null) {
            String selectedTaxonomyLevelKey = String.valueOf(selectedTaxonomyLevel.getKey());
            for (String taxonomyKey : qpoolTaxonomyTreeBuilder.getSelectableKeys()) {
                if (taxonomyKey.equals(selectedTaxonomyLevelKey)) {
                    taxonomyLevelEl.select(taxonomyKey, true);
                }
            }
        }
    }
    FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
    formLayout.add("buttons", buttonLayout);
    uifactory.addFormSubmitButton("process.start.review.button", buttonLayout);
    uifactory.addFormCancelButton("cancel", buttonLayout, ureq, getWindowControl());
}
Also used : QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)

Example 55 with QuestionItemImpl

use of org.olat.modules.qpool.model.QuestionItemImpl in project openolat by klemens.

the class QTIQPoolServiceProvider method createItem.

public QuestionItem createItem(Identity owner, QTI12ItemFactory.Type type, String title, Locale defaultLocale) {
    Translator trans = Util.createPackageTranslator(QTIEditorMainController.class, defaultLocale);
    Item item;
    switch(type) {
        case sc:
            item = QTIEditHelper.createSCItem(trans);
            break;
        case mc:
            item = QTIEditHelper.createMCItem(trans);
            break;
        case kprim:
            item = QTIEditHelper.createKPRIMItem(trans);
            break;
        case fib:
            item = QTIEditHelper.createFIBItem(trans);
            break;
        case essay:
            item = QTIEditHelper.createEssayItem(trans);
            break;
        default:
            return null;
    }
    item.setLabel(title);
    item.setTitle(title);
    QTIImportProcessor processor = new QTIImportProcessor(owner, defaultLocale);
    Document doc = QTIEditHelper.itemToXml(item);
    Element itemEl = (Element) doc.selectSingleNode("questestinterop/item");
    QuestionItemImpl qitem = processor.processItem(itemEl, "", null, "OpenOLAT", Settings.getVersion(), null, null);
    // save to file System
    VFSContainer baseDir = qpoolFileStorage.getContainer(qitem.getDirectory());
    VFSLeaf leaf = baseDir.createChildLeaf(qitem.getRootFilename());
    QTIEditHelper.serialiazeDoc(doc, leaf);
    return qitem;
}
Also used : Item(org.olat.ims.qti.editor.beecom.objects.Item) VFSItem(org.olat.core.util.vfs.VFSItem) QuestionItem(org.olat.modules.qpool.QuestionItem) VFSLeaf(org.olat.core.util.vfs.VFSLeaf) Translator(org.olat.core.gui.translator.Translator) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) Element(org.dom4j.Element) VFSContainer(org.olat.core.util.vfs.VFSContainer) Document(org.dom4j.Document)

Aggregations

QuestionItemImpl (org.olat.modules.qpool.model.QuestionItemImpl)108 QuestionItem (org.olat.modules.qpool.QuestionItem)32 Test (org.junit.Test)20 QuestionItemAuditLogBuilder (org.olat.modules.qpool.QuestionItemAuditLogBuilder)16 TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)16 Identity (org.olat.core.id.Identity)14 VFSContainer (org.olat.core.util.vfs.VFSContainer)14 QuestionItemView (org.olat.modules.qpool.QuestionItemView)14 File (java.io.File)12 VFSItem (org.olat.core.util.vfs.VFSItem)12 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)12 QItemEdited (org.olat.modules.qpool.ui.events.QItemEdited)12 ArrayList (java.util.ArrayList)10 QItemType (org.olat.modules.qpool.model.QItemType)10 SearchQuestionItemParams (org.olat.modules.qpool.model.SearchQuestionItemParams)10 ManifestBuilder (org.olat.ims.qti21.model.xml.ManifestBuilder)8 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)8 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)8 QuestionItemShort (org.olat.modules.qpool.QuestionItemShort)7 Taxonomy (org.olat.modules.taxonomy.Taxonomy)7