use of org.olat.modules.qpool.model.QuestionItemImpl in project OpenOLAT by OpenOLAT.
the class QuestionItemAuditLogDAOTest method shouldConvertToXMLAndBack.
@Test
public void shouldConvertToXMLAndBack() {
QItemType qItemType = qItemTypeDao.loadByType(QuestionType.MC.name());
Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("qitem-audit-log");
String title = "NGC 55";
String format = QTI21Constants.QTI_21_FORMAT;
String language = Locale.ENGLISH.getLanguage();
QuestionItemImpl item = questionDao.createAndPersist(id, title, format, language, null, null, null, qItemType);
String xml = sut.toXml(item);
QuestionItem itemFromXml = sut.questionItemFromXml(xml);
assertThat(itemFromXml.getTitle()).isEqualTo(title);
assertThat(itemFromXml.getFormat()).isEqualTo(format);
assertThat(itemFromXml.getLanguage()).isEqualTo(language);
}
use of org.olat.modules.qpool.model.QuestionItemImpl in project OpenOLAT by OpenOLAT.
the class OLATUpgrade_12_4_0 method migrateQpoolItemLicenses.
private void migrateQpoolItemLicenses() {
int counter = 0;
List<QuestionItemImpl> items;
do {
items = getQuestionItems(counter, BATCH_SIZE);
for (QuestionItemImpl item : items) {
try {
migrateQpoolLicense(item);
log.info("QPool item license successfully migrated: " + item);
} catch (Exception e) {
log.error("Not able to migrate question item license: " + item, e);
}
}
counter += items.size();
dbInstance.commitAndCloseSession();
log.info(counter + " QPool items processed.");
} while (items.size() == BATCH_SIZE);
}
use of org.olat.modules.qpool.model.QuestionItemImpl in project OpenOLAT by OpenOLAT.
the class QuestionDAOTest method copyQuestion.
@Test
public void copyQuestion() {
// create an item and fill it
Taxonomy taxonomy = taxonomyDao.createTaxonomy("ID-QP", "QPool taxonomy", null, null);
TaxonomyLevel taxonomyLevel = taxonomyLevelDao.createTaxonomyLevel("QP-L-1", "QLevel 1", "For testing only", null, null, null, null, taxonomy);
QEducationalContext eduContext = qEduContextDao.create("primary.school", true);
QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
QItemType essayType = qItemTypeDao.loadByType(QuestionType.ESSAY.name());
Identity author = JunitTestHelper.createAndPersistIdentityAsUser("QClone-1-" + UUID.randomUUID().toString());
Identity cloner = JunitTestHelper.createAndPersistIdentityAsUser("QClone-2-" + UUID.randomUUID().toString());
QuestionItemImpl original = questionDao.createAndPersist(author, "To copy", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), taxonomyLevel, null, "root.xml", fibType);
dbInstance.commit();
Assert.assertNotNull(original);
Assert.assertNotNull(original.getIdentifier());
Assert.assertNull(original.getMasterIdentifier());
// general
original.setTitle("Original");
original.setTopic("Topic");
original.setDescription("Original description");
original.setKeywords("original copy to");
original.setCoverage("New coverage");
original.setAdditionalInformations("Additional informations before copy");
original.setLanguage("en");
// educational
original.setEducationalContext(eduContext);
original.setEducationalLearningTime("PT1H30M");
// question
original.setType(essayType);
original.setDifficulty(new BigDecimal("0.1"));
original.setStdevDifficulty(new BigDecimal("0.2"));
original.setDifferentiation(new BigDecimal("-0.5"));
original.setNumOfAnswerAlternatives(4);
original.setUsage(5);
original.setAssessmentType("formative");
// lifecycle
original.setItemVersion("1.0");
original.setStatus(QuestionStatus.review.name());
// technical
original.setEditor("OpenOLAT");
original.setEditorVersion("9.0a");
original = questionDao.merge(original);
dbInstance.commitAndCloseSession();
// clone it
QuestionItemImpl clone = questionDao.copy(original);
questionDao.persist(cloner, clone);
// compare
Assert.assertEquals(1, questionDao.countItems(cloner));
// general
Assert.assertNotNull(clone.getIdentifier());
Assert.assertFalse(clone.getIdentifier().equals(original.getIdentifier()));
Assert.assertEquals(original.getIdentifier(), clone.getMasterIdentifier());
Assert.assertNotNull(clone.getTitle());
Assert.assertEquals("(Copy) " + original.getTitle(), clone.getTitle());
Assert.assertEquals(original.getTopic(), clone.getTopic());
Assert.assertEquals(original.getDescription(), clone.getDescription());
Assert.assertEquals(original.getKeywords(), clone.getKeywords());
Assert.assertEquals(original.getCoverage(), clone.getCoverage());
Assert.assertEquals(original.getAdditionalInformations(), clone.getAdditionalInformations());
Assert.assertEquals(original.getLanguage(), clone.getLanguage());
// classification
Assert.assertEquals(original.getTaxonomyLevelName(), clone.getTaxonomyLevelName());
// educational
Assert.assertEquals(original.getEducationalContext(), clone.getEducationalContext());
Assert.assertEquals(original.getEducationalLearningTime(), clone.getEducationalLearningTime());
// question
Assert.assertEquals(original.getType(), clone.getType());
Assert.assertNotNull(clone.getDifficulty());
Assert.assertEquals(original.getDifficulty().doubleValue(), clone.getDifficulty().doubleValue(), 0.000001);
Assert.assertNotNull(clone.getStdevDifficulty());
Assert.assertEquals(original.getStdevDifficulty().doubleValue(), clone.getStdevDifficulty().doubleValue(), 0.000001);
Assert.assertNotNull(clone.getDifferentiation());
Assert.assertEquals(original.getDifferentiation().doubleValue(), clone.getDifferentiation().doubleValue(), 0.000001);
Assert.assertEquals(original.getNumOfAnswerAlternatives(), clone.getNumOfAnswerAlternatives());
Assert.assertEquals(0, clone.getUsage());
Assert.assertEquals(original.getAssessmentType(), clone.getAssessmentType());
// lifecycle
Assert.assertEquals(QuestionStatus.draft.name(), clone.getStatus());
Assert.assertNotNull(clone.getQuestionStatusLastModified());
Assert.assertEquals(original.getItemVersion(), clone.getItemVersion());
// technical
Assert.assertEquals(original.getEditor(), clone.getEditor());
Assert.assertEquals(original.getEditorVersion(), clone.getEditorVersion());
Assert.assertEquals(original.getFormat(), clone.getFormat());
Assert.assertNotNull(clone.getCreationDate());
Assert.assertNotNull(clone.getLastModified());
}
use of org.olat.modules.qpool.model.QuestionItemImpl in project OpenOLAT by OpenOLAT.
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 OpenOLAT.
the class QuestionPoolServiceImpl method getRootContainer.
@Override
public VFSContainer getRootContainer(QuestionItemShort item) {
QuestionItemImpl reloadedItem = questionItemDao.loadById(item.getKey());
VFSContainer root = qpoolModule.getRootContainer();
VFSItem dir = root.resolve(reloadedItem.getDirectory());
if (dir instanceof VFSContainer) {
return (VFSContainer) dir;
}
return null;
}
Aggregations