Package org.jresponder.domain

Examples of org.jresponder.domain.Subscriber


        String myEmail = p.getString("email");
        Map<String,Object> myAttributesMap = p.getProps("props", null);
        String myMessageGroupName = p.getString("message_group_name");
       
        Subscriber mySubscriber =
            subscriberService.subscribe(myEmail, myAttributesMap, myMessageGroupName);
       
        return webApiUtil.jsonRpcResult(aId, aCallback, PropUtil.getInstance().mkprops("jr_subscriber_id", mySubscriber.getId()));
      }
      catch (ServiceException e) {
        return webApiUtil.jsonRpcError(aId, aCallback, e);
      }
View Full Code Here


                      @RequestParam("email") String aEmail,
                      @RequestParam("message_group_name") String aMessageGroupName,
                      @RequestParam("message_name") String aMessageName
                    ) throws Exception {

      Subscriber mySubscriber = subscriberService.lookupSubscriber(aEmail);
     
      if (mySubscriber == null) return webApiUtil.result404("Couldn't find subscriber");
     
      Subscription mySubscription = null;
      for (Subscription myTempSubscription: mySubscriber.getSubscriptions()) {
        if (myTempSubscription.getMessageGroupName().equals(aMessageGroupName)) {
          mySubscription = myTempSubscription;
        }
      }
     
View Full Code Here

       
      logger().debug("aSubscriberPropsMap: {}", aSubscriberPropsMap);

       
        // find existing subscriber
        Subscriber mySubscriber = mainDao.getSubscriberByEmail(aEmail);
      logger().debug("Looked up subscriber with email ({}) and got: {}", aEmail, mySubscriber);
       
      Subscription mySubscription = null;
     
        // doesn't exist, create it
        if (mySubscriber == null) {
         
          logger().debug("No subscriber for this email, making a new record");
         
          // create subscriber
          mySubscriber = new Subscriber();
          mySubscriber.setEmail(aEmail);
          mySubscriber.setPropsMap(aSubscriberPropsMap);
          mySubscriber.setSubscriberStatus(SubscriberStatus.OK);
          mainDao.persist(mySubscriber);
         
          logger().debug("Now making a new subscription record");

            // create subscription
            mySubscription = new Subscription(mySubscriber, aMessageGroupName);
            mySubscription.setNextSendDate(new Date());
            mySubscription.setToken(tokenUtil.generateToken());
           
            // send opt in confirm message if applicable
            if (myOptInConfirmMessageRef != null) {
              logger().debug("About to send opt-in confirm message...");
              doOptInConfirmMessage(myOptInConfirmMessageRef, myMessageGroup, mySubscriber, mySubscription);
            }
            // if no opt in, then just mark active
            else {
              logger().debug("No opt-in confirm message, just marking as active");
              mySubscription.setSubscriptionStatus(SubscriptionStatus.ACTIVE);
            }
           
          logger().debug("Saving subscription");
            mainDao.persist(mySubscription);
           
        /* ========================================================== */
        /* Make LogEntry                                              */
        /* ========================================================== */
            mainDao.logEntry
                      (
                          LogEntryType.SUBSCRIBED,
                          mySubscriber,
                          aMessageGroupName,
                          defaultLogEntryProps()
                      );
           
        }
       
        // already there, merge
        else {
         
          logger().debug("Already have a Subscriber object for email address ({}): {}", aEmail, mySubscriber);
         
          // update attributes
          mySubscriber.setPropsMap(
              (Map<String,Object>)PropUtil.getInstance().propMerge(mySubscriber.getPropsMap(), aSubscriberPropsMap)
              );
         
          if (logger().isDebugEnabled()) {
            logger().debug("Saving updated properties: {}", mySubscriber.getPropsMap());
          }
         
            mainDao.persist(mySubscriber);
         
            // see if the subscription is there
            mySubscription =
                mainDao.getSubscriptionBySubscriberAndMessageGroupName
                  (
                      mySubscriber,
                      myMessageGroup.getName()
                  );
           
        logger().debug("Looking for corresponding Subscription record for subscriber and message group ({}) found: {}", myMessageGroup.getName(), mySubscription);
           
            // no subscription, create it
            if (mySubscription == null) {
             
              mySubscription = new Subscription(mySubscriber, aMessageGroupName);
                mySubscription.setNextSendDate(new Date());
                mySubscription.setToken(tokenUtil.generateToken());

                // send opt in confirm message if applicable
                if (myOptInConfirmMessageRef != null) {
                  logger().debug("About to send opt-in confirm message...");
                  doOptInConfirmMessage(myOptInConfirmMessageRef, myMessageGroup, mySubscriber, mySubscription);
                }
                // if no opt in, then just mark active
                else {
                  logger().debug("No opt-in confirm message, just marking as active");
                  mySubscription.setSubscriptionStatus(SubscriptionStatus.ACTIVE);
                }

              logger().debug("Saving subscription");
                mainDao.persist(mySubscription);
               
          /* ========================================================== */
          /* Make LogEntry                                              */
          /* ========================================================== */
              mainDao.logEntry
                        (
                            LogEntryType.SUBSCRIBED,
                            mySubscriber,
                            aMessageGroupName,
                            defaultLogEntryProps()
                        );
            }
           
            // we do already have a subscription
            else {
             
              // see if it's active
              if (mySubscription.getSubscriptionStatus() != SubscriptionStatus.ACTIVE) {
               
                    // send opt in confirm message if applicable
                    if (myOptInConfirmMessageRef != null) {
                      doOptInConfirmMessage(myOptInConfirmMessageRef, myMessageGroup, mySubscriber, mySubscription);
                    }
                    // if no opt in, then just mark active
                    else {
                      mySubscription.setSubscriptionStatus(SubscriptionStatus.ACTIVE);
                    }
                   
              }
             
              // save subscription
              mainDao.persist(mySubscription);
             

          /* ========================================================== */
          /* Make LogEntry                                              */
          /* ========================================================== */
              mainDao.logEntry
                        (
                            LogEntryType.RESUBSCRIBED,
                            mySubscriber,
                            aMessageGroupName,
                            defaultLogEntryProps()
                        );
            }
           
        }
       
        // now that we've done all the work -
        // re-read subscriber, so we get the latest (probably not
        // necessary, but it makes it me feel better ;)
        mySubscriber = mainDao.getSubscriberById(mySubscriber.getId());
       
        // log an info, just for politeness
      logger().info("User '{}' subscribed to message group '{}' ({} opt-in confirm)",
              new Object[] { mySubscriber.getEmail(), mySubscription.getMessageGroupName(),
                  (myOptInConfirmMessageRef != null ? "with" : "without")});

        return mySubscriber;
       
      }
View Full Code Here

    mySubscription.setSubscriptionStatus(SubscriptionStatus.INACTIVE);
    mySubscription.setNextSendDate(null);
   
    mainDao.persist(mySubscription);
   
    Subscriber mySubscriber = mySubscription.getSubscriber();
    if (mySubscriber == null) {
      throw new IllegalStateException("Subscription record found but no corresponding subscriber record - this is an internal database error");
    }
   
    logger().info("Subscription corresponding to (email={} messageGroupName={}) was marked as INACTIVE (this particular email/message group combination is now not active)", mySubscriber.getEmail(), mySubscription.getMessageGroupName());

    return true;
  }
View Full Code Here

  public boolean removeFromToken(String aToken) {
   
    Subscription mySubscription = mainDao.getSubscriptionByToken(aToken);
    if (mySubscription == null) { return false; }
   
    Subscriber mySubscriber = mySubscription.getSubscriber();
    if (mySubscriber == null) {
      throw new IllegalStateException("Subscription record found but no corresponding subscriber record - this is an internal database error");
    }
   
    mySubscriber.setSubscriberStatus(SubscriberStatus.REMOVED);
    mainDao.persist(mySubscriber);
   
    logger().info("Subscriber with email ({}) was REMOVED (no more emails from an message groups)", mySubscriber.getEmail());
   
    return true;

  }
View Full Code Here

    if (mySubscription == null) {
      throw new ServiceException(ServiceExceptionType.NO_SUCH_SUBSCRIPTION,
          propUtil.mkprops("token", aToken));
    }
   
    Subscriber mySubscriber = mySubscription.getSubscriber();
    if (mySubscriber == null) {
      throw new ServiceException(ServiceExceptionType.NO_SUCH_SUBSCRIBER,
          propUtil.mkprops("token", aToken, "jr_subscription_id", mySubscription.getId()));
    }
   
    logger().debug("Attempting to confirm subscription (token={}) for subscriber (email={})",
        new Object[] { mySubscription.getToken(), mySubscriber.getEmail() });
   
    // make sure subscriber is marked as OK
    if (mySubscriber.getSubscriberStatus() != SubscriberStatus.OK) {
      logger().debug("Could not confirm, subscriber status was not OK, instead it was: {}", mySubscriber.getSubscriberStatus() );
      throw new ServiceException(ServiceExceptionType.SUBSCRIBER_NOT_OK,
          propUtil.mkprops("token", aToken));
    }
   
    // make sure subscription is marked as confirm wait or is already active
    if (!
        (
            mySubscription.getSubscriptionStatus() == SubscriptionStatus.CONFIRM_WAIT ||
            mySubscription.getSubscriptionStatus() == SubscriptionStatus.ACTIVE
        )
      ) {
      logger().debug("Could not confirm, subscription status was not CONFIRM_WAIT or ACTIVE, instead it was: {}", mySubscription.getSubscriptionStatus() );
      throw new ServiceException(ServiceExceptionType.UNEXPECTED_SUBSCRIPTION_STATUS,
          propUtil.mkprops("token", aToken));
    }
   
    mySubscription.setSubscriptionStatus(SubscriptionStatus.ACTIVE);
    // if next send date is null, then set it to now - so it goes to the
    // engine to be scheduled properly
    if (mySubscription.getNextSendDate() == null) {
      mySubscription.setNextSendDate(new Date());
    }
    mainDao.persist(mySubscription);
   
    logger().info("Subscription (email={},message_group_name={},token={}) was confirmed!",
        new Object[] { mySubscriber.getEmail(), mySubscription.getMessageGroupName(), mySubscription.getToken() });

  }
View Full Code Here

        if (aEmail == null) { return null; }
       
        aEmail = aEmail.toLowerCase();

        // find existing subscriber
        Subscriber mySubscriber = mainDao.getSubscriberByEmail(aEmail);
       
        // force Hibernate to populate the Subscriptions list
        if (mySubscriber != null) {
          mySubscriber.getSubscriptions();
        }
       
        return mySubscriber;
       
      }
View Full Code Here

   
    // the subscription we are now processing
    logger().debug("Got subscription with id: {}", mySubscription.getId());
   
    // look up the subscriber too
    Subscriber mySubscriber = mySubscription.getSubscriber();
   
    if (mySubscriber == null) {
      throw new RuntimeException("Data error, subscription with id " + mySubscription.getId() + " has null subscriber, should not be possible");
    }
   
    // Make sure we don't send to people who are asked off
   
    // if status is not okay...
    if (mySubscriber.getSubscriberStatus() != SubscriberStatus.OK) {
      // end this subscription
      endSubscription(mySubscription);
      // log for posterity
      logger().info("Was going to send to subscriber (email={}) but status is not OK, it's '{}', not sending and ending subscription.", mySubscriber.getEmail(), mySubscriber.getSubscriberStatus());
      // bail out
      return true;
    }
   
    // 2. for this Subscription, find last message processed in
View Full Code Here

 
  @Test
  public void testGetSubscriberByEmail() {
   
    Subscriber mySubscriber = new Subscriber();
    mySubscriber.setEmail("test@example.com");
    mySubscriber.setSubscriberStatus(SubscriberStatus.OK);
    mainDao.persist(mySubscriber);
   
    assertEquals(mySubscriber.getId(), mainDao.getSubscriberByEmail("test@example.com").getId());
       
  }
View Full Code Here

    // make sure a message was sent
    Assert.assertEquals(1, wiser.getMessages().size());
   
    wiser.dumpMessages(System.out);
   
    Subscriber mySubscriber = mainDao.getSubscriberByEmail("joey@example.com");
    Subscription mySubscription = mainDao.getSubscriptionBySubscriberAndMessageGroupName(mySubscriber, "list1");
   
    String myToken = mySubscription.getToken();
   
    System.out.println("Token: " + myToken);
   
    Assert.assertEquals(SubscriptionStatus.CONFIRM_WAIT, mySubscription.getSubscriptionStatus());
   
    // try confirm
    subscriberService.confirmFromToken(myToken);
   
    // get the subscription again directly from the db and check the status
    mySubscription = mainDao.getSubscriptionBySubscriberAndMessageGroupName(mySubscriber, "list1");
    Assert.assertEquals(SubscriptionStatus.ACTIVE, mySubscription.getSubscriptionStatus());
   
    // now try to unsubscribe
    subscriberService.unsubscribeFromToken(myToken);
   
    // check database
    mySubscription = mainDao.getSubscriptionBySubscriberAndMessageGroupName(mySubscriber, "list1");
    Assert.assertEquals(SubscriptionStatus.INACTIVE, mySubscription.getSubscriptionStatus());
   
    // now try remove
    subscriberService.removeFromToken(myToken);
   
    // check database
    mySubscriber = mainDao.getSubscriberByEmail("joey@example.com");
    Assert.assertEquals(SubscriberStatus.REMOVED, mySubscriber.getSubscriberStatus());
   
  }
View Full Code Here

TOP

Related Classes of org.jresponder.domain.Subscriber

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.