use of org.xwiki.watchlist.internal.api.WatchListException in project xwiki-platform by xwiki.
the class DefaultWatchListNotifier method sendNotification.
@Override
public void sendNotification(Collection<String> subscribers, List<WatchListEvent> events, Map<String, Object> notificationData) throws WatchListException {
try {
// FIXME: Temporary, until we move to all references.
List<DocumentReference> subscriberReferences = getSubscriberReferences(subscribers);
// Source
Map<String, Object> source = new HashMap<>();
source.put(EventsAndSubscribersSource.SUBSCRIBERS_PARAMETER, subscriberReferences);
source.put(EventsAndSubscribersSource.EVENTS_PARAMETER, events);
// Parameters
Map<String, Object> parameters = new HashMap<>();
parameters.put(WatchListEventMimeMessageFactory.HINT_PARAMETER, "template");
parameters.put(WatchListEventMimeMessageFactory.TEMPLATE_PARAMETER, notificationData.get(WatchListEventMimeMessageFactory.TEMPLATE_PARAMETER));
parameters.put(WatchListEventMimeMessageFactory.SKIP_CONTEXT_USER_PARAMETER, notificationData.get(WatchListEventMimeMessageFactory.SKIP_CONTEXT_USER_PARAMETER));
parameters.put(WatchListEventMimeMessageFactory.ATTACH_AUTHOR_AVATARS_PARAMETER, notificationData.get(WatchListEventMimeMessageFactory.ATTACH_AUTHOR_AVATARS_PARAMETER));
Map<String, Object> templateFactoryParameters = getTemplateFactoryParameters(notificationData);
parameters.put(WatchListEventMimeMessageFactory.PARAMETERS_PARAMETER, templateFactoryParameters);
// Create the message iterator and the other mail sender parameters.
Iterator<MimeMessage> messageIterator = messageFactory.createMessage(source, parameters);
Session session = this.sessionFactory.create(Collections.<String, String>emptyMap());
MailListener mailListener = mailListenerProvider.get();
// Pass it to the message sender to send it asynchronously.
// FIXME: !? There must be a better way instead of using IteratorIterable.
mailSender.sendAsynchronously(new IteratorIterable<MimeMessage>(messageIterator), session, mailListener);
} catch (Exception e) {
throw new WatchListException(String.format("Failed to send notification to subscribers [%s]", subscribers), e);
}
}
use of org.xwiki.watchlist.internal.api.WatchListException in project xwiki-platform by xwiki.
the class DefaultWatchListNotifier method sendNotification.
@Override
@Deprecated
public void sendNotification(String subscriber, List<WatchListEvent> events, String templateDocument, Date previousFireTime) throws XWikiException {
Map<String, Object> notificationData = new HashMap<>();
notificationData.put(WatchListEventMimeMessageFactory.TEMPLATE_PARAMETER, templateDocument);
notificationData.put(PREVIOUS_FIRE_TIME_VARIABLE, previousFireTime);
try {
this.sendNotification(Arrays.asList(subscriber), events, notificationData);
} catch (WatchListException e) {
throw new XWikiException("", e);
}
}
use of org.xwiki.watchlist.internal.api.WatchListException in project xwiki-platform by xwiki.
the class DefaultWatchListEventHTMLDiffExtractor method getHTMLDiff.
@Override
public String getHTMLDiff(WatchListEvent event) throws WatchListException {
XWikiContext context = contextProvider.get();
StringBuffer result = new StringBuffer();
try {
DiffPluginApi diff = (DiffPluginApi) context.getWiki().getPluginApi("diff", context);
XWikiDocument d2 = context.getWiki().getDocument(event.getDocumentReference(), context);
if (event.getType().equals(WatchListEventType.CREATE)) {
d2 = context.getWiki().getDocument(d2, INITIAL_DOCUMENT_VERSION, context);
}
XWikiDocument d1 = context.getWiki().getDocument(d2, event.getPreviousVersion(), context);
List<AttachmentDiff> attachDiffs = d2.getAttachmentDiff(d1, d2, context);
List<List<ObjectDiff>> objectDiffs = d2.getObjectDiff(d1, d2, context);
List<List<ObjectDiff>> classDiffs = d2.getClassDiff(d1, d2, context);
List<MetaDataDiff> metaDiffs = d2.getMetaDataDiff(d1, d2, context);
if (!d1.getContent().equals(d2.getContent())) {
Div contentDiv = createDiffDiv("contentDiff");
String contentDiff = diff.getDifferencesAsHTML(d1.getContent(), d2.getContent(), false);
contentDiv.addElement(contentDiff);
result.append(contentDiv);
}
for (AttachmentDiff aDiff : attachDiffs) {
Div attachmentDiv = createDiffDiv("attachmentDiff");
attachmentDiv.addElement(HTML_IMG_ATTACHMENT_PREFIX + HTML_IMG_PLACEHOLDER_SUFFIX);
attachmentDiv.addElement(aDiff.toString());
result.append(attachmentDiv);
}
result.append(getObjectsHTMLDiff(objectDiffs, false, event.getFullName(), diff));
result.append(getObjectsHTMLDiff(classDiffs, true, event.getFullName(), diff));
for (MetaDataDiff mDiff : metaDiffs) {
Div metaDiv = createDiffDiv("metaDiff");
metaDiv.addElement(HTML_IMG_METADATA_PREFIX + HTML_IMG_PLACEHOLDER_SUFFIX);
metaDiv.addElement(mDiff.toString());
result.append(metaDiv);
}
return result.toString();
} catch (Exception e) {
throw new WatchListException(String.format("Failed to compute HTML diff for event type [%s] on [%s]", event.getType(), event.getPrefixedFullName()), e);
}
}
Aggregations