Skip to content

Commit 78f80e0

Browse files
committed
Adding robustness around news querying when it does not exist any news to provide to news widgets.
1 parent 86bae0e commit 78f80e0

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

quickinfo/quickinfo-library/src/main/java/org/silverpeas/components/quickinfo/model/DefaultQuickInfoService.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
import javax.transaction.Transactional;
7070
import java.sql.Connection;
7171
import java.sql.SQLException;
72+
import java.util.Arrays;
7273
import java.util.Collection;
7374
import java.util.Date;
7475
import java.util.HashMap;
@@ -83,6 +84,7 @@
8384

8485
import static java.util.Arrays.asList;
8586
import static java.util.Collections.singletonList;
87+
import static java.util.function.Predicate.not;
8688
import static org.silverpeas.components.quickinfo.notification.QuickInfoDelayedVisibilityUserNotificationReminder.QUICKINFO_DELAYED_VISIBILITY_USER_NOTIFICATION;
8789
import static org.silverpeas.core.pdc.pdc.model.PdcClassification.aPdcClassificationOfContent;
8890

@@ -310,8 +312,12 @@ public List<News> getPlatformNews(String userId) {
310312
.getComponentIdsForUser(userId, QuickInfoComponentSettings.COMPONENT_NAME);
311313
int limit = QuickInfoComponentSettings.getSettings().getInteger("news.all.limit", 30);
312314
//noinspection SimplifyStreamApiCallChains
313-
return newsRepository.getByComponentIds(asList(allowedComponentIds))
315+
return Optional.ofNullable(allowedComponentIds)
316+
.map(Arrays::asList)
317+
.filter(not(List::isEmpty))
318+
.map(newsRepository::getByComponentIds)
314319
.stream()
320+
.flatMap(List::stream)
315321
.filter(n -> n.getPublishDate() != null)
316322
.map(n -> {
317323
decorateNews(singletonList(n), false);

0 commit comments

Comments
 (0)