Search in sources :

Example 91 with QuestionItemImpl

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

the class QuestionPoolServiceImplTest method shouldGetExportFormatOptions.

@Test
public void shouldGetExportFormatOptions() {
    String formatA = "A";
    String formatB = "B";
    QuestionItemImpl formatAItem = new QuestionItemImpl();
    formatAItem.setFormat(formatA);
    List<QuestionItemShort> items = Arrays.asList(formatAItem);
    ExportFormatOptions exportFormatAR = new DefaultExportFormat(formatA, Outcome.repository, null);
    ExportFormatOptions exportFormatAD = new DefaultExportFormat(formatA, Outcome.download, null);
    List<ExportFormatOptions> exportFormatsA = Arrays.asList(exportFormatAD, exportFormatAR);
    ExportFormatOptions exportFormatBR = new DefaultExportFormat(formatA, Outcome.repository, null);
    List<ExportFormatOptions> exportFormatsB = Arrays.asList(exportFormatBR);
    QPoolSPI spiA = mock(QPoolSPI.class);
    when(spiA.getTestExportFormats()).thenReturn(exportFormatsA);
    when(qPoolModuleMock.getQuestionPoolProvider(formatA)).thenReturn(spiA);
    QPoolSPI spiB = mock(QPoolSPI.class);
    when(spiB.getTestExportFormats()).thenReturn(exportFormatsB);
    when(qPoolModuleMock.getQuestionPoolProvider(formatB)).thenReturn(spiB);
    Set<ExportFormatOptions> exportFormatOptions = sut.getExportFormatOptions(items, Outcome.repository);
    assertThat(exportFormatOptions).hasSize(1).containsExactly(exportFormatAR);
}
Also used : ExportFormatOptions(org.olat.modules.qpool.ExportFormatOptions) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) QPoolSPI(org.olat.modules.qpool.QPoolSPI) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) DefaultExportFormat(org.olat.modules.qpool.model.DefaultExportFormat) Test(org.junit.Test)

Example 92 with QuestionItemImpl

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

the class QuestionPoolServiceImpl method rateItemInReview.

@Override
public void rateItemInReview(QuestionItem item, Identity identity, Float rating, String comment) {
    if (item == null || identity == null)
        return;
    if (rating != null && rating > 0f) {
        // Review is only in status review possible
        QuestionItem previousItem = loadItemById(item.getKey());
        if (QuestionStatus.review.equals(previousItem.getQuestionStatus())) {
            QuestionItemAuditLogBuilder builder = createAuditLogBuilder(identity, Action.REVIEW_QUESTION_ITEM);
            builder.withBefore(item);
            Integer newRating = Float.valueOf(rating).intValue();
            builder.withMessage("Rating: " + newRating);
            commentAndRatingService.createRating(identity, item, null, newRating);
            ReviewDecision decision = reviewService.decideStatus(item, rating);
            if (item instanceof QuestionItemImpl && decision.isStatusChanged()) {
                QuestionItemImpl itemImpl = (QuestionItemImpl) item;
                itemImpl.setQuestionStatus(decision.getStatus());
                updateItem(itemImpl);
            }
            builder.withAfter(item);
            persist(builder.create());
        }
    }
    if (StringHelper.containsNonWhitespace(comment)) {
        commentAndRatingService.createComment(identity, item, null, comment);
    }
}
Also used : QuestionItemAuditLogBuilder(org.olat.modules.qpool.QuestionItemAuditLogBuilder) ReviewDecision(org.olat.modules.qpool.model.ReviewDecision) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) QuestionItem(org.olat.modules.qpool.QuestionItem)

Example 93 with QuestionItemImpl

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

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

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

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)

Example 95 with QuestionItemImpl

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

the class QItemQueriesDAO method getSharedItemByResource.

public List<QuestionItemView> getSharedItemByResource(Identity identity, OLATResource resource, List<Long> inKeys, String format, 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(" shareditem.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 qshareitem shareditem").append(" inner join shareditem.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 shareditem.resource.key=:resourceKey");
    if (inKeys != null && inKeys.size() > 0) {
        sb.append(" and item.key in (:inKeys)");
    }
    if (StringHelper.containsNonWhitespace(format)) {
        sb.append(" and item.format=:format");
    }
    appendOrderBy(sb, "item", "taxonomyLevel", orderBy);
    TypedQuery<Object[]> query = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), Object[].class).setParameter("resourceKey", resource.getKey()).setParameter("identityKey", identity.getKey());
    if (inKeys != null && inKeys.size() > 0) {
        query.setParameter("inKeys", inKeys);
    }
    if (StringHelper.containsNonWhitespace(format)) {
        query.setParameter("format", format);
    }
    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]).setEditableInShare((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)

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