use of org.olat.modules.qpool.model.QItemType in project openolat by klemens.
the class PoolDAOTest method getPoolInfos_byItem.
@Test
public void getPoolInfos_byItem() {
// create a pool
String poolName = "NGC-" + UUID.randomUUID().toString();
Pool pool1 = poolDao.createPool(null, poolName, true);
Pool pool2 = poolDao.createPool(null, poolName, true);
QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
QuestionItem item = questionItemDao.createAndPersist(null, "Galaxy", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
List<Pool> pools = new ArrayList<Pool>(2);
pools.add(pool1);
pools.add(pool2);
poolDao.addItemToPool(item, pools, false);
dbInstance.commitAndCloseSession();
// retrieve
List<QuestionItem2Pool> infos = poolDao.getQuestionItem2Pool(item);
Assert.assertNotNull(infos);
Assert.assertEquals(2, infos.size());
}
use of org.olat.modules.qpool.model.QItemType in project openolat by klemens.
the class QuestionPoolServiceTest method deleteItems.
@Test
public void deleteItems() {
// create a group to share 2 items
QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Share-rm-" + UUID.randomUUID().toString());
BusinessGroup group = businessGroupDao.createAndPersist(id, "gdrm", "gdrm-desc", -1, -1, false, false, false, false, false);
QuestionItem item1 = questionDao.createAndPersist(id, "Share-item-rm-1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
QuestionItem item2 = questionDao.createAndPersist(id, "Share-item-rm-1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
dbInstance.commit();
// share them
questionDao.share(item1, group.getResource());
dbInstance.commitAndCloseSession();
// delete the items
List<QuestionItemShort> toDelete = new ArrayList<>();
toDelete.add(item1);
toDelete.add(item2);
qpoolService.deleteItems(toDelete);
// make sure that changes are committed
dbInstance.commit();
// check if they exists
QuestionItem deletedItem1 = questionDao.loadById(item1.getKey());
Assert.assertNull(deletedItem1);
QuestionItem deletedItem2 = questionDao.loadById(item2.getKey());
Assert.assertNull(deletedItem2);
}
use of org.olat.modules.qpool.model.QItemType in project openolat by klemens.
the class QuestionPoolTest method getAuthor.
@Test
public void getAuthor() throws IOException, URISyntaxException {
QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
Identity author = JunitTestHelper.createAndPersistIdentityAsRndUser("item-author-2");
QuestionItem item = questionDao.createAndPersist(author, "NGC 55", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
dbInstance.commitAndCloseSession();
RestConnection conn = new RestConnection();
Assert.assertTrue(conn.login("administrator", "openolat"));
URI request = UriBuilder.fromUri(getContextURI()).path("/qpool/items/" + item.getKey() + "/authors/" + author.getKey()).build();
HttpGet method = conn.createGet(request, MediaType.APPLICATION_JSON, true);
HttpResponse response = conn.execute(method);
Assert.assertEquals(200, response.getStatusLine().getStatusCode());
UserVO user = conn.parse(response.getEntity().getContent(), UserVO.class);
// check
Assert.assertNotNull(user);
Assert.assertTrue(author.getKey().equals(user.getKey()));
}
use of org.olat.modules.qpool.model.QItemType in project openolat by klemens.
the class MetaUIFactory method getQItemTypeKeyValues.
public static KeyValues getQItemTypeKeyValues(Translator translator, QPoolService qpoolService) {
List<QItemType> types = qpoolService.getAllItemTypes();
String[] typeKeys = new String[types.size()];
String[] typeValues = new String[types.size()];
int count = 0;
for (QItemType type : types) {
typeKeys[count] = type.getType();
String translation = translator.translate("item.type." + type.getType().toLowerCase());
if (translation.length() > 128) {
typeValues[count] = typeKeys[count];
} else {
typeValues[count] = translation;
}
count++;
}
return new KeyValues(typeKeys, typeValues);
}
use of org.olat.modules.qpool.model.QItemType in project openolat by klemens.
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