Ejemplo n.º 1
0
 void run()
     throws TException, NoSuchAlgorithmException, NoSuchProviderException, InvalidKeyException,
         SignatureException {
   final TBase o = construct();
   final long deviceToken = 99;
   final long notificationId = 999;
   notifier.put(deviceToken, new Notification(method, notificationId));
   final PendingNotification pendingNotification = new PendingNotification();
   pendingNotification.setId(notificationId);
   final ByteBuffer b = ByteBuffer.wrap(new TSerializer().serialize(o));
   b.mark();
   pendingNotification.setPayload(b);
   pendingNotificationDataStore.put(notificationId, pendingNotification);
   final LongId notificationLongId = new LongId(notificationId);
   final Future<T> future = new DefaultFutureResult<>();
   call(notificationLongId, sign(notificationLongId, clientId), future);
   assertTrue(future.succeeded());
   assertEquals(o, future.result());
 }
Ejemplo n.º 2
0
  /*
   * (non-Javadoc)
   *
   * @see
   * cc.kune.core.server.notifier.NotificationSender#send(cc.kune.core.server
   * .notifier.PendingNotification,
   * cc.kune.core.shared.dto.EmailNotificationFrequency)
   */
  @Override
  public void send(
      final PendingNotification notification, final EmailNotificationFrequency withFrequency) {
    final FormattedString subject = notification.getSubject().copy();
    final FormattedString body = notification.getBody();
    final NotificationType notifyType = notification.getNotifyType();
    final boolean forceSend = notification.isForceSend();
    final boolean isHtml = notification.isHtml();
    final String subjectPrefix = notification.getSubjectPrefix();
    final String subjectWithoutBra =
        subjectPrefix.equals(PendingNotification.SITE_DEFAULT_SUBJECT_PREFIX)
            ? siteName
            : subjectPrefix;
    subject.setTemplate(addBraquet(subjectWithoutBra) + subject.getTemplate());
    if (subject.shouldBeTranslated()) {
      // Translate per recipient language
      // final String subjectTranslation = i18n.tWithNT(user.getLanguage(),
      // subject.getTemplate(), "");
      // if (subjectTranslation != null) {
      // Right now commented because we are only testing
      // subject.setTemplate(subjectTranslation);
      // }
    }
    if (body.shouldBeTranslated()) {
      // final String bodyTranslation = i18n.tWithNT(user.getLanguage(),
      // body.getTemplate(), "");
      // if (bodyTranslation != null) {
      // Right now commented because we are only testing
      // body.setTemplate(bodyTranslation);
      // }
    }

    for (final Addressee user : notification.getDestProvider().getDest()) {
      final String username = user.getShortName();

      switch (notifyType) {
        case chat:
          // FIXME seems that html is not sending correctly... check server specs
          xmppManager.sendMessage(
              username, String.format("<b>%s</b>%s", subject.getString(), body.getString()));
          break;
        case email:
          if (forceSend
              || (user.isEmailVerified()
                  && noOnline(username)
                  && withFrequency == user.getFreq())) {
            // we'll send this notification if is mandatory or this user is not
            // only and has this freq configured
            mailService.send(
                subject,
                FormattedString.build(emailTemplate.replace("%s", body.getString())),
                isHtml,
                user.getAddress());
          }
          break;
        case wave:
          if (isHtml) {
            LOG.error("Wave html messages not supported yet");
          }
          waveService.createWave(
              subject.getString(), body.getString(), KuneWaveService.DO_NOTHING_CBACK, username);
          break;
      }
    }
  }