Search in sources :

Example 1 with QPoolSPI

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

the class QuestionItemDetailsController method doConfirmConversion.

private void doConfirmConversion(UserRequest ureq, QuestionItemShort item) {
    Map<String, List<QuestionItemShort>> formatToItems = new HashMap<>();
    List<QPoolSPI> spies = poolModule.getQuestionPoolProviders();
    for (QPoolSPI sp : spies) {
        if (sp != null && sp.isConversionPossible(item)) {
            List<QuestionItemShort> convertItems;
            if (formatToItems.containsKey(sp.getFormat())) {
                convertItems = formatToItems.get(sp.getFormat());
            } else {
                convertItems = new ArrayList<>(1);
                formatToItems.put(sp.getFormat(), Collections.singletonList(item));
            }
            convertItems.add(item);
        }
    }
    conversionConfirmationCtrl = new ConversionConfirmationController(ureq, getWindowControl(), formatToItems, itemSource);
    listenTo(conversionConfirmationCtrl);
    cmc = new CloseableModalController(getWindowControl(), translate("close"), conversionConfirmationCtrl.getInitialComponent(), true, translate("convert.item"));
    cmc.activate();
    listenTo(cmc);
}
Also used : HashMap(java.util.HashMap) QPoolSPI(org.olat.modules.qpool.QPoolSPI) CloseableModalController(org.olat.core.gui.control.generic.closablewrapper.CloseableModalController) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with QPoolSPI

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

the class QuestionItemDetailsController method setQuestionController.

private void setQuestionController(UserRequest ureq, QuestionItem item, QuestionItemSecurityCallback securityCallback) {
    removeAsListenerAndDispose(questionCtrl);
    questionCtrl = null;
    QPoolSPI spi = poolModule.getQuestionPoolProvider(item.getFormat());
    boolean canEditContent = securityCallback.canEditQuestion() && (spi != null && spi.isTypeEditable());
    if (canEditContent && !lock.isSuccess()) {
        canEditContent = false;
        String displayName = "???";
        if (lock.getOwner() != null) {
            displayName = userManager.getUserDisplayName(lock.getOwner());
        }
        showWarning("locked.readonly", new String[] { displayName });
    }
    if (spi != null) {
        if (canEditContent) {
            questionCtrl = spi.getEditableController(ureq, getWindowControl(), item);
        } else {
            questionCtrl = spi.getReadOnlyController(ureq, getWindowControl(), item);
        }
    }
    if (questionCtrl == null && spi != null) {
        questionCtrl = spi.getPreviewController(ureq, getWindowControl(), item, false);
    }
    if (questionCtrl == null) {
        questionCtrl = new QuestionItemRawController(ureq, getWindowControl());
    }
    listenTo(questionCtrl);
    if (mainVC != null) {
        mainVC.put("type_specifics", questionCtrl.getInitialComponent());
    }
}
Also used : QPoolSPI(org.olat.modules.qpool.QPoolSPI)

Example 3 with QPoolSPI

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

the class NewItemOptionsController method initForm.

@Override
protected void initForm(FormItemContainer formLayout, Controller listener, UserRequest ureq) {
    // title
    titleEl = uifactory.addTextElement("general.title", "general.title", 128, "", formLayout);
    // type
    List<QItemFactory> factories = new ArrayList<>();
    for (QPoolSPI spi : qpoolModule.getQuestionPoolProviders()) {
        for (QItemFactory factory : spi.getItemfactories()) {
            factories.add(factory);
        }
    }
    int count = 0;
    String[] typeKeys = new String[factories.size()];
    String[] valueKeys = new String[factories.size()];
    for (QItemFactory factory : factories) {
        String typeKey = "item.type." + count;
        typeKeys[count] = typeKey;
        keyToFactoryMap.put(typeKey, factory);
        valueKeys[count] = factory.getLabel(getLocale());
        count++;
    }
    typeEl = uifactory.addDropdownSingleselect("question.type", "menu.admin.types", formLayout, typeKeys, valueKeys, null);
    // subject
    taxonomyLevelEl = uifactory.addDropdownSingleselect("process.start.review.taxonomy.level", formLayout, qpoolTaxonomyTreeBuilder.getSelectableKeys(), qpoolTaxonomyTreeBuilder.getSelectableValues(), null);
    if (selectedTaxonomyLevel != null) {
        String selectedTaxonomyLevelKey = String.valueOf(selectedTaxonomyLevel.getKey());
        for (String taxonomyKey : qpoolTaxonomyTreeBuilder.getSelectableKeys()) {
            if (taxonomyKey.equals(selectedTaxonomyLevelKey)) {
                taxonomyLevelEl.select(taxonomyKey, true);
            }
        }
    }
    taxonomyLevelEl.setVisible(qPoolSecurityCallback.canUseTaxonomy());
    FormLayoutContainer buttonLayout = FormLayoutContainer.createButtonLayout("buttons", getTranslator());
    buttonLayout.setRootForm(mainForm);
    formLayout.add(buttonLayout);
    uifactory.addFormSubmitButton("new.item", buttonLayout);
    uifactory.addFormCancelButton("cancel", buttonLayout, ureq, getWindowControl());
}
Also used : QItemFactory(org.olat.modules.qpool.QItemFactory) QPoolSPI(org.olat.modules.qpool.QPoolSPI) ArrayList(java.util.ArrayList) FormLayoutContainer(org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)

Example 4 with QPoolSPI

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

the class QuestionItemPreviewController method updateItem.

public void updateItem(UserRequest ureq, QuestionItem updatedItem) {
    this.item = updatedItem;
    removeAsListenerAndDispose(previewCtrl);
    if (updatedItem == null) {
        previewCtrl = null;
        previewPanel.setContent(null);
    } else {
        Component content;
        QPoolSPI spi = poolModule.getQuestionPoolProvider(updatedItem.getFormat());
        if (spi == null) {
            content = getRawContent();
        } else {
            previewCtrl = spi.getPreviewController(ureq, getWindowControl(), updatedItem, true);
            if (previewCtrl == null) {
                content = getRawContent();
            } else {
                listenTo(previewCtrl);
                content = previewCtrl.getInitialComponent();
            }
        }
        previewPanel.setContent(content);
    }
}
Also used : QPoolSPI(org.olat.modules.qpool.QPoolSPI) Component(org.olat.core.gui.components.Component)

Example 5 with QPoolSPI

use of org.olat.modules.qpool.QPoolSPI 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)

Aggregations

QPoolSPI (org.olat.modules.qpool.QPoolSPI)24 ArrayList (java.util.ArrayList)10 QuestionItemShort (org.olat.modules.qpool.QuestionItemShort)10 QuestionItem (org.olat.modules.qpool.QuestionItem)6 QuestionItemImpl (org.olat.modules.qpool.model.QuestionItemImpl)6 HashMap (java.util.HashMap)4 List (java.util.List)4 CloseableModalController (org.olat.core.gui.control.generic.closablewrapper.CloseableModalController)4 QuestionItemFull (org.olat.modules.qpool.QuestionItemFull)4 StringTokenizer (java.util.StringTokenizer)2 Document (org.apache.lucene.document.Document)2 StringField (org.apache.lucene.document.StringField)2 TextField (org.apache.lucene.document.TextField)2 Test (org.junit.Test)2 ResourceLicense (org.olat.core.commons.services.license.ResourceLicense)2 Component (org.olat.core.gui.components.Component)2 FormLayoutContainer (org.olat.core.gui.components.form.flexible.impl.FormLayoutContainer)2 MediaResource (org.olat.core.gui.media.MediaResource)2 Identity (org.olat.core.id.Identity)2 User (org.olat.core.id.User)2