@Override public Collection<NotificationFilterPreference> getFilterPreferences(DocumentReference user) throws NotificationException { Set<NotificationFilterPreference> filterPreferences = new HashSet<>(); try { List<NotificationFilterPreferenceProvider> providers = componentManager.getInstanceList(NotificationFilterPreferenceProvider.class); for (NotificationFilterPreferenceProvider provider : providers) { filterPreferences.addAll(provider.getFilterPreferences(user)); } return filterPreferences; } catch (ComponentLookupException e) { throw new NotificationException(String.format("Unable to fetch a list of notification preference " + "providers with user [%s].", user)); } }
/** * Add an event to the composite event. * @param event the event to add * @param similarity the similarity between the event to add and the events of the composite events * @throws NotificationException if the addition is illegal (lower similarity for example) */ public void add(Event event, int similarity) throws NotificationException { if (similarity < similarityBetweenEvents) { throw new NotificationException("Invalid addition of an event inside a CompositeEvent"); } similarityBetweenEvents = similarity; events.add(event); // Ensure the events are always sorted by date (more recent firsts) Collections.sort(events, (e1, e2) -> e2.getDate().compareTo(e1.getDate())); }
@Override public void setStartDateForUser(DocumentReference user, Date startDate) throws NotificationException { try { List<NotificationFilterPreferenceProvider> providers = componentManager.getInstanceList(NotificationFilterPreferenceProvider.class); for (NotificationFilterPreferenceProvider provider : providers) { provider.setStartDateForUser(user, startDate); } } catch (ComponentLookupException e) { throw new NotificationException(String.format("Unable to set the starting date for filter preferences" + " with user [%s].", user)); } } }
/** * Ensure that the given author has the administrative rights in the current context. * * @param documentReference the working entity * @param authorReference the author that should have its rights checked * @throws NotificationException if the author rights are not sufficient */ private void checkRights(DocumentReference documentReference, DocumentReference authorReference) throws NotificationException { if (!this.authorizationManager.hasAccess(Right.ADMIN, authorReference, documentReference.getWikiReference())) { throw new NotificationException( "Registering custom Notification Filter Displayers requires wiki administration rights."); } } }
@Override public Collection<NotificationFilter> getAllFilters(boolean allWikis) throws NotificationException { if (allWikis) { String currentWikiId = wikiDescriptorManager.getCurrentWikiId(); Map<String, NotificationFilter> filters = new HashMap<>(); try { for (String wikiId : wikiDescriptorManager.getAllIds()) { modelContext.setCurrentEntityReference(new WikiReference(wikiId)); filters.putAll(componentManager.getInstanceMap(NotificationFilter.class)); } } catch (Exception e) { throw new NotificationException(ERROR_MESSAGE, e); } finally { modelContext.setCurrentEntityReference(new WikiReference(currentWikiId)); } return new HashSet<>(filters.values()); } else { // Get filters from the current wiki only try { return new HashSet<>(componentManager.getInstanceList(NotificationFilter.class)); } catch (Exception e) { throw new NotificationException(ERROR_MESSAGE, e); } } }
@Override public Block displayFilter(NotificationFilter filter, NotificationFilterPreference preference) throws NotificationException { /** * Try to find a {@link NotificationFilterDisplayer} that corresponds to the given filter. * If no renderer is found, fallback on the default one. */ try { List<NotificationFilterDisplayer> renderers = componentManager.getInstanceList(NotificationFilterDisplayer.class); for (NotificationFilterDisplayer renderer : renderers) { if (renderer.getSupportedFilters().contains(filter.getName())) { return renderer.display(filter, preference); } } return defaultNotificationFilterDisplayer.display(filter, preference); } catch (ComponentLookupException e) { throw new NotificationException(String.format( "Unable get a list of NotificationFilterDisplayer for filter [%s].", filter), e); } } }
@Override public Block display(NotificationFilter filter, NotificationFilterPreference preference) throws NotificationException { try { setUpContext(scriptContextManager, filter, preference); // Try to get a template using the filter name ; if no template is found, fallback on the default one. String templateName = String.format("notification/filters/%s.vm", filter.getName().replaceAll("\\/", ".")); Template template = templateManager.getTemplate(templateName); return (template != null) ? templateManager.execute(template) : templateManager.execute("notification/filters/default.vm"); } catch (Exception e) { throw new NotificationException( String.format("Failed to display the notification filter [%s] with the filter preference [%s].", filter, preference), e); } finally { cleanUpContext(); } }
throw new NotificationException( String.format("Failed to migrate the notification preferences for the user [%s].", user), e);
@Override public Block display(NotificationFilter filter, NotificationFilterPreference preference) throws NotificationException { try { setUpContext(scriptContextManager, filter, preference); // If we have no template defined, fallback on the default displayer if (filterTemplate == null) { return ((NotificationFilterDisplayer) componentManager.getInstance(NotificationFilterDisplayer.class)) .display(filter, preference); } return templateManager.execute(filterTemplate); } catch (Exception e) { throw new NotificationException( String.format("Unable to display the notification filter template for the filters [%s].", componentHint), e); } finally { cleanUpContext(); } }
@Override public Map<String, Boolean> getToggeableFilterActivations(DocumentReference user) throws NotificationException { XWikiContext context = contextProvider.get(); XWiki xwiki = context.getWiki(); final DocumentReference notificationPreferencesScopeClass = TOGGLEABLE_FILTER_PREFERENCE_CLASS.setWikiReference(user.getWikiReference()); Map<String, Boolean> filterStatus = new HashMap<>(); try { XWikiDocument doc = xwiki.getDocument(user, context); for (NotificationFilter filter : componentManager.<NotificationFilter>getInstanceList( NotificationFilter.class)) { if (filter instanceof ToggleableNotificationFilter) { ToggleableNotificationFilter toggleableFilter = (ToggleableNotificationFilter) filter; boolean status = toggleableFilter.isEnabledByDefault(); BaseObject obj = doc.getXObject(notificationPreferencesScopeClass, FIELD_FILTER_NAME, filter.getName()); if (obj != null) { status = obj.getIntValue(FIELD_IS_ENABLED, status ? 1 : 0) != 0; } filterStatus.put(filter.getName(), status); } } } catch (Exception e) { throw new NotificationException( String.format("Failed to get the toggleable filters preferences for the user [%s].", user), e); } return filterStatus; }
throw new NotificationException(String.format( "Error while loading the notification filter preferences of the user [%s].", serializedUser), e);
throw new NotificationException( String.format("Unable to construct a new WikiNotificationFilterDisplayer from" + " the base object [%s]", baseObject), e);
hibernateStore.endTransaction(context, false); throw new NotificationException("Failed to save the notification filter preferences.", e); } finally { if (!currentWiki.equals(context.getWikiId())) {