public AttachmentQuery forNotification(Notification notification) { this.notificationId = notification.getNotificationId(); return this; }
public NotificationRef toNotificationRef() { return new NotificationRef(domainName, notificationId, revision); }
@JsonIgnore public boolean isInternalException() { return isInternal() && hasException(); } }
public NotificationRef createAttachment(CreateAttachment create) { CouchMediaType mediaType = CouchMediaType.fromString(create.getContentType()); NotificationRef notificationRef = create.getNotificationRef(); WriteResponse response = couchDatabase.put().attachment( notificationRef.getNotificationId(), notificationRef.getRevision(), create.getAttachmentName(), mediaType, create.getInputStream()) .onError(r -> throwError(r, format("Failure storing notification attachment in couch [%s] - %s", r.getHttpStatus(), r.getErrorReason()))) .execute(); return new NotificationRef(notificationRef.getDomainName(), notificationRef.getNotificationId(), response.getDocumentRevision()); }
public boolean isMatch(Notification notification) { try { engine.eval(jsFunc); return (boolean) invocable.invokeFunction("eval", notification); } catch (Exception e) { notify(notification, e, format("Exception testing match (domain=%s, notification=%s, route=%s)", notification.getDomainName(), notification.getNotificationId(), route.getName())); // Don't blow up the world, just return false. return false; } }
private List<Push> toSmsPush(Notification notification, String from, List<String> recipients) { return recipients.stream() .map(recipient -> TwilioSmsPush.newPush(from, recipient, notification.getSummary(), null)) .collect(Collectors.toList()); }
private void notify(Notification notification, Exception e, String msg) { try { if (notification != null && notification.isInternalException()) log.error("SUPPRESSED: "+msg, e); else { SendNotificationResponse response = notifier.begin().summary(msg).exception(e).send().get(); } } catch (Exception ex) { log.error("Exception sending notification", ex); } } }
public static CreateTask create(NotificationRef notification, Destination destination) { return new CreateTask(notification.getNotificationId(), destination); }
public Notification toNotificationWithRevision(String revisionArg) { return new Notification(internal,null, domainName, notificationId, revisionArg, topic, summary, trackingId, createdAt, traitMap, links, exceptionInfo, listAttachmentInfo()); }
public TaskEntity newEmailTaskEntity(Notification notification) { DestinationDef destinationDef = new DestinationDef("local", DestinationStatus.ENABLED, "push", "type:emailMsg", "recipient:test@jacobparr.com"); CreateTask create = CreateTask.create(notification.toNotificationRef(), destinationDef.toDestination()); return notificationKernel.createTask(create, notification); }
public void deleteNotification(String domainName, Notification notification) { Response response = client.target(apiPath + "/v2/admin/domains").path(domainName).path("notifications").path(notification.getNotificationId()) .request(MediaType.APPLICATION_JSON_TYPE) .delete(); HttpStatusCode statusCode = HttpStatusCode.findByCode(response.getStatus()); if (statusCode != HttpStatusCode.NO_CONTENT) { throw ApiException.fromCode(statusCode, "Delete of notification FAILED: " + response.getStatusInfo()); } }
private List<Push> toJabber(Notification notification, List<String> recipients) { return recipients.stream() .map(recipient -> XmppPush.newPush(recipient, notification.getSummary(), null)) .collect(Collectors.toList()); }
public NotificationRef toNotificationRef() { return new NotificationRef(domainName, notificationId, revision); }
private void notify(Notification notification, Exception e, String msg) { try { if (notification != null && notification.isInternalException()) log.error("SUPPRESSED: "+msg, e); else notifier.begin().summary(msg).exception(e).send().get(); } catch (Exception ex) { log.error("Exception sending notification", ex); } } }
public Notification newNotification(CreateNotification create) { NotificationRef notificationRef = notificationKernel.createNotification(create); return notificationKernel.findNotificationById(notificationRef.getNotificationId()); }
public Notification toNotification() { return new Notification(internal, null, domainName, notificationId, revision, topic, summary, trackingId, createdAt, traitMap, links, exceptionInfo, listAttachmentInfo()); }
public NotificationRef createNotification(CreateNotification create) { ExceptionUtils.assertNotNull(create, "create", ApiBadRequestException.class); NotificationEntity entity = NotificationEntity.newEntity(getDomainName(), create); Notification notification = notificationStore.saveAndReload(entity).toNotification(); // Immediately pass the notification on to the task generate. taskGenerator.generateTasks(this, notification); return notification.toNotificationRef(); }
private void createTask(NotificationDomain notificationDomain, Notification notification, List<TaskEntity> tasks, NotificationRef notificationRef, Destination destination) { try { log.info("Creating task (notification={}, destination={})", notification.getNotificationId(), destination.getName()); CreateTask create = CreateTask.create(notificationRef, destination); TaskEntity task = notificationDomain.createTask(create, notification); tasks.add(task); // log.info("Signalling creation of the task (notification={}, destination={}, task={})", notification.getNotificationId(), task.getTaskId(), destination); // eventBus.taskCreated(notificationDomain.getDomainName(), task, notification); } catch (Exception e) { notify(notification, e, format("Exception generating task (notification=%s, destination=%s).", notification.getNotificationId(), destination.getName())); } }
private void notify(Notification notification, Exception e, String msg) { try { if (notification != null && notification.isInternalException()) log.error("SUPPRESSED: "+msg, e); else notifier.begin().summary(msg).exception(e).send().get(); } catch (Exception ex) { log.error("Exception sending notification", ex); } } }
@Override public void taskCreated(String domainName, TaskEntity task, Notification notification) { try { NotificationDomain notificationDomain = domainKernel.notificationDomain(domainName); Map<String, List<TaskEntity>> tasks = new HashMap<>(); tasks.put(task.getDestination().getProvider(), Arrays.asList(task)); processTasksByProvider(notificationDomain, tasks); } catch (Exception e) { notify(notification, e, format("Unexpected exception while processing task (domain=%s, notification=%s, task=%s).", domainName, notification.getNotificationId(), task.getTaskId())); } }