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;
}
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);
}
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);
}
}
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);
}
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;
}
Aggregations