diff --git a/pom.xml b/pom.xml index a29614a4ae1728c28df36b49d0a62bc829bfbecd..f6b31a3a840aa18973a16453b9bdcb0f049e8dc8 100644 --- a/pom.xml +++ b/pom.xml @@ -70,7 +70,7 @@ <org.mysql.version>5.1.46</org.mysql.version> <org.postgresql.version>42.2.5</org.postgresql.version> <org.infinispan.version>9.2.3.Final</org.infinispan.version> - <lucene.version>4.8.0</lucene.version> + <lucene.version>7.5.0</lucene.version> <version.selenium>3.13.0</version.selenium> <version.drone>2.5.1</version.drone> <activemq.version>5.11.1</activemq.version> diff --git a/src/main/java/org/olat/modules/qpool/manager/QuestionItemDocumentFactory.java b/src/main/java/org/olat/modules/qpool/manager/QuestionItemDocumentFactory.java index 99494efc12d03866f50d983c41ee27a982cad571..d36d4b466756d604f0c22df1e2cd1383e00b8f2e 100644 --- a/src/main/java/org/olat/modules/qpool/manager/QuestionItemDocumentFactory.java +++ b/src/main/java/org/olat/modules/qpool/manager/QuestionItemDocumentFactory.java @@ -111,54 +111,54 @@ public class QuestionItemDocumentFactory { if(provider != null) { String content = provider.extractTextContent(item); if(content != null) { - addStringField(document, AbstractOlatDocument.CONTENT_FIELD_NAME, content, 0.8f); + addStringField(document, AbstractOlatDocument.CONTENT_FIELD_NAME, content); } } if(item.getDescription() != null) { - addStringField(document, AbstractOlatDocument.CONTENT_FIELD_NAME, item.getDescription(), 1.0f); + addStringField(document, AbstractOlatDocument.CONTENT_FIELD_NAME, item.getDescription()); } //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); + addStringField(document, QItemDocument.IDENTIFIER_FIELD, item.getIdentifier()); + addStringField(document, QItemDocument.MASTER_IDENTIFIER_FIELD, item.getMasterIdentifier()); + addTextField(document, QItemDocument.KEYWORDS_FIELD, item.getKeywords()); + addTextField(document, QItemDocument.COVERAGE_FIELD, item.getCoverage()); + addTextField(document, QItemDocument.ADD_INFOS_FIELD, item.getAdditionalInformations()); + addStringField(document, QItemDocument.LANGUAGE_FIELD, item.getLanguage()); + addTextField(document, QItemDocument.TOPIC_FIELD, item.getTopic()); //educational if (qpoolModule.isEducationalContextEnabled()) { if(item.getEducationalContext() != null) { String context = item.getEducationalContext().getLevel(); - addStringField(document, QItemDocument.EDU_CONTEXT_FIELD, context, 1.0f); + addStringField(document, QItemDocument.EDU_CONTEXT_FIELD, context); } } //question if(item.getType() != null) { String itemType = item.getType().getType(); - addStringField(document, QItemDocument.ITEM_TYPE_FIELD, itemType, 1.0f); + addStringField(document, QItemDocument.ITEM_TYPE_FIELD, itemType); } - addStringField(document, QItemDocument.ASSESSMENT_TYPE_FIELD, item.getAssessmentType(), 1.0f); + addStringField(document, QItemDocument.ASSESSMENT_TYPE_FIELD, item.getAssessmentType()); //lifecycle - addStringField(document, QItemDocument.ITEM_VERSION_FIELD, item.getItemVersion(), 1.0f); + addStringField(document, QItemDocument.ITEM_VERSION_FIELD, item.getItemVersion()); if(item.getQuestionStatus() != null) { - addStringField(document, QItemDocument.ITEM_STATUS_FIELD, item.getQuestionStatus().name(), 1.0f); + addStringField(document, QItemDocument.ITEM_STATUS_FIELD, item.getQuestionStatus().name()); } //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); + addTextField(document, QItemDocument.LICENSE_TYPE_FIELD_NAME, licenseKey); } //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); + addTextField(document, QItemDocument.EDITOR_FIELD, item.getEditor()); + addStringField(document, QItemDocument.EDITOR_VERSION_FIELD, item.getEditorVersion()); + addStringField(document, QItemDocument.FORMAT_FIELD, item.getFormat()); //save owners key for(Identity owner:owners) { @@ -189,7 +189,6 @@ public class QuestionItemDocumentFactory { 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); } } @@ -197,10 +196,9 @@ public class QuestionItemDocumentFactory { return document; } - private void addStringField(Document doc, String fieldName, String content, float boost) { + private void addStringField(Document doc, String fieldName, String content) { if(StringHelper.containsNonWhitespace(content)) { TextField field = new TextField(fieldName, content, Field.Store.YES); - field.setBoost(boost); doc.add(field); } } @@ -212,10 +210,9 @@ public class QuestionItemDocumentFactory { * @param boost * @return */ - private void addTextField(Document doc, String fieldName, String content, float boost) { + private void addTextField(Document doc, String fieldName, String content) { if(StringHelper.containsNonWhitespace(content)) { TextField field = new TextField(fieldName, content, Field.Store.YES); - field.setBoost(boost); doc.add(field); } } diff --git a/src/main/java/org/olat/modules/qpool/manager/QuestionPoolServiceImpl.java b/src/main/java/org/olat/modules/qpool/manager/QuestionPoolServiceImpl.java index 24d9790d9de03fb543fe0bf5dcd48dc4792eac46..6ea8c1396e0cef56b5fb5ad26ac927627f9a489c 100644 --- a/src/main/java/org/olat/modules/qpool/manager/QuestionPoolServiceImpl.java +++ b/src/main/java/org/olat/modules/qpool/manager/QuestionPoolServiceImpl.java @@ -580,7 +580,7 @@ public class QuestionPoolServiceImpl implements QPoolService { } addConditionsOfParams(condQueries, searchParams); List<Long> results = searchClient.doSearch(queryString, condQueries, searchParams.getIdentity(), - searchParams.getRoles(), 0, MAX_NUMBER_DOCS); + searchParams.getRoles(), searchParams.getLocale(), 0, MAX_NUMBER_DOCS); if (!results.isEmpty()) { List<QuestionItemView> items = itemQueriesDao.getItems(searchParams, results, firstResult, maxResults, orderBy); @@ -613,7 +613,7 @@ public class QuestionPoolServiceImpl implements QPoolService { } condQueries.add("pool:" + searchParams.getPoolKey()); List<Long> results = searchClient.doSearch(queryString, condQueries, - searchParams.getIdentity(), searchParams.getRoles(), 0, MAX_NUMBER_DOCS); + searchParams.getIdentity(), searchParams.getRoles(), searchParams.getLocale(), 0, MAX_NUMBER_DOCS); if(results.isEmpty()) { return new DefaultResultInfos<>(); @@ -641,7 +641,7 @@ public class QuestionPoolServiceImpl implements QPoolService { } condQueries.add(QItemDocument.OWNER_FIELD + ":" + author.getKey()); List<Long> results = searchClient.doSearch(queryString, condQueries, - searchParams.getIdentity(), searchParams.getRoles(), 0, MAX_NUMBER_DOCS); + searchParams.getIdentity(), searchParams.getRoles(), searchParams.getLocale(), 0, MAX_NUMBER_DOCS); if(results.isEmpty()) { return new DefaultResultInfos<>(); @@ -681,7 +681,7 @@ public class QuestionPoolServiceImpl implements QPoolService { } condQueries.add(getDbKeyConditionalQuery(favoritKeys)); List<Long> results = searchClient.doSearch(queryString, condQueries, - searchParams.getIdentity(), searchParams.getRoles(), 0, MAX_NUMBER_DOCS); + searchParams.getIdentity(), searchParams.getRoles(), searchParams.getLocale(), 0, MAX_NUMBER_DOCS); if(results.isEmpty()) { return new DefaultResultInfos<>(); @@ -758,7 +758,7 @@ public class QuestionPoolServiceImpl implements QPoolService { } condQueries.add(QItemDocument.SHARE_FIELD + ":" + resource.getKey()); List<Long> results = searchClient.doSearch(queryString, condQueries, - searchParams.getIdentity(), searchParams.getRoles(), 0, MAX_NUMBER_DOCS); + searchParams.getIdentity(), searchParams.getRoles(), searchParams.getLocale(), 0, MAX_NUMBER_DOCS); if(results.isEmpty()) { return new DefaultResultInfos<>(); } @@ -842,7 +842,7 @@ public class QuestionPoolServiceImpl implements QPoolService { } condQueries.add(getDbKeyConditionalQuery(content)); List<Long> results = searchClient.doSearch(queryString, condQueries, - searchParams.getIdentity(), searchParams.getRoles(), 0, MAX_NUMBER_DOCS); + searchParams.getIdentity(), searchParams.getRoles(), searchParams.getLocale(), 0, MAX_NUMBER_DOCS); if(results.isEmpty()) { return new DefaultResultInfos<>(); diff --git a/src/main/java/org/olat/modules/qpool/model/SearchQuestionItemParams.java b/src/main/java/org/olat/modules/qpool/model/SearchQuestionItemParams.java index 615ce133d1bb80843ece8c40309d78dfecbe528e..01a8b3e54885cc3d84d2a22624129d5c02aca8b6 100644 --- a/src/main/java/org/olat/modules/qpool/model/SearchQuestionItemParams.java +++ b/src/main/java/org/olat/modules/qpool/model/SearchQuestionItemParams.java @@ -22,6 +22,7 @@ package org.olat.modules.qpool.model; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import java.util.Locale; import org.olat.core.id.Identity; import org.olat.core.id.Roles; @@ -57,10 +58,12 @@ public class SearchQuestionItemParams { private final Identity identity; private final Roles roles; + private final Locale locale; - public SearchQuestionItemParams(Identity identity, Roles roles) { + public SearchQuestionItemParams(Identity identity, Roles roles, Locale locale) { this.identity = identity; this.roles = roles; + this.locale = locale; } public Long getPoolKey() { @@ -191,9 +194,13 @@ public class SearchQuestionItemParams { return roles; } + public Locale getLocale() { + return locale; + } + @Override public SearchQuestionItemParams clone() { - SearchQuestionItemParams clone = new SearchQuestionItemParams(identity, roles); + SearchQuestionItemParams clone = new SearchQuestionItemParams(identity, roles, locale); clone.poolKey = poolKey; clone.format = format; clone.searchString = searchString; diff --git a/src/main/java/org/olat/modules/qpool/ui/ItemListMyCompetencesController.java b/src/main/java/org/olat/modules/qpool/ui/ItemListMyCompetencesController.java index 4672e2860ef9b2e847dbe9ad82bf475469db4821..df88358e369a5fee053fb609facd4413cec4294d 100644 --- a/src/main/java/org/olat/modules/qpool/ui/ItemListMyCompetencesController.java +++ b/src/main/java/org/olat/modules/qpool/ui/ItemListMyCompetencesController.java @@ -113,7 +113,7 @@ public class ItemListMyCompetencesController extends AbstractItemListController if(level == null) { updateSource(new EmptyItemsSource()); } else { - FinalItemsSource source = new FinalItemsSource(getIdentity(), ureq.getUserSession().getRoles(), level); + FinalItemsSource source = new FinalItemsSource(getIdentity(), ureq.getUserSession().getRoles(), getLocale(), level); source.getDefaultParams().setFormat(restrictToFormat); updateSource(source); } diff --git a/src/main/java/org/olat/modules/qpool/ui/ItemListMyListsController.java b/src/main/java/org/olat/modules/qpool/ui/ItemListMyListsController.java index 235fbc4cb799bd3566322465a77c8ec4fde60d47..d4b0f71acacf9d294cd2d507ab0f2420c402d6d8 100644 --- a/src/main/java/org/olat/modules/qpool/ui/ItemListMyListsController.java +++ b/src/main/java/org/olat/modules/qpool/ui/ItemListMyListsController.java @@ -90,7 +90,7 @@ public class ItemListMyListsController extends AbstractItemListController { myListEl.select(myListKeys[0], true); QuestionItemCollection firstCollection = myCollections.get(0); - CollectionOfItemsSource source = new CollectionOfItemsSource(firstCollection, getIdentity(), ureq.getUserSession().getRoles()); + CollectionOfItemsSource source = new CollectionOfItemsSource(firstCollection, getIdentity(), ureq.getUserSession().getRoles(), getLocale()); source.setRestrictToFormat(restrictToFormat); updateSource(source); } else { @@ -132,7 +132,7 @@ public class ItemListMyListsController extends AbstractItemListController { if(myCollection == null) { updateSource(new EmptyItemsSource()); } else { - CollectionOfItemsSource source = new CollectionOfItemsSource(myCollection, getIdentity(), ureq.getUserSession().getRoles()); + CollectionOfItemsSource source = new CollectionOfItemsSource(myCollection, getIdentity(), ureq.getUserSession().getRoles(), getLocale()); source.setRestrictToFormat(restrictToFormat); updateSource(source); } diff --git a/src/main/java/org/olat/modules/qpool/ui/ItemListMySharesController.java b/src/main/java/org/olat/modules/qpool/ui/ItemListMySharesController.java index 91eea4d660a601e4daac8637c2db1bf5e703897a..6c55a75b49bba7c1b5cfe3e309eefdce27c40150 100644 --- a/src/main/java/org/olat/modules/qpool/ui/ItemListMySharesController.java +++ b/src/main/java/org/olat/modules/qpool/ui/ItemListMySharesController.java @@ -118,12 +118,12 @@ public class ItemListMySharesController extends AbstractItemListController { myShareEl.select(myShareKeys[0], true); if(myPools.size() > 0) { Pool firstPool = myPools.get(0); - PoolItemsSource source = new PoolItemsSource(getIdentity(), roles, firstPool); + PoolItemsSource source = new PoolItemsSource(getIdentity(), roles, getLocale(), 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); + SharedItemsSource source = new SharedItemsSource(firstGroup, getIdentity(), roles, getLocale(), false); source.setRestrictToFormat(restrictToFormat); updateSource(source); } @@ -171,7 +171,7 @@ public class ItemListMySharesController extends AbstractItemListController { if(myPool == null) { updateSource(new EmptyItemsSource()); } else { - PoolItemsSource source = new PoolItemsSource(getIdentity(), ureq.getUserSession().getRoles(), myPool); + PoolItemsSource source = new PoolItemsSource(getIdentity(), ureq.getUserSession().getRoles(), getLocale(), myPool); source.getDefaultParams().setFormat(restrictToFormat); updateSource(source); } @@ -188,7 +188,7 @@ public class ItemListMySharesController extends AbstractItemListController { if(myGroup == null) { updateSource(new EmptyItemsSource()); } else { - SharedItemsSource source = new SharedItemsSource(myGroup, getIdentity(), ureq.getUserSession().getRoles(), false); + SharedItemsSource source = new SharedItemsSource(myGroup, getIdentity(), ureq.getUserSession().getRoles(), getLocale(), false); source.setRestrictToFormat(restrictToFormat); updateSource(source); } diff --git a/src/main/java/org/olat/modules/qpool/ui/SelectItemController.java b/src/main/java/org/olat/modules/qpool/ui/SelectItemController.java index eab6c900faec1cf4d25c066fea3d42eee00b8259..b4dfdc327ffc7223a310fe1d260a0c1ee64b2ef3 100644 --- a/src/main/java/org/olat/modules/qpool/ui/SelectItemController.java +++ b/src/main/java/org/olat/modules/qpool/ui/SelectItemController.java @@ -145,7 +145,7 @@ public class SelectItemController extends BasicController { private int updateMarkedItems(UserRequest ureq) { if(markedItemsCtrl == null) { - DefaultItemsSource source = new MarkedItemsSource(getIdentity(), ureq.getUserSession().getRoles(), "Fav"); + DefaultItemsSource source = new MarkedItemsSource(getIdentity(), ureq.getUserSession().getRoles(), getLocale(), "Fav"); source.getDefaultParams().setFavoritOnly(true); source.getDefaultParams().setFormat(restrictToFormat); markedItemsCtrl = new ItemListController(ureq, getWindowControl(), secCallback, source); @@ -158,7 +158,7 @@ public class SelectItemController extends BasicController { private void updateOwnedGroups(UserRequest ureq) { if(ownedItemsCtrl == null) { - DefaultItemsSource source = new MyItemsSource(getIdentity(), ureq.getUserSession().getRoles(), "My"); + DefaultItemsSource source = new MyItemsSource(getIdentity(), ureq.getUserSession().getRoles(), getLocale(), "My"); source.getDefaultParams().setAuthor(getIdentity()); source.getDefaultParams().setFormat(restrictToFormat); ownedItemsCtrl = new ItemListController(ureq, getWindowControl(), secCallback, source); diff --git a/src/main/java/org/olat/modules/qpool/ui/datasource/AllItemsSource.java b/src/main/java/org/olat/modules/qpool/ui/datasource/AllItemsSource.java index 38f548fb24571a2227d892b44eb09749561b2e8f..da509d3c502854c82d83bf745ca490e5289bd306 100644 --- a/src/main/java/org/olat/modules/qpool/ui/datasource/AllItemsSource.java +++ b/src/main/java/org/olat/modules/qpool/ui/datasource/AllItemsSource.java @@ -20,6 +20,7 @@ package org.olat.modules.qpool.ui.datasource; import java.util.List; +import java.util.Locale; import org.olat.core.gui.translator.Translator; import org.olat.core.id.Identity; @@ -35,8 +36,8 @@ import org.olat.modules.qpool.QuestionStatus; */ public class AllItemsSource extends DefaultItemsSource { - public AllItemsSource(Identity me, Roles roles, String name) { - super(me, roles, name); + public AllItemsSource(Identity me, Roles roles, Locale locale, String name) { + super(me, roles, locale, name); } @Override diff --git a/src/main/java/org/olat/modules/qpool/ui/datasource/CollectionOfItemsSource.java b/src/main/java/org/olat/modules/qpool/ui/datasource/CollectionOfItemsSource.java index 85417e16939954d9eac816c8ab337b20bec29e39..8b16d2707af686f455f27b72bf785e9de75400db 100644 --- a/src/main/java/org/olat/modules/qpool/ui/datasource/CollectionOfItemsSource.java +++ b/src/main/java/org/olat/modules/qpool/ui/datasource/CollectionOfItemsSource.java @@ -22,6 +22,7 @@ package org.olat.modules.qpool.ui.datasource; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Locale; import org.olat.core.CoreSpringFactory; import org.olat.core.commons.persistence.ResultInfos; @@ -51,14 +52,16 @@ import org.olat.modules.qpool.ui.QuestionItemsSource; public class CollectionOfItemsSource implements QuestionItemsSource { private final Roles roles; + private final Locale locale; private final Identity identity; private final QPoolService qpoolService; private final QuestionItemCollection collection; private String restrictToFormat; - public CollectionOfItemsSource(QuestionItemCollection collection, Identity identity, Roles roles) { + public CollectionOfItemsSource(QuestionItemCollection collection, Identity identity, Roles roles, Locale locale) { this.roles = roles; + this.locale = locale; this.identity = identity; this.collection = collection; qpoolService = CoreSpringFactory.getImpl(QPoolService.class); @@ -180,7 +183,7 @@ public class CollectionOfItemsSource implements QuestionItemsSource { @Override public int getNumOfItems() { - SearchQuestionItemParams params = new SearchQuestionItemParams(identity, roles); + SearchQuestionItemParams params = new SearchQuestionItemParams(identity, roles, locale); if(StringHelper.containsNonWhitespace(restrictToFormat)) { params.setFormat(restrictToFormat); } @@ -189,7 +192,7 @@ public class CollectionOfItemsSource implements QuestionItemsSource { @Override public List<QuestionItemView> getItems(Collection<Long> key) { - SearchQuestionItemParams params = new SearchQuestionItemParams(identity, roles); + SearchQuestionItemParams params = new SearchQuestionItemParams(identity, roles, locale); params.setItemKeys(key); if(StringHelper.containsNonWhitespace(restrictToFormat)) { params.setFormat(restrictToFormat); @@ -205,7 +208,7 @@ public class CollectionOfItemsSource implements QuestionItemsSource { @Override public ResultInfos<QuestionItemView> getItems(String query, List<String> condQueries, int firstResult, int maxResults, SortKey... orderBy) { - SearchQuestionItemParams params = new SearchQuestionItemParams(identity, roles); + SearchQuestionItemParams params = new SearchQuestionItemParams(identity, roles, locale); params.setSearchString(query); params.setCondQueries(condQueries); if(StringHelper.containsNonWhitespace(restrictToFormat)) { diff --git a/src/main/java/org/olat/modules/qpool/ui/datasource/DefaultItemsSource.java b/src/main/java/org/olat/modules/qpool/ui/datasource/DefaultItemsSource.java index 3fac77f7a09a82105aa3673e4e1b0d87d3038f92..d7213bf73bb229c4052434d4a8cc63fe552f2ab1 100644 --- a/src/main/java/org/olat/modules/qpool/ui/datasource/DefaultItemsSource.java +++ b/src/main/java/org/olat/modules/qpool/ui/datasource/DefaultItemsSource.java @@ -21,6 +21,7 @@ package org.olat.modules.qpool.ui.datasource; import java.util.Collection; import java.util.List; +import java.util.Locale; import org.olat.core.CoreSpringFactory; import org.olat.core.commons.persistence.ResultInfos; @@ -52,10 +53,10 @@ public abstract class DefaultItemsSource implements QuestionItemsSource { protected final QPoolService qpoolService; private final SearchQuestionItemParams defaultParams; - public DefaultItemsSource(Identity me, Roles roles, String name) { + public DefaultItemsSource(Identity me, Roles roles, Locale locale, String name) { this.name = name; this.identity = me; - defaultParams = new SearchQuestionItemParams(me, roles); + defaultParams = new SearchQuestionItemParams(me, roles, locale); qpoolService = CoreSpringFactory.getImpl(QPoolService.class); } diff --git a/src/main/java/org/olat/modules/qpool/ui/datasource/FinalItemsSource.java b/src/main/java/org/olat/modules/qpool/ui/datasource/FinalItemsSource.java index 9069c77b5b2aa9d7705508a5323bfa9c7d65afdf..4bd66bb924a45b3ee03d00752e6b0111c4fc72e3 100644 --- a/src/main/java/org/olat/modules/qpool/ui/datasource/FinalItemsSource.java +++ b/src/main/java/org/olat/modules/qpool/ui/datasource/FinalItemsSource.java @@ -20,6 +20,7 @@ package org.olat.modules.qpool.ui.datasource; import java.util.Date; +import java.util.Locale; import org.olat.core.CoreSpringFactory; import org.olat.core.id.Identity; @@ -37,10 +38,10 @@ import org.olat.modules.taxonomy.TaxonomyService; */ public class FinalItemsSource extends TaxonomyLevelItemsSource { - final boolean isManager; + private final boolean isManager; - public FinalItemsSource(Identity me, Roles roles, TaxonomyLevel taxonomyLevel) { - super(me, roles, taxonomyLevel); + public FinalItemsSource(Identity me, Roles roles, Locale locale, TaxonomyLevel taxonomyLevel) { + super(me, roles, locale, taxonomyLevel); setStatusFilter(QuestionStatus.finalVersion); TaxonomyService taxonomyService = CoreSpringFactory.getImpl(TaxonomyService.class); isManager = taxonomyService.hasCompetenceByLevel(taxonomyLevel, me, new Date(), TaxonomyCompetenceTypes.manage); diff --git a/src/main/java/org/olat/modules/qpool/ui/datasource/MarkedItemsSource.java b/src/main/java/org/olat/modules/qpool/ui/datasource/MarkedItemsSource.java index f46de8075ad5fd4397375190939523e2014b645d..afc0623a9a1c6fce147a05d596e8504cdc5b5c8c 100644 --- a/src/main/java/org/olat/modules/qpool/ui/datasource/MarkedItemsSource.java +++ b/src/main/java/org/olat/modules/qpool/ui/datasource/MarkedItemsSource.java @@ -20,6 +20,7 @@ package org.olat.modules.qpool.ui.datasource; import java.util.List; +import java.util.Locale; import org.olat.core.CoreSpringFactory; import org.olat.core.commons.services.mark.MarkManager; @@ -40,8 +41,8 @@ public class MarkedItemsSource extends DefaultItemsSource { private final Identity identity; private final MarkManager markManager; - public MarkedItemsSource(Identity me, Roles roles, String name) { - super(me, roles, name); + public MarkedItemsSource(Identity me, Roles roles, Locale locale, String name) { + super(me, roles, locale, name); identity = me; getDefaultParams().setFavoritOnly(true); markManager = CoreSpringFactory.getImpl(MarkManager.class); diff --git a/src/main/java/org/olat/modules/qpool/ui/datasource/MyItemsSource.java b/src/main/java/org/olat/modules/qpool/ui/datasource/MyItemsSource.java index 92fd195fd299498dea2f4a5ea872827de771228e..893f590d93acb0dafc7808c98669a96ef488f407 100644 --- a/src/main/java/org/olat/modules/qpool/ui/datasource/MyItemsSource.java +++ b/src/main/java/org/olat/modules/qpool/ui/datasource/MyItemsSource.java @@ -20,6 +20,7 @@ package org.olat.modules.qpool.ui.datasource; import java.util.List; +import java.util.Locale; import org.olat.core.gui.translator.Translator; import org.olat.core.id.Identity; @@ -35,8 +36,8 @@ import org.olat.modules.qpool.QuestionStatus; */ public class MyItemsSource extends DefaultItemsSource { - public MyItemsSource(Identity me, Roles roles, String name) { - super(me, roles, name); + public MyItemsSource(Identity me, Roles roles, Locale locale, String name) { + super(me, roles, locale, name); getDefaultParams().setAuthor(me); } diff --git a/src/main/java/org/olat/modules/qpool/ui/datasource/MyTaxonomyLevelItemsSource.java b/src/main/java/org/olat/modules/qpool/ui/datasource/MyTaxonomyLevelItemsSource.java index 19af60016ebb172321722c28c3364b064d42dc71..bd3f83dba859b8be3ee0d22b6aa97b94b8e0de64 100644 --- a/src/main/java/org/olat/modules/qpool/ui/datasource/MyTaxonomyLevelItemsSource.java +++ b/src/main/java/org/olat/modules/qpool/ui/datasource/MyTaxonomyLevelItemsSource.java @@ -19,6 +19,8 @@ */ package org.olat.modules.qpool.ui.datasource; +import java.util.Locale; + import org.olat.core.id.Identity; import org.olat.core.id.Roles; import org.olat.modules.qpool.QuestionStatus; @@ -32,8 +34,8 @@ import org.olat.modules.taxonomy.TaxonomyLevel; */ public class MyTaxonomyLevelItemsSource extends TaxonomyLevelItemsSource { - public MyTaxonomyLevelItemsSource(Identity me, Roles roles, TaxonomyLevel taxonomyLevel) { - super(me, roles, taxonomyLevel); + public MyTaxonomyLevelItemsSource(Identity me, Roles roles, Locale locale, TaxonomyLevel taxonomyLevel) { + super(me, roles, locale, taxonomyLevel); setStatusFilter(QuestionStatus.draft); getDefaultParams().setOnlyAuthor(me); } diff --git a/src/main/java/org/olat/modules/qpool/ui/datasource/PoolItemsSource.java b/src/main/java/org/olat/modules/qpool/ui/datasource/PoolItemsSource.java index e931da62f3311b2982ad15090ff65adc95966e73..9e4f7cb72e39e6820755faf0b4a297245d29631b 100644 --- a/src/main/java/org/olat/modules/qpool/ui/datasource/PoolItemsSource.java +++ b/src/main/java/org/olat/modules/qpool/ui/datasource/PoolItemsSource.java @@ -21,6 +21,7 @@ package org.olat.modules.qpool.ui.datasource; import java.util.Collections; import java.util.List; +import java.util.Locale; import org.olat.core.gui.translator.Translator; import org.olat.core.id.Identity; @@ -40,8 +41,8 @@ public class PoolItemsSource extends DefaultItemsSource { private final Pool pool; - public PoolItemsSource(Identity me, Roles roles, Pool pool) { - super(me, roles, pool.getName()); + public PoolItemsSource(Identity me, Roles roles, Locale locale, Pool pool) { + super(me, roles, locale, pool.getName()); this.pool = pool; getDefaultParams().setPoolKey(pool.getKey()); } diff --git a/src/main/java/org/olat/modules/qpool/ui/datasource/ReviewItemsSource.java b/src/main/java/org/olat/modules/qpool/ui/datasource/ReviewItemsSource.java index fe9d447cf3a65356c83845d42f16e0b50ca95a00..9f5ddf6bccc0896b15123871cae7f7ff1dfaaad2 100644 --- a/src/main/java/org/olat/modules/qpool/ui/datasource/ReviewItemsSource.java +++ b/src/main/java/org/olat/modules/qpool/ui/datasource/ReviewItemsSource.java @@ -19,6 +19,8 @@ */ package org.olat.modules.qpool.ui.datasource; +import java.util.Locale; + import org.olat.core.id.Identity; import org.olat.core.id.Roles; import org.olat.modules.qpool.QuestionStatus; @@ -32,8 +34,8 @@ import org.olat.modules.taxonomy.TaxonomyLevel; */ public class ReviewItemsSource extends TaxonomyLevelItemsSource { - public ReviewItemsSource(Identity me, Roles roles, TaxonomyLevel taxonomyLevel) { - super(me, roles, taxonomyLevel); + public ReviewItemsSource(Identity me, Roles roles, Locale locale, TaxonomyLevel taxonomyLevel) { + super(me, roles, locale, taxonomyLevel); setStatusFilter(QuestionStatus.review); getDefaultParams().setExcludeAuthor(me); getDefaultParams().setExcludeRated(me); diff --git a/src/main/java/org/olat/modules/qpool/ui/datasource/SharedItemsSource.java b/src/main/java/org/olat/modules/qpool/ui/datasource/SharedItemsSource.java index 3b1e3bfdd9271bc4d50bc5d019182a0b527478a5..225801cf9e87d1159304e23db79bd9dbdf9e5b38 100644 --- a/src/main/java/org/olat/modules/qpool/ui/datasource/SharedItemsSource.java +++ b/src/main/java/org/olat/modules/qpool/ui/datasource/SharedItemsSource.java @@ -22,6 +22,7 @@ package org.olat.modules.qpool.ui.datasource; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Locale; import org.olat.core.CoreSpringFactory; import org.olat.core.commons.persistence.ResultInfos; @@ -52,16 +53,18 @@ public class SharedItemsSource implements QuestionItemsSource { private final boolean admin; private final Roles roles; + private final Locale locale; private final Identity identity; private final BusinessGroup group; private final QPoolService qpoolService; private String restrictToFormat; - public SharedItemsSource(BusinessGroup group, Identity identity, Roles roles, boolean admin) { + public SharedItemsSource(BusinessGroup group, Identity identity, Roles roles, Locale locale, boolean admin) { this.admin = admin; this.roles = roles; this.identity = identity; + this.locale = locale; this.group = group; qpoolService = CoreSpringFactory.getImpl(QPoolService.class); } @@ -178,7 +181,7 @@ public class SharedItemsSource implements QuestionItemsSource { @Override public int getNumOfItems() { - SearchQuestionItemParams params = new SearchQuestionItemParams(identity, roles); + SearchQuestionItemParams params = new SearchQuestionItemParams(identity, roles, locale); if(StringHelper.containsNonWhitespace(restrictToFormat)) { params.setFormat(restrictToFormat); } @@ -187,7 +190,7 @@ public class SharedItemsSource implements QuestionItemsSource { @Override public List<QuestionItemView> getItems(Collection<Long> keys) { - SearchQuestionItemParams params = new SearchQuestionItemParams(identity, roles); + SearchQuestionItemParams params = new SearchQuestionItemParams(identity, roles, locale); params.setItemKeys(keys); if(StringHelper.containsNonWhitespace(restrictToFormat)) { params.setFormat(restrictToFormat); @@ -204,7 +207,7 @@ public class SharedItemsSource implements QuestionItemsSource { @Override public ResultInfos<QuestionItemView> getItems(String query, List<String> condQueries, int firstResult, int maxResults, SortKey... orderBy) { - SearchQuestionItemParams params = new SearchQuestionItemParams(identity, roles); + SearchQuestionItemParams params = new SearchQuestionItemParams(identity, roles, locale); params.setSearchString(query); params.setCondQueries(condQueries); if(StringHelper.containsNonWhitespace(restrictToFormat)) { diff --git a/src/main/java/org/olat/modules/qpool/ui/datasource/TaxonomyLevelItemsSource.java b/src/main/java/org/olat/modules/qpool/ui/datasource/TaxonomyLevelItemsSource.java index e2e0d5b932a0cf28233f940dbc12be9dc7bfc29b..dd23cc04cb768c5d48abb47675484a8a0017afb5 100644 --- a/src/main/java/org/olat/modules/qpool/ui/datasource/TaxonomyLevelItemsSource.java +++ b/src/main/java/org/olat/modules/qpool/ui/datasource/TaxonomyLevelItemsSource.java @@ -20,6 +20,7 @@ package org.olat.modules.qpool.ui.datasource; import java.util.List; +import java.util.Locale; import org.olat.core.gui.translator.Translator; import org.olat.core.id.Identity; @@ -39,8 +40,8 @@ public abstract class TaxonomyLevelItemsSource extends DefaultItemsSource { private final TaxonomyLevel taxonomyLevel; - public TaxonomyLevelItemsSource(Identity me, Roles roles, TaxonomyLevel taxonomyLevel) { - super(me, roles, taxonomyLevel.getDisplayName()); + public TaxonomyLevelItemsSource(Identity me, Roles roles, Locale locale, TaxonomyLevel taxonomyLevel) { + super(me, roles, locale, taxonomyLevel.getDisplayName()); this.taxonomyLevel = taxonomyLevel; getDefaultParams().setLikeTaxonomyLevel(taxonomyLevel); } diff --git a/src/main/java/org/olat/modules/qpool/ui/datasource/WithoutAuthorItemSource.java b/src/main/java/org/olat/modules/qpool/ui/datasource/WithoutAuthorItemSource.java index 02284a5f2b1bdbf1a265aab89833842a60732f97..240876db84a1dd3690f72f7702ae24fa276b4e0c 100644 --- a/src/main/java/org/olat/modules/qpool/ui/datasource/WithoutAuthorItemSource.java +++ b/src/main/java/org/olat/modules/qpool/ui/datasource/WithoutAuthorItemSource.java @@ -19,6 +19,8 @@ */ package org.olat.modules.qpool.ui.datasource; +import java.util.Locale; + import org.olat.core.id.Identity; import org.olat.core.id.Roles; @@ -30,8 +32,8 @@ import org.olat.core.id.Roles; */ public class WithoutAuthorItemSource extends AllItemsSource { - public WithoutAuthorItemSource(Identity me, Roles roles, String name) { - super(me, roles, name); + public WithoutAuthorItemSource(Identity me, Roles roles, Locale locale, String name) { + super(me, roles, locale, name); getDefaultParams().setWithoutAuthorOnly(true); } diff --git a/src/main/java/org/olat/modules/qpool/ui/datasource/WithoutTaxonomyLevelItemSource.java b/src/main/java/org/olat/modules/qpool/ui/datasource/WithoutTaxonomyLevelItemSource.java index 9618e65de783ed019fdc0b86ed2afd4e24dc39c6..40d0f2c9f6b42fa2309f3f9cb240f95a5f655fb4 100644 --- a/src/main/java/org/olat/modules/qpool/ui/datasource/WithoutTaxonomyLevelItemSource.java +++ b/src/main/java/org/olat/modules/qpool/ui/datasource/WithoutTaxonomyLevelItemSource.java @@ -19,6 +19,8 @@ */ package org.olat.modules.qpool.ui.datasource; +import java.util.Locale; + import org.olat.core.id.Identity; import org.olat.core.id.Roles; @@ -30,8 +32,8 @@ import org.olat.core.id.Roles; */ public class WithoutTaxonomyLevelItemSource extends AllItemsSource { - public WithoutTaxonomyLevelItemSource(Identity me, Roles roles, String name) { - super(me, roles, name); + public WithoutTaxonomyLevelItemSource(Identity me, Roles roles, Locale locale, String name) { + super(me, roles, locale, name); getDefaultParams().setWithoutTaxonomyLevelOnly(true); } diff --git a/src/main/java/org/olat/modules/qpool/ui/tree/AllQuestionsTreeNode.java b/src/main/java/org/olat/modules/qpool/ui/tree/AllQuestionsTreeNode.java index 2520ed9e734ce4e13182cf7898319a36e821adac..3effed69eaee4b2970254aae4243d0d700d944b4 100644 --- a/src/main/java/org/olat/modules/qpool/ui/tree/AllQuestionsTreeNode.java +++ b/src/main/java/org/olat/modules/qpool/ui/tree/AllQuestionsTreeNode.java @@ -64,8 +64,7 @@ public class AllQuestionsTreeNode extends GenericTreeNode implements ControllerT public Controller getController(UserRequest ureq, WindowControl wControl) { if(questionsCtrl == null) { QuestionItemsSource source = new AllItemsSource( - ureq.getIdentity(), - ureq.getUserSession().getRoles(), + ureq.getIdentity(), ureq.getUserSession().getRoles(), ureq.getLocale(), ALL); WindowControl swControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ureq, ORES, null, wControl, true); diff --git a/src/main/java/org/olat/modules/qpool/ui/tree/BusinessGroupTreeNode.java b/src/main/java/org/olat/modules/qpool/ui/tree/BusinessGroupTreeNode.java index 74cbd57e352c1f87b4badb1370cb29b7fa963fb9..a29806c039a6b5d1e607c65273af50498cf79f5b 100644 --- a/src/main/java/org/olat/modules/qpool/ui/tree/BusinessGroupTreeNode.java +++ b/src/main/java/org/olat/modules/qpool/ui/tree/BusinessGroupTreeNode.java @@ -77,8 +77,7 @@ public class BusinessGroupTreeNode extends GenericTreeNode implements Controller boolean shareAdmin = isShareAdmin(ureq, group); QuestionItemsSource source = new SharedItemsSource( group, - ureq.getIdentity(), - ureq.getUserSession().getRoles(), + ureq.getIdentity(), ureq.getUserSession().getRoles(), ureq.getLocale(), shareAdmin); WindowControl swControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ureq, group, null, wControl, true); @@ -90,8 +89,8 @@ public class BusinessGroupTreeNode extends GenericTreeNode implements Controller return questionsCtrl; } - private boolean isShareAdmin(UserRequest ureq, BusinessGroup group) { + private boolean isShareAdmin(UserRequest ureq, BusinessGroup businessGroup) { Identity identity = ureq.getIdentity(); - return businessGroupService.isIdentityInBusinessGroup(identity, group.getKey(), true, false, null); + return businessGroupService.isIdentityInBusinessGroup(identity, businessGroup.getKey(), true, false, null); } } diff --git a/src/main/java/org/olat/modules/qpool/ui/tree/CollectionTreeNode.java b/src/main/java/org/olat/modules/qpool/ui/tree/CollectionTreeNode.java index 528362cb5ea0f7b3b79626bb63706fd41a935d79..c5871d8ff1d7b47d7672aca571b99df669cb4337 100644 --- a/src/main/java/org/olat/modules/qpool/ui/tree/CollectionTreeNode.java +++ b/src/main/java/org/olat/modules/qpool/ui/tree/CollectionTreeNode.java @@ -68,7 +68,7 @@ public class CollectionTreeNode extends GenericTreeNode implements ControllerTre QuestionItemsSource source = new CollectionOfItemsSource( questionItemCollection, ureq.getIdentity(), - ureq.getUserSession().getRoles()); + ureq.getUserSession().getRoles(), ureq.getLocale()); if (questionsCtrl == null) { WindowControl swControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ureq, questionItemCollection, null, wControl, true); questionsCtrl = new QuestionsController(ureq, swControl, stackPanel, source, securityCallback, diff --git a/src/main/java/org/olat/modules/qpool/ui/tree/FinalTreeNode.java b/src/main/java/org/olat/modules/qpool/ui/tree/FinalTreeNode.java index 97f7787bc726f8e053ebb5fb999fb723e0060cda..b12474968739470a5ad51bdd40a886dde88b545c 100644 --- a/src/main/java/org/olat/modules/qpool/ui/tree/FinalTreeNode.java +++ b/src/main/java/org/olat/modules/qpool/ui/tree/FinalTreeNode.java @@ -60,13 +60,13 @@ public class FinalTreeNode extends GenericTreeNode implements ControllerTreeNode this.securityCallback = securityCallback; this.taxonomyLevel = taxonomyLevel; - this.setTitle(taxonomyLevel.getDisplayName()); + setTitle(taxonomyLevel.getDisplayName()); TaxonomyLevelType type = taxonomyLevel.getType(); if (type != null && StringHelper.containsNonWhitespace(type.getCssClass())) { setIconCssClass(type.getCssClass()); } - this.setUserObject(taxonomyLevel); + setUserObject(taxonomyLevel); } public TaxonomyLevel getTanonomyLevel() { @@ -77,8 +77,7 @@ public class FinalTreeNode extends GenericTreeNode implements ControllerTreeNode public Controller getController(UserRequest ureq, WindowControl wControl) { if (questionsCtrl == null) { QuestionItemsSource source = new FinalItemsSource( - ureq.getIdentity(), - ureq.getUserSession().getRoles(), + ureq.getIdentity(), ureq.getUserSession().getRoles(), ureq.getLocale(), taxonomyLevel); String resName = FINAL + "_" + taxonomyLevel.getIdentifier(); OLATResourceable ores = OresHelper.createOLATResourceableInstanceWithoutCheck(resName, taxonomyLevel.getKey()); diff --git a/src/main/java/org/olat/modules/qpool/ui/tree/MarkedQuestionsTreeNode.java b/src/main/java/org/olat/modules/qpool/ui/tree/MarkedQuestionsTreeNode.java index 1722087b2cc169af6effb7eaebf84f216dbe85f8..41e9c284e2c86c71eb6efa5966678fbd38cf4a1e 100644 --- a/src/main/java/org/olat/modules/qpool/ui/tree/MarkedQuestionsTreeNode.java +++ b/src/main/java/org/olat/modules/qpool/ui/tree/MarkedQuestionsTreeNode.java @@ -58,19 +58,18 @@ public class MarkedQuestionsTreeNode extends GenericTreeNode implements Controll this.stackPanel = stackPanel; this.securityCallback = securityCallback; - this.setTitle(title); - this.setIconCssClass(ICON_CSS_CLASS); + setTitle(title); + setIconCssClass(ICON_CSS_CLASS); // The user object is used to findNodeByPersistableUserObject - this.setUserObject(USER_OBJECT); + setUserObject(USER_OBJECT); } @Override public Controller getController(UserRequest ureq, WindowControl wControl) { if(questionsCtrl == null) { QuestionItemsSource source = new MarkedItemsSource( - ureq.getIdentity(), - ureq.getUserSession().getRoles(), + ureq.getIdentity(), ureq.getUserSession().getRoles(), ureq.getLocale(), ITEM_SOURCE_NAME); WindowControl swControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ureq, ORES, null, wControl, true); diff --git a/src/main/java/org/olat/modules/qpool/ui/tree/MyQuestionsTreeNode.java b/src/main/java/org/olat/modules/qpool/ui/tree/MyQuestionsTreeNode.java index 38679e00048ff2904f1c0051b8d6b7c9bb61f0e1..a53f0803fda85fd96e51918d54ccdc278f6cd05b 100644 --- a/src/main/java/org/olat/modules/qpool/ui/tree/MyQuestionsTreeNode.java +++ b/src/main/java/org/olat/modules/qpool/ui/tree/MyQuestionsTreeNode.java @@ -58,19 +58,18 @@ public class MyQuestionsTreeNode extends GenericTreeNode implements ControllerTr this.stackPanel = stackPanel; this.securityCallback = securityCallback; - this.setTitle(title); - this.setIconCssClass(ICON_CSS_CLASS); + setTitle(title); + setIconCssClass(ICON_CSS_CLASS); // The user object is used to findNodeByPersistableUserObject - this.setUserObject(USER_OBJECT); + setUserObject(USER_OBJECT); } @Override public Controller getController(UserRequest ureq, WindowControl wControl) { if(questionsCtrl == null) { QuestionItemsSource source = new MyItemsSource( - ureq.getIdentity(), - ureq.getUserSession().getRoles(), + ureq.getIdentity(), ureq.getUserSession().getRoles(), ureq.getLocale(), ITEM_SOURCE_NAME); WindowControl swControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ureq, ORES, null, wControl, true); diff --git a/src/main/java/org/olat/modules/qpool/ui/tree/MyTaxonomyLevelTreeNode.java b/src/main/java/org/olat/modules/qpool/ui/tree/MyTaxonomyLevelTreeNode.java index b3280eb9828a49eed4c4710ca21103a770327796..c58ed8e88d106971540dd1ac47ce9a4451ee74fd 100644 --- a/src/main/java/org/olat/modules/qpool/ui/tree/MyTaxonomyLevelTreeNode.java +++ b/src/main/java/org/olat/modules/qpool/ui/tree/MyTaxonomyLevelTreeNode.java @@ -60,21 +60,20 @@ public class MyTaxonomyLevelTreeNode extends GenericTreeNode implements Controll this.securityCallback = securityCallback; this.taxonomyLevel = taxonomyLevel; - this.setTitle(taxonomyLevel.getDisplayName()); + setTitle(taxonomyLevel.getDisplayName()); TaxonomyLevelType type = taxonomyLevel.getType(); if (type != null && StringHelper.containsNonWhitespace(type.getCssClass())) { setIconCssClass(type.getCssClass()); } - this.setUserObject(taxonomyLevel); + setUserObject(taxonomyLevel); } @Override public Controller getController(UserRequest ureq, WindowControl wControl) { if (questionsCtrl == null) { QuestionItemsSource source = new MyTaxonomyLevelItemsSource( - ureq.getIdentity(), - ureq.getUserSession().getRoles(), + ureq.getIdentity(), ureq.getUserSession().getRoles(), ureq.getLocale(), taxonomyLevel); OLATResourceable ores = OresHelper.createOLATResourceableInstanceWithoutCheck(MY_TAX_LEVEL + "_" + taxonomyLevel.getIdentifier(), taxonomyLevel.getKey()); WindowControl swControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ureq, ores, null, wControl, true); diff --git a/src/main/java/org/olat/modules/qpool/ui/tree/PoolTreeNode.java b/src/main/java/org/olat/modules/qpool/ui/tree/PoolTreeNode.java index 03a5d5bfec5ac784257ac1af5dc4906838f6cbfb..19012c4f04285797db7b16adb62d9218440f3472 100644 --- a/src/main/java/org/olat/modules/qpool/ui/tree/PoolTreeNode.java +++ b/src/main/java/org/olat/modules/qpool/ui/tree/PoolTreeNode.java @@ -60,11 +60,11 @@ public class PoolTreeNode extends GenericTreeNode implements ControllerTreeNode this.securityCallback = securityCallback; this.qpoolService = CoreSpringFactory.getImpl(QPoolService.class); - this.setTitle(pool.getName()); - this.setIconCssClass(ICON_CSS_CLASS); + setTitle(pool.getName()); + setIconCssClass(ICON_CSS_CLASS); // The user object is used to findNodeByPersistableUserObject - this.setUserObject(pool); + setUserObject(pool); } public Pool getPool() { @@ -75,8 +75,7 @@ public class PoolTreeNode extends GenericTreeNode implements ControllerTreeNode public Controller getController(UserRequest ureq, WindowControl wControl) { if(questionsCtrl == null) { PoolItemsSource source = new PoolItemsSource( - ureq.getIdentity(), - ureq.getUserSession().getRoles(), + ureq.getIdentity(), ureq.getUserSession().getRoles(), ureq.getLocale(), pool); source.setRemoveEnabled(isRemoveEnabled(ureq, pool)); WindowControl swControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ureq, pool, null, diff --git a/src/main/java/org/olat/modules/qpool/ui/tree/QuestionPoolMenuTreeModel.java b/src/main/java/org/olat/modules/qpool/ui/tree/QuestionPoolMenuTreeModel.java index fedaa516fe55d8f7c57a89aa40208ad866e3bfe8..1df20bacc06534784b2684e4bddb0dcda97d9a2a 100644 --- a/src/main/java/org/olat/modules/qpool/ui/tree/QuestionPoolMenuTreeModel.java +++ b/src/main/java/org/olat/modules/qpool/ui/tree/QuestionPoolMenuTreeModel.java @@ -61,6 +61,7 @@ public class QuestionPoolMenuTreeModel extends GenericTreeModel implements DnDTr private final TooledStackedPanel stackPanel; private final Identity identity; private final Roles roles; + private final Locale locale; private final QPoolService qpoolService; private final QPoolTaxonomyTreeBuilder qpoolTaxonomyTreeBuilder; private final Translator translator; @@ -76,6 +77,7 @@ public class QuestionPoolMenuTreeModel extends GenericTreeModel implements DnDTr this( stackPanel, identity, roles, + locale, Util.createPackageTranslator(QuestionPoolMainEditorController.class, locale), CoreSpringFactory.getImpl(QPoolService.class), CoreSpringFactory.getImpl(QPoolTaxonomyTreeBuilder.class), @@ -83,12 +85,13 @@ public class QuestionPoolMenuTreeModel extends GenericTreeModel implements DnDTr ); } - public QuestionPoolMenuTreeModel(TooledStackedPanel stackPanel, Identity identity, Roles roles, Translator translator, + public QuestionPoolMenuTreeModel(TooledStackedPanel stackPanel, Identity identity, Roles roles, Locale locale, Translator translator, QPoolService qpoolService, QPoolTaxonomyTreeBuilder qpoolTaxonomyTreeBuilder, QPoolSecurityCallbackFactory qPoolSecurityCallbackFactory) { super(); this.stackPanel = stackPanel; this.identity = identity; this.roles = roles; + this.locale = locale; this.securityCallback = qPoolSecurityCallbackFactory.createQPoolSecurityCallback(roles); this.translator = translator; this.qpoolService = qpoolService; @@ -299,7 +302,7 @@ public class QuestionPoolMenuTreeModel extends GenericTreeModel implements DnDTr rootNode.addChild(reviewNode); for(TaxonomyLevel taxonomyLevel:taxonomyLevels) { - TreeNode node = new ReviewTreeNode(stackPanel, securityCallback, taxonomyLevel, identity, roles); + TreeNode node = new ReviewTreeNode(stackPanel, securityCallback, taxonomyLevel, identity, roles, locale); reviewNode.addChild(node); } setFirstChildAsDelegate(reviewNode); diff --git a/src/main/java/org/olat/modules/qpool/ui/tree/ReviewTreeNode.java b/src/main/java/org/olat/modules/qpool/ui/tree/ReviewTreeNode.java index 7702fab5dcdd527ca6422aa3988a8e40027a3157..ef071f4db58056087becd8bfb2a6dc7f42a57dd8 100644 --- a/src/main/java/org/olat/modules/qpool/ui/tree/ReviewTreeNode.java +++ b/src/main/java/org/olat/modules/qpool/ui/tree/ReviewTreeNode.java @@ -19,6 +19,8 @@ */ package org.olat.modules.qpool.ui.tree; +import java.util.Locale; + import org.olat.core.gui.UserRequest; import org.olat.core.gui.components.badge.Badge; import org.olat.core.gui.components.stack.TooledStackedPanel; @@ -58,12 +60,12 @@ public class ReviewTreeNode extends GenericTreeNode implements ControllerTreeNod private final QuestionItemsSource source; public ReviewTreeNode(TooledStackedPanel stackPanel, QPoolSecurityCallback securityCallback, - TaxonomyLevel taxonomyLevel, Identity identity, Roles roles) { + TaxonomyLevel taxonomyLevel, Identity identity, Roles roles, Locale locale) { super(); this.stackPanel = stackPanel; this.securityCallback = securityCallback; this.taxonomyLevel = taxonomyLevel; - source = new ReviewItemsSource(identity, roles, taxonomyLevel); + source = new ReviewItemsSource(identity, roles, locale, taxonomyLevel); setTitle(taxonomyLevel.getDisplayName()); TaxonomyLevelType type = taxonomyLevel.getType(); @@ -72,7 +74,7 @@ public class ReviewTreeNode extends GenericTreeNode implements ControllerTreeNod } reloadCount(); - this.setUserObject(taxonomyLevel); + setUserObject(taxonomyLevel); } @Override diff --git a/src/main/java/org/olat/modules/qpool/ui/tree/WithoutAuthorTreeNode.java b/src/main/java/org/olat/modules/qpool/ui/tree/WithoutAuthorTreeNode.java index 6cbea7631999d96e50848fb823acf51934f28a03..0abe536af5aa75c470069cfac4e4925820073834 100644 --- a/src/main/java/org/olat/modules/qpool/ui/tree/WithoutAuthorTreeNode.java +++ b/src/main/java/org/olat/modules/qpool/ui/tree/WithoutAuthorTreeNode.java @@ -55,17 +55,15 @@ public class WithoutAuthorTreeNode extends GenericTreeNode implements Controller this.stackPanel = stackPanel; this.securityCallback = securityCallback; - this.setTitle(title); - - this.setUserObject(WITHOUT_AUTHOR); + setTitle(title); + setUserObject(WITHOUT_AUTHOR); } @Override public Controller getController(UserRequest ureq, WindowControl wControl) { if(questionsCtrl == null) { QuestionItemsSource source = new WithoutAuthorItemSource( - ureq.getIdentity(), - ureq.getUserSession().getRoles(), + ureq.getIdentity(), ureq.getUserSession().getRoles(), ureq.getLocale(), WITHOUT_AUTHOR); WindowControl swControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ureq, ORES, null, wControl, true); diff --git a/src/main/java/org/olat/modules/qpool/ui/tree/WithoutTaxonomyLevelTreeNode.java b/src/main/java/org/olat/modules/qpool/ui/tree/WithoutTaxonomyLevelTreeNode.java index e5b4a9fb35ae783467185bcbd026a89d526fc70d..16afae9aede7b06b3580c417fcf19ed2cd4006c8 100644 --- a/src/main/java/org/olat/modules/qpool/ui/tree/WithoutTaxonomyLevelTreeNode.java +++ b/src/main/java/org/olat/modules/qpool/ui/tree/WithoutTaxonomyLevelTreeNode.java @@ -55,17 +55,15 @@ public class WithoutTaxonomyLevelTreeNode extends GenericTreeNode implements Con this.stackPanel = stackPanel; this.securityCallback = securityCallback; - this.setTitle(title); - - this.setUserObject(WITHOUT_TAXONOMY_LEVEL); + setTitle(title); + setUserObject(WITHOUT_TAXONOMY_LEVEL); } @Override public Controller getController(UserRequest ureq, WindowControl wControl) { if(questionsCtrl == null) { QuestionItemsSource source = new WithoutTaxonomyLevelItemSource( - ureq.getIdentity(), - ureq.getUserSession().getRoles(), + ureq.getIdentity(), ureq.getUserSession().getRoles(), ureq.getLocale(), WITHOUT_TAXONOMY_LEVEL); WindowControl swControl = BusinessControlFactory.getInstance().createBusinessWindowControl(ureq, ORES, null, wControl, true); diff --git a/src/main/java/org/olat/portfolio/manager/EPFrontendManager.java b/src/main/java/org/olat/portfolio/manager/EPFrontendManager.java index f6df9786248a0e47624a69290ac4f46da51fe677..441dbba4c89e3a316c835a620fb8883566b5c68d 100755 --- a/src/main/java/org/olat/portfolio/manager/EPFrontendManager.java +++ b/src/main/java/org/olat/portfolio/manager/EPFrontendManager.java @@ -24,6 +24,7 @@ import java.util.Collections; import java.util.Date; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; @@ -505,8 +506,8 @@ public class EPFrontendManager implements UserDataDeletable, DeletableGroupData * @param filterSettings Settings for the filter to work on * @return */ - public List<AbstractArtefact> filterArtefactsByFilterSettings(EPFilterSettings filterSettings, Identity identity, Roles roles) { - List<Long> artefactKeys = fulltextSearchAfterArtefacts(filterSettings, identity, roles); + public List<AbstractArtefact> filterArtefactsByFilterSettings(EPFilterSettings filterSettings, Identity identity, Roles roles, Locale locale) { + List<Long> artefactKeys = fulltextSearchAfterArtefacts(filterSettings, identity, roles, locale); if(artefactKeys == null || artefactKeys.isEmpty()) { List<AbstractArtefact> allArtefacts = artefactManager.getArtefactPoolForUser(identity); return artefactManager.filterArtefactsByFilterSettings(allArtefacts, filterSettings); @@ -518,16 +519,16 @@ public class EPFrontendManager implements UserDataDeletable, DeletableGroupData return artefactManager.filterArtefactsByFilterSettings(artefacts, settings); } - private List<Long> fulltextSearchAfterArtefacts(EPFilterSettings filterSettings, Identity identity, Roles roles) { + private List<Long> fulltextSearchAfterArtefacts(EPFilterSettings filterSettings, Identity identity, Roles roles, Locale locale) { String query = filterSettings.getTextFilter(); if (StringHelper.containsNonWhitespace(query)) { try { - List<String> queries = new ArrayList<String>(); + List<String> queries = new ArrayList<>(); appendAnd(queries, AbstractOlatDocument.RESERVED_TO, ":\"", identity.getKey().toString(), "\""); appendAnd(queries, "(", AbstractOlatDocument.DOCUMENTTYPE_FIELD_NAME, ":(", PortfolioArtefactIndexer.TYPE, "*))"); - SearchResults searchResults = searchClient.doSearch(query, queries, identity, roles, 0, 1000, false); + SearchResults searchResults = searchClient.doSearch(query, queries, identity, roles, locale, 0, 1000, false); - List<Long> keys = new ArrayList<Long>(); + List<Long> keys = new ArrayList<>(); if (searchResults != null) { String marker = AbstractArtefact.class.getSimpleName(); for (ResultDocument doc : searchResults.getList()) { diff --git a/src/main/java/org/olat/portfolio/ui/EPArtefactPoolRunController.java b/src/main/java/org/olat/portfolio/ui/EPArtefactPoolRunController.java index 458669538c06fdf9667bd3c89762d5a32fba72b1..fb5beb7b45d484f395ecc9fd8831bc0a4e1e41d3 100755 --- a/src/main/java/org/olat/portfolio/ui/EPArtefactPoolRunController.java +++ b/src/main/java/org/olat/portfolio/ui/EPArtefactPoolRunController.java @@ -219,7 +219,7 @@ public class EPArtefactPoolRunController extends BasicController implements Acti private void initTPFilterView(UserRequest ureq) { List<AbstractArtefact> filteredArtefacts = ePFMgr.filterArtefactsByFilterSettings(filterSettings, - getIdentity(), ureq.getUserSession().getRoles()); + getIdentity(), ureq.getUserSession().getRoles(), getLocale()); initMultiArtefactCtrl(ureq, filteredArtefacts); initFilterPanel(ureq, Filter.extended); setSegmentContent(artCtrl); diff --git a/src/main/java/org/olat/repository/RepositoryService.java b/src/main/java/org/olat/repository/RepositoryService.java index c3d3e28abcf566816f2eaddb8f751194a0145012..1f6e3eabcfce6084265d7102fd00351bfbb508c4 100644 --- a/src/main/java/org/olat/repository/RepositoryService.java +++ b/src/main/java/org/olat/repository/RepositoryService.java @@ -85,6 +85,8 @@ public interface RepositoryService { * @return The olat resource of the repository entry */ public OLATResource loadRepositoryEntryResourceBySoftKey(String softkey); + + public List<RepositoryEntry> loadRepositoryEntries(int firstResult, int maxResult); public VFSLeaf getIntroductionImage(RepositoryEntry re); diff --git a/src/main/java/org/olat/repository/manager/RepositoryEntryDAO.java b/src/main/java/org/olat/repository/manager/RepositoryEntryDAO.java index e1d9f8f9f8e5a87ea49b4d134626a1360f5e619c..58d7c13e017da78f75304ab333d2b91dbb2f522d 100644 --- a/src/main/java/org/olat/repository/manager/RepositoryEntryDAO.java +++ b/src/main/java/org/olat/repository/manager/RepositoryEntryDAO.java @@ -150,6 +150,15 @@ public class RepositoryEntryDAO { .getResultList(); } + public List<RepositoryEntry> loadRepositoryEntries(int firstResult, int maxResult) { + String query = "select v from repositoryentry as v order by v.key asc"; + return dbInstance.getCurrentEntityManager() + .createQuery(query, RepositoryEntry.class) + .setFirstResult(firstResult) + .setMaxResults(maxResult) + .getResultList(); + } + public RepositoryEntry loadByResourceId(String resourceName, Long resourceId) { List<RepositoryEntry> entries = dbInstance.getCurrentEntityManager() .createNamedQuery("loadRepositoryEntryByResourceId", RepositoryEntry.class) diff --git a/src/main/java/org/olat/repository/manager/RepositoryServiceImpl.java b/src/main/java/org/olat/repository/manager/RepositoryServiceImpl.java index aa5f8288acb007a82ab5621388019a84e845dfcd..278f81208b3da8f1a73f5f3142028c13430a21cf 100644 --- a/src/main/java/org/olat/repository/manager/RepositoryServiceImpl.java +++ b/src/main/java/org/olat/repository/manager/RepositoryServiceImpl.java @@ -363,6 +363,11 @@ public class RepositoryServiceImpl implements RepositoryService, OrganisationDat return repositoryEntryDAO.loadRepositoryEntriesByExternalRef(externalRef); } + @Override + public List<RepositoryEntry> loadRepositoryEntries(int firstResult, int maxResult) { + return repositoryEntryDAO.loadRepositoryEntries(firstResult, maxResult); + } + @Override public VFSLeaf getIntroductionImage(RepositoryEntry re) { VFSContainer repositoryHome = new LocalFolderImpl(new File(FolderConfig.getCanonicalRepositoryHome())); diff --git a/src/main/java/org/olat/search/SearchService.java b/src/main/java/org/olat/search/SearchService.java index ff9e815bf0246f50a01368e7be8b678f89b6b878..cf2271f34d232fa16cdb67dadd72b8960bfbefa4 100644 --- a/src/main/java/org/olat/search/SearchService.java +++ b/src/main/java/org/olat/search/SearchService.java @@ -26,11 +26,11 @@ package org.olat.search; import java.util.List; +import java.util.Locale; import java.util.Set; import org.apache.lucene.document.Document; import org.apache.lucene.queryparser.classic.ParseException; -import org.apache.lucene.util.Version; import org.olat.core.commons.persistence.SortKey; import org.olat.core.id.Identity; import org.olat.core.id.Roles; @@ -41,8 +41,6 @@ import org.olat.core.id.Roles; */ public interface SearchService { - public static final Version OO_LUCENE_VERSION = Version.LUCENE_48; - /** * * @param query Lucene query string @@ -51,7 +49,7 @@ public interface SearchService { * @param doHighlighting Highlights founded text fragements in result * @return Search result for queury */ - public SearchResults doSearch(String queryString, List<String> condQueries, Identity identity, Roles roles, + public SearchResults doSearch(String queryString, List<String> condQueries, Identity identity, Roles roles, Locale locale, int firstResult, int maxReturns, boolean doHighlighting) throws ServiceNotAvailableException, ParseException, QueryException; @@ -70,7 +68,7 @@ public interface SearchService { * @throws ParseException * @throws QueryException */ - public List<Long> doSearch(String queryString, List<String> condQueries, Identity identity, Roles roles, + public List<Long> doSearch(String queryString, List<String> condQueries, Identity identity, Roles roles, Locale locale, int firstResult, int maxReturns, SortKey... orderBy) throws ServiceNotAvailableException, ParseException, QueryException; diff --git a/src/main/java/org/olat/search/model/OlatDocument.java b/src/main/java/org/olat/search/model/OlatDocument.java index 0339e07d2c42ae3a499cc9465e7d30c497136ab5..22f69af0dc9484929159f4c5019ce5ffe0e6e8ca 100644 --- a/src/main/java/org/olat/search/model/OlatDocument.java +++ b/src/main/java/org/olat/search/model/OlatDocument.java @@ -85,9 +85,9 @@ public class OlatDocument extends AbstractOlatDocument { if(getId() != null) { document.add(new StringField(DB_ID_NAME, getId().toString(), Field.Store.YES)); } - document.add(createTextField(TITLE_FIELD_NAME, getTitle(), 4)); - document.add(createTextField(DESCRIPTION_FIELD_NAME, getDescription(), 2)); - document.add(createTextField(CONTENT_FIELD_NAME, getContent(), 0.5f)); + document.add(new TextField(TITLE_FIELD_NAME, getTitle(), Field.Store.YES)); + document.add(new TextField(DESCRIPTION_FIELD_NAME, getDescription(), Field.Store.YES)); + document.add(new TextField(CONTENT_FIELD_NAME, getContent(), Field.Store.YES)); document.add(new StringField(RESOURCEURL_FIELD_NAME, getResourceUrl(), Field.Store.YES)); document.add(new StringField(RESOURCEURL_MD5_FIELD_NAME, Encoder.md5hash(getResourceUrl()), Field.Store.YES)); document.add(new StringField(DOCUMENTTYPE_FIELD_NAME, getDocumentType(), Field.Store.YES)); @@ -95,8 +95,8 @@ public class OlatDocument extends AbstractOlatDocument { document.add(new StringField(CSS_ICON, getCssIcon(), Field.Store.YES)); } document.add(new StringField(FILETYPE_FIELD_NAME, getFileType(), Field.Store.YES)); - document.add(createTextField(AUTHOR_FIELD_NAME, getAuthor(), 2)); - document.add(createTextField(LOCATION_FIELD_NAME, getLocation(), 2)); + document.add(new TextField(AUTHOR_FIELD_NAME, getAuthor(), Field.Store.YES)); + document.add(new TextField(LOCATION_FIELD_NAME, getLocation(), Field.Store.YES)); appendDayField(document, CREATED_FIELD_NAME, getCreatedDate()); appendDayField(document, CHANGED_FIELD_NAME, getLastChange()); @@ -108,13 +108,13 @@ public class OlatDocument extends AbstractOlatDocument { for (Entry<String, List<String>> metaDataEntry : metadata.entrySet()) { String key = metaDataEntry.getKey(); for (String value : metaDataEntry.getValue()) { - document.add(createTextField(key, value, 2) ); + document.add(new TextField(key, value, Field.Store.YES)); } } } - document.add(createTextField(PARENT_CONTEXT_TYPE_FIELD_NAME, getParentContextType(), 1.0f)); - document.add(createTextField(PARENT_CONTEXT_NAME_FIELD_NAME, getParentContextName(), 1.0f)); + document.add(new TextField(PARENT_CONTEXT_TYPE_FIELD_NAME, getParentContextType(), Field.Store.YES)); + document.add(new TextField(PARENT_CONTEXT_NAME_FIELD_NAME, getParentContextName(), Field.Store.YES)); if(StringHelper.containsNonWhitespace(getReservedTo())) { for(StringTokenizer tokenizer = new StringTokenizer(getReservedTo(), " "); tokenizer.hasMoreTokens(); ) { String reserved = tokenizer.nextToken(); @@ -144,10 +144,8 @@ public class OlatDocument extends AbstractOlatDocument { * @param boost * @return */ - protected static Field createTextField(String fieldName, String content, float boost) { - TextField field = new TextField(fieldName, content, Field.Store.YES); - field.setBoost(boost); - return field; + protected static Field createTextField(String fieldName, String content) { + return new TextField(fieldName, content, Field.Store.YES); } protected static Field createDayField(String fieldName, Date date) { diff --git a/src/main/java/org/olat/search/service/GetDocumentByCallable.java b/src/main/java/org/olat/search/service/GetDocumentByCallable.java index 8ade7d9eef807b5c55c02392888b6ee8c3a8e490..1e1c621780fa5e9bf02294c579375f7a538a40bd 100644 --- a/src/main/java/org/olat/search/service/GetDocumentByCallable.java +++ b/src/main/java/org/olat/search/service/GetDocumentByCallable.java @@ -32,7 +32,6 @@ import org.apache.lucene.search.TopDocs; import org.olat.core.logging.OLog; import org.olat.core.logging.Tracing; import org.olat.core.util.Encoder; -import org.olat.search.SearchService; import org.olat.search.model.AbstractOlatDocument; /** @@ -62,14 +61,14 @@ class GetDocumentByCallable implements Callable<Document> { searcher = searchService.getIndexSearcher(); String url = Encoder.md5hash(resourceUrl); String queryStr = "+" + AbstractOlatDocument.RESOURCEURL_MD5_FIELD_NAME + ":\"" + url + "\""; - QueryParser idQueryParser = new QueryParser(SearchService.OO_LUCENE_VERSION, queryStr, new KeywordAnalyzer()); + QueryParser idQueryParser = new QueryParser(queryStr, new KeywordAnalyzer()); Query query = idQueryParser.parse(queryStr); TopDocs docs = searcher.search(query, 500); - int numOfDocs = docs.totalHits; + long numOfDocs = docs.totalHits; - Set<String> retrievedFields = new HashSet<String>(); + Set<String> retrievedFields = new HashSet<>(); retrievedFields.add(AbstractOlatDocument.RESOURCEURL_FIELD_NAME); retrievedFields.add(AbstractOlatDocument.RESOURCEURL_MD5_FIELD_NAME); diff --git a/src/main/java/org/olat/search/service/SearchCallable.java b/src/main/java/org/olat/search/service/SearchCallable.java index 0cafbf58728971f84510f7ea568e7628084230bc..53e2fab73941bc9dd1adf8ac6ef4fc06cc0e578f 100644 --- a/src/main/java/org/olat/search/service/SearchCallable.java +++ b/src/main/java/org/olat/search/service/SearchCallable.java @@ -20,11 +20,13 @@ package org.olat.search.service; import java.util.List; +import java.util.Locale; import java.util.concurrent.Callable; import org.apache.lucene.queryparser.classic.ParseException; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.IndexSearcher; +import org.apache.lucene.search.Query; import org.apache.lucene.search.TopDocs; import org.olat.core.commons.persistence.DBFactory; import org.olat.core.id.Identity; @@ -45,19 +47,21 @@ class SearchCallable implements Callable<SearchResults> { private static final OLog log = Tracing.createLoggerFor(SearchCallable.class); - private String queryString; - private List<String> condQueries; - private Identity identity; - private Roles roles; - private int firstResult; - private int maxResults; - private boolean doHighlighting; - private SearchServiceImpl searchService; + private final Locale locale; + private final String queryString; + private final List<String> condQueries; + private final Identity identity; + private final Roles roles; + private final int firstResult; + private final int maxResults; + private final boolean doHighlighting; + private final SearchServiceImpl searchService; - public SearchCallable(String queryString, List<String> condQueries, Identity identity, Roles roles, + public SearchCallable(String queryString, List<String> condQueries, Identity identity, Roles roles, Locale locale, int firstResult, int maxResults, boolean doHighlighting, SearchServiceImpl searchService) { this.queryString = queryString; this.condQueries = condQueries; + this.locale = locale; this.identity = identity; this.roles = roles; this.firstResult = firstResult; @@ -79,8 +83,8 @@ class SearchCallable implements Callable<SearchResults> { if(debug) log.debug("queryString=" + queryString); searcher = searchService.getIndexSearcher(); - BooleanQuery query = searchService.createQuery(queryString, condQueries); - if(debug) log.debug("query=" + query); + BooleanQuery.Builder queryBuilder = searchService.createQuery(queryString, condQueries, locale); + if(debug) log.debug("query=" + queryBuilder); if(Thread.interrupted()) { throw new InterruptedException(); @@ -89,6 +93,7 @@ class SearchCallable implements Callable<SearchResults> { long startTime = System.currentTimeMillis(); int n = SearchServiceFactory.getService().getSearchModuleConfig().getMaxHits(); + Query query = queryBuilder.build(); TopDocs docs = searcher.search(query, n); long queryTime = System.currentTimeMillis() - startTime; if(debug) log.debug("hits.length()=" + docs.totalHits); diff --git a/src/main/java/org/olat/search/service/SearchOrderByCallable.java b/src/main/java/org/olat/search/service/SearchOrderByCallable.java index cd0ec3cad50412d7b64f5ade4d9c25ca42b7bf6a..1460f24e5657b28b840b827243ec6f4b6f515b25 100644 --- a/src/main/java/org/olat/search/service/SearchOrderByCallable.java +++ b/src/main/java/org/olat/search/service/SearchOrderByCallable.java @@ -22,24 +22,24 @@ package org.olat.search.service; import java.util.ArrayList; import java.util.HashSet; import java.util.List; +import java.util.Locale; import java.util.Set; import java.util.concurrent.Callable; import org.apache.lucene.document.Document; import org.apache.lucene.queryparser.classic.QueryParser; +import org.apache.lucene.search.BooleanClause.Occur; import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; import org.apache.lucene.search.Sort; import org.apache.lucene.search.SortField; import org.apache.lucene.search.TopDocs; -import org.apache.lucene.search.BooleanClause.Occur; import org.olat.core.commons.persistence.DBFactory; import org.olat.core.commons.persistence.SortKey; import org.olat.core.logging.OLog; import org.olat.core.logging.Tracing; import org.olat.core.util.StringHelper; -import org.olat.search.SearchService; import org.olat.search.ServiceNotAvailableException; import org.olat.search.model.AbstractOlatDocument; @@ -55,15 +55,17 @@ class SearchOrderByCallable implements Callable<List<Long>> { private String queryString; private List<String> condQueries; + private Locale locale; private SortKey[] orderBy; private int firstResult; private int maxResults; private SearchServiceImpl searchService; - public SearchOrderByCallable(String queryString, List<String> condQueries, SortKey[] orderBy, + public SearchOrderByCallable(String queryString, List<String> condQueries, SortKey[] orderBy, Locale locale, int firstResult, int maxResults, SearchServiceImpl searchService) { this.queryString = queryString; this.condQueries = condQueries; + this.locale = locale; this.orderBy = orderBy; this.firstResult = firstResult; this.maxResults = maxResults; @@ -81,13 +83,13 @@ class SearchOrderByCallable implements Callable<List<Long>> { } searcher = searchService.getIndexSearcher(); - BooleanQuery query = searchService.createQuery(queryString, condQueries); + BooleanQuery.Builder queryBuilder = searchService.createQuery(queryString, condQueries, locale); //only search document with an primary key String idNotNull = AbstractOlatDocument.DB_ID_NAME + ":[* TO *]"; - QueryParser idQueryParser = new QueryParser(SearchService.OO_LUCENE_VERSION, idNotNull, searchService.getAnalyzer()); + QueryParser idQueryParser = new QueryParser(idNotNull, searchService.getAnalyzer()); Query idQuery = idQueryParser.parse(idNotNull); - query.add(idQuery, Occur.MUST); + queryBuilder.add(idQuery, Occur.MUST); int n = searchService.getSearchModuleConfig().getMaxHits(); TopDocs docs; @@ -97,16 +99,16 @@ class SearchOrderByCallable implements Callable<List<Long>> { sortFields[i] = new SortField(orderBy[i].getKey(), SortField.Type.STRING_VAL, orderBy[i].isAsc()); } Sort sort = new Sort(sortFields); - docs = searcher.search(query, n, sort); + docs = searcher.search(queryBuilder.build(), n, sort); } else { - docs = searcher.search(query, n); + docs = searcher.search(queryBuilder.build(), n); } - int numOfDocs = Math.min(n, docs.totalHits); - Set<String> retrievedFields = new HashSet<String>(); + long numOfDocs = Math.min(n, docs.totalHits); + Set<String> retrievedFields = new HashSet<>(); retrievedFields.add(AbstractOlatDocument.DB_ID_NAME); - List<Long> res = new ArrayList<Long>(); + List<Long> res = new ArrayList<>(); for (int i=firstResult; i<numOfDocs && res.size() < maxResults; i++) { Document doc = searcher.doc(docs.scoreDocs[i].doc, retrievedFields); String dbKeyStr = doc.get(AbstractOlatDocument.DB_ID_NAME); diff --git a/src/main/java/org/olat/search/service/SearchResourceContext.java b/src/main/java/org/olat/search/service/SearchResourceContext.java index ae39ee4ce1aab54062ccdabfe67572b99a358537..2160f1f849e671b816ac65e552a83d787404361c 100644 --- a/src/main/java/org/olat/search/service/SearchResourceContext.java +++ b/src/main/java/org/olat/search/service/SearchResourceContext.java @@ -139,7 +139,7 @@ public class SearchResourceContext { */ public void setBusinessControlFor(CourseNode courseNode) { if (log.isDebug()) log.debug("Course-node-ID=" + courseNode.getIdent()); - setBusinessControlFor(OresHelper.createOLATResourceableInstance(CourseNode.class,new Long(courseNode.getIdent()))); + setBusinessControlFor(OresHelper.createOLATResourceableInstance(CourseNode.class, Long.valueOf(courseNode.getIdent()))); } /** diff --git a/src/main/java/org/olat/search/service/SearchServiceDisabled.java b/src/main/java/org/olat/search/service/SearchServiceDisabled.java index be196fd1a5dcf049e91b1b4e8bafb8f338afd60e..32ff19168caec47d02261c95e68dcee8c0714ad3 100644 --- a/src/main/java/org/olat/search/service/SearchServiceDisabled.java +++ b/src/main/java/org/olat/search/service/SearchServiceDisabled.java @@ -26,6 +26,7 @@ package org.olat.search.service; import java.util.List; +import java.util.Locale; import java.util.Set; import org.apache.lucene.document.Document; @@ -71,17 +72,21 @@ public class SearchServiceDisabled implements SearchService { return false; } + @Override public void init() { + // } - + @Override public SearchServiceStatus getStatus() { return null; } + @Override public void setIndexInterval(long indexInterval) { } - + + @Override public long getIndexInterval() { return 0; } @@ -90,20 +95,20 @@ public class SearchServiceDisabled implements SearchService { * * @return Resturn search module configuration. */ + @Override public SearchModule getSearchModuleConfig() { return null; } - /** - * - * @see org.olat.search.SearchService#spellCheck(java.lang.String) - */ + @Override public Set<String> spellCheck(String query) throws ServiceNotAvailableException { log.error("call spellCheck on disabled search service"); throw new ServiceNotAvailableException("call spellCheck on disabled search service"); } + @Override public void stop() { + // } public boolean isEnabled() { @@ -116,7 +121,7 @@ public class SearchServiceDisabled implements SearchService { } @Override - public SearchResults doSearch(String queryString, List<String> condQueries, Identity identity, Roles roles, + public SearchResults doSearch(String queryString, List<String> condQueries, Identity identity, Roles roles, Locale locale, int firstResult, int maxResults, boolean doHighlighting) throws ServiceNotAvailableException, ParseException, QueryException { log.error("call doSearch on disabled search service"); @@ -124,7 +129,7 @@ public class SearchServiceDisabled implements SearchService { } @Override - public List<Long> doSearch(String queryString, List<String> condQueries, Identity identity, Roles roles, + public List<Long> doSearch(String queryString, List<String> condQueries, Identity identity, Roles roles, Locale locale, int firstResult, int maxReturns, SortKey... orderBy) throws ServiceNotAvailableException, ParseException, QueryException { log.error("call doSearch on disabled search service"); diff --git a/src/main/java/org/olat/search/service/SearchServiceImpl.java b/src/main/java/org/olat/search/service/SearchServiceImpl.java index e35ef1748f906183a799011bd276451a602d3067..ab014c48956d08e7302da2c314b1d60e2e4e6d30 100644 --- a/src/main/java/org/olat/search/service/SearchServiceImpl.java +++ b/src/main/java/org/olat/search/service/SearchServiceImpl.java @@ -30,8 +30,11 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Locale; +import java.util.Map; import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; @@ -54,7 +57,6 @@ import org.apache.lucene.search.BooleanQuery; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; import org.apache.lucene.search.ReferenceManager; -import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; import org.olat.core.commons.persistence.SortKey; import org.olat.core.gui.control.Event; @@ -116,7 +118,7 @@ public class SearchServiceImpl implements SearchService, GenericEventListener { private ExecutorService searchExecutor; private OOSearcherManager indexSearcherRefMgr; - private String fields[] = { + private String[] fields = { AbstractOlatDocument.TITLE_FIELD_NAME, AbstractOlatDocument.DESCRIPTION_FIELD_NAME, AbstractOlatDocument.CONTENT_FIELD_NAME, AbstractOlatDocument.AUTHOR_FIELD_NAME, AbstractOlatDocument.LOCATION_FIELD_NAME, AbstractOlatDocument.DOCUMENTTYPE_FIELD_NAME, @@ -145,7 +147,7 @@ public class SearchServiceImpl implements SearchService, GenericEventListener { this.searchModuleConfig = searchModule; this.mainIndexer = mainIndexer; this.coordinatorManager = coordinatorManager; - analyzer = new StandardAnalyzer(SearchService.OO_LUCENE_VERSION); + analyzer = new StandardAnalyzer(); searchProvider.setSearchService(this); coordinatorManager.getCoordinator().getEventBus().registerFor(this, null, IndexerEvent.INDEX_ORES); } @@ -300,21 +302,18 @@ public class SearchServiceImpl implements SearchService, GenericEventListener { * @return SearchResults object for this query */ @Override - public SearchResults doSearch(String queryString, List<String> condQueries, Identity identity, Roles roles, + public SearchResults doSearch(String queryString, List<String> condQueries, Identity identity, Roles roles, Locale locale, int firstResult, int maxResults, boolean doHighlighting) throws ServiceNotAvailableException, ParseException { Future<SearchResults> futureResults = null; try { - SearchCallable run = new SearchCallable(queryString, condQueries, identity, roles, firstResult, maxResults, doHighlighting, this); + SearchCallable run = new SearchCallable(queryString, condQueries, identity, roles, locale, firstResult, maxResults, doHighlighting, this); futureResults = searchExecutor.submit(run); SearchResults results = futureResults.get(searchModuleConfig.getSearchTimeout(), TimeUnit.SECONDS); queryCount++; return results; - } catch (InterruptedException e) { - log.error("", e); - return null; - } catch (TimeoutException e) { + } catch (InterruptedException | TimeoutException e) { cancelSearch(futureResults); log.error("", e); return null; @@ -331,18 +330,18 @@ public class SearchServiceImpl implements SearchService, GenericEventListener { } @Override - public List<Long> doSearch(String queryString, List<String> condQueries, Identity identity, Roles roles, + public List<Long> doSearch(String queryString, List<String> condQueries, Identity identity, Roles roles, Locale locale, int firstResult, int maxResults, SortKey... orderBy) throws ServiceNotAvailableException, ParseException, QueryException { Future<List<Long>> futureResults = null; try { - SearchOrderByCallable run = new SearchOrderByCallable(queryString, condQueries, orderBy, firstResult, maxResults, this); + SearchOrderByCallable run = new SearchOrderByCallable(queryString, condQueries, orderBy, locale, firstResult, maxResults, this); futureResults = searchExecutor.submit(run); List<Long> results = futureResults.get(searchModuleConfig.getSearchTimeout(), TimeUnit.SECONDS); queryCount++; if(results == null) { - results = new ArrayList<Long>(1); + results = new ArrayList<>(1); } return results; } catch (TimeoutException e) { @@ -351,7 +350,7 @@ public class SearchServiceImpl implements SearchService, GenericEventListener { return null; } catch (Exception e) { log.error("", e); - return new ArrayList<Long>(1); + return new ArrayList<>(1); } } @@ -383,21 +382,22 @@ public class SearchServiceImpl implements SearchService, GenericEventListener { } } - protected BooleanQuery createQuery(String queryString, List<String> condQueries) + protected BooleanQuery.Builder createQuery(String queryString, List<String> condQueries, Locale locale) throws ParseException { - BooleanQuery query = new BooleanQuery(); + BooleanQuery.Builder query = new BooleanQuery.Builder(); if(StringHelper.containsNonWhitespace(queryString)) { String[] fieldsArr = getFieldsToSearchIn(); - QueryParser queryParser = new MultiFieldQueryParser(SearchService.OO_LUCENE_VERSION, fieldsArr, analyzer); - queryParser.setLowercaseExpandedTerms(false);//some add. fields are not tokenized and not lowered case + Map<String,Float> boosters = getFieldsBoosters(); + QueryParser queryParser = new MultiFieldQueryParser(fieldsArr, analyzer, boosters); + queryParser.setLocale(locale);//some add. fields are not tokenized and not lowered case Query multiFieldQuery = queryParser.parse(queryString.toLowerCase()); query.add(multiFieldQuery, Occur.MUST); } if(condQueries != null && !condQueries.isEmpty()) { for(String condQueryString:condQueries) { - QueryParser condQueryParser = new QueryParser(SearchService.OO_LUCENE_VERSION, condQueryString, analyzer); - condQueryParser.setLowercaseExpandedTerms(false); + QueryParser condQueryParser = new QueryParser(condQueryString, analyzer); + condQueryParser.setLocale(locale); Query condQuery = condQueryParser.parse(condQueryString); query.add(condQuery, Occur.MUST); } @@ -405,6 +405,23 @@ public class SearchServiceImpl implements SearchService, GenericEventListener { return query; } + private Map<String,Float> getFieldsBoosters() { + Map<String,Float> boosters = new HashMap<>(); + boosters.put(AbstractOlatDocument.TITLE_FIELD_NAME, Float.valueOf(4.0f)); + + boosters.put(AbstractOlatDocument.DESCRIPTION_FIELD_NAME, Float.valueOf(2.0f)); + boosters.put(AbstractOlatDocument.AUTHOR_FIELD_NAME, Float.valueOf(2.0f)); + boosters.put(AbstractOlatDocument.LOCATION_FIELD_NAME, Float.valueOf(2.0f)); + boosters.put(QItemDocument.LICENSE_TYPE_FIELD_NAME, 2.0f); + boosters.put(QItemDocument.COVERAGE_FIELD, 2.0f); + boosters.put(QItemDocument.KEYWORDS_FIELD, 2.0f); + boosters.put(QItemDocument.LICENSE_TYPE_FIELD_NAME, 2.0f); + + boosters.put(AbstractOlatDocument.CONTENT_FIELD_NAME, Float.valueOf(0.5f)); + + return boosters; + } + private String[] getFieldsToSearchIn() { return fields; } @@ -497,8 +514,8 @@ public class SearchServiceImpl implements SearchService, GenericEventListener { private IndexSearcher newSearcher() throws IOException { - DirectoryReader classicReader = DirectoryReader.open(FSDirectory.open(new File(indexPath))); - DirectoryReader permanentReader = DirectoryReader.open(FSDirectory.open(new File(permanentIndexPath))); + DirectoryReader classicReader = DirectoryReader.open(FSDirectory.open(new File(indexPath).toPath())); + DirectoryReader permanentReader = DirectoryReader.open(FSDirectory.open(new File(permanentIndexPath).toPath())); OOMultiReader mReader = new OOMultiReader(classicReader, permanentReader); return new IndexSearcher(mReader); } @@ -508,7 +525,7 @@ public class SearchServiceImpl implements SearchService, GenericEventListener { private final DirectoryReader reader; private final DirectoryReader permanentReader; - public OOMultiReader(DirectoryReader reader, DirectoryReader permanentReader) { + public OOMultiReader(DirectoryReader reader, DirectoryReader permanentReader) throws IOException { super(reader, permanentReader); this.reader = reader; this.permanentReader = permanentReader; @@ -572,8 +589,7 @@ public class SearchServiceImpl implements SearchService, GenericEventListener { public static IndexSearcher getSearcher(SearchServiceImpl searcherFactory) throws IOException { - IndexSearcher searcher = searcherFactory.newSearcher(); - return searcher; + return searcherFactory.newSearcher(); } } @@ -600,18 +616,19 @@ public class SearchServiceImpl implements SearchService, GenericEventListener { */ protected boolean existIndex() throws IOException { - try { + File indexFile = new File(searchModuleConfig.getFullIndexPath()); if(indexFile.exists()) { - Directory directory = FSDirectory.open(indexFile); File permIndexFile = new File(searchModuleConfig.getFullPermanentIndexPath()); - Directory permDirectory = FSDirectory.open(permIndexFile); - return DirectoryReader.indexExists(directory) && DirectoryReader.indexExists(permDirectory); + try(FSDirectory directory = FSDirectory.open(indexFile.toPath()); + FSDirectory permDirectory = FSDirectory.open(permIndexFile.toPath())) { + return DirectoryReader.indexExists(directory) && DirectoryReader.indexExists(permDirectory); + } catch(IOException e) { + log.error("", e); + } } return false; - } catch (IOException e) { - throw e; - } + } /** diff --git a/src/main/java/org/olat/search/service/document/file/FileDocumentFactory.java b/src/main/java/org/olat/search/service/document/file/FileDocumentFactory.java index 6a8e9427bbe5927742967af251d005caad00040c..89eef29f456b979ee5d8cd318aa019f953661424 100644 --- a/src/main/java/org/olat/search/service/document/file/FileDocumentFactory.java +++ b/src/main/java/org/olat/search/service/document/file/FileDocumentFactory.java @@ -64,24 +64,24 @@ public class FileDocumentFactory { private static OLog log = Tracing.createLoggerFor(FileDocumentFactory.class); - private final static String PDF_SUFFIX = "pdf"; - private final static String EXCEL_SUFFIX = "xls"; - private final static String WORD_SUFFIX = "doc"; - private final static String POWERPOINT_SUFFIX = "ppt"; - private final static String EXCEL_X_SUFFIX = "xlsx"; - private final static String WORD_X_SUFFIX = "docx"; - private final static String POWERPOINT_X_SUFFIX = "pptx"; - private final static String OD_TEXT_SUFFIX = "odt"; - private final static String OD_SPREADSHEET_SUFFIX = "ods"; - private final static String OD_PRESENTATION_SUFFIX = "odp"; - private final static String OD_FORMULA_SUFFIX = "odf"; - private final static String OD_GRAPHIC_SUFFIX = "odg"; + private static final String PDF_SUFFIX = "pdf"; + private static final String EXCEL_SUFFIX = "xls"; + private static final String WORD_SUFFIX = "doc"; + private static final String POWERPOINT_SUFFIX = "ppt"; + private static final String EXCEL_X_SUFFIX = "xlsx"; + private static final String WORD_X_SUFFIX = "docx"; + private static final String POWERPOINT_X_SUFFIX = "pptx"; + private static final String OD_TEXT_SUFFIX = "odt"; + private static final String OD_SPREADSHEET_SUFFIX = "ods"; + private static final String OD_PRESENTATION_SUFFIX = "odp"; + private static final String OD_FORMULA_SUFFIX = "odf"; + private static final String OD_GRAPHIC_SUFFIX = "odg"; - private final static String HTML_SUFFIX = "htm html xhtml"; - private final static String XML_SUFFIX = "xml"; - private final static String TEXT_SUFFIX = "txt tex readme csv"; + private static final String HTML_SUFFIX = "htm html xhtml"; + private static final String XML_SUFFIX = "xml"; + private static final String TEXT_SUFFIX = "txt tex readme csv"; - //as a special parser; + // IMS manifest has a special parser private static final String IMS_MANIFEST_FILE = "imsmanifest.xml"; private int excludedFileSizeCount = 0; diff --git a/src/main/java/org/olat/search/service/indexer/Index.java b/src/main/java/org/olat/search/service/indexer/Index.java index 3ebeb196de6d68cfb85a758574cc380b77c40264..42f96abeed228dfa2fa971108ae457a78317d890 100644 --- a/src/main/java/org/olat/search/service/indexer/Index.java +++ b/src/main/java/org/olat/search/service/indexer/Index.java @@ -101,7 +101,7 @@ public class Index { public boolean existIndex() { try { File indexFile = new File(indexPath); - Directory directory = FSDirectory.open(indexFile); + Directory directory = FSDirectory.open(indexFile.toPath()); return DirectoryReader.indexExists(directory); } catch (IOException e) { log.error("", e); @@ -112,7 +112,7 @@ public class Index { public boolean existPermanentIndex() { try { File indexFile = new File(permanentIndexPath); - Directory directory = FSDirectory.open(indexFile); + Directory directory = FSDirectory.open(indexFile.toPath()); return DirectoryReader.indexExists(directory); } catch (IOException e) { log.error("", e); diff --git a/src/main/java/org/olat/search/service/indexer/JmsIndexer.java b/src/main/java/org/olat/search/service/indexer/JmsIndexer.java index 5cbdee229241a03b68d545826ec670f82c5ab5c9..8f558ff03ee3308242ce861dbabf67fdf7287674 100644 --- a/src/main/java/org/olat/search/service/indexer/JmsIndexer.java +++ b/src/main/java/org/olat/search/service/indexer/JmsIndexer.java @@ -58,12 +58,9 @@ import org.olat.core.logging.OLog; import org.olat.core.logging.Tracing; import org.olat.core.util.coordinate.CoordinatorManager; import org.olat.search.SearchModule; -import org.olat.search.SearchService; import org.olat.search.model.AbstractOlatDocument; /** - * TODO or not: to make the Indexer cluster wide functional. It would be - * possible to create on the fly an IndexWriter with a doInSync. * * Initial date: 04.03.2013<br> * @author srosse, stephane.rosse@frentix.com, http://www.frentix.com @@ -89,7 +86,7 @@ public class JmsIndexer implements MessageListener, LifeFullIndexer, ConfigOnOff private double ramBufferSizeMB; private boolean indexingNode; - private List<LifeIndexer> indexers = new ArrayList<LifeIndexer>(); + private List<LifeIndexer> indexers = new ArrayList<>(); public JmsIndexer(SearchModule searchModuleConfig, CoordinatorManager coordinatorManager) { indexingNode = searchModuleConfig.isSearchServiceEnabled(); @@ -145,7 +142,7 @@ public class JmsIndexer implements MessageListener, LifeFullIndexer, ConfigOnOff } public List<LifeIndexer> getIndexerByType(String type) { - List<LifeIndexer> indexerByType = new ArrayList<LifeIndexer>(); + List<LifeIndexer> indexerByType = new ArrayList<>(); for(LifeIndexer indexer:indexers) { if(type.equals(indexer.getSupportedTypeName())) { indexerByType.add(indexer); @@ -179,7 +176,7 @@ public class JmsIndexer implements MessageListener, LifeFullIndexer, ConfigOnOff public void initDirectory() { try { File tempIndexDir = new File(permanentIndexPath); - Directory indexPath = FSDirectory.open(tempIndexDir); + Directory indexPath = FSDirectory.open(tempIndexDir.toPath()); if(indexingNode) { permanentIndexWriter = new IndexWriterHolder(indexPath, this); boolean created = permanentIndexWriter.ensureIndexExists(); @@ -202,8 +199,8 @@ public class JmsIndexer implements MessageListener, LifeFullIndexer, ConfigOnOff } public IndexWriterConfig newIndexWriterConfig() { - Analyzer analyzer = new StandardAnalyzer(SearchService.OO_LUCENE_VERSION); - IndexWriterConfig indexWriterConfig = new IndexWriterConfig(SearchService.OO_LUCENE_VERSION, analyzer); + Analyzer analyzer = new StandardAnalyzer(); + IndexWriterConfig indexWriterConfig = new IndexWriterConfig(analyzer); indexWriterConfig.setMergePolicy(newLogMergePolicy()); indexWriterConfig.setRAMBufferSizeMB(ramBufferSizeMB);// for better performance set to 48MB (see lucene docu 'how to make indexing faster") indexWriterConfig.setOpenMode(OpenMode.CREATE_OR_APPEND); @@ -327,7 +324,7 @@ public class JmsIndexer implements MessageListener, LifeFullIndexer, ConfigOnOff String type = workUnit.getIndexType(); List<LifeIndexer> lifeIndexers = getIndexerByType(type); for(LifeIndexer indexer:lifeIndexers) { - if(workUnit.getKeyList() != null && workUnit.getKeyList().size() > 0) { + if(workUnit.getKeyList() != null && !workUnit.getKeyList().isEmpty()) { for(Long key:workUnit.getKeyList()) { indexer.deleteDocument(key, this); } diff --git a/src/main/java/org/olat/search/service/indexer/OlatFullIndexer.java b/src/main/java/org/olat/search/service/indexer/OlatFullIndexer.java index 506f18999529c24078ee59eacd629a798c29e9d4..f6bbe6428b4de632adbdc2d809a539e92228f614 100644 --- a/src/main/java/org/olat/search/service/indexer/OlatFullIndexer.java +++ b/src/main/java/org/olat/search/service/indexer/OlatFullIndexer.java @@ -213,8 +213,8 @@ public class OlatFullIndexer { public IndexWriterConfig newIndexWriterConfig() { - Analyzer analyzer = new StandardAnalyzer(SearchService.OO_LUCENE_VERSION); - IndexWriterConfig indexWriterConfig = new IndexWriterConfig(SearchService.OO_LUCENE_VERSION, analyzer); + Analyzer analyzer = new StandardAnalyzer(); + IndexWriterConfig indexWriterConfig = new IndexWriterConfig(analyzer); indexWriterConfig.setMergePolicy(newLogMergePolicy()); indexWriterConfig.setRAMBufferSizeMB(ramBufferSizeMB);// for better performance set to 48MB (see lucene docu 'how to make indexing faster") indexWriterConfig.setOpenMode(OpenMode.CREATE_OR_APPEND); @@ -231,17 +231,17 @@ public class OlatFullIndexer { private void doIndex() throws InterruptedException{ try { if(indexerExecutor == null) { - BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(2); + BlockingQueue<Runnable> queue = new LinkedBlockingQueue<>(2); indexerExecutor = new ThreadPoolExecutor(indexerPoolSize, indexerPoolSize, 0L, TimeUnit.MILLISECONDS, queue, indexWorkersThreadFactory, new ThreadPoolExecutor.CallerRunsPolicy()); } if(indexerWriterExecutor == null) { - BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(2); + BlockingQueue<Runnable> queue = new LinkedBlockingQueue<>(2); indexerWriterExecutor = new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, queue, indexWriterThreadFactory); } File tempIndexDir = new File(tempIndexPath); - Directory tmpIndexPath = FSDirectory.open(new File(tempIndexDir, "main")); + Directory tmpIndexPath = FSDirectory.open(new File(tempIndexDir, "main").toPath()); indexWriter = new IndexWriter(tmpIndexPath, newIndexWriterConfig());// analyzer, true, IndexWriter.MAX_TERM_LENGTH.UNLIMITED); indexWriter.deleteAll(); @@ -256,7 +256,6 @@ public class OlatFullIndexer { indexerExecutor.awaitTermination(10, TimeUnit.MINUTES); DBFactory.getInstance().commitAndCloseSession(); - log.info("Wait until index writer executor is finished"); int waitWriter = 0; while (indexerWriterExecutor.getActiveCount() > 0 && (waitWriter++ < MAX_WAITING_COUNT)) { @@ -362,7 +361,7 @@ public class OlatFullIndexer { * @param document * @throws IOException */ - public void addDocument(Document document) throws IOException,InterruptedException { + public void addDocument(Document document) throws InterruptedException { DBFactory.getInstance().commitAndCloseSession(); if (!stopIndexing && indexerWriterExecutor != null && !indexerWriterExecutor.isShutdown()) { @@ -391,7 +390,7 @@ public class OlatFullIndexer { intValue = fileCounter.intValue(); } intValue++; - fileTypeCounters.put(fileType, new Integer(intValue)); + fileTypeCounters.put(fileType, Integer.valueOf(intValue)); } } @@ -403,7 +402,7 @@ public class OlatFullIndexer { intValue = docCounter.intValue(); } intValue++; - documentCounters.put(documentType, new Integer(intValue)); + documentCounters.put(documentType, Integer.valueOf(intValue)); } private void countIndexPerMinute() { @@ -452,8 +451,8 @@ public class OlatFullIndexer { } private void resetDocumentCounters() { - documentCounters = new Hashtable<String,Integer>(); - fileTypeCounters = new Hashtable<String,Integer>(); + documentCounters = new Hashtable<>(); + fileTypeCounters = new Hashtable<>(); } private class CloseIndexCallable implements Callable<Boolean> { diff --git a/src/main/java/org/olat/search/service/indexer/QuestionItemIndexer.java b/src/main/java/org/olat/search/service/indexer/QuestionItemIndexer.java index 467190a07b36f543a8b711eceadc884e3e0ed9d9..539ea6db9bf1e5913347966202452016953cba5c 100644 --- a/src/main/java/org/olat/search/service/indexer/QuestionItemIndexer.java +++ b/src/main/java/org/olat/search/service/indexer/QuestionItemIndexer.java @@ -88,7 +88,7 @@ public class QuestionItemIndexer implements LifeIndexer { } counter += items.size(); } while(items.size() == BATCH_SIZE); - + log.info(counter + " question items indexed."); } catch (Exception e) { log.error("", e); } finally { diff --git a/src/main/java/org/olat/search/service/indexer/repository/RepositoryIndexer.java b/src/main/java/org/olat/search/service/indexer/repository/RepositoryIndexer.java index 3e3a0d81085990a377740445096e1e35012da918..d9205f2c2ea97ed68e78a0419b40b87bfca5bdc0 100644 --- a/src/main/java/org/olat/search/service/indexer/repository/RepositoryIndexer.java +++ b/src/main/java/org/olat/search/service/indexer/repository/RepositoryIndexer.java @@ -45,7 +45,6 @@ import org.olat.repository.RepositoryManager; import org.olat.repository.RepositoryService; import org.olat.repository.manager.RepositoryEntryDocumentFactory; import org.olat.repository.model.RepositoryEntrySecurity; -import org.olat.repository.model.SearchRepositoryEntryParameters; import org.olat.resource.accesscontrol.ACService; import org.olat.resource.accesscontrol.AccessResult; import org.olat.resource.accesscontrol.OfferAccess; @@ -120,13 +119,7 @@ public class RepositoryIndexer extends AbstractHierarchicalIndexer { @Override public void doIndex(SearchResourceContext parentResourceContext, Object businessObj, OlatFullIndexer indexWriter) throws IOException,InterruptedException { - final Roles roles = Roles.administratorRoles(); - - final SearchRepositoryEntryParameters params = new SearchRepositoryEntryParameters(); - params.setRoles(roles); boolean debug = isLogDebugEnabled(); - - // loop over all repository-entries // committing here to make sure the loadBusinessGroup below does actually // reload from the database and not only use the session cache @@ -137,12 +130,12 @@ public class RepositoryIndexer extends AbstractHierarchicalIndexer { int counter = 0; List<RepositoryEntry> repositoryList; do { - repositoryList = repositoryManager.genericANDQueryWithRolesRestriction(params, counter, BATCH_SIZE, true); + repositoryList = repositoryService.loadRepositoryEntries(counter, BATCH_SIZE); for(RepositoryEntry repositoryEntry:repositoryList) { try { // reload the repositoryEntry here before indexing it to make sure it has not been deleted in the meantime - RepositoryEntry reloadedRepositoryEntry = repositoryManager.lookupRepositoryEntry(repositoryEntry.getKey()); + RepositoryEntry reloadedRepositoryEntry = repositoryService.loadByKey(repositoryEntry.getKey()); if (reloadedRepositoryEntry==null) { logInfo("doIndex: repositoryEntry was deleted while we were indexing. The deleted repositoryEntry was: "+repositoryEntry); continue; diff --git a/src/main/java/org/olat/search/service/searcher/JmsSearchProvider.java b/src/main/java/org/olat/search/service/searcher/JmsSearchProvider.java index 926b9de6c6d3e8ee5fedb2f79547f2832eb59bb2..0470cdf1d75ae3a953f0bd4caa863bb1e323f20f 100644 --- a/src/main/java/org/olat/search/service/searcher/JmsSearchProvider.java +++ b/src/main/java/org/olat/search/service/searcher/JmsSearchProvider.java @@ -28,6 +28,7 @@ package org.olat.search.service.searcher; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; +import java.util.Locale; import java.util.Set; import javax.jms.Connection; @@ -68,14 +69,13 @@ import org.olat.search.ServiceNotAvailableException; */ public class JmsSearchProvider implements MessageListener { - private OLog log_ = Tracing.createLoggerFor(this.getClass()); + private static final OLog log = Tracing.createLoggerFor(JmsSearchProvider.class); private SearchService searchService; - private ConnectionFactory connectionFactory_; - private Connection connection_; - private Queue searchQueue_; - private Session session_; - private MessageConsumer consumer_; - private LinkedList<Session> sessions_ = new LinkedList<Session>(); + private ConnectionFactory connectionFactory; + private Connection connection; + private Queue searchQueue; + private Session session; + private LinkedList<Session> sessions = new LinkedList<>(); private long receiveTimeout = 60000; private TaskExecutorManager taskExecutorManager; @@ -88,11 +88,11 @@ public class JmsSearchProvider implements MessageListener { } public void setConnectionFactory(ConnectionFactory conFac) { - connectionFactory_ = conFac; + connectionFactory = conFac; } public void setSearchQueue(Queue searchQueue) { - this.searchQueue_ = searchQueue; + this.searchQueue = searchQueue; } public void setReceiveTimeout(long receiveTimeout) { @@ -107,9 +107,12 @@ public class JmsSearchProvider implements MessageListener { * Delegates execution to the searchService. * @see org.olat.search.service.searcher.OLATSearcher#doSearch(java.lang.String, org.olat.core.id.Identity, org.olat.core.id.Roles, boolean) */ - public SearchResults doSearch(String queryString, List<String> condQueries, Identity identity, Roles roles, int firstResult, int maxResults, boolean doHighlighting) throws ServiceNotAvailableException, ParseException, QueryException { - if (searchService == null) throw new AssertException("searchService in ClusteredSearchProvider is null, please check the search configuration!"); - return searchService.doSearch(queryString, condQueries, identity, roles, firstResult, maxResults, doHighlighting); + public SearchResults doSearch(String queryString, List<String> condQueries, Identity identity, Roles roles, Locale locale, + int firstResult, int maxResults, boolean doHighlighting) throws ServiceNotAvailableException, ParseException, QueryException { + if (searchService == null) { + throw new AssertException("searchService in ClusteredSearchProvider is null, please check the search configuration!"); + } + return searchService.doSearch(queryString, condQueries, identity, roles, locale, firstResult, maxResults, doHighlighting); } @@ -119,28 +122,20 @@ public class JmsSearchProvider implements MessageListener { return searchService.spellCheck(query); } - /** - * - * @see org.olat.search.service.searcher.OLATSearcher#getQueryCount() - */ public long getQueryCount() { if (searchService == null) throw new AssertException("searchService in ClusteredSearchProvider is null, please check the search configuration!"); return searchService.getQueryCount(); } - /** - * - * @see org.olat.search.service.searcher.OLATSearcher#stop() - */ public void stop() { if (searchService == null) throw new AssertException("searchService in ClusteredSearchProvider is null, please check the search configuration!"); searchService.stop(); try { - session_.close(); - connection_.close(); - log_.info("ClusteredSearchProvider stopped"); + session.close(); + connection.close(); + log.info("ClusteredSearchProvider stopped"); } catch (JMSException e) { - log_.warn("Exception in stop ClusteredSearchProvider, ",e); + log.warn("Exception in stop ClusteredSearchProvider, ",e); } } @@ -154,17 +149,18 @@ public class JmsSearchProvider implements MessageListener { } public void springInit() throws JMSException { - connection_ = connectionFactory_.createConnection(); - session_ = connection_.createSession(false, Session.AUTO_ACKNOWLEDGE); - consumer_ = session_.createConsumer(searchQueue_); - consumer_.setMessageListener(this); - connection_.start(); - log_.info("ClusteredSearchProvider JMS started"); + connection = connectionFactory.createConnection(); + session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + MessageConsumer consumer = session.createConsumer(searchQueue); + consumer.setMessageListener(this); + connection.start(); + log.info("ClusteredSearchProvider JMS started"); } + @Override public void onMessage(Message message) { - if ( log_.isDebug() ) { - log_.debug("onMessage, message=" + message); + if ( log.isDebug() ) { + log.debug("onMessage, message=" + message); } try{ long sentTimestamp = message.getJMSTimestamp(); @@ -176,87 +172,75 @@ public class JmsSearchProvider implements MessageListener { if (message instanceof ObjectMessage) { ObjectMessage objectMessage = (ObjectMessage) message; final SearchRequest searchRequest = (SearchRequest) objectMessage.getObject(); - taskExecutorManager.execute(new Runnable() { - - public void run() { - onSearchMessage(searchRequest, correlationID, replyTo); - } - + taskExecutorManager.execute(() -> { + onSearchMessage(searchRequest, correlationID, replyTo); }); } else if (message instanceof TextMessage) { TextMessage testMessage = (TextMessage)message; final String spellText = testMessage.getText(); - taskExecutorManager.execute(new Runnable() { - - public void run() { - onSpellMessage(spellText, correlationID, replyTo); - } - + taskExecutorManager.execute(() -> { + onSpellMessage(spellText, correlationID, replyTo); }); } } else { // JMS message is too old, discard it (do nothing) - log_.warn("JMS message was too old, discard message, timeout=" + receiveTimeout + "ms , received time=" + (currentTimestamp - sentTimestamp) + "ms"); + log.warn("JMS message was too old, discard message, timeout=" + receiveTimeout + "ms , received time=" + (currentTimestamp - sentTimestamp) + "ms"); } } catch(JMSException e) { - log_.error("error when receiving jms messages", e); - return; //signal search not available + log.error("error when receiving jms messages", e); } catch (Error err) { - log_.warn("Error in onMessage, ",err); + log.warn("Error in onMessage, ",err); // OLAT-3973: don't throw exceptions here } catch (RuntimeException runEx) { - log_.warn("RuntimeException in onMessage, ",runEx); + log.warn("RuntimeException in onMessage, ",runEx); // OLAT-3973: don't throw exceptions here } } private synchronized Session acquireSession() throws JMSException { - if (sessions_.size()==0) { - return connection_.createSession(false, Session.AUTO_ACKNOWLEDGE); + if (sessions.isEmpty()) { + return connection.createSession(false, Session.AUTO_ACKNOWLEDGE); } else { - return sessions_.getFirst(); + return sessions.getFirst(); } } - private synchronized void releaseSession(Session session) { - if (session==null) { - return; + private synchronized void releaseSession(Session sessionToRelease) { + if (sessionToRelease != null) { + sessions.addLast(sessionToRelease); } - sessions_.addLast(session); } void onSearchMessage(SearchRequest searchRequest, String correlationID, Destination replyTo) { - if ( log_.isDebug() ) { - log_.debug("onSearchMessage, correlationID=" + correlationID + " , replyTo=" + replyTo + " , searchRequest=" + searchRequest); + if ( log.isDebug() ) { + log.debug("onSearchMessage, correlationID=" + correlationID + " , replyTo=" + replyTo + " , searchRequest=" + searchRequest); } - Session session = null; + Session searchSession = null; try{ Identity identity = BaseSecurityManager.getInstance().loadIdentityByKey(searchRequest.getIdentityId()); - SearchResults searchResults = this.doSearch(searchRequest.getQueryString(), searchRequest.getCondQueries(), identity, searchRequest.getRoles(), + SearchResults searchResults = doSearch(searchRequest.getQueryString(), searchRequest.getCondQueries(), + identity, searchRequest.getRoles(), searchRequest.getLocale(), searchRequest.getFirstResult(), searchRequest.getMaxResults(), searchRequest.isDoHighlighting()); - if (log_.isDebug()) { - log_.debug("searchResults: " + searchResults.size()); + if (log.isDebug()) { + log.debug("searchResults: " + searchResults.size()); } if (searchResults != null) { - session = acquireSession(); - Message responseMessage = session.createObjectMessage(searchResults); + searchSession = acquireSession(); + Message responseMessage = searchSession.createObjectMessage(searchResults); responseMessage.setJMSCorrelationID(correlationID); responseMessage.setStringProperty(SearchClientProxy.JMS_RESPONSE_STATUS_PROPERTY_NAME, SearchClientProxy.JMS_RESPONSE_STATUS_OK); - MessageProducer producer = session.createProducer(replyTo); - if ( log_.isDebug() ) { - log_.debug("onSearchMessage, send ResponseMessage=" + responseMessage + " to replyTo=" + replyTo); + MessageProducer producer = searchSession.createProducer(replyTo); + if ( log.isDebug() ) { + log.debug("onSearchMessage, send ResponseMessage=" + responseMessage + " to replyTo=" + replyTo); } producer.send(responseMessage); producer.close(); - return; } else { - log_.info("onSearchMessage, no searchResults (searchResults=null)"); + log.info("onSearchMessage, no searchResults (searchResults=null)"); } } catch (JMSException e) { - log_.error("error when receiving jms messages", e); - return; //signal search not available - // do not throw exceptions here throw new OLATRuntimeException(); + log.error("error when receiving jms messages", e); } catch (ServiceNotAvailableException sex) { sendErrorResponse(SearchClientProxy.JMS_RESPONSE_STATUS_SERVICE_NOT_AVAILABLE_EXCEPTION, correlationID, replyTo); } catch (ParseException pex) { @@ -264,63 +248,52 @@ public class JmsSearchProvider implements MessageListener { } catch (QueryException qex) { sendErrorResponse(SearchClientProxy.JMS_RESPONSE_STATUS_QUERY_EXCEPTION, correlationID, replyTo); } catch (Throwable th) { - log_.error("error at ClusteredSearchProvider.receive()", th); - return;// signal search not available - // do not throw exceptions throw new OLATRuntimeException(); + log.error("error at ClusteredSearchProvider.receive()", th); } finally{ - releaseSession(session); + releaseSession(searchSession); DBFactory.getInstance().commitAndCloseSession(); } } private void sendErrorResponse(String jmsResponseStatus, String correlationID, Destination replyTo) { - Session session = null; + Session sendSession = null; try { - session = acquireSession(); - Message responseMessage = session.createObjectMessage(); + sendSession = acquireSession(); + Message responseMessage = sendSession.createObjectMessage(); responseMessage.setJMSCorrelationID(correlationID); responseMessage.setStringProperty(SearchClientProxy.JMS_RESPONSE_STATUS_PROPERTY_NAME, jmsResponseStatus); - MessageProducer producer = session.createProducer(replyTo); - if ( log_.isDebug() ) { - log_.debug("onSearchMessage, send ResponseMessage=" + responseMessage + " to replyTo=" + replyTo); + MessageProducer producer = sendSession.createProducer(replyTo); + if ( log.isDebug() ) { + log.debug("onSearchMessage, send ResponseMessage=" + responseMessage + " to replyTo=" + replyTo); } producer.send(responseMessage); producer.close(); - return; - } catch (JMSException e) { - log_.error("error when receiving jms messages", e); - return; //signal search not available + log.error("error when receiving jms messages", e); } finally{ - releaseSession(session); + releaseSession(sendSession); } } void onSpellMessage(String spellText, String correlationID, Destination replyTo) { - Session session = null; + Session spellSession = null; try { Set<String> spellStrings = this.spellCheck(spellText); if(spellStrings!=null) { - ArrayList<String> spellStringList = new ArrayList<String>(spellStrings); - session = acquireSession(); - Message responseMessage = session.createObjectMessage(spellStringList); + ArrayList<String> spellStringList = new ArrayList<>(spellStrings); + spellSession = acquireSession(); + Message responseMessage = spellSession.createObjectMessage(spellStringList); responseMessage.setJMSCorrelationID(correlationID); - MessageProducer producer = session.createProducer(replyTo); + MessageProducer producer = spellSession.createProducer(replyTo); producer.send(responseMessage); producer.close(); - return; } - return; // signal search not available } catch (JMSException e) { - log_.error("error when receiving jms messages", e); - return; //signal search not available - // do not throw exceptions here throw new OLATRuntimeException(); + log.error("error when receiving jms messages", e); } catch (Throwable th) { - log_.error("error at ClusteredSearchProvider.receive()", th); - return;// signal search not available - // do not throw exceptions throw new OLATRuntimeException(); + log.error("error at ClusteredSearchProvider.receive()", th); } finally{ - releaseSession(session); + releaseSession(spellSession); DBFactory.getInstance().commitAndCloseSession(); } } diff --git a/src/main/java/org/olat/search/service/searcher/SearchClient.java b/src/main/java/org/olat/search/service/searcher/SearchClient.java index adbda778b21fd88ee2bb9d7b3aeec0a3be13f7f7..bf686a01a9a9e5a9a23d2437f7359814da56f874 100644 --- a/src/main/java/org/olat/search/service/searcher/SearchClient.java +++ b/src/main/java/org/olat/search/service/searcher/SearchClient.java @@ -20,6 +20,7 @@ package org.olat.search.service.searcher; import java.util.List; +import java.util.Locale; import java.util.Set; import org.apache.lucene.queryparser.classic.ParseException; @@ -41,10 +42,11 @@ import org.olat.search.ServiceNotAvailableException; */ public interface SearchClient { - public SearchResults doSearch(String queryString, List<String> condQueries, Identity identity, Roles roles, int firstResult, int maxResults, boolean doHighlighting) + public SearchResults doSearch(String queryString, List<String> condQueries, Identity identity, Roles roles, Locale locale, + int firstResult, int maxResults, boolean doHighlighting) throws ServiceNotAvailableException, ParseException, QueryException; - public List<Long> doSearch(String queryString, List<String> condQueries, Identity identity, Roles roles, + public List<Long> doSearch(String queryString, List<String> condQueries, Identity identity, Roles roles, Locale locale, int firstResult, int maxResults, SortKey... orderBy) throws ServiceNotAvailableException, ParseException, QueryException; diff --git a/src/main/java/org/olat/search/service/searcher/SearchClientLocal.java b/src/main/java/org/olat/search/service/searcher/SearchClientLocal.java index 4d460aa74d6012fbceb7d2a83e983832e081459e..ddca083393f2e4df50384152196cfc46ccbff990 100644 --- a/src/main/java/org/olat/search/service/searcher/SearchClientLocal.java +++ b/src/main/java/org/olat/search/service/searcher/SearchClientLocal.java @@ -20,6 +20,7 @@ package org.olat.search.service.searcher; import java.util.List; +import java.util.Locale; import java.util.Set; import org.apache.lucene.queryparser.classic.ParseException; @@ -55,19 +56,19 @@ public class SearchClientLocal implements SearchClient { } @Override - public SearchResults doSearch(String queryString, List<String> condQueries, Identity identity, Roles roles, + public SearchResults doSearch(String queryString, List<String> condQueries, Identity identity, Roles roles, Locale locale, int firstResult, int maxReturns, boolean doHighlighting) throws ServiceNotAvailableException, ParseException, QueryException { dbInstance.commitAndCloseSession(); - return SearchServiceFactory.getService().doSearch(queryString, condQueries, identity, roles, firstResult, maxReturns, doHighlighting); + return SearchServiceFactory.getService().doSearch(queryString, condQueries, identity, roles, locale, firstResult, maxReturns, doHighlighting); } @Override - public List<Long> doSearch(String queryString, List<String> condQueries, Identity identity, Roles roles, + public List<Long> doSearch(String queryString, List<String> condQueries, Identity identity, Roles roles, Locale locale, int firstResult, int maxResults, SortKey... orderBy) throws ServiceNotAvailableException, ParseException, QueryException { dbInstance.commitAndCloseSession(); - return SearchServiceFactory.getService().doSearch(queryString, condQueries, identity, roles, firstResult, maxResults, orderBy); + return SearchServiceFactory.getService().doSearch(queryString, condQueries, identity, roles, locale, firstResult, maxResults, orderBy); } @Override diff --git a/src/main/java/org/olat/search/service/searcher/SearchClientProxy.java b/src/main/java/org/olat/search/service/searcher/SearchClientProxy.java index 7520f75f60642917ca91d88f64c8ab43f4892fd2..baedf96974772b0d72c64d9066b8e069ac9bce8b 100644 --- a/src/main/java/org/olat/search/service/searcher/SearchClientProxy.java +++ b/src/main/java/org/olat/search/service/searcher/SearchClientProxy.java @@ -25,10 +25,12 @@ package org.olat.search.service.searcher; +import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.Locale; import java.util.Random; import java.util.Set; @@ -82,8 +84,8 @@ public class SearchClientProxy implements SearchClient { private long receiveTimeout_ = 45000; private long timeToLive_ = 45000; private Connection connection_; - private LinkedList<Destination> tempQueues_ = new LinkedList<Destination>(); - private LinkedList<Session> sessions_ = new LinkedList<Session>(); + private LinkedList<Destination> tempQueues_ = new LinkedList<>(); + private LinkedList<Session> sessions_ = new LinkedList<>(); /** * [used by spring] @@ -115,7 +117,7 @@ public class SearchClientProxy implements SearchClient { } private synchronized Destination acquireTempQueue(Session session) throws JMSException { - if (tempQueues_.size()==0) { + if (tempQueues_.isEmpty()) { if (session==null) { Session s = connection_.createSession(false, Session.AUTO_ACKNOWLEDGE); Destination tempQ = s.createTemporaryQueue(); @@ -129,7 +131,7 @@ public class SearchClientProxy implements SearchClient { } private synchronized Session acquireSession() throws JMSException { - if (sessions_.size()==0) { + if (sessions_.isEmpty()) { return connection_.createSession(false, Session.AUTO_ACKNOWLEDGE); } else { return sessions_.removeFirst(); @@ -155,12 +157,13 @@ public class SearchClientProxy implements SearchClient { * @see org.olat.search.service.searcher.OLATSearcher#doSearch(java.lang.String, org.olat.core.id.Identity, org.olat.core.id.Roles, boolean) */ @Override - public SearchResults doSearch(String queryString, List<String> condQueries, Identity identity, Roles roles, int firstResult, int maxResults, boolean doHighlighting) throws ServiceNotAvailableException, ParseException, QueryException { + public SearchResults doSearch(String queryString, List<String> condQueries, Identity identity, Roles roles, Locale locale, + int firstResult, int maxResults, boolean doHighlighting) throws ServiceNotAvailableException, ParseException, QueryException { boolean isDebug = log.isDebug(); if(isDebug){ log.debug("STARTqueryString=" + queryString); } - SearchRequest searchRequest = new SearchRequest(queryString, condQueries, identity.getKey(), roles, firstResult, maxResults, doHighlighting); + SearchRequest searchRequest = new SearchRequest(queryString, condQueries, identity.getKey(), roles, locale, firstResult, maxResults, doHighlighting); Session session = null; try { session = acquireSession(); @@ -200,15 +203,13 @@ public class SearchClientProxy implements SearchClient { } } - - @Override public List<Long> doSearch(String queryString, List<String> condQueries, - Identity identity, Roles roles, int firstResult, int maxResults, + Identity identity, Roles roles, Locale locale, int firstResult, int maxResults, SortKey... orderBy) throws ServiceNotAvailableException, ParseException, QueryException { - // TODO Auto-generated method stub - return null; + // only goes local + return Collections.emptyList(); } /** @@ -224,7 +225,7 @@ public class SearchClientProxy implements SearchClient { if(returnedMessage!=null){ @SuppressWarnings("unchecked") List<String> spellStringList = (List<String>)((ObjectMessage)returnedMessage).getObject(); - return new HashSet<String>(spellStringList); + return new HashSet<>(spellStringList); } else { //null returnedMessage throw new ServiceNotAvailableException("spellCheck, communication error with JMS - cannot receive messages!!!"); diff --git a/src/main/java/org/olat/search/service/searcher/SearchRequest.java b/src/main/java/org/olat/search/service/searcher/SearchRequest.java index 194268c2fad278f6ddf060d804e4147422b06c3a..f4951e3a0c2f20fafb01e6078cd0e9774023c349 100644 --- a/src/main/java/org/olat/search/service/searcher/SearchRequest.java +++ b/src/main/java/org/olat/search/service/searcher/SearchRequest.java @@ -26,6 +26,7 @@ package org.olat.search.service.searcher; import java.io.Serializable; import java.util.List; +import java.util.Locale; import org.olat.core.id.Roles; @@ -42,19 +43,20 @@ public class SearchRequest implements Serializable { private static final long serialVersionUID = -2886090379563029101L; private String queryString; - private List<String> condQueries; - private Long identityId; - private Roles roles; - private boolean doHighlighting; - private int firstResult; - private int maxResults; + private List<String> condQueries; + private Long identityId; + private Roles roles; + private Locale locale; + private boolean doHighlighting; + private int firstResult; + private int maxResults; - public SearchRequest() { - //default constructor - } + public SearchRequest() { + //default constructor + } - public SearchRequest(String queryString, List<String> condQueries, Long identityId, Roles roles, int firstResult, int maxResults, - boolean doHighlighting) { + public SearchRequest(String queryString, List<String> condQueries, Long identityId, Roles roles, Locale locale, + int firstResult, int maxResults, boolean doHighlighting) { super(); this.queryString = queryString; this.condQueries = condQueries; @@ -62,6 +64,7 @@ public class SearchRequest implements Serializable { this.maxResults = maxResults; this.identityId = identityId; this.roles = roles; + this.locale = locale; this.doHighlighting = doHighlighting; } @@ -121,6 +124,14 @@ public class SearchRequest implements Serializable { this.roles = roles; } + public Locale getLocale() { + return locale; + } + + public void setLocale(Locale locale) { + this.locale = locale; + } + @Override public String toString() { //dummy impl diff --git a/src/main/java/org/olat/search/service/searcher/SearchResultsImpl.java b/src/main/java/org/olat/search/service/searcher/SearchResultsImpl.java index 06f30f8d1da251618119a88b9291dcc0fc8bb35f..0dce04f5243b10c6d24aa1b5a29dc559f368e100 100644 --- a/src/main/java/org/olat/search/service/searcher/SearchResultsImpl.java +++ b/src/main/java/org/olat/search/service/searcher/SearchResultsImpl.java @@ -74,11 +74,11 @@ public class SearchResultsImpl implements SearchResults { private static final String HIGHLIGHT_SEPARATOR = "...<br />"; /* Define in module config */ - private int maxHits; - private int totalHits; - private int totalDocs; + private long maxHits; + private long totalHits; + private long totalDocs; private long queryTime; - private int numberOfIndexDocuments; + private long numberOfIndexDocuments; /* List of ResultDocument. */ private List<ResultDocument> resultList; private transient Indexer mainIndexer; @@ -138,15 +138,16 @@ public class SearchResultsImpl implements SearchResults { * Set number of search-index-elements. * @param numberOfIndexDocuments Number of search-index-elements. */ - public void setNumberOfIndexDocuments(int numberOfIndexDocuments) { + public void setNumberOfIndexDocuments(long numberOfIndexDocuments) { this.numberOfIndexDocuments = numberOfIndexDocuments; } /** * @return Number of search-index-elements. */ + @Override public String getNumberOfIndexDocuments() { - return Integer.toString(numberOfIndexDocuments); + return Long.toString(numberOfIndexDocuments); } /** @@ -154,15 +155,16 @@ public class SearchResultsImpl implements SearchResults { */ @Override public int getTotalHits() { - return totalHits; + return (int)totalHits; } - + + @Override public int getTotalDocs() { - return totalDocs; + return (int)totalDocs; } public String getMaxHits() { - return Integer.toString(maxHits); + return Long.toString(maxHits); } public boolean hasTooManyResults() { @@ -184,7 +186,7 @@ public class SearchResultsImpl implements SearchResults { maxHits = SearchServiceFactory.getService().getSearchModuleConfig().getMaxHits(); totalHits = docs.totalHits; totalDocs = (docs.scoreDocs == null ? 0 : docs.scoreDocs.length); - int numOfDocs = Math.min(maxHits, docs.totalHits); + long numOfDocs = Math.min(maxHits, docs.totalHits); List<ResultDocument> res = new ArrayList<>(maxReturns + 1); for (int i=firstResult; i<numOfDocs && res.size() < maxReturns; i++) { Document doc; diff --git a/src/main/java/org/olat/search/service/spell/SearchSpellChecker.java b/src/main/java/org/olat/search/service/spell/SearchSpellChecker.java index d322b14daac14d9674b568eaa625a8f034b2abb8..6d8465ee5f151f27ef01cb410791422ab1c99b0c 100644 --- a/src/main/java/org/olat/search/service/spell/SearchSpellChecker.java +++ b/src/main/java/org/olat/search/service/spell/SearchSpellChecker.java @@ -49,7 +49,6 @@ import org.olat.core.logging.OLog; import org.olat.core.logging.Tracing; import org.olat.core.util.FileUtils; import org.olat.search.SearchModule; -import org.olat.search.SearchService; import org.olat.search.model.OlatDocument; /** @@ -102,7 +101,7 @@ public class SearchSpellChecker { return null; } catch (Exception e) { log.warn("Can not spell check",e); - return new HashSet<String>(); + return new HashSet<>(); } } @@ -120,106 +119,124 @@ public class SearchSpellChecker { if(spellChecker==null) { //lazy initialization try { synchronized(spellDictionaryPath) {//o_clusterOK by:pb if service is only configured on one vm, which is recommended way - File spellDictionaryFile = new File(spellDictionaryPath); - Directory spellIndexDirectory = FSDirectory.open(spellDictionaryFile); + File spellDictionaryFile = new File(spellDictionaryPath); + Directory spellIndexDirectory = FSDirectory.open(spellDictionaryFile.toPath()); if (spellChecker==null && DirectoryReader.indexExists(spellIndexDirectory) && isSpellCheckEnabled ) { - spellChecker = new SpellChecker(spellIndexDirectory); - spellChecker.setAccuracy(0.7f); - } + spellChecker = new SpellChecker(spellIndexDirectory); + spellChecker.setAccuracy(0.7f); + } } } catch (IOException e) { log.warn("Can not initialze SpellChecker",e); } } - return spellChecker; - } + return spellChecker; + } /** * Creates a new spell-check index based on search-index * */ - public void createSpellIndex() { - if (isSpellCheckEnabled) { - IndexReader indexReader = null; - try { - log.info("Start generating Spell-Index..."); - long startSpellIndexTime = 0; - if (log.isDebug()) startSpellIndexTime = System.currentTimeMillis(); - Directory indexDir = FSDirectory.open(new File(indexPath)); - indexReader = DirectoryReader.open(indexDir); - - // 1. Create content spellIndex - File spellDictionaryFile = new File(spellDictionaryPath); - FSDirectory contentSpellIndexDirectory = FSDirectory.open(new File(spellDictionaryPath + CONTENT_PATH));//true - SpellChecker contentSpellChecker = new SpellChecker(contentSpellIndexDirectory); - Dictionary contentDictionary = new LuceneDictionary(indexReader, OlatDocument.CONTENT_FIELD_NAME); - Analyzer analyzer = new StandardAnalyzer(SearchService.OO_LUCENE_VERSION); - IndexWriterConfig contentIndexWriterConfig = new IndexWriterConfig(SearchService.OO_LUCENE_VERSION, analyzer); - contentSpellChecker.indexDictionary(contentDictionary, contentIndexWriterConfig, true); - - // 2. Create title spellIndex - FSDirectory titleSpellIndexDirectory = FSDirectory.open(new File(spellDictionaryPath + TITLE_PATH));//true - SpellChecker titleSpellChecker = new SpellChecker(titleSpellIndexDirectory); - Dictionary titleDictionary = new LuceneDictionary(indexReader, OlatDocument.TITLE_FIELD_NAME); - IndexWriterConfig titleIndexWriterConfig = new IndexWriterConfig(SearchService.OO_LUCENE_VERSION, analyzer); - titleSpellChecker.indexDictionary(titleDictionary, titleIndexWriterConfig, true); - - // 3. Create description spellIndex - FSDirectory descriptionSpellIndexDirectory = FSDirectory.open(new File(spellDictionaryPath + DESCRIPTION_PATH));//true - SpellChecker descriptionSpellChecker = new SpellChecker(descriptionSpellIndexDirectory); - Dictionary descriptionDictionary = new LuceneDictionary(indexReader, OlatDocument.DESCRIPTION_FIELD_NAME); - IndexWriterConfig descIndexWriterConfig = new IndexWriterConfig(SearchService.OO_LUCENE_VERSION, analyzer); - descriptionSpellChecker.indexDictionary(descriptionDictionary, descIndexWriterConfig, true); - // 4. Create author spellIndex - - FSDirectory authorSpellIndexDirectory = FSDirectory.open(new File(spellDictionaryPath + AUTHOR_PATH));//true - SpellChecker authorSpellChecker = new SpellChecker(authorSpellIndexDirectory); - Dictionary authorDictionary = new LuceneDictionary(indexReader, OlatDocument.AUTHOR_FIELD_NAME); - IndexWriterConfig authorIndexWriterConfig = new IndexWriterConfig(SearchService.OO_LUCENE_VERSION, analyzer); - authorSpellChecker.indexDictionary(authorDictionary, authorIndexWriterConfig, true); - - // Merge all part spell indexes (content,title etc.) to one common spell index - Directory spellIndexDirectory = FSDirectory.open(spellDictionaryFile);//true - - //clean up the main index - IndexWriterConfig spellIndexWriterConfig = new IndexWriterConfig(SearchService.OO_LUCENE_VERSION, analyzer); - IndexWriter merger = new IndexWriter(spellIndexDirectory, spellIndexWriterConfig); - merger.deleteAll(); - merger.commit(); - - Directory[] directories = { contentSpellIndexDirectory, titleSpellIndexDirectory, descriptionSpellIndexDirectory, authorSpellIndexDirectory}; - for(Directory directory:directories) { - merger.addIndexes(directory); - } - - merger.close(); - contentSpellChecker.close(); - titleSpellChecker.close(); - descriptionSpellChecker.close(); - authorSpellChecker.close(); - - //remove all files - FileUtils.deleteDirsAndFiles(contentSpellIndexDirectory.getDirectory(), true, true); - FileUtils.deleteDirsAndFiles(titleSpellIndexDirectory.getDirectory(), true, true); - FileUtils.deleteDirsAndFiles(descriptionSpellIndexDirectory.getDirectory(), true, true); - FileUtils.deleteDirsAndFiles(authorSpellIndexDirectory.getDirectory(), true, true); - - spellChecker = new SpellChecker(spellIndexDirectory); - spellChecker.setAccuracy(0.7f); - if (log.isDebug()) log.debug("SpellIndex created in " + (System.currentTimeMillis() - startSpellIndexTime) + "ms"); - log.info("New generated Spell-Index ready to use."); - } catch(IOException ioEx) { - log.warn("Can not create SpellIndex",ioEx); - } finally { - if (indexReader != null) { - try { - indexReader.close(); - } catch (IOException e) { - log.warn("Can not close indexReader properly",e); - } - } + public void createSpellIndex() { + if (isSpellCheckEnabled) { + IndexReader indexReader = null; + try { + log.info("Start generating Spell-Index..."); + long startSpellIndexTime = 0; + if (log.isDebug()) startSpellIndexTime = System.currentTimeMillis(); + + Directory indexDir = FSDirectory.open(new File(indexPath).toPath()); + indexReader = DirectoryReader.open(indexDir); + + // 1. Create content spellIndex + File spellDictionaryFile = new File(spellDictionaryPath); + FSDirectory contentSpellIndexDirectory = FSDirectory.open(new File(spellDictionaryPath + CONTENT_PATH).toPath());// true + SpellChecker contentSpellChecker = new SpellChecker(contentSpellIndexDirectory); + Dictionary contentDictionary = new LuceneDictionary(indexReader, + OlatDocument.CONTENT_FIELD_NAME); + Analyzer analyzer = new StandardAnalyzer(); + IndexWriterConfig contentIndexWriterConfig = new IndexWriterConfig( + analyzer); + contentSpellChecker.indexDictionary(contentDictionary, + contentIndexWriterConfig, true); + + // 2. Create title spellIndex + FSDirectory titleSpellIndexDirectory = FSDirectory.open(new File(spellDictionaryPath + TITLE_PATH).toPath());// true + SpellChecker titleSpellChecker = new SpellChecker(titleSpellIndexDirectory); + Dictionary titleDictionary = new LuceneDictionary(indexReader, OlatDocument.TITLE_FIELD_NAME); + IndexWriterConfig titleIndexWriterConfig = new IndexWriterConfig(analyzer); + titleSpellChecker.indexDictionary(titleDictionary, titleIndexWriterConfig, true); + + // 3. Create description spellIndex + FSDirectory descriptionSpellIndexDirectory = FSDirectory + .open(new File(spellDictionaryPath + DESCRIPTION_PATH).toPath());// true + SpellChecker descriptionSpellChecker = new SpellChecker(descriptionSpellIndexDirectory); + Dictionary descriptionDictionary = new LuceneDictionary( + indexReader, OlatDocument.DESCRIPTION_FIELD_NAME); + IndexWriterConfig descIndexWriterConfig = new IndexWriterConfig(analyzer); + descriptionSpellChecker.indexDictionary(descriptionDictionary, + descIndexWriterConfig, true); + // 4. Create author spellIndex + + FSDirectory authorSpellIndexDirectory = FSDirectory.open(new File(spellDictionaryPath + AUTHOR_PATH).toPath());// true + SpellChecker authorSpellChecker = new SpellChecker(authorSpellIndexDirectory); + Dictionary authorDictionary = new LuceneDictionary(indexReader,OlatDocument.AUTHOR_FIELD_NAME); + IndexWriterConfig authorIndexWriterConfig = new IndexWriterConfig(analyzer); + authorSpellChecker.indexDictionary(authorDictionary, authorIndexWriterConfig, true); + + // Merge all part spell indexes (content,title etc.) to one + // common spell index + Directory spellIndexDirectory = FSDirectory.open(spellDictionaryFile.toPath());// true + + // clean up the main index + IndexWriterConfig spellIndexWriterConfig = new IndexWriterConfig(analyzer); + IndexWriter merger = new IndexWriter(spellIndexDirectory,spellIndexWriterConfig); + merger.deleteAll(); + merger.commit(); + + Directory[] directories = { contentSpellIndexDirectory, + titleSpellIndexDirectory, + descriptionSpellIndexDirectory, + authorSpellIndexDirectory }; + for (Directory directory : directories) { + merger.addIndexes(directory); + } + + merger.close(); + contentSpellChecker.close(); + titleSpellChecker.close(); + descriptionSpellChecker.close(); + authorSpellChecker.close(); + + // remove all files + FileUtils.deleteDirsAndFiles(contentSpellIndexDirectory.getDirectory().toFile(), + true, true); + FileUtils.deleteDirsAndFiles(titleSpellIndexDirectory.getDirectory().toFile(), + true, true); + FileUtils.deleteDirsAndFiles(descriptionSpellIndexDirectory.getDirectory().toFile(), + true, true); + FileUtils.deleteDirsAndFiles(authorSpellIndexDirectory.getDirectory().toFile(), + true, true); + + spellChecker = new SpellChecker(spellIndexDirectory); + spellChecker.setAccuracy(0.7f); + if (log.isDebug()) + log.debug("SpellIndex created in " + + (System.currentTimeMillis() - startSpellIndexTime) + + "ms"); + log.info("New generated Spell-Index ready to use."); + } catch (IOException ioEx) { + log.warn("Can not create SpellIndex", ioEx); + } finally { + if (indexReader != null) { + try { + indexReader.close(); + } catch (IOException e) { + log.warn("Can not close indexReader properly", e); + } + } } - } + } } /** diff --git a/src/main/java/org/olat/search/ui/SearchInputController.java b/src/main/java/org/olat/search/ui/SearchInputController.java index 196b387b347ab972389a379ed3dd8adc2d85c1f9..4794358a96f6d4453928326aac9f84c958d804ec 100644 --- a/src/main/java/org/olat/search/ui/SearchInputController.java +++ b/src/main/java/org/olat/search/ui/SearchInputController.java @@ -469,7 +469,8 @@ public class SearchInputController extends FormBasicController implements Generi query = getQueryString(searchString, false); condQueries = getCondQueryStrings(condSearchStrings, parentCtxt, docType, rsrcUrl); - SearchResults searchResults = searchClient.doSearch(query, condQueries, ureq.getIdentity(), ureq.getUserSession().getRoles(), firstResult, maxReturns, true); + SearchResults searchResults = searchClient.doSearch(query, condQueries, + getIdentity(), ureq.getUserSession().getRoles(), getLocale(), firstResult, maxReturns, true); if(searchResults == null) { getWindowControl().setWarning(translate("search.service.unexpected.error")); @@ -510,7 +511,8 @@ public class SearchInputController extends FormBasicController implements Generi hideDidYouMeanWords(); String query = getQueryString(searchString, true); List<String> condQueries = getCondQueryStrings(condSearchStrings, parentCtxt, docType, rsrcUrl); - return searchClient.doSearch(query, condQueries, ureq.getIdentity(), ureq.getUserSession().getRoles(), firstResult, maxReturns, true); + return searchClient.doSearch(query, condQueries, + getIdentity(), ureq.getUserSession().getRoles(), getLocale(), firstResult, maxReturns, true); } public Set<String> getDidYouMeanWords() { diff --git a/src/main/java/org/olat/upgrade/OLATUpgrade_13_0_0.java b/src/main/java/org/olat/upgrade/OLATUpgrade_13_0_0.java index 14a3d8c5e3b7a48bf24851e24b5cd3ad31f50435..271210f10082bc7116dfd9259560d6d6ef4caaae 100644 --- a/src/main/java/org/olat/upgrade/OLATUpgrade_13_0_0.java +++ b/src/main/java/org/olat/upgrade/OLATUpgrade_13_0_0.java @@ -19,6 +19,7 @@ */ package org.olat.upgrade; +import java.io.File; import java.util.Collections; import java.util.List; @@ -33,6 +34,7 @@ import org.olat.core.gui.control.navigation.SiteConfiguration; import org.olat.core.gui.control.navigation.SiteDefinitions; import org.olat.core.id.Identity; import org.olat.core.id.Organisation; +import org.olat.core.util.FileUtils; import org.olat.modules.forms.EvaluationFormManager; import org.olat.modules.forms.EvaluationFormParticipation; import org.olat.modules.forms.EvaluationFormParticipationStatus; @@ -54,6 +56,7 @@ import org.olat.repository.RepositoryEntryStatusEnum; import org.olat.repository.RepositoryService; import org.olat.repository.manager.RepositoryEntryRelationDAO; import org.olat.repository.manager.RepositoryEntryToOrganisationDAO; +import org.olat.search.SearchModule; import org.olat.upgrade.model.RepositoryEntryAccessUpgrade; import org.olat.upgrade.model.RepositoryEntryAccessUpgradeStatus; import org.olat.user.UserManager; @@ -75,6 +78,7 @@ public class OLATUpgrade_13_0_0 extends OLATUpgrade { private static final String MIGRATE_SEND_APPEAL_DATES = "LECTURES SEND APPEAL DATES"; private static final String MIGRATE_ADMIN_SITE_SEC = "MIGRATE ADMIN SITE SECURITY CALLBACK"; private static final String MIGRATE_REPO_ENTRY_ACCESS = "MIGRATE REPO ENTRY ACCESS"; + private static final String MIGRATE_LUCENE = "MIGRATE LUCENE 7.5"; @Autowired private DB dbInstance; @@ -100,6 +104,8 @@ public class OLATUpgrade_13_0_0 extends OLATUpgrade { private EvaluationFormManager evaManger; @Autowired private SiteDefinitions sitesModule; + @Autowired + private SearchModule searchModule; public OLATUpgrade_13_0_0() { super(); @@ -133,6 +139,7 @@ public class OLATUpgrade_13_0_0 extends OLATUpgrade { allOk &= migrateLecturesSendAppealDates(upgradeManager, uhd); allOk &= migrateAdminSiteSecurityCallback(upgradeManager, uhd); allOk &= migrateRepositoryEntriesAccess(upgradeManager, uhd); + allOk &= migrateLucene(upgradeManager, uhd); uhd.setInstallationComplete(allOk); upgradeManager.setUpgradesHistory(uhd, VERSION); @@ -144,6 +151,37 @@ public class OLATUpgrade_13_0_0 extends OLATUpgrade { return allOk; } + private boolean migrateLucene(UpgradeManager upgradeManager, UpgradeHistoryData uhd) { + boolean allOk = true; + if (!uhd.getBooleanDataValue(MIGRATE_LUCENE)) { + try { + String indexPath = searchModule.getFullIndexPath(); + deleteIndex(indexPath); + String permIndexPath = searchModule.getFullPermanentIndexPath(); + deleteIndex(permIndexPath); + String tempIndexPath = searchModule.getFullTempIndexPath(); + deleteIndex(tempIndexPath); + String spellIndexPath = searchModule.getSpellCheckDictionaryPath(); + deleteIndex(spellIndexPath); + } catch (Exception e) { + log.error("", e); + allOk &= false; + } + + uhd.setBooleanDataValue(MIGRATE_LUCENE, allOk); + upgradeManager.setUpgradesHistory(uhd, VERSION); + } + return allOk; + } + + private void deleteIndex(String path) { + File index = new File(path); + if(index.exists() && index.isDirectory()) { + FileUtils.deleteDirsAndFiles(index, true, true); + log.info("Delete Lucene index at: " + index); + } + } + private boolean migrateAdminSiteSecurityCallback(UpgradeManager upgradeManager, UpgradeHistoryData uhd) { boolean allOk = true; if (!uhd.getBooleanDataValue(MIGRATE_ADMIN_SITE_SEC)) { diff --git a/src/test/java/org/olat/modules/qpool/manager/PoolDAOTest.java b/src/test/java/org/olat/modules/qpool/manager/PoolDAOTest.java index 99bf6ec13b2aa1930a3b12b6d439a7515721a71b..30bb2c441370977affaaeba14e1c7711b5ea24f1 100644 --- a/src/test/java/org/olat/modules/qpool/manager/PoolDAOTest.java +++ b/src/test/java/org/olat/modules/qpool/manager/PoolDAOTest.java @@ -215,7 +215,7 @@ public class PoolDAOTest extends OlatTestCase { poolDao.addItemToPool(item, Collections.singletonList(pool), false); dbInstance.commit(); - SearchQuestionItemParams params = new SearchQuestionItemParams(null, null); + SearchQuestionItemParams params = new SearchQuestionItemParams(null, null, Locale.ENGLISH); params.setPoolKey(pool.getKey()); //check @@ -253,9 +253,9 @@ public class PoolDAOTest extends OlatTestCase { poolDao.addItemToPool(item2, Collections.singletonList(pool2), false); dbInstance.commit(); - SearchQuestionItemParams params1 = new SearchQuestionItemParams(id, null); + SearchQuestionItemParams params1 = new SearchQuestionItemParams(id, null, Locale.ENGLISH); params1.setPoolKey(pool1.getKey()); - SearchQuestionItemParams params2 = new SearchQuestionItemParams(id, null); + SearchQuestionItemParams params2 = new SearchQuestionItemParams(id, null, Locale.ENGLISH); params2.setPoolKey(pool2.getKey()); //check @@ -338,7 +338,7 @@ public class PoolDAOTest extends OlatTestCase { dbInstance.commitAndCloseSession(); - SearchQuestionItemParams params = new SearchQuestionItemParams(id, null); + SearchQuestionItemParams params = new SearchQuestionItemParams(id, null, Locale.ENGLISH); params.setPoolKey(pool.getKey()); //check the pool and remove the items diff --git a/src/test/java/org/olat/modules/qpool/manager/QItemQueriesDAOTest.java b/src/test/java/org/olat/modules/qpool/manager/QItemQueriesDAOTest.java index f2c1ba99ad5368473b44776a4992844ee9345d13..696146eee9e398bb3bb70905b4c1098e30bd4cf8 100644 --- a/src/test/java/org/olat/modules/qpool/manager/QItemQueriesDAOTest.java +++ b/src/test/java/org/olat/modules/qpool/manager/QItemQueriesDAOTest.java @@ -123,7 +123,7 @@ public class QItemQueriesDAOTest extends OlatTestCase { markManager.setMark(item2, id, null, "[QuestionItem:" + item2 + "]"); dbInstance.commitAndCloseSession(); - SearchQuestionItemParams params = new SearchQuestionItemParams(id, null); + SearchQuestionItemParams params = new SearchQuestionItemParams(id, null, Locale.ENGLISH); List<QuestionItemView> favorits = qItemQueriesDao.getFavoritItems(params, null, 0, -1); List<Long> favoritKeys = new ArrayList<>(); for(QuestionItemView favorit:favorits) { @@ -155,7 +155,7 @@ public class QItemQueriesDAOTest extends OlatTestCase { markManager.setMark(item2, id, null, "[QuestionItem:" + item2 + "]"); dbInstance.commitAndCloseSession(); - SearchQuestionItemParams params = new SearchQuestionItemParams(id, null); + SearchQuestionItemParams params = new SearchQuestionItemParams(id, null, Locale.ENGLISH); //test order by for(QuestionItemView.OrderBy order: QuestionItemView.OrderBy.values()) { @@ -225,12 +225,12 @@ public class QItemQueriesDAOTest extends OlatTestCase { @Test public void getItemsByAuthor() { //create an author with 2 items - Identity id = JunitTestHelper.createAndPersistIdentityAsUser("QOwn-2-" + UUID.randomUUID().toString()); + Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("QOwn-2-"); QuestionItem item1 = questionDao.createAndPersist(id, "NGC 2171", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType); QuestionItem item2 = questionDao.createAndPersist(id, "NGC 2172", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType); dbInstance.commitAndCloseSession(); - SearchQuestionItemParams params = new SearchQuestionItemParams(id, null); + SearchQuestionItemParams params = new SearchQuestionItemParams(id, null, Locale.ENGLISH); params.setAuthor(id); //count the items of the author @@ -261,14 +261,14 @@ public class QItemQueriesDAOTest extends OlatTestCase { @Test public void getItemsByAuthor_orderBy() { //create an author with 2 items - Identity id = JunitTestHelper.createAndPersistIdentityAsUser("QOwn-2-" + UUID.randomUUID().toString()); + Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("QOwn-2-"); QuestionItem item1 = questionDao.createAndPersist(id, "NGC 2171", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType); QuestionItem item2 = questionDao.createAndPersist(id, "NGC 2172", QTIConstants.QTI_12_FORMAT, Locale.ENGLISH.getLanguage(), null, null, null, qItemType); dbInstance.commitAndCloseSession(); Assert.assertNotNull(item1); Assert.assertNotNull(item2); - SearchQuestionItemParams params = new SearchQuestionItemParams(id, null); + SearchQuestionItemParams params = new SearchQuestionItemParams(id, null, Locale.ENGLISH); params.setAuthor(id); //test order by @@ -285,7 +285,7 @@ public class QItemQueriesDAOTest extends OlatTestCase { @Test public void getItemsOfPool() { - Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Poolman-" + UUID.randomUUID().toString()); + Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("Poolman-"); //create a pool String poolTitle = "NGC-" + UUID.randomUUID().toString(); Pool pool = poolDao.createPool(null, poolTitle, true); @@ -293,7 +293,7 @@ public class QItemQueriesDAOTest extends OlatTestCase { poolDao.addItemToPool(item, Collections.singletonList(pool), false); dbInstance.commitAndCloseSession(); - SearchQuestionItemParams params = new SearchQuestionItemParams(id, null); + SearchQuestionItemParams params = new SearchQuestionItemParams(id, null, Locale.ENGLISH); params.setPoolKey(pool.getKey()); //retrieve @@ -308,7 +308,7 @@ public class QItemQueriesDAOTest extends OlatTestCase { @Test public void getItemsOfPool_orderBy() { - Identity id = JunitTestHelper.createAndPersistIdentityAsUser("Poolman-" + UUID.randomUUID().toString()); + Identity id = JunitTestHelper.createAndPersistIdentityAsRndUser("Poolman-"); //create a pool String poolTitle = "NGC-" + UUID.randomUUID().toString(); Pool pool = poolDao.createPool(null, poolTitle, true); @@ -316,7 +316,7 @@ public class QItemQueriesDAOTest extends OlatTestCase { poolDao.addItemToPool(item, Collections.singletonList(pool), false); dbInstance.commitAndCloseSession(); - SearchQuestionItemParams params = new SearchQuestionItemParams(id, null); + SearchQuestionItemParams params = new SearchQuestionItemParams(id, null, Locale.ENGLISH); params.setPoolKey(pool.getKey()); //test order by @@ -425,7 +425,7 @@ public class QItemQueriesDAOTest extends OlatTestCase { createRandomItem(owner1); dbInstance.commitAndCloseSession(); - SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null); + SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null, Locale.ENGLISH); params.setFormat(QTIConstants.QTI_12_FORMAT); int countItems = qItemQueriesDao.countItems(params); @@ -444,7 +444,7 @@ public class QItemQueriesDAOTest extends OlatTestCase { QuestionItem item23 = createRandomItem(owner2); dbInstance.commitAndCloseSession(); - SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null); + SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null, Locale.ENGLISH); List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1); assertThat(loadedItems).hasSize(6); @@ -464,7 +464,7 @@ public class QItemQueriesDAOTest extends OlatTestCase { dbInstance.commitAndCloseSession(); List<Long> inKeys = Arrays.asList(item12.getKey(), item21.getKey()); - SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null); + SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null, Locale.ENGLISH); List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, inKeys, 0, -1); assertThat(loadedItems).hasSize(inKeys.size()); @@ -481,7 +481,7 @@ public class QItemQueriesDAOTest extends OlatTestCase { QuestionItem item13 = createRandomItem(owner1); dbInstance.commitAndCloseSession(); - SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null); + SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null, Locale.ENGLISH); params.setFormat(QTIConstants.QTI_12_FORMAT); List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1); @@ -499,7 +499,7 @@ public class QItemQueriesDAOTest extends OlatTestCase { QuestionItem item21 = createRandomItem(owner2); dbInstance.commitAndCloseSession(); - SearchQuestionItemParams params = new SearchQuestionItemParams(owner1, null); + SearchQuestionItemParams params = new SearchQuestionItemParams(owner1, null, Locale.ENGLISH); List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1); assertThat(filterByKey(loadedItems, item11).isAuthor()).isTrue(); @@ -522,17 +522,17 @@ public class QItemQueriesDAOTest extends OlatTestCase { item12.setTaxonomyLevel(taxonomySubLevel); dbInstance.commitAndCloseSession(); - SearchQuestionItemParams params = new SearchQuestionItemParams(ownerAndTeacher, null); + SearchQuestionItemParams params = new SearchQuestionItemParams(ownerAndTeacher, null, Locale.ENGLISH); List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1); assertThat(filterByKey(loadedItems, item11).isTeacher()).isTrue(); assertThat(filterByKey(loadedItems, item12).isTeacher()).isTrue(); - params = new SearchQuestionItemParams(ownerAndTeacher, null); + params = new SearchQuestionItemParams(ownerAndTeacher, null, Locale.ENGLISH); loadedItems = qItemQueriesDao.getItems(params, null, 0, -1); assertThat(filterByKey(loadedItems, item11).isTeacher()).isTrue(); assertThat(filterByKey(loadedItems, item12).isTeacher()).isTrue(); - params = new SearchQuestionItemParams(noTeacher, null); + params = new SearchQuestionItemParams(noTeacher, null, Locale.ENGLISH); loadedItems = qItemQueriesDao.getItems(params, null, 0, -1); assertThat(filterByKey(loadedItems, item11).isTeacher()).isFalse(); assertThat(filterByKey(loadedItems, item12).isTeacher()).isFalse(); @@ -554,17 +554,17 @@ public class QItemQueriesDAOTest extends OlatTestCase { item12.setTaxonomyLevel(taxonomySubLevel); dbInstance.commitAndCloseSession(); - SearchQuestionItemParams params = new SearchQuestionItemParams(ownerAndManager, null); + SearchQuestionItemParams params = new SearchQuestionItemParams(ownerAndManager, null, Locale.ENGLISH); List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1); assertThat(filterByKey(loadedItems, item11).isManager()).isTrue(); assertThat(filterByKey(loadedItems, item12).isManager()).isTrue(); - params = new SearchQuestionItemParams(ownerAndManager, null); + params = new SearchQuestionItemParams(ownerAndManager, null, Locale.ENGLISH); loadedItems = qItemQueriesDao.getItems(params, null, 0, -1); assertThat(filterByKey(loadedItems, item11).isManager()).isTrue(); assertThat(filterByKey(loadedItems, item12).isManager()).isTrue(); - params = new SearchQuestionItemParams(noManager, null); + params = new SearchQuestionItemParams(noManager, null, Locale.ENGLISH); loadedItems = qItemQueriesDao.getItems(params, null, 0, -1); assertThat(filterByKey(loadedItems, item11).isManager()).isFalse(); assertThat(filterByKey(loadedItems, item12).isManager()).isFalse(); @@ -578,7 +578,7 @@ public class QItemQueriesDAOTest extends OlatTestCase { commentAndRatingService.createRating(owner1, item11, null, 2); dbInstance.commitAndCloseSession(); - SearchQuestionItemParams params = new SearchQuestionItemParams(owner1, null); + SearchQuestionItemParams params = new SearchQuestionItemParams(owner1, null, Locale.ENGLISH); List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1); assertThat(filterByKey(loadedItems, item11).isRater()).isTrue(); @@ -596,7 +596,7 @@ public class QItemQueriesDAOTest extends OlatTestCase { poolDao.addItemToPool(item12, Collections.singletonList(pool), false); dbInstance.commitAndCloseSession(); - SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null); + SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null, Locale.ENGLISH); List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1); assertThat(filterByKey(loadedItems, item11).isEditableInPool()).isTrue(); @@ -616,7 +616,7 @@ public class QItemQueriesDAOTest extends OlatTestCase { questionDao.share(item12, groupResources, false); dbInstance.commitAndCloseSession(); - SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null); + SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null, Locale.ENGLISH); List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1); assertThat(filterByKey(loadedItems, item11).isEditableInShare()).isTrue(); @@ -632,7 +632,7 @@ public class QItemQueriesDAOTest extends OlatTestCase { markManager.setMark(item11, owner1, null, "[QuestionItem:" + item11 + "]"); dbInstance.commitAndCloseSession(); - SearchQuestionItemParams params = new SearchQuestionItemParams(owner1, null); + SearchQuestionItemParams params = new SearchQuestionItemParams(owner1, null, Locale.ENGLISH); List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1); assertThat(filterByKey(loadedItems, item11).isMarked()).isTrue(); @@ -648,7 +648,7 @@ public class QItemQueriesDAOTest extends OlatTestCase { commentAndRatingService.createRating(createRandomIdentity(), item11, null, 4); dbInstance.commitAndCloseSession(); - SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null); + SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null, Locale.ENGLISH); List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1); assertThat(filterByKey(loadedItems, item11).getRating()).isEqualTo(3); @@ -666,7 +666,7 @@ public class QItemQueriesDAOTest extends OlatTestCase { commentAndRatingService.createRating(createRandomIdentity(), item12, null, 4); dbInstance.commitAndCloseSession(); - SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null); + SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null, Locale.ENGLISH); List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1); assertThat(filterByKey(loadedItems, item11).getNumberOfRatings()).isEqualTo(4); @@ -688,7 +688,7 @@ public class QItemQueriesDAOTest extends OlatTestCase { QuestionItem item23 = createRandomItem(createRandomIdentity()); dbInstance.commitAndCloseSession(); - SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null); + SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null, Locale.ENGLISH); params.setLikeTaxonomyLevel(taxonomyLevel); List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1); @@ -713,7 +713,7 @@ public class QItemQueriesDAOTest extends OlatTestCase { QuestionItem item23 = createRandomItem(createRandomIdentity()); dbInstance.commitAndCloseSession(); - SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null); + SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null, Locale.ENGLISH); params.setQuestionStatus(status); List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1); @@ -742,7 +742,7 @@ public class QItemQueriesDAOTest extends OlatTestCase { QuestionItem item23 = createRandomItem(createRandomIdentity()); dbInstance.commitAndCloseSession(); - SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null); + SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null, Locale.ENGLISH); params.setWithoutTaxonomyLevelOnly(true); List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1); @@ -765,7 +765,7 @@ public class QItemQueriesDAOTest extends OlatTestCase { dbInstance.commitAndCloseSession(); - SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null); + SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null, Locale.ENGLISH); params.setWithoutAuthorOnly(true); List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1); @@ -788,7 +788,7 @@ public class QItemQueriesDAOTest extends OlatTestCase { QuestionItem item23 = createRandomItem(createRandomIdentity()); dbInstance.commitAndCloseSession(); - SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null); + SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null, Locale.ENGLISH); params.setOnlyAuthor(owner1); List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1); @@ -811,7 +811,7 @@ public class QItemQueriesDAOTest extends OlatTestCase { QuestionItem item23 = createRandomItem(createRandomIdentity()); dbInstance.commitAndCloseSession(); - SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null); + SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null, Locale.ENGLISH); params.setExcludeAuthor(owner1); List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1); @@ -838,7 +838,7 @@ public class QItemQueriesDAOTest extends OlatTestCase { commentAndRatingService.createRating(rater1, item23, null, 2); dbInstance.commitAndCloseSession(); - SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null); + SearchQuestionItemParams params = new SearchQuestionItemParams(createRandomIdentity(), null, Locale.ENGLISH); params.setExcludeRated(rater1);; List<QuestionItemView> loadedItems = qItemQueriesDao.getItems(params, null, 0, -1); diff --git a/src/test/java/org/olat/modules/qpool/manager/QuestionPoolServiceTest.java b/src/test/java/org/olat/modules/qpool/manager/QuestionPoolServiceTest.java index d8d12c4ff66dfec72c8ce255c5fdaec90df602f0..fdf5dcc56b8d5ecad3b07816757bddd097bc467e 100644 --- a/src/test/java/org/olat/modules/qpool/manager/QuestionPoolServiceTest.java +++ b/src/test/java/org/olat/modules/qpool/manager/QuestionPoolServiceTest.java @@ -114,7 +114,7 @@ public class QuestionPoolServiceTest extends OlatTestCase { Assert.assertEquals("My private collection", newColl.getName()); dbInstance.commit();//check if it's alright - SearchQuestionItemParams params = new SearchQuestionItemParams(id, null); + SearchQuestionItemParams params = new SearchQuestionItemParams(id, null, Locale.ENGLISH); //retrieve the list of items in the collection int numOfItemsInCollection = qpoolService.countItemsOfCollection(newColl, params); diff --git a/src/test/java/org/olat/portfolio/EPPerformanceTest.java b/src/test/java/org/olat/portfolio/EPPerformanceTest.java index a8f83eadd8a814e8a1f0c640f0cc4d51aadc39cc..36adea6207ede18d06e49fe0edf05d3e75123b61 100644 --- a/src/test/java/org/olat/portfolio/EPPerformanceTest.java +++ b/src/test/java/org/olat/portfolio/EPPerformanceTest.java @@ -28,6 +28,7 @@ import java.util.Collections; import java.util.Date; import java.util.Iterator; import java.util.List; +import java.util.Locale; import java.util.UUID; import org.junit.After; @@ -140,14 +141,14 @@ public class EPPerformanceTest extends OlatTestCase { EPFilterSettings filterSettings = new EPFilterSettings(); filterSettings.setTagFilter(new ArrayList<String>(Arrays.asList("Schule"))); start = System.currentTimeMillis(); - artList = epFrontendManager.filterArtefactsByFilterSettings(filterSettings, ident1, Roles.userRoles()); + artList = epFrontendManager.filterArtefactsByFilterSettings(filterSettings, ident1, Roles.userRoles(), Locale.ENGLISH); now = System.currentTimeMillis(); logger.info("filter artefacts by one tag took: " + (now - start) + " ms."); assertEquals(artList.size(), artefactAmount/2); filterSettings.setTagFilter(tagList1); start = System.currentTimeMillis(); - artList = epFrontendManager.filterArtefactsByFilterSettings(filterSettings, ident1, Roles.userRoles()); + artList = epFrontendManager.filterArtefactsByFilterSettings(filterSettings, ident1, Roles.userRoles(), Locale.ENGLISH); now = System.currentTimeMillis(); logger.info("filter artefacts by tagList1 took: " + (now - start) + " ms."); assertEquals(artList.size(), artefactAmount/2);