Search in sources :

Example 11 with QuestionItemImpl

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

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 12 with QuestionItemImpl

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

the class QItemQueriesDAO method getItemsOfPool.

public List<QuestionItemView> getItemsOfPool(SearchQuestionItemParams params, Collection<Long> inKeys, int firstResult, int maxResults, SortKey... orderBy) {
    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("pool2item.editable,").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 qpool2item pool2item").append(" inner join pool2item.item item").append(" inner join fetch item.ownerGroup ownerGroup").append(" left join fetch item.type itemType").append(" left join fetch item.taxonomyLevel taxonomyLevel").append(" left join fetch item.educationalContext educationalContext").append(" where pool2item.pool.key=:poolKey");
    if (inKeys != null && inKeys.size() > 0) {
        sb.append(" and item.key in (:inKeys)");
    }
    if (StringHelper.containsNonWhitespace(params.getFormat())) {
        sb.append(" and item.format=:format");
    }
    appendOrderBy(sb, "item", "taxonomyLevel", orderBy);
    TypedQuery<Object[]> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("poolKey", params.getPoolKey()).setParameter("identityKey", params.getIdentity().getKey());
    if (inKeys != null && inKeys.size() > 0) {
        query.setParameter("inKeys", inKeys);
    }
    appendParameters(params, query);
    if (firstResult >= 0) {
        query.setFirstResult(firstResult);
    }
    if (maxResults > 0) {
        query.setMaxResults(maxResults);
    }
    List<Object[]> results = query.getResultList();
    List<QuestionItemView> views = new ArrayList<>();
    for (Object[] result : results) {
        ItemWrapper itemWrapper = ItemWrapper.builder((QuestionItemImpl) result[0]).setAuthor((Number) result[1]).setTeacher((Number) result[2]).setManager((Number) result[3]).setEditableInPool((Boolean) result[4]).setMarked((Number) result[5]).setRater((Number) result[6]).setRating((Double) result[7]).setNumberOfRatings((Number) result[8]).create();
        views.add(itemWrapper);
    }
    return views;
}
Also used : QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) ArrayList(java.util.ArrayList) MarkImpl(org.olat.core.commons.services.mark.impl.MarkImpl) ItemWrapper(org.olat.modules.qpool.model.ItemWrapper) SecurityGroupMembershipImpl(org.olat.basesecurity.SecurityGroupMembershipImpl) QuestionItemView(org.olat.modules.qpool.QuestionItemView)

Example 13 with QuestionItemImpl

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

the class QuestionItemDocumentFactory method createDocument.

public Document createDocument(SearchResourceContext searchResourceContext, QuestionItemFull item) {
    OlatDocument oDocument = new OlatDocument();
    oDocument.setId(item.getKey());
    oDocument.setCreatedDate(item.getCreationDate());
    oDocument.setLastChange(item.getLastModified());
    oDocument.setTitle(item.getTitle());
    oDocument.setDescription(item.getDescription());
    oDocument.setResourceUrl(getResourceUrl(item.getKey()));
    oDocument.setDocumentType(QItemDocument.TYPE);
    oDocument.setCssIcon("o_qitem_icon");
    oDocument.setParentContextType(searchResourceContext.getParentContextType());
    oDocument.setParentContextName(searchResourceContext.getParentContextName());
    // author
    StringBuilder authorSb = new StringBuilder();
    List<Identity> owners = qpoolService.getAuthors(item);
    for (Identity owner : owners) {
        User user = owner.getUser();
        authorSb.append(user.getProperty(UserConstants.FIRSTNAME, null)).append(" ").append(user.getProperty(UserConstants.LASTNAME, null)).append(" ");
    }
    oDocument.setAuthor(authorSb.toString());
    // add specific fields
    Document document = oDocument.getLuceneDocument();
    // content
    QPoolSPI provider = qpoolModule.getQuestionPoolProvider(item.getFormat());
    if (provider != null) {
        String content = provider.extractTextContent(item);
        if (content != null) {
            addStringField(document, AbstractOlatDocument.CONTENT_FIELD_NAME, content, 0.8f);
        }
    }
    if (item.getDescription() != null) {
        addStringField(document, AbstractOlatDocument.CONTENT_FIELD_NAME, item.getDescription(), 1.0f);
    }
    // general fields
    addStringField(document, QItemDocument.IDENTIFIER_FIELD, item.getIdentifier(), 1.0f);
    addStringField(document, QItemDocument.MASTER_IDENTIFIER_FIELD, item.getMasterIdentifier(), 1.0f);
    addTextField(document, QItemDocument.KEYWORDS_FIELD, item.getKeywords(), 2.0f);
    addTextField(document, QItemDocument.COVERAGE_FIELD, item.getCoverage(), 2.0f);
    addTextField(document, QItemDocument.ADD_INFOS_FIELD, item.getAdditionalInformations(), 2.0f);
    addStringField(document, QItemDocument.LANGUAGE_FIELD, item.getLanguage(), 1.0f);
    addTextField(document, QItemDocument.TOPIC_FIELD, item.getTopic(), 2.0f);
    // educational
    if (qpoolModule.isEducationalContextEnabled()) {
        if (item.getEducationalContext() != null) {
            String context = item.getEducationalContext().getLevel();
            addStringField(document, QItemDocument.EDU_CONTEXT_FIELD, context, 1.0f);
        }
    }
    // question
    if (item.getType() != null) {
        String itemType = item.getType().getType();
        addStringField(document, QItemDocument.ITEM_TYPE_FIELD, itemType, 1.0f);
    }
    addStringField(document, QItemDocument.ASSESSMENT_TYPE_FIELD, item.getAssessmentType(), 1.0f);
    // lifecycle
    addStringField(document, QItemDocument.ITEM_VERSION_FIELD, item.getItemVersion(), 1.0f);
    if (item.getQuestionStatus() != null) {
        addStringField(document, QItemDocument.ITEM_STATUS_FIELD, item.getQuestionStatus().name(), 1.0f);
    }
    // rights
    ResourceLicense license = licenseService.loadLicense(item);
    if (license != null && license.getLicenseType() != null) {
        String licenseKey = String.valueOf(license.getLicenseType().getKey());
        addTextField(document, QItemDocument.LICENSE_TYPE_FIELD_NAME, licenseKey, 2.0f);
    }
    // technical
    addTextField(document, QItemDocument.EDITOR_FIELD, item.getEditor(), 2.0f);
    addStringField(document, QItemDocument.EDITOR_VERSION_FIELD, item.getEditorVersion(), 1.0f);
    addStringField(document, QItemDocument.FORMAT_FIELD, item.getFormat(), 1.0f);
    // save owners key
    for (Identity owner : owners) {
        document.add(new StringField(QItemDocument.OWNER_FIELD, owner.getKey().toString(), Field.Store.NO));
    }
    // link resources
    List<OLATResource> resources = questionItemDao.getSharedResources(item);
    for (OLATResource resource : resources) {
        document.add(new StringField(QItemDocument.SHARE_FIELD, resource.getKey().toString(), Field.Store.NO));
    }
    // need pools
    List<Pool> pools = poolDao.getPools(item);
    for (Pool pool : pools) {
        document.add(new StringField(QItemDocument.POOL_FIELD, pool.getKey().toString(), Field.Store.NO));
    }
    // need path
    if (qpoolModule.isTaxonomyEnabled()) {
        String path = item.getTaxonomicPath();
        if (StringHelper.containsNonWhitespace(path)) {
            for (StringTokenizer tokenizer = new StringTokenizer(path, "/"); tokenizer.hasMoreTokens(); ) {
                String nextToken = tokenizer.nextToken();
                document.add(new TextField(QItemDocument.TAXONOMIC_PATH_FIELD, nextToken, Field.Store.NO));
            }
            if (item instanceof QuestionItemImpl) {
                Long key = ((QuestionItemImpl) item).getTaxonomyLevel().getKey();
                TextField field = new TextField(QItemDocument.TAXONOMIC_FIELD, key.toString(), Field.Store.YES);
                field.setBoost(3.0f);
                document.add(field);
            }
        }
    }
    return document;
}
Also used : User(org.olat.core.id.User) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) OLATResource(org.olat.resource.OLATResource) Document(org.apache.lucene.document.Document) AbstractOlatDocument(org.olat.search.model.AbstractOlatDocument) OlatDocument(org.olat.search.model.OlatDocument) QItemDocument(org.olat.modules.qpool.model.QItemDocument) ResourceLicense(org.olat.core.commons.services.license.ResourceLicense) AbstractOlatDocument(org.olat.search.model.AbstractOlatDocument) OlatDocument(org.olat.search.model.OlatDocument) StringTokenizer(java.util.StringTokenizer) QPoolSPI(org.olat.modules.qpool.QPoolSPI) StringField(org.apache.lucene.document.StringField) TextField(org.apache.lucene.document.TextField) Pool(org.olat.modules.qpool.Pool) Identity(org.olat.core.id.Identity)

Example 14 with QuestionItemImpl

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

the class QuestionPoolServiceImpl method copyItems.

@Override
public List<QuestionItem> copyItems(Identity owner, List<QuestionItemShort> itemsToCopy) {
    List<QuestionItem> copies = new ArrayList<>();
    for (QuestionItemShort itemToCopy : itemsToCopy) {
        QuestionItemImpl original = questionItemDao.loadById(itemToCopy.getKey());
        QuestionItemImpl copy = questionItemDao.copy(original);
        questionItemDao.persist(owner, copy);
        QPoolSPI provider = qpoolModule.getQuestionPoolProvider(copy.getFormat());
        if (provider != null) {
            provider.copyItem(original, copy);
        }
        licenseService.copy(original, copy);
        copies.add(copy);
    }
    dbInstance.commit();
    index(copies);
    return copies;
}
Also used : QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) QPoolSPI(org.olat.modules.qpool.QPoolSPI) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) ArrayList(java.util.ArrayList) QuestionItem(org.olat.modules.qpool.QuestionItem)

Example 15 with QuestionItemImpl

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

the class QuestionPoolServiceImpl method createAndPersistItem.

@Override
public QuestionItem createAndPersistItem(Identity owner, String subject, String format, String language, TaxonomyLevel taxonLevel, String dir, String rootFilename, QItemType type) {
    QuestionItemImpl newItem = questionItemDao.createAndPersist(owner, subject, format, language, taxonLevel, dir, rootFilename, type);
    dbInstance.commit();
    lifeIndexer.indexDocument(QItemDocument.TYPE, newItem.getKey());
    return newItem;
}
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