use of org.olat.modules.qpool.QuestionItemView in project OpenOLAT by OpenOLAT.
the class QuestionPoolServiceTest method createCollection.
@Test
public void createCollection() {
// create an user with 2 items
QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Coll-Owner-3-" + UUID.randomUUID().toString());
QuestionItem item1 = questionDao.createAndPersist(id, "NGC 92", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
QuestionItem item2 = questionDao.createAndPersist(id, "NGC 97", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
dbInstance.commit();
// load the items of the collection
List<QuestionItemShort> items = new ArrayList<>();
items.add(item1);
items.add(item2);
QuestionItemCollection newColl = qpoolService.createCollection(id, "My private collection", items);
Assert.assertNotNull(newColl);
Assert.assertEquals("My private collection", newColl.getName());
// check if it's alright
dbInstance.commit();
SearchQuestionItemParams params = new SearchQuestionItemParams(id, null);
// retrieve the list of items in the collection
int numOfItemsInCollection = qpoolService.countItemsOfCollection(newColl, params);
Assert.assertEquals(2, numOfItemsInCollection);
ResultInfos<QuestionItemView> itemsOfCollection = qpoolService.getItemsOfCollection(newColl, params, 0, -1);
Assert.assertNotNull(itemsOfCollection);
Assert.assertEquals(2, itemsOfCollection.getObjects().size());
List<Long> itemKeys = new ArrayList<>();
for (QuestionItemView item : itemsOfCollection.getObjects()) {
itemKeys.add(item.getKey());
}
Assert.assertTrue(itemKeys.contains(item1.getKey()));
Assert.assertTrue(itemKeys.contains(item2.getKey()));
}
use of org.olat.modules.qpool.QuestionItemView in project OpenOLAT by OpenOLAT.
the class CollectionDAOTest method removeFromCollection_paranoid.
@Test
public void removeFromCollection_paranoid() {
// create 2 collections with 2 items
QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Coll-Onwer-4-" + UUID.randomUUID().toString());
QuestionItemCollection coll1 = collectionDao.createCollection("NGC collection 8", id);
QuestionItemCollection coll2 = collectionDao.createCollection("NGC collection 9", id);
QuestionItem item1 = questionDao.createAndPersist(null, "NGC 103", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
QuestionItem item2 = questionDao.createAndPersist(null, "NGC 104", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
collectionDao.addItemToCollection(item1, singletonList(coll1));
collectionDao.addItemToCollection(item1, singletonList(coll2));
collectionDao.addItemToCollection(item2, singletonList(coll1));
collectionDao.addItemToCollection(item2, singletonList(coll2));
dbInstance.commit();
// check if it's alright
int numOfItems_1 = collectionDao.countItemsOfCollection(coll1, null);
Assert.assertEquals(2, numOfItems_1);
int numOfItems_2 = collectionDao.countItemsOfCollection(coll2, null);
Assert.assertEquals(2, numOfItems_2);
// remove
collectionDao.removeItemFromCollection(Collections.<QuestionItemShort>singletonList(item1), coll2);
dbInstance.commitAndCloseSession();
// check if the item has been removed
int numOfStayingItems_1 = collectionDao.countItemsOfCollection(coll1, null);
Assert.assertEquals(2, numOfStayingItems_1);
int numOfStayingItems_2 = collectionDao.countItemsOfCollection(coll2, null);
Assert.assertEquals(1, numOfStayingItems_2);
List<QuestionItemView> items_2 = qItemQueriesDao.getItemsOfCollection(id, coll2, null, null, 0, -1);
Assert.assertEquals(1, items_2.size());
Assert.assertEquals(item2.getKey(), items_2.get(0).getKey());
}
use of org.olat.modules.qpool.QuestionItemView in project OpenOLAT by OpenOLAT.
the class CollectionDAOTest method removeFromCollections.
@Test
public void removeFromCollections() {
// create a collection with 2 items
QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Coll-Onwer-4-" + UUID.randomUUID().toString());
QuestionItemCollection coll = collectionDao.createCollection("NGC collection 10", id);
QuestionItem item1 = questionDao.createAndPersist(null, "NGC 107", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
QuestionItem item2 = questionDao.createAndPersist(null, "NGC 108", QTIConstants.QTI_12_FORMAT, Locale.GERMAN.getLanguage(), null, null, null, fibType);
collectionDao.addItemToCollection(item1, singletonList(coll));
collectionDao.addItemToCollection(item2, singletonList(coll));
dbInstance.commit();
// check if it's alright
int numOfItems = collectionDao.countItemsOfCollection(coll, null);
Assert.assertEquals(2, numOfItems);
// remove
collectionDao.deleteItemFromCollections(Collections.<QuestionItemShort>singletonList(item1));
dbInstance.commitAndCloseSession();
// check if the item has been removed
int numOfStayingItems = collectionDao.countItemsOfCollection(coll, null);
Assert.assertEquals(1, numOfStayingItems);
List<QuestionItemView> items_2 = qItemQueriesDao.getItemsOfCollection(id, coll, null, null, 0, -1);
Assert.assertEquals(1, items_2.size());
Assert.assertEquals(item2.getKey(), items_2.get(0).getKey());
}
use of org.olat.modules.qpool.QuestionItemView in project OpenOLAT by OpenOLAT.
the class QuestionDAOTest method shareItems_removeFromBusinessGroups.
@Test
public void shareItems_removeFromBusinessGroups() {
// create a group to share 2 items
QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Share-item-" + UUID.randomUUID().toString());
BusinessGroup group = businessGroupDao.createAndPersist(id, "gdao", "gdao-desc", -1, -1, false, false, false, false, false);
QuestionItem item = questionDao.createAndPersist(id, "Share-Item-Dup-1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
questionDao.share(item, group.getResource());
dbInstance.commit();
// check them
List<QuestionItemView> shared = qItemQueriesDao.getSharedItemByResource(id, group.getResource(), null, null, 0, -1);
Assert.assertNotNull(shared);
Assert.assertEquals(1, shared.size());
// remove
questionDao.removeFromShare(Collections.<QuestionItemShort>singletonList(item), group.getResource());
dbInstance.commitAndCloseSession();
// check
int numOfStayingItems = questionDao.countSharedItemByResource(group.getResource(), null);
Assert.assertEquals(0, numOfStayingItems);
}
use of org.olat.modules.qpool.QuestionItemView in project OpenOLAT by OpenOLAT.
the class QItemQueriesDAO method getItemsOfCollection.
public List<QuestionItemView> getItemsOfCollection(Identity identity, QuestionItemCollection collection, Collection<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(" (select count(pool2item.key) from qpool2item pool2item").append(" where pool2item.item.key=item.key").append(" and pool2item.editable is true").append(" ) as pools,").append(" (select count(shareditem.key) from qshareitem shareditem").append(" where shareditem.item.key=item.key").append(" and shareditem.editable is true").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 qcollection2item coll2item").append(" inner join coll2item.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 coll2item.collection.key=:collectionKey");
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("collectionKey", collection.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]).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();
views.add(itemWrapper);
}
return views;
}
Aggregations