Search in sources :

Example 46 with QuestionItemImpl

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

the class GeneralMetadataEditController method buildTaxonomyLevelEl.

private void buildTaxonomyLevelEl() {
    qpoolTaxonomyTreeBuilder.loadTaxonomyLevelsSelection(getIdentity(), securityCallback.canRemoveTaxonomy(), ignoreCompetences);
    String[] selectableKeys = qpoolTaxonomyTreeBuilder.getSelectableKeys();
    String[] selectableValues = qpoolTaxonomyTreeBuilder.getSelectableValues();
    taxonomyLevelEl.setKeysAndValues(selectableKeys, selectableValues, null);
    if (item instanceof QuestionItemImpl) {
        QuestionItemImpl itemImpl = (QuestionItemImpl) item;
        TaxonomyLevel selectedTaxonomyLevel = itemImpl.getTaxonomyLevel();
        if (selectedTaxonomyLevel != null) {
            String selectedTaxonomyLevelKey = String.valueOf(selectedTaxonomyLevel.getKey());
            for (String taxonomyKey : qpoolTaxonomyTreeBuilder.getSelectableKeys()) {
                if (taxonomyKey.equals(selectedTaxonomyLevelKey)) {
                    taxonomyLevelEl.select(taxonomyKey, true);
                }
            }
            if (!taxonomyLevelEl.isOneSelected() && itemImpl.getTaxonomyLevel() != null) {
                if (selectableKeys.length == 0) {
                    selectableKeys = new String[] { "dummy" };
                    selectableValues = new String[1];
                }
                selectableValues[0] = itemImpl.getTaxonomyLevel().getDisplayName();
                taxonomyLevelEl.setEnabled(false);
            }
        }
    }
    taxonomyLevelEl.addActionListener(FormEvent.ONCHANGE);
    setTaxonomicPath();
}
Also used : QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) TaxonomyLevel(org.olat.modules.taxonomy.TaxonomyLevel)

Example 47 with QuestionItemImpl

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

the class QuestionItemDAO method addAuthors.

public void addAuthors(List<Identity> authors, QuestionItemShort item) {
    QuestionItemImpl lockedItem = loadForUpdate(item);
    SecurityGroup secGroup = lockedItem.getOwnerGroup();
    for (Identity author : authors) {
        if (!securityManager.isIdentityInSecurityGroup(author, secGroup)) {
            securityManager.addIdentityToSecurityGroup(author, secGroup);
        }
    }
    dbInstance.commit();
}
Also used : QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) SecurityGroup(org.olat.basesecurity.SecurityGroup) Identity(org.olat.core.id.Identity)

Example 48 with QuestionItemImpl

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

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 49 with QuestionItemImpl

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

the class QuestionItemDocumentFactory method createDocument.

public Document createDocument(SearchResourceContext searchResourceContext, QuestionItemFull item) {
    OlatDocument oDocument = new OlatDocument();
    oDocument.setId(item.getKey());
    oDocument.setCreatedDate(item.getCreationDate());
    oDocument.setLastChange(item.getLastModified());
    oDocument.setTitle(item.getTitle());
    oDocument.setDescription(item.getDescription());
    oDocument.setResourceUrl(getResourceUrl(item.getKey()));
    oDocument.setDocumentType(QItemDocument.TYPE);
    oDocument.setCssIcon("o_qitem_icon");
    oDocument.setParentContextType(searchResourceContext.getParentContextType());
    oDocument.setParentContextName(searchResourceContext.getParentContextName());
    // author
    StringBuilder authorSb = new StringBuilder();
    List<Identity> owners = qpoolService.getAuthors(item);
    for (Identity owner : owners) {
        User user = owner.getUser();
        authorSb.append(user.getProperty(UserConstants.FIRSTNAME, null)).append(" ").append(user.getProperty(UserConstants.LASTNAME, null)).append(" ");
    }
    oDocument.setAuthor(authorSb.toString());
    // add specific fields
    Document document = oDocument.getLuceneDocument();
    // content
    QPoolSPI provider = qpoolModule.getQuestionPoolProvider(item.getFormat());
    if (provider != null) {
        String content = provider.extractTextContent(item);
        if (content != null) {
            addStringField(document, AbstractOlatDocument.CONTENT_FIELD_NAME, content, 0.8f);
        }
    }
    if (item.getDescription() != null) {
        addStringField(document, AbstractOlatDocument.CONTENT_FIELD_NAME, item.getDescription(), 1.0f);
    }
    // general fields
    addStringField(document, QItemDocument.IDENTIFIER_FIELD, item.getIdentifier(), 1.0f);
    addStringField(document, QItemDocument.MASTER_IDENTIFIER_FIELD, item.getMasterIdentifier(), 1.0f);
    addTextField(document, QItemDocument.KEYWORDS_FIELD, item.getKeywords(), 2.0f);
    addTextField(document, QItemDocument.COVERAGE_FIELD, item.getCoverage(), 2.0f);
    addTextField(document, QItemDocument.ADD_INFOS_FIELD, item.getAdditionalInformations(), 2.0f);
    addStringField(document, QItemDocument.LANGUAGE_FIELD, item.getLanguage(), 1.0f);
    addTextField(document, QItemDocument.TOPIC_FIELD, item.getTopic(), 2.0f);
    // educational
    if (qpoolModule.isEducationalContextEnabled()) {
        if (item.getEducationalContext() != null) {
            String context = item.getEducationalContext().getLevel();
            addStringField(document, QItemDocument.EDU_CONTEXT_FIELD, context, 1.0f);
        }
    }
    // question
    if (item.getType() != null) {
        String itemType = item.getType().getType();
        addStringField(document, QItemDocument.ITEM_TYPE_FIELD, itemType, 1.0f);
    }
    addStringField(document, QItemDocument.ASSESSMENT_TYPE_FIELD, item.getAssessmentType(), 1.0f);
    // lifecycle
    addStringField(document, QItemDocument.ITEM_VERSION_FIELD, item.getItemVersion(), 1.0f);
    if (item.getQuestionStatus() != null) {
        addStringField(document, QItemDocument.ITEM_STATUS_FIELD, item.getQuestionStatus().name(), 1.0f);
    }
    // rights
    ResourceLicense license = licenseService.loadLicense(item);
    if (license != null && license.getLicenseType() != null) {
        String licenseKey = String.valueOf(license.getLicenseType().getKey());
        addTextField(document, QItemDocument.LICENSE_TYPE_FIELD_NAME, licenseKey, 2.0f);
    }
    // technical
    addTextField(document, QItemDocument.EDITOR_FIELD, item.getEditor(), 2.0f);
    addStringField(document, QItemDocument.EDITOR_VERSION_FIELD, item.getEditorVersion(), 1.0f);
    addStringField(document, QItemDocument.FORMAT_FIELD, item.getFormat(), 1.0f);
    // save owners key
    for (Identity owner : owners) {
        document.add(new StringField(QItemDocument.OWNER_FIELD, owner.getKey().toString(), Field.Store.NO));
    }
    // link resources
    List<OLATResource> resources = questionItemDao.getSharedResources(item);
    for (OLATResource resource : resources) {
        document.add(new StringField(QItemDocument.SHARE_FIELD, resource.getKey().toString(), Field.Store.NO));
    }
    // need pools
    List<Pool> pools = poolDao.getPools(item);
    for (Pool pool : pools) {
        document.add(new StringField(QItemDocument.POOL_FIELD, pool.getKey().toString(), Field.Store.NO));
    }
    // need path
    if (qpoolModule.isTaxonomyEnabled()) {
        String path = item.getTaxonomicPath();
        if (StringHelper.containsNonWhitespace(path)) {
            for (StringTokenizer tokenizer = new StringTokenizer(path, "/"); tokenizer.hasMoreTokens(); ) {
                String nextToken = tokenizer.nextToken();
                document.add(new TextField(QItemDocument.TAXONOMIC_PATH_FIELD, nextToken, Field.Store.NO));
            }
            if (item instanceof QuestionItemImpl) {
                Long key = ((QuestionItemImpl) item).getTaxonomyLevel().getKey();
                TextField field = new TextField(QItemDocument.TAXONOMIC_FIELD, key.toString(), Field.Store.YES);
                field.setBoost(3.0f);
                document.add(field);
            }
        }
    }
    return document;
}
Also used : User(org.olat.core.id.User) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) OLATResource(org.olat.resource.OLATResource) Document(org.apache.lucene.document.Document) AbstractOlatDocument(org.olat.search.model.AbstractOlatDocument) OlatDocument(org.olat.search.model.OlatDocument) QItemDocument(org.olat.modules.qpool.model.QItemDocument) ResourceLicense(org.olat.core.commons.services.license.ResourceLicense) AbstractOlatDocument(org.olat.search.model.AbstractOlatDocument) OlatDocument(org.olat.search.model.OlatDocument) StringTokenizer(java.util.StringTokenizer) QPoolSPI(org.olat.modules.qpool.QPoolSPI) StringField(org.apache.lucene.document.StringField) TextField(org.apache.lucene.document.TextField) Pool(org.olat.modules.qpool.Pool) Identity(org.olat.core.id.Identity)

Example 50 with QuestionItemImpl

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

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;
}
Also used : QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) VFSContainer(org.olat.core.util.vfs.VFSContainer) VFSItem(org.olat.core.util.vfs.VFSItem)

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