Search in sources :

Example 76 with QuestionItemImpl

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

the class QuestionItemDAO method loadForUpdate.

public QuestionItemImpl loadForUpdate(QuestionItemShort item) {
    StringBuilder sb = new StringBuilder();
    sb.append("select item from questionitem item where item.key=:key");
    QuestionItemImpl lockedItem = dbInstance.getCurrentEntityManager().createQuery(sb.toString(), QuestionItemImpl.class).setParameter("key", item.getKey()).setLockMode(LockModeType.PESSIMISTIC_WRITE).getSingleResult();
    return lockedItem;
}
Also used : QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl)

Example 77 with QuestionItemImpl

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

the class QuestionItemDAO method create.

public QuestionItemImpl create(String title, String format, String dir, String rootFilename) {
    QuestionItemImpl item = new QuestionItemImpl();
    Date now = new Date();
    String uuid = UUID.randomUUID().toString();
    item.setIdentifier(uuid);
    item.setCreationDate(now);
    item.setLastModified(now);
    item.setTitle(title);
    item.setStatus(QuestionStatus.draft.name());
    item.setQuestionStatusLastModified(now);
    item.setUsage(0);
    item.setNumOfAnswerAlternatives(0);
    item.setFormat(format);
    if (dir == null) {
        item.setDirectory(qpoolFileStorage.generateDir(uuid));
    } else {
        item.setDirectory(dir);
    }
    item.setRootFilename(rootFilename);
    return item;
}
Also used : QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) Date(java.util.Date)

Example 78 with QuestionItemImpl

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

the class QTIImportProcessor method processItem.

protected QuestionItemImpl processItem(Element itemEl, String comment, String originalItemFilename, String editor, String editorVersion, DocInfos docInfos, ItemAndMetadata metadata) {
    // filename
    String filename;
    String ident = getAttributeValue(itemEl, "ident");
    if (originalItemFilename != null) {
        filename = originalItemFilename;
    } else if (StringHelper.containsNonWhitespace(ident)) {
        filename = StringHelper.transformDisplayNameToFileSystemName(ident) + ".xml";
    } else {
        filename = "item.xml";
    }
    String dir = qpoolFileStorage.generateDir();
    // title
    String title = getAttributeValue(itemEl, "title");
    if (!StringHelper.containsNonWhitespace(title)) {
        title = ident;
    }
    if (!StringHelper.containsNonWhitespace(title)) {
        title = importedFilename;
    }
    QuestionItemImpl poolItem = questionItemDao.create(title, QTIConstants.QTI_12_FORMAT, dir, filename);
    // description
    poolItem.setDescription(comment);
    // language from default
    poolItem.setLanguage(defaultLocale.getLanguage());
    // question type first
    boolean ooFormat = processItemQuestionType(poolItem, ident, itemEl);
    if (StringHelper.containsNonWhitespace(editor)) {
        poolItem.setEditor(editor);
        poolItem.setEditorVersion(editorVersion);
    } else if (ooFormat) {
        poolItem.setEditor("OpenOLAT");
    }
    // if question type not found, can be overridden by the metadatas
    processItemMetadata(poolItem, itemEl);
    if (poolItem.getType() == null) {
        QItemType defType = qItemTypeDao.loadByType(QuestionType.UNKOWN.name());
        poolItem.setType(defType);
    }
    if (docInfos != null) {
        processSidecarMetadata(poolItem, docInfos);
    }
    if (metadata != null) {
        processItemMetadata(poolItem, metadata);
        createLicense(poolItem, metadata);
    }
    questionItemDao.persist(owner, poolItem);
    return poolItem;
}
Also used : QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) QItemType(org.olat.modules.qpool.model.QItemType)

Example 79 with QuestionItemImpl

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

the class QTI12EditorController method updateQuestionItem.

private void updateQuestionItem(UserRequest ureq, Item assessmentItem) {
    if (qitem instanceof QuestionItemImpl && assessmentItem != null) {
        String title = assessmentItem.getTitle();
        QuestionItemImpl itemImpl = (QuestionItemImpl) qitem;
        itemImpl.setTitle(title);
        qpoolService.updateItem(itemImpl);
        fireEvent(ureq, new QItemEdited(qitem));
    }
}
Also used : QItemEdited(org.olat.modules.qpool.ui.events.QItemEdited) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl)

Example 80 with QuestionItemImpl

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

the class QTI21QPoolServiceProvider method importAssessmentItemRef.

/**
 * Very important, the ManifestMetadataBuilder will be changed, it need to be a clone
 *
 * @param owner The future owner of the question
 * @param assessmentItem The assessment item to convert
 * @param itemFile The file where the assessment item is saved
 * @param clonedMetadataBuilder The metadata builder need to be a clone!
 * @param fUnzippedDirRoot The directory of the assessment item or the assessment test.
 * @param defaultLocale The locale used by some translation
 * @return
 */
public QuestionItem importAssessmentItemRef(Identity owner, AssessmentItem assessmentItem, File itemFile, ManifestMetadataBuilder clonedMetadataBuilder, Locale defaultLocale) {
    QTI21ImportProcessor processor = new QTI21ImportProcessor(owner, defaultLocale);
    AssessmentItemMetadata metadata = new AssessmentItemMetadata(clonedMetadataBuilder);
    String editor = null;
    String editorVersion = null;
    if (StringHelper.containsNonWhitespace(assessmentItem.getToolName())) {
        editor = assessmentItem.getToolName();
    }
    if (StringHelper.containsNonWhitespace(assessmentItem.getToolVersion())) {
        editorVersion = assessmentItem.getToolVersion();
    }
    String originalItemFilename = itemFile.getName();
    QuestionItemImpl qitem = processor.processItem(assessmentItem, null, originalItemFilename, editor, editorVersion, metadata);
    // storage
    File itemStorage = qpoolFileStorage.getDirectory(qitem.getDirectory());
    FileUtils.copyDirContentsToDir(itemFile, itemStorage, false, "QTI21 import item xml in pool");
    // create manifest
    ManifestBuilder manifest = ManifestBuilder.createAssessmentItemBuilder();
    ResourceType resource = manifest.appendAssessmentItem(UUID.randomUUID().toString(), originalItemFilename);
    ManifestMetadataBuilder exportedMetadataBuilder = manifest.getMetadataBuilder(resource, true);
    exportedMetadataBuilder.setMetadata(clonedMetadataBuilder.getMetadata());
    manifest.write(new File(itemStorage, "imsmanifest.xml"));
    // process material
    File materialDirRoot = itemFile.getParentFile();
    List<String> materials = ImportExportHelper.getMaterials(assessmentItem);
    for (String material : materials) {
        if (material.indexOf("://") < 0) {
            // material can be an external URL
            try {
                File materialFile = new File(materialDirRoot, material);
                if (materialFile.isFile() && materialFile.exists()) {
                    File itemMaterialFile = new File(itemStorage, material);
                    if (!itemMaterialFile.getParentFile().exists()) {
                        itemMaterialFile.getParentFile().mkdirs();
                    }
                    Files.copy(materialFile.toPath(), itemMaterialFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
                }
            } catch (IOException e) {
                log.error("", e);
            }
        }
    }
    return qitem;
}
Also used : ManifestBuilder(org.olat.ims.qti21.model.xml.ManifestBuilder) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) AssessmentItemMetadata(org.olat.ims.qti21.model.xml.AssessmentItemMetadata) ResourceType(org.olat.imscp.xml.manifest.ResourceType) IOException(java.io.IOException) File(java.io.File) ManifestMetadataBuilder(org.olat.ims.qti21.model.xml.ManifestMetadataBuilder)

Aggregations

QuestionItemImpl (org.olat.modules.qpool.model.QuestionItemImpl)108 QuestionItem (org.olat.modules.qpool.QuestionItem)32 Test (org.junit.Test)20 QuestionItemAuditLogBuilder (org.olat.modules.qpool.QuestionItemAuditLogBuilder)16 TaxonomyLevel (org.olat.modules.taxonomy.TaxonomyLevel)16 Identity (org.olat.core.id.Identity)14 VFSContainer (org.olat.core.util.vfs.VFSContainer)14 QuestionItemView (org.olat.modules.qpool.QuestionItemView)14 File (java.io.File)12 VFSItem (org.olat.core.util.vfs.VFSItem)12 VFSLeaf (org.olat.core.util.vfs.VFSLeaf)12 QItemEdited (org.olat.modules.qpool.ui.events.QItemEdited)12 ArrayList (java.util.ArrayList)10 QItemType (org.olat.modules.qpool.model.QItemType)10 SearchQuestionItemParams (org.olat.modules.qpool.model.SearchQuestionItemParams)10 ManifestBuilder (org.olat.ims.qti21.model.xml.ManifestBuilder)8 AssessmentItem (uk.ac.ed.ph.jqtiplus.node.item.AssessmentItem)8 ResolvedAssessmentItem (uk.ac.ed.ph.jqtiplus.resolution.ResolvedAssessmentItem)8 QuestionItemShort (org.olat.modules.qpool.QuestionItemShort)7 Taxonomy (org.olat.modules.taxonomy.Taxonomy)7