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);
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations