Search in sources :

Example 26 with QItemType

use of org.olat.modules.qpool.model.QItemType in project OpenOLAT by OpenOLAT.

the class QuestionDAOTest method shareItems_countSharedItemByResource_format.

@Test
public void shareItems_countSharedItemByResource_format() {
    // create a group to share 2 items
    QItemType mcType = qItemTypeDao.loadByType(QuestionType.MC.name());
    QItemType fibType = qItemTypeDao.loadByType(QuestionType.FIB.name());
    BusinessGroup group = businessGroupDao.createAndPersist(null, "gdao", "gdao-desc", -1, -1, false, false, false, false, false);
    QuestionItem item1 = questionDao.createAndPersist(null, "Count-shared-Item-1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    QuestionItem item2 = questionDao.createAndPersist(null, "Count-shared-Item-2", QTI21Constants.QTI_21_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    QuestionItem item3 = questionDao.createAndPersist(null, "Count-shared-Item-3", QTIConstants.QTI_12_FORMAT, Locale.FRENCH.getLanguage(), null, null, null, fibType);
    dbInstance.commit();
    // share them
    questionDao.share(item1, group.getResource());
    questionDao.share(item2, group.getResource());
    questionDao.share(item3, group.getResource());
    dbInstance.commitAndCloseSession();
    // retrieve them
    int sharedItems = questionDao.countSharedItemByResource(group.getResource(), QTI21Constants.QTI_21_FORMAT);
    Assert.assertEquals(1, sharedItems);
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 27 with QItemType

use of org.olat.modules.qpool.model.QItemType in project OpenOLAT by OpenOLAT.

the class QuestionDAOTest method removeFromShare.

@Test
public void removeFromShare() {
    // 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 item = questionDao.createAndPersist(id, "Share-item-rm-1", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, mcType);
    dbInstance.commit();
    // share them
    questionDao.share(item, group.getResource());
    // retrieve them as a check
    List<QuestionItemView> shared = qItemQueriesDao.getSharedItemByResource(id, group.getResource(), null, null, 0, -1);
    Assert.assertEquals(1, shared.size());
    // and remove the items
    List<QuestionItemShort> toDelete = Collections.<QuestionItemShort>singletonList(shared.get(0));
    int count = questionDao.removeFromShares(toDelete);
    Assert.assertEquals(1, count);
    // make sure that changes are committed
    dbInstance.commit();
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) Identity(org.olat.core.id.Identity) QuestionItemView(org.olat.modules.qpool.QuestionItemView) QuestionItem(org.olat.modules.qpool.QuestionItem) QItemType(org.olat.modules.qpool.model.QItemType) Test(org.junit.Test)

Example 28 with QItemType

use of org.olat.modules.qpool.model.QItemType in project OpenOLAT by OpenOLAT.

the class QTI21ImportProcessor method processItemMetadata.

// additionalInformations, assessmentType
protected void processItemMetadata(QuestionItemImpl poolItem, AssessmentItemMetadata metadata) {
    // non heuristic set of question type
    String typeStr = null;
    QTI21QuestionType questionType = metadata.getQuestionType();
    if (questionType != null && questionType.getPoolQuestionType() != null) {
        typeStr = questionType.getPoolQuestionType().name();
    }
    if (typeStr != null) {
        QItemType type = qItemTypeDao.loadByType(typeStr);
        if (type != null) {
            poolItem.setType(type);
        }
    }
    String coverage = metadata.getCoverage();
    if (StringHelper.containsNonWhitespace(coverage)) {
        poolItem.setCoverage(coverage);
    }
    String language = metadata.getLanguage();
    if (StringHelper.containsNonWhitespace(language)) {
        poolItem.setLanguage(language);
    }
    String keywords = metadata.getKeywords();
    if (StringHelper.containsNonWhitespace(keywords)) {
        poolItem.setKeywords(keywords);
    }
    String taxonomyPath = metadata.getTaxonomyPath();
    if (StringHelper.containsNonWhitespace(taxonomyPath)) {
        QTIMetadataConverter converter = new QTIMetadataConverter(qItemTypeDao, qEduContextDao, qpoolService);
        TaxonomyLevel taxonomyLevel = converter.toTaxonomy(taxonomyPath);
        poolItem.setTaxonomyLevel(taxonomyLevel);
    }
    // educational
    String level = metadata.getLevel();
    if (StringHelper.containsNonWhitespace(level)) {
        QTIMetadataConverter converter = new QTIMetadataConverter(qItemTypeDao, qEduContextDao, qpoolService);
        QEducationalContext educationalContext = converter.toEducationalContext(level);
        poolItem.setEducationalContext(educationalContext);
    }
    String time = metadata.getTypicalLearningTime();
    if (StringHelper.containsNonWhitespace(time)) {
        poolItem.setEducationalLearningTime(time);
    }
    String editor = metadata.getEditor();
    if (StringHelper.containsNonWhitespace(editor)) {
        poolItem.setEditor(editor);
    }
    String editorVersion = metadata.getEditorVersion();
    if (StringHelper.containsNonWhitespace(editorVersion)) {
        poolItem.setEditorVersion(editorVersion);
    }
    // OpenOLAT
    poolItem.setDifficulty(metadata.getDifficulty());
    poolItem.setDifferentiation(metadata.getDifferentiation());
    poolItem.setStdevDifficulty(metadata.getStdevDifficulty());
    int numOfAnswerAlternatives = metadata.getNumOfAnswerAlternatives();
    if (numOfAnswerAlternatives > 0) {
        poolItem.setNumOfAnswerAlternatives(numOfAnswerAlternatives);
    }
    poolItem.setTopic(metadata.getTopic());
    poolItem.setAssessmentType(metadata.getAssessmentType());
    poolItem.setAdditionalInformations(metadata.getAdditionalInformations());
}
Also used : QTIMetadataConverter(org.olat.ims.qti.qpool.QTIMetadataConverter) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel) QTI21QuestionType(org.olat.ims.qti21.model.QTI21QuestionType) QEducationalContext(org.olat.modules.qpool.model.QEducationalContext) QItemType(org.olat.modules.qpool.model.QItemType)

Example 29 with QItemType

use of org.olat.modules.qpool.model.QItemType in project OpenOLAT by OpenOLAT.

the class QTI21ImportProcessor method processItem.

protected QuestionItemImpl processItem(AssessmentItem assessmentItem, String comment, String originalItemFilename, String editor, String editorVersion, String dir, AssessmentItemMetadata metadata) {
    // filename
    String filename;
    String ident = assessmentItem.getIdentifier();
    if (originalItemFilename != null) {
        filename = originalItemFilename;
    } else if (StringHelper.containsNonWhitespace(ident)) {
        filename = StringHelper.transformDisplayNameToFileSystemName(ident) + ".xml";
    } else {
        filename = "item.xml";
    }
    // title
    String title = assessmentItem.getTitle();
    if (!StringHelper.containsNonWhitespace(title)) {
        title = assessmentItem.getLabel();
    }
    if (!StringHelper.containsNonWhitespace(title)) {
        title = ident;
    }
    QuestionItemImpl poolItem = questionItemDao.create(title, QTI21Constants.QTI_21_FORMAT, dir, filename);
    // description
    poolItem.setDescription(comment);
    // language from default
    poolItem.setLanguage(defaultLocale.getLanguage());
    // question type first
    if (StringHelper.containsNonWhitespace(editor)) {
        poolItem.setEditor(editor);
        poolItem.setEditorVersion(editorVersion);
    }
    // if question type not found, can be overridden by the metadatas
    processItemMetadata(poolItem, metadata);
    if (poolItem.getType() == null) {
        QItemType defType = convertType(assessmentItem);
        poolItem.setType(defType);
    }
    questionItemDao.persist(owner, poolItem);
    createLicense(poolItem, metadata);
    return poolItem;
}
Also used : QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) QItemType(org.olat.modules.qpool.model.QItemType)

Example 30 with QItemType

use of org.olat.modules.qpool.model.QItemType in project openolat by klemens.

the class QTI21ImportProcessor method processItem.

protected QuestionItemImpl processItem(AssessmentItem assessmentItem, String comment, String originalItemFilename, String editor, String editorVersion, String dir, AssessmentItemMetadata metadata) {
    // filename
    String filename;
    String ident = assessmentItem.getIdentifier();
    if (originalItemFilename != null) {
        filename = originalItemFilename;
    } else if (StringHelper.containsNonWhitespace(ident)) {
        filename = StringHelper.transformDisplayNameToFileSystemName(ident) + ".xml";
    } else {
        filename = "item.xml";
    }
    // title
    String title = assessmentItem.getTitle();
    if (!StringHelper.containsNonWhitespace(title)) {
        title = assessmentItem.getLabel();
    }
    if (!StringHelper.containsNonWhitespace(title)) {
        title = ident;
    }
    QuestionItemImpl poolItem = questionItemDao.create(title, QTI21Constants.QTI_21_FORMAT, dir, filename);
    // description
    poolItem.setDescription(comment);
    // language from default
    poolItem.setLanguage(defaultLocale.getLanguage());
    // question type first
    if (StringHelper.containsNonWhitespace(editor)) {
        poolItem.setEditor(editor);
        poolItem.setEditorVersion(editorVersion);
    }
    // if question type not found, can be overridden by the metadatas
    processItemMetadata(poolItem, metadata);
    if (poolItem.getType() == null) {
        QItemType defType = convertType(assessmentItem);
        poolItem.setType(defType);
    }
    questionItemDao.persist(owner, poolItem);
    createLicense(poolItem, metadata);
    return poolItem;
}
Also used : QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) 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