Search in sources :

Example 6 with QItemType

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);
}
Also used : QuestionItem2Pool(org.olat.modules.qpool.QuestionItem2Pool) Pool(org.olat.modules.qpool.Pool) Identity(org.olat.core.id.Identity) SearchQuestionItemParams(org.olat.modules.qpool.model.SearchQuestionItemParams) QuestionItemView(org.olat.modules.qpool.QuestionItemView) QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 7 with QItemType

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());
}
Also used : QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) QuestionItem2Pool(org.olat.modules.qpool.QuestionItem2Pool) Pool(org.olat.modules.qpool.Pool) Identity(org.olat.core.id.Identity) SearchQuestionItemParams(org.olat.modules.qpool.model.SearchQuestionItemParams) QuestionItemView(org.olat.modules.qpool.QuestionItemView) QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 8 with QItemType

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));
}
Also used : HttpResponse(org.apache.http.HttpResponse) Identity(org.olat.core.id.Identity) QuestionItem(org.olat.modules.qpool.QuestionItem) URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 9 with QItemType

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);
}
Also used : VFSLeaf(org.olat.core.util.vfs.VFSLeaf) QPoolService(org.olat.modules.qpool.QPoolService) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) VFSContainer(org.olat.core.util.vfs.VFSContainer) ZipOutputStream(java.util.zip.ZipOutputStream) OutputStream(java.io.OutputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) QItemType(org.olat.modules.qpool.model.QItemType)

Example 10 with QItemType

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());
}
Also used : AbstractComponent(org.olat.core.gui.components.AbstractComponent) MetaUIFactory.bigDToString(org.olat.modules.qpool.ui.metadata.MetaUIFactory.bigDToString) LOMDuration(org.olat.modules.qpool.model.LOMDuration) QItemType(org.olat.modules.qpool.model.QItemType)

Aggregations

QItemType (org.olat.modules.qpool.model.QItemType)118 Test (org.junit.Test)94 QuestionItem (org.olat.modules.qpool.QuestionItem)82 Identity (org.olat.core.id.Identity)58 BusinessGroup (org.olat.group.BusinessGroup)22 QuestionItemView (org.olat.modules.qpool.QuestionItemView)18 Pool (org.olat.modules.qpool.Pool)12 QuestionItem2Pool (org.olat.modules.qpool.QuestionItem2Pool)12 QuestionItemCollection (org.olat.modules.qpool.QuestionItemCollection)12 QuestionItemImpl (org.olat.modules.qpool.model.QuestionItemImpl)10 URI (java.net.URI)8 ArrayList (java.util.ArrayList)8 HttpResponse (org.apache.http.HttpResponse)8 QuestionItemShort (org.olat.modules.qpool.QuestionItemShort)8 QEducationalContext (org.olat.modules.qpool.model.QEducationalContext)8 SearchQuestionItemParams (org.olat.modules.qpool.model.SearchQuestionItemParams)8 QuestionItemFull (org.olat.modules.qpool.QuestionItemFull)6 QuestionType (org.olat.modules.qpool.QuestionType)6 TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)6 InputStream (java.io.InputStream)4