* Velocity context used to generate notification message
*/
private void createNewNotification(final Person recipient, final NotificationType inType,
final Map<String, Object> inProperties, final Context velocityContext)
{
InAppNotificationEntity dbNotif = new InAppNotificationEntity();
dbNotif.setNotificationType(inType);
dbNotif.setRecipient(recipient);
dbNotif.setUrl((String) inProperties.get(NotificationPropertyKeys.URL));
dbNotif.setHighPriority(Boolean.TRUE.equals(inProperties.get(NotificationPropertyKeys.HIGH_PRIORITY)));
Object obj = inProperties.get(NotificationPropertyKeys.SOURCE);
if (obj instanceof Identifiable)
{
Identifiable source = (Identifiable) obj;
dbNotif.setSourceType(source.getEntityType());
dbNotif.setSourceUniqueId(source.getUniqueId());
dbNotif.setSourceName(source.getDisplayName());
}
obj = inProperties.get(NotificationPropertyKeys.ACTOR);
if (obj instanceof Identifiable)
{
Identifiable actor = (Identifiable) obj;
dbNotif.setAvatarOwnerType(actor.getEntityType());
dbNotif.setAvatarOwnerUniqueId(actor.getUniqueId());
}
String template = templates.get(inType);
if (template == null)
{
return;
}
velocityContext.put("recipient", recipient);
StringWriter writer = new StringWriter();
velocityEngine.evaluate(velocityContext, writer, "InAppNotification-" + inType, template);
String message = writer.toString();
dbNotif.setMessage(message);
insertMapper.execute(new PersistenceRequest<InAppNotificationEntity>(dbNotif));
syncMapper.execute(recipient.getId());
}