Package com.dotmarketing.portlets.communications.model

Examples of com.dotmarketing.portlets.communications.model.Communication


    Campaign c;
    while(itCampaign.hasNext()) {
      campaignRecipient = (HashMap<String, Object>) itCampaign.next();
      c = (Campaign) campaignRecipient.get("campaign");
      r = (Recipient) campaignRecipient.get("recipient");
      Communication communication = (Communication) InodeFactory.getChildOfClass(c, Communication.class);
      if (InodeUtils.isSet(communication.getInode()) && (communication.getCommunicationType().equalsIgnoreCase("alert"))) {
        String[] comm = new String[2];
        if(UtilMethods.isSet(user)){
          comm[0] = DeliverCampaignThread.replaceTextVar(communication.getTitle(), r, user, communication);
          comm[1] = DeliverCampaignThread.replaceTextVar(communication.getTextMessage(), r, user, communication);
        }
        communications.add(comm);
      }
    }
    return communications;
View Full Code Here


    }
   
    Iterator itCampaign = campaigns.iterator();
    while(itCampaign.hasNext()) {
      Campaign c = (Campaign) itCampaign.next();
      Communication communication = (Communication) InodeFactory.getChildOfClass(c, Communication.class);
      if (InodeUtils.isSet(communication.getInode()) && (communication.getCommunicationType().equalsIgnoreCase("alert"))) {
        alertMessagesCount++;
      }
    }
    return alertMessagesCount;
  }
View Full Code Here

      Campaign campaign = (Campaign) InodeFactory.getParentOfClass(r, Campaign.class);
      if (InodeUtils.isSet(campaign.getInode())) {
        if (UtilMethods.isSet(campaign.getExpirationDate()) && now.after(campaign.getExpirationDate())) {
          break;
        }
        Communication communication = (Communication) InodeFactory.getChildOfClass(campaign, Communication.class);
        if (InodeUtils.isSet(communication.getInode()) && (communication.getCommunicationType().equalsIgnoreCase("alert"))) {
          r.setOpened(now);
          r.setLastMessage("Alert Displayed");
         
          HibernateUtil.saveOrUpdate(r);
        }
View Full Code Here

   
    while(itRecipient.hasNext()){
      Recipient r = (Recipient) itRecipient.next();
      Campaign campaign = (Campaign) InodeFactory.getParentOfClass(r, Campaign.class);
      if (InodeUtils.isSet(campaign.getInode())) {
        Communication communication = (Communication) InodeFactory.getChildOfClass(campaign, Communication.class);
        if (InodeUtils.isSet(communication.getInode()) && (communication.getCommunicationType().equalsIgnoreCase("alert"))) {
          String[] comm = new String[3];
          if(UtilMethods.isSet(user)){
            comm[0] = DeliverCampaignThread.replaceTextVar(communication.getTitle(), r, user, communication);
            comm[1] = DeliverCampaignThread.replaceTextVar(communication.getTextMessage(), r, user, communication);
          }
          comm[2] = UtilMethods.dateToPrettyHTMLDate2(r.getOpened());
          communications.add(comm);
        }
      }
View Full Code Here

          childCampaign.setLocked(true);
          HibernateUtil.saveOrUpdate(childCampaign);

          MailingList ml = (MailingList) InodeFactory.getChildOfClass(c, MailingList.class);
          HTMLPage page = (HTMLPage) InodeFactory.getChildOfClass(c, HTMLPage.class);
          Communication comm = (Communication) InodeFactory.getChildOfClass(c, Communication.class);
          UserFilter userfilter = (UserFilter) InodeFactory.getChildOfClass(c, UserFilter.class);

          if(InodeUtils.isSet(ml.getInode())){
            relationshipAPI.addRelationship(childCampaign.getInode(), ml.getInode(), "child");
          }
          if(InodeUtils.isSet(page.getInode())){
            relationshipAPI.addRelationship(childCampaign.getInode(), page.getInode(), "child");
          }
          if (InodeUtils.isSet(comm.getInode())) {
            relationshipAPI.addRelationship(childCampaign.getInode(), comm.getInode(), "child");
          }
          if (InodeUtils.isSet(userfilter.getInode())) {
            relationshipAPI.addRelationship(childCampaign.getInode(), userfilter.getInode(), "child");
          }
          HibernateUtil.saveOrUpdate(childCampaign);


          campaigns.add(childCampaign);



          c.setLocked(false);
        }
        catch (Exception ex) {
          Logger.debug(this, ex.getMessage());
        }
      }
    }
    else {
      //get a list of waiting queues
      campaigns = CampaignFactory.getWaitingCampaigns();
    }

    StringBuffer message = null;

    if (campaigns.size() == 0)
    {
      campaigns = null;
      return;
    }

    try {

      Logger.debug(DeliverCampaignThread.class, "GOING to deliver campaigns");
      Iterator<Campaign> campIter = campaigns.iterator();
     
      //### LOOP THE CAMPAIGNS ###
      while (campIter.hasNext())
      {
        //Obtain the campaign
        Campaign c = (Campaign) campIter.next();
        Communication comm = (Communication) InodeFactory.getChildOfClass(c, Communication.class);
       
        if ((comm == null) || (!InodeUtils.isSet(comm.getInode()))) {
          Logger.info(DeliverCampaignThread.class, "I didn't find a communication for campaign inode=" + c.getInode());
         
          c.setCompletedDate(new java.util.Date());
          c.setLocked(false);
          message = null;
          HibernateUtil.saveOrUpdate(c);
         
          continue;
        }

        Logger.debug(DeliverCampaignThread.class, "got campaign:" + c.getTitle());
        //Mailing list
        String campaingSendTo = c.getSendTo();

        MailingList ml = null;
        UserFilter uf = null;
        List<UserProxy> subscribers =  null;
        if ((campaingSendTo != null) && campaingSendTo.equalsIgnoreCase("mailingList")) {
          ml = (MailingList) InodeFactory.getChildOfClass(c,MailingList.class);
          if (!InodeUtils.isSet(ml.getInode()))
          {
            Logger.info(DeliverCampaignThread.class, "I didn't find a mailing list for campaign inode=" + c.getInode());
           
            c.setCompletedDate(new java.util.Date());
            c.setLocked(false);
            message = null;
            HibernateUtil.saveOrUpdate(c);
           
            continue;
          }
          else
          {
            Logger.debug(DeliverCampaignThread.class, "got mailingList:" + ml.getTitle());
            //Get the subscribers
            subscribers = MailingListFactory.getMailingListSubscribers(ml);
            Logger.debug(DeliverCampaignThread.class, "Got subscribers:" + subscribers.size());
          }
        }
        else if ((campaingSendTo != null) && campaingSendTo.equalsIgnoreCase("userFilter")) {
          uf = (UserFilter) InodeFactory.getChildOfClass(c,UserFilter.class);
          if (!InodeUtils.isSet(uf.getInode()))
          {
            Logger.info(DeliverCampaignThread.class, "I didn't find an user filter for campaign inode=" + c.getInode());
           
            c.setCompletedDate(new java.util.Date());
            c.setLocked(false);
            message = null;
            HibernateUtil.saveOrUpdate(c);
           
            continue;
          }
          else
          {
            Logger.debug(DeliverCampaignThread.class, "got user filter:" + uf.getUserFilterTitle());
            //Get the subscribers
            try {
              subscribers = UserFilterFactory.getUserProxiesFromFilter(uf);
            }
            catch (Exception e) {
              Logger.info(DeliverCampaignThread.class, "Error getting subscriber from user filter for campaign inode=" + c.getInode());
             
              c.setCompletedDate(new java.util.Date());
              c.setLocked(false);
              message = null;
              HibernateUtil.saveOrUpdate(c);
             
              continue;
            }
            Logger.debug(DeliverCampaignThread.class, "Got subscribers:" + subscribers.size());
          }
        }

        //Unsubscriber mailing list
        MailingList unSubscribers = MailingListFactory.getUnsubscribersMailingList();

        //do we have an html page?
        String alternateTextMessage = null;
        HTMLPageAPI pageAPI = APILocator.getHTMLPageAPI();
        HTMLPage htmlPage = (HTMLPage) pageAPI.loadWorkingPageById(comm.getHtmlPage(), APILocator.getUserAPI().getSystemUser(), false);
        String serverName;
        if (htmlPage != null && UtilMethods.isSet(htmlPage.getTitle())) {
          html = true;
          Logger.debug(DeliverCampaignThread.class, "Got htmlPage:"+ htmlPage.getTitle());

          // get the newsletter and the attachments
          Identifier id = APILocator.getIdentifierAPI().find(htmlPage);

          serverName = APILocator.getHostAPI().find(id.getHostId(), APILocator.getUserAPI().getSystemUser(), false).getHostname();

          //rewrite the urls
          try {
            Logger.debug(DeliverCampaignThread.class, "Retrieving page from url " + "http://"+ serverName + UtilMethods.encodeURIComponent(id.getURI()));
            message = new StringBuffer(UtilMethods.escapeUnicodeCharsForHTML(UtilMethods.getURL("http://"+ serverName + UtilMethods.encodeURIComponent(id.getURI())).toString()));
            Logger.debug(DeliverCampaignThread.class, "Page retrieved " + message);
            message = EmailFactory.alterBodyHTML(message, serverName);
            Logger.debug(DeliverCampaignThread.class, "Page altered " + message);
            alternateTextMessage = "If you are having trouble reading this message, click here: "+ "http://"+ serverName + UtilMethods.encodeURIComponent(id.getURI());
          }catch(Exception e){
            /**
             * This condition was included to avoid send 
             * campaigns without content
             * */
           
            Logger.info(DeliverCampaignThread.class, "Error generating message for campaign inode=" + c.getInode() + " and htmlPage inode=" + htmlPage.getInode());
           
            c.setCompletedDate(new java.util.Date());
            c.setLocked(false);
            message = null;
            HibernateUtil.saveOrUpdate(c);
           
            continue;
          }

        } else {
          serverName = APILocator.getHostAPI().findDefaultHost(APILocator.getUserAPI().getSystemUser(), false).getHostname();
          html = false;
          if (comm.getTextMessage() != null){

            message = new StringBuffer(UtilMethods.escapeUnicodeCharsForHTML(comm.getTextMessage()));
            message = EmailFactory.alterBodyHTML(message, serverName);
          }
          else
            message = new StringBuffer("");
        }
        //add tracking shim
        message.append("<img src='http://"+ serverName + "/imageShim?r=<rId>' width='1' height='1'>");

        // big loop over recipients
        Iterator<UserProxy> subscriberIterator = subscribers.iterator();
        String send_per_hour = c.getSendsPerHour();
        User user = new User();
        try {
          user = APILocator.getUserAPI().loadUserById(c.getUserId(),APILocator.getUserAPI().getSystemUser(),false);
        } catch (Exception e) {
          Logger.error(DeliverCampaignThread.class, "deliverCampaigns Failed - getting campaign owner: "+ c.getUserId()+ " " + e.getMessage());
        }


        //### LOOP THE SUBSCRIBERS OF EACH CAMPAIGN ###
        while (subscriberIterator.hasNext())
        {
          UserProxy userProxy = (UserProxy) subscriberIterator.next();
          try {
            // validting permissions over subscriber
            try {
              _checkUserPermissions(userProxy, user, PERMISSION_READ);
            }catch(Exception e){
              continue;
            }
 
            User member = new User();
            try {
              member = APILocator.getUserAPI().loadUserById(userProxy.getUserId(), APILocator.getUserAPI().getSystemUser(), false);
            } catch (Exception e) {
              Logger.error(DeliverCampaignThread.class, "deliverCampaigns Failed - getting subscriber: " + userProxy.getUserId() + " " + e.getMessage());
             
            }
 
            Recipient recipient = RecipientFactory.getRecipientByCampaignAndSubscriber(c, member);
            recipient.setUserId(member.getUserId());
            if (EmailFactory.isSubscribed(unSubscribers,member))
            {
              recipient.setLastMessage("On "+MailingListFactory.getUnsubscribersMailingList().getTitle());
              recipient.setLastResult(500);
              userProxy.setLastMessage("On "+MailingListFactory.getUnsubscribersMailingList().getTitle());
              userProxy.setLastResult(500);
              c.addChild(recipient);
              continue;
            }
 
            //if this recipient already got the email
            List<UserComment> l = UserCommentsFactory.getUserCommentsByComm(userProxy.getInode(), comm.getInode());
 
            if (InodeUtils.isSet(recipient.getInode()) || l.size() > 0)
            {
              Logger.debug(EmailFactory.class,"Already got this email:" + recipient.getEmail());
              if (!c.isSendEmail()) {
                continue;
              }
            }
 
            recipient.setEmail(member.getEmailAddress());
            recipient.setName(member.getFirstName());
            recipient.setLastname(member.getLastName());
 
            recipient.setSent(new java.util.Date());
            HibernateUtil.saveOrUpdate(recipient);
 
            setRecipient(recipient);
            setCampaign(c);
            setSubscriber(member);
            setAlternateTextMessage(alternateTextMessage);
            setMessage(message);
            setHtml(true);
            c.addChild(recipient);
           
            if (!comm.getCommunicationType().equalsIgnoreCase("alert")) {
              if(!sendEmail()) {
                //If got errors sending the email then we mark it as a bounce
                //from the mailing list
                MailingListFactory.markAsBounceFromMailingList(ml, userProxy);
              }
View Full Code Here

    //add it to the campaign's children
    //campaign.addChild(recipient);


    Campaign campaign = getCampaign();
    Communication comm = (Communication) InodeFactory.getChildOfClass(campaign, Communication.class);
    Mailer Mailer = new Mailer();

    //get subject and message
    String subject = comm.getEmailSubject();

    User tempUser = new User();
    try {
      BeanUtils.copyProperties(tempUser, subscriber);
    } catch (Exception e) {
    }
    tempUser.setFirstName(recipient.getName());
    subject = replaceTextVar(subject, recipient, tempUser, comm);

    Mailer.setRecipientId(recipient.getInode());
    Mailer.setFromName(replaceTextVar(comm.getFromName(), recipient, subscriber, comm));
    Logger.debug(DeliverCampaignThread.class, "comm.getFromName()="+comm.getFromName());
    Mailer.setFromEmail(replaceTextVar(comm.getFromEmail(), recipient, subscriber, comm));
    Logger.debug(DeliverCampaignThread.class, "comm.getFromEmail()="+comm.getFromEmail());
    Mailer.setToEmail(recipient.getEmail());

    if(UtilMethods.isSet(recipient.getLastname()))
      Mailer.setToName(recipient.getName()+" "+recipient.getLastname());
    else
      Mailer.setToName(recipient.getName());

    Mailer.setSubject(subject);

    String finalMessageStr = message.toString();

    Logger.debug(DeliverCampaignThread.class, "sendEmail: message = " + message);

    finalMessageStr = replaceTextVar(finalMessageStr, recipient, subscriber, comm);

    if (html) {
      //personalize
      Mailer.setHTMLBody(finalMessageStr);
      if (alternateTextMessage != null) {
        Mailer.setTextBody(alternateTextMessage);
      }
    }
    else {
      //personalize
      Mailer.setTextBody(finalMessageStr);
    }

    boolean sent = Mailer.sendMessage();
    if (!sent) {

      recipient.setLastResult(500);
      recipient.setLastMessage(Mailer.getErrorMessage());
    }
    else{
      recipient.setLastResult(200);
      recipient.setLastMessage("Mail Sent");

      //add the comment to the user record
      Date today = new Date();
      String commentComment = "Campaign: "+comm.getTitle() + " sent on " + UtilMethods.dateToHTMLDate(today);
      UserComment comment = new UserComment();

      comment.setComment(commentComment);
      comment.setDate(today);
      comment.setMethod(UserComment.METHOD_MARKETING_LIST);
      comment.setTypeComment(UserComment.TYPE_OUTGOING);
      comment.setType("mailing_list");
      comment.setSubject(commentComment);
      comment.setCommentUserId(subscriber.getUserId());
      comment.setUserId(subscriber.getUserId());
      comment.setCommunicationId(comm.getInode());
      UserCommentsFactory.saveUserComment(comment);
    }
    HibernateUtil.commitTransaction();

    return sent;
View Full Code Here

  public void _retrieveCommunication(ActionRequest req, ActionResponse res,PortletConfig config,ActionForm form, User user)
  throws Exception {
   
    String inode = (req.getParameter("inode")!=null) ? req.getParameter("inode") : "";
   
    Communication c = null;
    c = CommunicationsFactory.getCommunication(inode);
   
    if(!InodeUtils.isSet(c.getInode())){
      c = CommunicationsFactory.newInstance();
      req.setAttribute(WebKeys.COMMUNICATION_EDIT_FORM_PERMISSION, true);
    }
   
    req.setAttribute(WebKeys.COMMUNICATION_EDIT, c);
View Full Code Here

 
  public void _editCommunication(ActionRequest req, ActionResponse res,PortletConfig config,ActionForm form, User user)
  throws Exception {
   
    CommunicationsForm cfform = (CommunicationsForm) form;
    Communication c = (Communication) req.getAttribute(WebKeys.COMMUNICATION_EDIT);
   
    BeanUtils.copyProperties(cfform, c);
   
    if(cfform.getModDate() == null)
      cfform.setModDate(new java.util.Date());
View Full Code Here

  }
 
  public void _saveCommunication(ActionRequest req, ActionResponse res,PortletConfig config,ActionForm form, User user)
  throws Exception {
   
    Communication c = (Communication) req.getAttribute(WebKeys.COMMUNICATION_EDIT);
    CommunicationsForm cfform = (CommunicationsForm) form;
   
    BeanUtils.copyProperties(req.getAttribute(WebKeys.COMMUNICATION_EDIT), cfform);
   
    if(cfform.getModDate() == null){
      c.setModDate(new java.util.Date());
    }
   
    c.setModifiedBy(user.getUserId());
   
    _checkUserPermissions(c, user, PERMISSION_WRITE);
   
    if (req.getParameter("typeContent").equals("HTMLPage") &&
        !cfform.getCommunicationType().equalsIgnoreCase("alert")) {
      c.setTextMessage("");
    }
    if (!cfform.getCommunicationType().equalsIgnoreCase("email")) {
      c.setFromEmail("");
      c.setFromName("");
      c.setEmailSubject("");
      c.setHtmlPage(null);
      cfform.setHtmlPage(null);
    }
    if (!cfform.getCommunicationType().equalsIgnoreCase("external")) {
      c.setTrackBackLinkInode(null);
      c.setExternalCommunicationIdentifier("");
      cfform.setTrackBackLinkInode(null);
    }

    try {

      // HibernateUtil.saveOrUpdate(c);
      HibernateUtil.saveOrUpdate(c);

    } catch (DotHibernateException dhe) {
      SessionMessages.add(req, "error", "error.communications.not-saved");
      //setForward(req,"portlet.ext.communications.edit_communication");
      throw new ActionException(dhe.getMessage());
    }

   
    // wipe the old HTML page entries
    HTMLPage page = (HTMLPage) InodeFactory.getChildOfClass(c, HTMLPage.class);
    if (InodeUtils.isSet(page.getInode()))
      c.deleteChild(page);
   
    if (req.getParameter("typeContent").equals("HTMLPage")) {
      //try to get the Communication's page
      if (InodeUtils.isSet(cfform.getHtmlPage())) {
        page = (HTMLPage) InodeFactory.getInode(String.valueOf(cfform.getHtmlPage()), HTMLPage.class);
        if (InodeUtils.isSet(page.getInode())) {
          c.addChild(page);
          c.setHtmlPage(page.getIdentifier());
        }
      }
    }
   
    // wipe the old VirtualLink entries
    VirtualLink vl = (VirtualLink) InodeFactory.getChildOfClass(c, VirtualLink.class);
    if (InodeUtils.isSet(vl.getInode()))
      c.deleteChild(vl);
   
    //try to get the Communication's virtual link
    if (InodeUtils.isSet(cfform.getTrackBackLinkInode())) {
      vl = VirtualLinkFactory.getVirtualLink(String.valueOf(cfform.getTrackBackLinkInode()));
      if (InodeUtils.isSet(vl.getInode())) {
        c.addChild(vl);
        c.setTrackBackLinkInode(vl.getInode());
      }
    }
       
    //add message
    SessionMessages.add(req, "message", "message.communications.saved");
View Full Code Here

 
 
  public void _deleteCommunication(ActionRequest req, ActionResponse res,PortletConfig config,ActionForm form, User user)
  throws Exception {
   
    Communication c = (Communication) req.getAttribute(WebKeys.COMMUNICATION_EDIT);
    CommunicationsFactory.deleteCommunication(c, user.getUserId());
    SessionMessages.add(req, "message", "message.communications.deleted");
   
  }
View Full Code Here

TOP

Related Classes of com.dotmarketing.portlets.communications.model.Communication

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.