Search in sources :

Example 26 with Pool

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

the class QuestionPoolMenuTreeModel method buildPoolTreeNodes.

private void buildPoolTreeNodes(TreeNode parentNode) {
    if (!securityCallback.canUsePools())
        return;
    List<Pool> pools = qpoolService.getPools(identity, roles).stream().sorted(Comparator.comparing(Pool::getName)).collect(Collectors.toList());
    for (Pool pool : pools) {
        TreeNode node = new PoolTreeNode(stackPanel, securityCallback, pool);
        parentNode.addChild(node);
    }
}
Also used : GenericTreeNode(org.olat.core.gui.components.tree.GenericTreeNode) TreeNode(org.olat.core.gui.components.tree.TreeNode) QuestionItem2Pool(org.olat.modules.qpool.QuestionItem2Pool) Pool(org.olat.modules.qpool.Pool)

Example 27 with Pool

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

the class PoolsController method formInnerEvent.

@Override
protected void formInnerEvent(UserRequest ureq, FormItem source, FormEvent event) {
    if (source == poolTable) {
        if (event instanceof SelectionEvent) {
            SelectionEvent se = (SelectionEvent) event;
            if ("select-pool".equals(se.getCommand())) {
                Pool row = model.getObject(se.getIndex());
                fireEvent(ureq, new QPoolSelectionEvent(Collections.singletonList(row)));
            }
        }
    } else if (source == selectButton) {
        Set<Integer> selectIndexes = poolTable.getMultiSelectedIndex();
        if (!selectIndexes.isEmpty()) {
            List<Pool> rows = new ArrayList<Pool>(selectIndexes.size());
            for (Integer index : selectIndexes) {
                Pool row = model.getObject(index.intValue());
                rows.add(row);
            }
            fireEvent(ureq, new QPoolSelectionEvent(rows));
        }
    }
    super.formInnerEvent(ureq, source, event);
}
Also used : Set(java.util.Set) QPoolSelectionEvent(org.olat.modules.qpool.ui.events.QPoolSelectionEvent) QPoolSelectionEvent(org.olat.modules.qpool.ui.events.QPoolSelectionEvent) SelectionEvent(org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionEvent) Pool(org.olat.modules.qpool.Pool) ArrayList(java.util.ArrayList) List(java.util.List)

Example 28 with Pool

use of org.olat.modules.qpool.Pool 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 29 with Pool

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

the class ShareItemOptionController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    StringBuilder names = new StringBuilder();
    if (groups != null && !groups.isEmpty()) {
        for (BusinessGroup group : groups) {
            if (names.length() > 0)
                names.append(", ");
            names.append(group.getName());
        }
    }
    if (pools != null && !pools.isEmpty()) {
        for (Pool pool : pools) {
            if (names.length() > 0)
                names.append(", ");
            names.append(pool.getName());
        }
    }
    if (formLayout instanceof FormLayoutContainer) {
        ((FormLayoutContainer) formLayout).contextPut("shares", names.toString());
    }
    FormLayoutContainer mailCont = FormLayoutContainer.createDefaultFormLayout("editable", getTranslator());
    formLayout.add(mailCont);
    String[] values = new String[] { translate("yes"), translate("no") };
    editableEl = uifactory.addRadiosVertical("share.editable", "share.editable", mailCont, keys, values);
    editableEl.select("no", true);
    FormLayoutContainer buttonsCont = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
    buttonsCont.setRootForm(mainForm);
    formLayout.add(buttonsCont);
    uifactory.addFormSubmitButton("ok", "ok", buttonsCont);
    uifactory.addFormCancelButton("cancel", buttonsCont, ureq, getWindowControl());
}
Also used : BusinessGroup(org.olat.group.BusinessGroup) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer) Pool(org.olat.modules.qpool.Pool)

Example 30 with Pool

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

the class PoolDAO method addItemToPool.

public void addItemToPool(QuestionItemShort item, List<Pool> pools, boolean editable) {
    QuestionItem lockedItem = questionItemDao.loadForUpdate(item);
    for (Pool pool : pools) {
        if (!isInPool(lockedItem, pool)) {
            PoolToItem p2i = new PoolToItem();
            p2i.setCreationDate(new Date());
            p2i.setItem(lockedItem);
            p2i.setEditable(editable);
            p2i.setPool(pool);
            dbInstance.getCurrentEntityManager().persist(p2i);
        }
    }
    // release lock asap
    dbInstance.commit();
}
Also used : PoolToItem(org.olat.modules.qpool.model.PoolToItem) QuestionItem2Pool(org.olat.modules.qpool.QuestionItem2Pool) Pool(org.olat.modules.qpool.Pool) QuestionItem(org.olat.modules.qpool.QuestionItem) Date(java.util.Date)

Aggregations

Pool (org.olat.modules.qpool.Pool)52 QuestionItem2Pool (org.olat.modules.qpool.QuestionItem2Pool)32 Test (org.junit.Test)30 Identity (org.olat.core.id.Identity)22 QuestionItem (org.olat.modules.qpool.QuestionItem)20 QItemType (org.olat.modules.qpool.model.QItemType)12 SearchQuestionItemParams (org.olat.modules.qpool.model.SearchQuestionItemParams)12 QuestionItemView (org.olat.modules.qpool.QuestionItemView)10 BusinessGroup (org.olat.group.BusinessGroup)8 ArrayList (java.util.ArrayList)6 List (java.util.List)4 SelectionEvent (org.olat.core.gui.components.form.flexible.impl.elements.table.SelectionEvent)4 TreeNode (org.olat.core.gui.components.tree.TreeNode)4 QuestionItemShort (org.olat.modules.qpool.QuestionItemShort)4 PoolItemsSource (org.olat.modules.qpool.ui.datasource.PoolItemsSource)4 Date (java.util.Date)2 Set (java.util.Set)2 StringTokenizer (java.util.StringTokenizer)2 Document (org.apache.lucene.document.Document)2 StringField (org.apache.lucene.document.StringField)2