Search in sources :

Example 96 with QuestionItemImpl

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

the class QItemQueriesDAO method getItem.

public QuestionItemView getItem(Long itemKey, Identity identity, Long restrictToPoolKey, Long restrictToGroupKey) {
    if (itemKey == null || identity == null)
        return null;
    StringBuilder sb = new StringBuilder();
    sb.append("select item, ").append(" (select count(sgmi.key) from ").append(SecurityGroupMembershipImpl.class.getName()).append(" as sgmi").append("   where sgmi.identity.key=:identityKey and sgmi.securityGroup=ownerGroup").append(" ) as owners,").append(" (select count(competence.key) from ctaxonomycompetence competence").append("   where taxonomyLevel.materializedPathKeys like concat(competence.taxonomyLevel.materializedPathKeys, '%')").append("     and competence.identity.key=:identityKey").append("     and competence.type='").append(TaxonomyCompetenceTypes.teach).append("'").append(" ) as teacher,").append(" (select count(competence.key) from ctaxonomycompetence competence").append("   where taxonomyLevel.materializedPathKeys like concat(competence.taxonomyLevel.materializedPathKeys, '%')").append("     and competence.identity.key=:identityKey").append("     and competence.type='").append(TaxonomyCompetenceTypes.manage).append("'").append(" ) as manager,").append(" (select count(pool2item.key) from qpool2item pool2item").append("    where pool2item.item.key=item.key").append("      and pool2item.editable is true");
    if (restrictToPoolKey != null) {
        sb.append(" and pool2item.pool.key=:restrictToPoolKey");
    }
    sb.append(" ) as pools,").append(" (select count(shareditem.key) from qshareitem shareditem").append("    where shareditem.item.key=item.key").append("      and shareditem.editable is true");
    if (restrictToGroupKey != null) {
        sb.append(" and shareditem.resource=:restrictToGroupKey");
    }
    sb.append(" ) as groups,").append(" (select count(mark.key) from ").append(MarkImpl.class.getName()).append(" as mark ").append("   where mark.creator.key=:identityKey and mark.resId=item.key and mark.resName='QuestionItem'").append(" ) as marks,").append(" (select count(rating.key) from userrating as rating").append("   where rating.resId=item.key and rating.resName='QuestionItem'").append("     and rating.creator.key=:identityKey").append(" ) as numberOfRatingsIdentity,").append(" (select avg(rating.rating) from userrating as rating").append("   where rating.resId=item.key and rating.resName='QuestionItem'").append(" ) as rating,").append(" (select count(rating.key) from userrating as rating").append("   where rating.resId=item.key and rating.resName='QuestionItem'").append(" ) as numberOfRatingsTotal").append(" from questionitem item").append(" left join fetch item.ownerGroup ownerGroup").append(" left join fetch item.taxonomyLevel taxonomyLevel").append(" left join fetch item.type itemType").append(" left join fetch item.educationalContext educationalContext").append(" where item.key=:itemKey");
    TypedQuery<Object[]> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("itemKey", itemKey).setParameter("identityKey", identity.getKey());
    if (restrictToPoolKey != null) {
        query.setParameter("restrictToPoolKey", restrictToPoolKey);
    }
    if (restrictToGroupKey != null) {
        query.setParameter("restrictToGroupKey", restrictToPoolKey);
    }
    ItemWrapper itemWrapper = null;
    List<Object[]> results = query.getResultList();
    if (!results.isEmpty()) {
        Object[] result = results.get(0);
        itemWrapper = ItemWrapper.builder((QuestionItemImpl) result[0]).setAuthor((Number) result[1]).setTeacher((Number) result[2]).setManager((Number) result[3]).setEditableInPool((Number) result[4]).setEditableInShare((Number) result[5]).setMarked((Number) result[6]).setRater((Number) result[7]).setRating((Double) result[8]).setNumberOfRatings((Number) result[9]).create();
    }
    return itemWrapper;
}
Also used : ItemWrapper(org.olat.modules.qpool.model.ItemWrapper) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) SecurityGroupMembershipImpl(org.olat.basesecurity.SecurityGroupMembershipImpl)

Example 97 with QuestionItemImpl

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

the class QuestionItemDAO method loadForUpdate.

public QuestionItemImpl loadForUpdate(QuestionItemShort item) {
    StringBuilder sb = new StringBuilder();
    sb.append("select item from questionitem item where item.key=:key");
    QuestionItemImpl lockedItem = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), QuestionItemImpl.class).setParameter("key", item.getKey()).setLockMode(LockModeType.PESSIMISTIC_WRITE).getSingleResult();
    return lockedItem;
}
Also used : QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl)

Example 98 with QuestionItemImpl

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

the class QuestionItemDAO method copy.

/**
 * The method make a copy of the original question. The copy is not persisted.
 *
 * @param original
 * @return A copy of the question.
 */
public QuestionItemImpl copy(QuestionItemImpl original) {
    String title = "(Copy) " + original.getTitle();
    QuestionItemImpl copy = create(title, original.getFormat(), null, original.getRootFilename());
    // general
    copy.setMasterIdentifier(original.getIdentifier());
    copy.setDescription(original.getDescription());
    copy.setKeywords(original.getKeywords());
    copy.setCoverage(original.getCoverage());
    copy.setAdditionalInformations(original.getAdditionalInformations());
    copy.setLanguage(original.getLanguage());
    // classification
    copy.setTaxonomyLevel(original.getTaxonomyLevel());
    copy.setTopic(original.getTopic());
    // educational
    copy.setEducationalContext(original.getEducationalContext());
    copy.setEducationalLearningTime(original.getEducationalLearningTime());
    // item
    copy.setType(original.getType());
    copy.setDifficulty(original.getDifficulty());
    copy.setStdevDifficulty(original.getStdevDifficulty());
    copy.setDifferentiation(original.getDifferentiation());
    copy.setNumOfAnswerAlternatives(original.getNumOfAnswerAlternatives());
    copy.setUsage(0);
    copy.setAssessmentType(original.getAssessmentType());
    // lifecycle
    copy.setItemVersion(original.getItemVersion());
    copy.setStatus(QuestionStatus.draft.name());
    // technical
    copy.setEditor(original.getEditor());
    copy.setEditorVersion(original.getEditorVersion());
    return copy;
}
Also used : QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl)

Example 99 with QuestionItemImpl

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

the class OLATUpgrade_12_3_0 method migrateQpoolTitles.

private void migrateQpoolTitles() {
    int counter = 0;
    List<QuestionItemImpl> items;
    do {
        items = getQuestionItems(counter, BATCH_SIZE);
        for (QuestionItemImpl item : items) {
            try {
                migrateQPoolTitle(item);
                log.info("QPool item successfully migrated: " + item);
            } catch (Exception e) {
                log.error("Not able to migrate question title: " + item, e);
            }
        }
        counter += items.size();
        dbInstance.commitAndCloseSession();
        log.info(counter + " QPool items processed.");
    } while (items.size() == BATCH_SIZE);
}
Also used : QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) ConversionException(com.thoughtworks.xstream.converters.ConversionException)

Example 100 with QuestionItemImpl

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

the class OLATUpgrade_12_4_0 method migrateQpoolItemLicenses.

private void migrateQpoolItemLicenses() {
    int counter = 0;
    List<QuestionItemImpl> items;
    do {
        items = getQuestionItems(counter, BATCH_SIZE);
        for (QuestionItemImpl item : items) {
            try {
                migrateQpoolLicense(item);
                log.info("QPool item license successfully migrated: " + item);
            } catch (Exception e) {
                log.error("Not able to migrate question item license: " + item, e);
            }
        }
        counter += items.size();
        dbInstance.commitAndCloseSession();
        log.info(counter + " QPool items processed.");
    } while (items.size() == BATCH_SIZE);
}
Also used : QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl)

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