Search in sources :

Example 6 with QPoolSPI

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

the class QuestionPoolServiceImpl method copyItems.

@Override
public List<QuestionItem> copyItems(Identity owner, List<QuestionItemShort> itemsToCopy) {
    List<QuestionItem> copies = new ArrayList<>();
    for (QuestionItemShort itemToCopy : itemsToCopy) {
        QuestionItemImpl original = questionItemDao.loadById(itemToCopy.getKey());
        QuestionItemImpl copy = questionItemDao.copy(original);
        questionItemDao.persist(owner, copy);
        QPoolSPI provider = qpoolModule.getQuestionPoolProvider(copy.getFormat());
        if (provider != null) {
            provider.copyItem(original, copy);
        }
        licenseService.copy(original, copy);
        copies.add(copy);
    }
    dbInstance.commit();
    index(copies);
    return copies;
}
Also used : QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) QPoolSPI(org.olat.modules.qpool.QPoolSPI) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) ArrayList(java.util.ArrayList) QuestionItem(org.olat.modules.qpool.QuestionItem)

Example 7 with QPoolSPI

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

the class QuestionPoolServiceImplTest method shouldGetExportFormatOptions.

@Test
public void shouldGetExportFormatOptions() {
    String formatA = "A";
    String formatB = "B";
    QuestionItemImpl formatAItem = new QuestionItemImpl();
    formatAItem.setFormat(formatA);
    List<QuestionItemShort> items = Arrays.asList(formatAItem);
    ExportFormatOptions exportFormatAR = new DefaultExportFormat(formatA, Outcome.repository, null);
    ExportFormatOptions exportFormatAD = new DefaultExportFormat(formatA, Outcome.download, null);
    List<ExportFormatOptions> exportFormatsA = Arrays.asList(exportFormatAD, exportFormatAR);
    ExportFormatOptions exportFormatBR = new DefaultExportFormat(formatA, Outcome.repository, null);
    List<ExportFormatOptions> exportFormatsB = Arrays.asList(exportFormatBR);
    QPoolSPI spiA = mock(QPoolSPI.class);
    when(spiA.getTestExportFormats()).thenReturn(exportFormatsA);
    when(qPoolModuleMock.getQuestionPoolProvider(formatA)).thenReturn(spiA);
    QPoolSPI spiB = mock(QPoolSPI.class);
    when(spiB.getTestExportFormats()).thenReturn(exportFormatsB);
    when(qPoolModuleMock.getQuestionPoolProvider(formatB)).thenReturn(spiB);
    Set<ExportFormatOptions> exportFormatOptions = sut.getExportFormatOptions(items, Outcome.repository);
    assertThat(exportFormatOptions).hasSize(1).containsExactly(exportFormatAR);
}
Also used : ExportFormatOptions(org.olat.modules.qpool.ExportFormatOptions) QuestionItemImpl(org.olat.modules.qpool.model.QuestionItemImpl) QPoolSPI(org.olat.modules.qpool.QPoolSPI) QuestionItemShort(org.olat.modules.qpool.QuestionItemShort) DefaultExportFormat(org.olat.modules.qpool.model.DefaultExportFormat) Test(org.junit.Test)

Example 8 with QPoolSPI

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

the class QuestionListController method doConfirmConversion.

private void doConfirmConversion(UserRequest ureq, List<QuestionItemShort> items) {
    Map<String, List<QuestionItemShort>> formatToItems = new HashMap<>();
    List<QPoolSPI> spies = qpoolModule.getQuestionPoolProviders();
    for (QuestionItemShort item : items) {
        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<>(items.size());
                    formatToItems.put(sp.getFormat(), convertItems);
                }
                convertItems.add(item);
            }
        }
    }
    if (formatToItems.isEmpty()) {
        showWarning("convert.item.not.possible");
    } else {
        conversionConfirmationCtrl = new ConversionConfirmationController(ureq, getWindowControl(), formatToItems, getSource());
        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) QItemList(org.olat.modules.qpool.model.QItemList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 9 with QPoolSPI

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

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 10 with QPoolSPI

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

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