use of org.olat.modules.qpool.model.QItemType in project OpenOLAT by OpenOLAT.
the class PoolDAOTest method removeItemFromPool_paranoid.
@Test
public void removeItemFromPool_paranoid() {
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Poolman-" + UUID.randomUUID().toString());
// create a pool
String name1 = "NGC-" + UUID.randomUUID().toString();
Pool pool1 = poolDao.createPool(null, name1, true);
String name2 = "NGC-" + UUID.randomUUID().toString();
Pool pool2 = poolDao.createPool(null, name2, true);
QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
QuestionItem item1 = questionItemDao.createAndPersist(id, "Cluster of stars", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
QuestionItem item2 = questionItemDao.createAndPersist(id, "Nebula", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
poolDao.addItemToPool(item1, Collections.singletonList(pool1), false);
poolDao.addItemToPool(item1, Collections.singletonList(pool2), false);
poolDao.addItemToPool(item2, Collections.singletonList(pool1), false);
poolDao.addItemToPool(item2, Collections.singletonList(pool2), false);
dbInstance.commit();
SearchQuestionItemParams params1 = new SearchQuestionItemParams(id, null);
params1.setPoolKey(pool1.getKey());
SearchQuestionItemParams params2 = new SearchQuestionItemParams(id, null);
params2.setPoolKey(pool2.getKey());
// check
int numOfItems_1 = poolDao.countItemsInPool(params1);
Assert.assertEquals(2, numOfItems_1);
int numOfItems_2 = poolDao.countItemsInPool(params2);
Assert.assertEquals(2, numOfItems_2);
// remove
poolDao.removeFromPool(Collections.<QuestionItemShort>singletonList(item1), pool2);
dbInstance.commit();
// check empty pool
int numOfStayingItems_1 = poolDao.countItemsInPool(params1);
Assert.assertEquals(2, numOfStayingItems_1);
int numOfStayingItems_2 = poolDao.countItemsInPool(params2);
Assert.assertEquals(1, numOfStayingItems_2);
// check content
List<QuestionItemView> items_1 = qItemQueriesDao.getItemsOfPool(params1, null, 0, -1);
Assert.assertEquals(2, items_1.size());
List<QuestionItemView> items_2 = qItemQueriesDao.getItemsOfPool(params2, null, 0, -1);
Assert.assertEquals(1, items_2.size());
Assert.assertEquals(item2.getKey(), items_2.get(0).getKey());
// but item exists
QuestionItem reloadedItem = questionItemDao.loadById(item1.getKey());
Assert.assertNotNull(reloadedItem);
}
use of org.olat.modules.qpool.model.QItemType in project OpenOLAT by OpenOLAT.
the class PoolDAOTest method removeItemFromPools.
@Test
public void removeItemFromPools() {
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Poolman-" + UUID.randomUUID().toString());
// create a pool with an item
String poolName = "NGC-" + UUID.randomUUID().toString();
Pool pool = poolDao.createPool(null, poolName, true);
QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
QuestionItem item = questionItemDao.createAndPersist(id, "Galaxy", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
poolDao.addItemToPool(item, Collections.singletonList(pool), false);
dbInstance.commitAndCloseSession();
SearchQuestionItemParams params = new SearchQuestionItemParams(id, null);
params.setPoolKey(pool.getKey());
// check the pool and remove the items
List<QuestionItemView> items = qItemQueriesDao.getItemsOfPool(params, null, 0, -1);
Assert.assertEquals(1, items.size());
List<QuestionItemShort> toDelete = Collections.<QuestionItemShort>singletonList(items.get(0));
int count = poolDao.removeFromPools(toDelete);
Assert.assertEquals(1, count);
dbInstance.commitAndCloseSession();
// check if the pool is empty
List<QuestionItemView> emptyItems = qItemQueriesDao.getItemsOfPool(params, null, 0, -1);
Assert.assertTrue(emptyItems.isEmpty());
}
use of org.olat.modules.qpool.model.QItemType in project OpenOLAT by OpenOLAT.
the class QuestionPoolTest method addAuthor.
@Test
public void addAuthor() throws IOException, URISyntaxException {
QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("item-author-1");
QuestionItem item = questionDao.createAndPersist(author, "NGC 55", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
Identity coAuthor = JunitTestHelper.createAndPersistIdentityAsRndUser("item-author-1");
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("/qpool/items/" + item.getKey() + "/authors/" + coAuthor.getKey()).build();
HttpPut method = conn.createPut(request, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
EntityUtils.consume(response.getEntity());
// check
List<Identity> authors = qpoolService.getAuthors(item);
Assert.assertNotNull(authors);
Assert.assertEquals(2, authors.size());
Assert.assertTrue(authors.contains(author));
Assert.assertTrue(authors.contains(coAuthor));
}
use of org.olat.modules.qpool.model.QItemType in project OpenOLAT by OpenOLAT.
the class AbstractQPoolServiceProvider method importItem.
public QuestionItem importItem(Identity owner, Locale defaultLocale, String filename, File file) {
String dir = getFileStorage().generateDir();
VFSContainer itemDir = getFileStorage().getContainer(dir);
VFSLeaf leaf = itemDir.createChildLeaf(filename);
OutputStream out = leaf.getOutputStream(false);
InputStream in = null;
try {
in = new FileInputStream(file);
IOUtils.copy(in, out);
} catch (FileNotFoundException e) {
log.error("", e);
} catch (IOException e) {
log.error("", e);
} finally {
IOUtils.closeQuietly(in);
IOUtils.closeQuietly(out);
}
String language = defaultLocale.getLanguage();
QItemType type = getDefaultType();
return CoreSpringFactory.getImpl(QPoolService.class).createAndPersistItem(owner, filename, getFormat(), language, null, dir, filename, type);
}
use of org.olat.modules.qpool.model.QItemType in project OpenOLAT by OpenOLAT.
the class QuestionMetadataEditController method initForm.
@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
typeEl = uifactory.addStaticTextElement("question.type", "", formLayout);
QItemType type = item.getType();
if (type == null || type.getType() == null) {
typeEl.setValue("");
} else {
String translation = translate("item.type." + type.getType().toLowerCase());
if (translation.length() > 128) {
translation = type.getType();
}
typeEl.setValue(translation);
}
String page = velocity_root + "/learning_time.html";
learningTimeContainer = FormLayoutContainer.createCustomFormLayout("learningTime", getTranslator(), page);
((AbstractComponent) learningTimeContainer.getComponent()).setDomReplacementWrapperRequired(false);
learningTimeContainer.setRootForm(mainForm);
learningTimeContainer.setLabel("educational.learningTime", null);
formLayout.add(learningTimeContainer);
LOMDuration duration = MetadataConverterHelper.convertDuration(item.getEducationalLearningTime());
learningTimeDayElement = uifactory.addIntegerElement("learningTime.day", "", duration.getDay(), learningTimeContainer);
((AbstractComponent) learningTimeDayElement.getComponent()).setDomReplacementWrapperRequired(false);
learningTimeDayElement.setDisplaySize(3);
learningTimeDayElement.setMandatory(true);
learningTimeHourElement = uifactory.addIntegerElement("learningTime.hour", "", duration.getHour(), learningTimeContainer);
((AbstractComponent) learningTimeHourElement.getComponent()).setDomReplacementWrapperRequired(false);
learningTimeHourElement.setDisplaySize(3);
learningTimeHourElement.setMandatory(true);
learningTimeMinuteElement = uifactory.addIntegerElement("learningTime.minute", "", duration.getMinute(), learningTimeContainer);
((AbstractComponent) learningTimeMinuteElement.getComponent()).setDomReplacementWrapperRequired(false);
learningTimeMinuteElement.setDisplaySize(3);
learningTimeMinuteElement.setMandatory(true);
learningTimeSecondElement = uifactory.addIntegerElement("learningTime.second", "", duration.getSeconds(), learningTimeContainer);
((AbstractComponent) learningTimeSecondElement.getComponent()).setDomReplacementWrapperRequired(false);
learningTimeSecondElement.setDisplaySize(3);
learningTimeSecondElement.setMandatory(true);
String difficulty = bigDToString(item.getDifficulty());
difficultyEl = uifactory.addTextElement("question.difficulty", "question.difficulty", 24, difficulty, formLayout);
difficultyEl.setExampleKey("question.difficulty.example", null);
difficultyEl.setDisplaySize(4);
String stdevDifficulty = bigDToString(item.getStdevDifficulty());
stdevDifficultyEl = uifactory.addTextElement("question.stdevDifficulty", "question.stdevDifficulty", 24, stdevDifficulty, formLayout);
stdevDifficultyEl.setExampleKey("question.stdevDifficulty.example", null);
stdevDifficultyEl.setDisplaySize(4);
String differentiation = bigDToString(item.getDifferentiation());
differentiationEl = uifactory.addTextElement("question.differentiation", "question.differentiation", 24, differentiation, formLayout);
differentiationEl.setExampleKey("question.differentiation.example", null);
differentiationEl.setDisplaySize(4);
String numAnswerAlt = item.getNumOfAnswerAlternatives() < 0 ? "" : Integer.toString(item.getNumOfAnswerAlternatives());
numAnswerAltEl = uifactory.addTextElement("question.numOfAnswerAlternatives", "question.numOfAnswerAlternatives", 24, numAnswerAlt, formLayout);
numAnswerAltEl.setDisplaySize(4);
String numUsage = item.getUsage() < 0 ? "" : Integer.toString(item.getUsage());
usageEl = uifactory.addTextElement("question.usage", "question.usage", 24, numUsage, formLayout);
usageEl.setDisplaySize(4);
buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
buttonsCont.setRootForm(mainForm);
formLayout.add(buttonsCont);
uifactory.addFormSubmitButton("ok", "ok", buttonsCont);
uifactory.addFormCancelButton("cancel", buttonsCont, ureq, getWindowControl());
}
Aggregations