Search in sources :

Example 11 with Pool

use of org.olat.modules.qpool.Pool in project OpenOLAT by OpenOLAT.

the class ItemListMySharesController method initButtons.

@Override
protected void initButtons(UserRequest ureq, FormItemContainer formLayout) {
    getItemsTable().setMultiSelect(true);
    selectLink = uifactory.addFormLink("select-to-import", "select", null, formLayout, Link.BUTTON);
    Roles roles = ureq.getUserSession().getRoles();
    if (qpoolModule.isPoolsEnabled()) {
        myPools = qpoolService.getPools(getIdentity(), roles);
    } else {
        myPools = Collections.emptyList();
    }
    if (qpoolModule.isSharesEnabled()) {
        myGroups = qpoolService.getResourcesWithSharedItems(getIdentity());
    } else {
        myGroups = Collections.emptyList();
    }
    String[] myShareKeys;
    String[] myShareValues;
    if (myPools.isEmpty() && myGroups.isEmpty()) {
        myShareKeys = new String[1];
        myShareValues = new String[1];
        myShareKeys[0] = "";
        myShareValues[0] = "";
    } else {
        int numOfShares = myPools.size() + myGroups.size();
        myShareKeys = new String[numOfShares];
        myShareValues = new String[numOfShares];
        int pos = 0;
        for (Pool myPool : myPools) {
            myShareKeys[pos] = "pool" + myPool.getKey().toString();
            myShareValues[pos++] = myPool.getName();
        }
        for (BusinessGroup group : myGroups) {
            myShareKeys[pos] = "grou" + group.getKey().toString();
            myShareValues[pos++] = group.getName();
        }
    }
    myShareEl = uifactory.addDropdownSingleselect("source.selector", "my.list", formLayout, myShareKeys, myShareValues, null);
    myShareEl.setDomReplacementWrapperRequired(false);
    myShareEl.getLabelC().setDomReplaceable(false);
    myShareEl.addActionListener(FormEvent.ONCHANGE);
    if (myPools.isEmpty() && myGroups.isEmpty()) {
        myShareEl.setEnabled(false);
    } else {
        myShareEl.select(myShareKeys[0], true);
        if (myPools.size() > 0) {
            Pool firstPool = myPools.get(0);
            PoolItemsSource source = new PoolItemsSource(getIdentity(), roles, firstPool);
            source.getDefaultParams().setFormat(restrictToFormat);
            updateSource(source);
        } else if (myGroups.size() > 0) {
            BusinessGroup firstGroup = myGroups.get(0);
            SharedItemsSource source = new SharedItemsSource(firstGroup, getIdentity(), roles, false);
            source.setRestrictToFormat(restrictToFormat);
            updateSource(source);
        }
    }
}
Also used : PoolItemsSource(org.olat.modules.qpool.ui.datasource.PoolItemsSource) SharedItemsSource(org.olat.modules.qpool.ui.datasource.SharedItemsSource) BusinessGroup(org.olat.group.BusinessGroup) Roles(org.olat.core.id.Roles) Pool(org.olat.modules.qpool.Pool)

Example 12 with Pool

use of org.olat.modules.qpool.Pool in project OpenOLAT by OpenOLAT.

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)

Example 13 with Pool

use of org.olat.modules.qpool.Pool in project OpenOLAT by OpenOLAT.

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 14 with Pool

use of org.olat.modules.qpool.Pool in project OpenOLAT by OpenOLAT.

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 15 with Pool

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

the class PoolDAOTest method isMemberOfPrivatePools_poolOnly.

@Test
public void isMemberOfPrivatePools_poolOnly() {
    Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Pool-owner-" + UUID.randomUUID().toString());
    Pool pool = poolDao.createPool(id, "NGC owned", false);
    Assert.assertNotNull(pool);
    dbInstance.commitAndCloseSession();
    boolean isMember = poolDao.isMemberOfPrivatePools(id);
    Assert.assertTrue(isMember);
}
Also used : QuestionItem2Pool(org.olat.modules.qpool.QuestionItem2Pool) Pool(org.olat.modules.qpool.Pool) Identity(org.olat.core.id.Identity) Test(org.junit.Test)

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