Package org.jresponder.message

Examples of org.jresponder.message.MessageRef


     
      MessageGroup myMessageGroup = messageGroupSource.getMessageGroupByName(aMessageGroupName);
     
      if (myMessageGroup == null) return webApiUtil.result404("Couldn't find message group");
     
      MessageRef myMessageRef = myMessageGroup.getMessageRefByName(aMessageName);
     
      MimeMessage myMimeMessage = javaMailSender.createMimeMessage();
     
      SendConfig mySendConfig =
          sendConfigGroup.lookupSendConfig(mySubscriber, mySubscription, myMessageGroup, myMessageRef);
     
      if (mySendConfig == null) {
        throw new IllegalStateException("No SendConfig for this message, cannot continue!");
      }
     
      myMessageRef.populateMessage(myMimeMessage, mySendConfig, mySubscriber, mySubscription);
     
      ByteArrayOutputStream myByteArrayOutputStream =  new ByteArrayOutputStream();
      myMimeMessage.writeTo(myByteArrayOutputStream);
     
      return webApiUtil.plainTextResult(myByteArrayOutputStream.toString("UTF-8"));
View Full Code Here


        // get the message group
        MessageGroup myMessageGroup = messageGroupSource.getMessageGroupByName(aMessageGroupName);
      logger().debug("Using MessageGroup: {}", myMessageGroup);
     
        // the opt-in-confirm message, if it exists
        MessageRef myOptInConfirmMessageRef = myMessageGroup.getOptInConfirmMessageRef();
      logger().debug("myOptInConfirmMessageRef: {}", myOptInConfirmMessageRef);
       
        // make sure we have an attribute map, even if it's empty
        if (aSubscriberPropsMap == null) {
          aSubscriberPropsMap = new HashMap<String,Object>();
View Full Code Here

    // 3. get the next message
   
    List<MessageRef> myMessageRefList = myMessageGroup.getMessageRefList();
   
    // the MessageRef that we are to send
    MessageRef mySendMessageRef = null;
    if (mySendMessageRefIndex >= 0) {
      // make sure we haven't gone beyond the end of the messages
      if (myMessageRefList.size() > mySendMessageRefIndex) {
        mySendMessageRef = myMessageRefList.get(mySendMessageRefIndex);
      }
    }
    logger().debug("about to send mySendMessageRef: {}", mySendMessageRef);

   
    // no message to send (either couldn't find last message or
    // there is no next message); also check for the case where
    // the last send date is not set (should never happen, but just
    // to keep it from breaking the system we treat it like end
    // of list)
    if (mySendMessageRef == null || mySubscription.getLastSendDate() == null) {
      logger().debug("no more messages to send for this subscription");
      /* ====================================================== */
      /* clear next send date of subscription                   */
      /* ====================================================== */
      endSubscription(mySubscription);
      return true;
    }
   

    if (mySubscription.getLastSendDate() == null) {
      logger().warn("last_send_date was null on subscription, should never happen");
    }
   
    // 3a.read the time on it and recalculate, confirm that
    //    time is now past
   
    Long myWait = mySendMessageRef.getWaitAfterLastMessage();
    if (myWait == null) {
      /* ====================================================== */
      /* clear next send date of subscription                   */
      /* ====================================================== */
      logger().warn("'wait after last message' value was not set for this message, ending the subscription");
      endSubscription(mySubscription);
      return true;
    }
   
    // 3b.if not past then set next consideration date to recalced date
    //    and kick back
   
    // see if it's time to send yet
    long myLastSendDate = mySubscription.getLastSendDate().getTime();
    if (myLastSendDate + myWait > new Date().getTime()) {
      logger().debug("it is not yet time to send this message, putting it back for later");
      // not time to send (possibly message changed since
      // this subscription record was last edited - also first
      // subscription looks like this);
      // reset the nextSendDate and move on
      mySubscription.setNextSendDate(new Date(myLastSendDate + myWait));
      mainDao.persist(mySubscription);
      return true;
    }
   
   
    // 4. render and send message
   
    boolean mySendWorked = sendMessage(
            mySendMessageRef,
            myMessageGroup,
            mySubscriber,
            mySubscription,
            LogEntryType.MESSAGE_SENT
        );
   
    // if the sending was skipped...
    if (!mySendWorked) {
     
      // write a log entry for the skipping
      mainDao.logEntry
            (
                 LogEntryType.MESSAGE_SKIPPED,
                 mySubscriber,
                 myMessageGroup.getName(),
                 propUtil.mkprops(
                     "message_name", mySendMessageRef.getName()
                     )
            );

    }
   
   
   
   
    // 5. get next message in the list and recalculate date based on that,
    //    update last message name and save
   
    // update the last sent info
    mySubscription.setLastMessageName(mySendMessageRef.getName());
    mySubscription.setLastSendDate(new Date());
   
    // index of next message
    int myNextMessageRefIndex = mySendMessageRefIndex + 1;
   
   
    // 5a.if no more messages, then next consideration date is set to null
   
    if (myNextMessageRefIndex >= myMessageRefList.size()) {
      mySubscription.setNextSendDate(null);
    }
   
    // if we have a next message, then calc when it fires
    else {
     
      MessageRef myNextMessageRef = myMessageRefList.get(myNextMessageRefIndex);
      Long myNextWait = myNextMessageRef.getWaitAfterLastMessage();
      mySubscription.setNextSendDate(
            new Date(mySubscription.getLastSendDate().getTime() + myNextWait)
          );

    }
View Full Code Here

TOP

Related Classes of org.jresponder.message.MessageRef

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.