Package com.dotmarketing.portlets.campaigns.model

Examples of com.dotmarketing.portlets.campaigns.model.Campaign


        return campaign;
    }

    public static Campaign getCampaign(String inode) {
        HibernateUtil dh = new HibernateUtil(Campaign.class);
        Campaign campaign = new Campaign();
        try {
      dh.setQuery(
          "from inode in class com.dotmarketing.portlets.campaigns.model.Campaign where type='campaign' and inode = ?");
      dh.setParam(inode);
      campaign = (Campaign) dh.load();
View Full Code Here


    }
        return campaign;
    }

    public static Campaign newInstance() {
        Campaign c = new Campaign();
        c.setType("campaign");
        c.setCStartDate(new java.util.Date());

        return c;
    }
View Full Code Here

      Iterator i = list.iterator();

      while (i.hasNext()) {
        Logger.debug(CampaignFactory.class, "gettingWaitingCampaigns");
       
          Campaign c = (Campaign) i.next();
          c.setLocked(true);
          HibernateUtil.flush();
      }
    } catch (DotHibernateException e) {
      Logger.error(CampaignFactory.class, "getWaitingCampaigns failed:" + e,e);
    }
View Full Code Here

    } catch (ActionException ae) {
      _handleException(ae, req);
    }

    Campaign c = (Campaign) req.getAttribute(WebKeys.CAMPAIGN_EDIT);
    if(c.isLocked()){
      //add message
      SessionMessages.add(req, "message", "message.campaign.locked");
      setForward(req,"portlet.ext.campaigns.view_campaigns");
    }

    //getting the user roles
    boolean isCampaignManagerAdmin = false;
    String campaignManagerAdminRoleKey = "";
    try {
      Role campaignManagerAdminRole = APILocator.getRoleAPI().loadRoleByKey(Config.getStringProperty("CAMPAIGN_MANAGER_ADMIN"));
      campaignManagerAdminRoleKey = campaignManagerAdminRole.getRoleKey();
    }
    catch (Exception e) {}

    boolean isCampaignManagerEditor = false;
    String campaignManagerEditorRoleKey = "";
    try {
      Role campaignManagerEditorRole = APILocator.getRoleAPI().loadRoleByKey(Config.getStringProperty("CAMPAIGN_MANAGER_EDITOR"));
      campaignManagerEditorRoleKey = campaignManagerEditorRole.getRoleKey();
    }
    catch (Exception e) {}

    Role[] userRoles = (Role[])APILocator.getRoleAPI().loadRolesForUser(user.getUserId()).toArray(new Role[0]);
    for (int i = 0; i < userRoles.length; i++) {
      Role userrole = (Role) userRoles[i];
      if ((userrole.getRoleKey() != null) && userrole.getRoleKey().equals(campaignManagerAdminRoleKey)) {
        isCampaignManagerAdmin = true;
        if (isCampaignManagerEditor)
          break;
      }
      if ((userrole.getRoleKey() != null) && userrole.getRoleKey().equals(campaignManagerEditorRoleKey)) {
        isCampaignManagerEditor = true;
        if (isCampaignManagerAdmin)
          break;
      }
    }

    /*
     * We are editing the campaign
     */
    if ((cmd != null) && cmd.equals(Constants.EDIT)) {
      try {
        _editCampaign(req, res, config, form, user);
        setForward(req,"portlet.ext.campaigns.edit_campaign");
       
        if ((!InodeUtils.isSet(c.getParentCampaign())) && UtilMethods.isSet(c.getCompletedDate())) {
          setForward(req,"portlet.ext.campaigns.view_report");
        }
        else{
          String parentCampaign = c.getParentCampaign();
          if (InodeUtils.isSet(parentCampaign)) {
            if (c.getWasSent())
              setForward(req,"portlet.ext.campaigns.view_report");
            else
              setForward(req,"portlet.ext.campaigns.edit_pending_campaign");
          }
        }
        if (c.getIsRecurrent() && c.isActive()) {
          if (UtilMethods.isSet(c.getExpirationDate()) && c.getExpirationDate().before(new Date())) {
            setForward(req,"portlet.ext.campaigns.view_report");
          }
          else {
            List<ScheduledTask> jobs = QuartzUtils.getStandardScheduledTask(String.valueOf(c.getInode()), "Recurrent Campaign");
            if (jobs.size() == 0) {
              setForward(req,"portlet.ext.campaigns.view_report");
            }
            else {
              Date endDate = jobs.get(0).getEndDate();
View Full Code Here

  }
 
  public void _resendCampaign(ActionRequest req, ActionResponse res,PortletConfig config,ActionForm form, User user)
  throws Exception {

    Campaign cToResend = CampaignFactory.getCampaign("0");

    CampaignForm cfform = (CampaignForm) form;

    Date now = new Date();
    SimpleDateFormat DATE_TO_PRETTY_HTML_DATE = new SimpleDateFormat("MM/dd/yyyy HH:mm");
View Full Code Here

  public void _retrieveCampaign(ActionRequest req, ActionResponse res,PortletConfig config,ActionForm form, User user)
  throws Exception {

    String inode = (req.getParameter("inode")!=null) ? req.getParameter("inode") : "0";

    Campaign c = null;
    c = CampaignFactory.getCampaign(inode);

    if(!InodeUtils.isSet(c.getInode())){
      c = CampaignFactory.newInstance()
      c.setUserId(user.getUserId());
      c.setSendTo("mailingList");
    }

    req.setAttribute(WebKeys.CAMPAIGN_EDIT, c);

    List<Communication> list = CommunicationsFactory.getCommunications("","lower(title)");
View Full Code Here

  }
  public void _editCampaign(ActionRequest req, ActionResponse res,PortletConfig config,ActionForm form, User user)
  throws Exception {

    CampaignForm cfform = (CampaignForm) form;
    Campaign c = (Campaign) req.getAttribute(WebKeys.CAMPAIGN_EDIT);

    BeanUtils.copyProperties(cfform, c);

    if (InodeUtils.isSet(c.getInode())) {
      //add the campaigns mailing list to the form
      MailingList ml = (MailingList) InodeFactory.getChildOfClass(c, MailingList.class);
      cfform.setMailingList(ml.getInode());

      //add the html page to the campaign
      HTMLPage page = (HTMLPage) InodeFactory.getChildOfClass(c, HTMLPage.class);
      if (InodeUtils.isSet(page.getInode())) {
        cfform.setHtmlPage(page.getInode());
        cfform.setSelectedHtmlPage(page.getTitle());
      }

      UserFilter uf = (UserFilter) InodeFactory.getChildOfClass(c, UserFilter.class);
      cfform.setUserFilterInode(uf.getInode());
    }
    else {
      cfform.setMailingList(null);
      cfform.setHtmlPage(null);
      cfform.setCommunicationInode(null);
      cfform.setUserFilterInode(null);
    }

    if (c.getIsRecurrent()) {
      // getting recurrency data
      List<ScheduledTask> jobs = QuartzUtils.getStandardScheduledTask(String.valueOf(c.getInode()), "Recurrent Campaign");

      if (jobs.size() > 0) {

        SimpleDateFormat sdf = new SimpleDateFormat(WebKeys.DateFormats.DOTSCHEDULER_DATE2);
View Full Code Here

  throws Exception {

    boolean result = true;
   
    HibernateUtil.startTransaction();
    Campaign c = (Campaign) req.getAttribute(WebKeys.CAMPAIGN_EDIT);

    String updateCampaignPermissionsOnly = req.getParameter(com.dotmarketing.util.Constants.UPDATE_CAMPAIGN_PERMISSIONS_ONLY);
    boolean updateAll = false;

    if ((updateCampaignPermissionsOnly == null) || (updateCampaignPermissionsOnly.equalsIgnoreCase("false")))
      updateAll = true;

    if ((updateCampaignPermissionsOnly != null) && (!updateAll)) {
      try {
        int temp = Integer.parseInt(updateCampaignPermissionsOnly);
        if (temp < 1)
          updateAll = true;
      } catch (Exception e) {
      }
    }

    if (updateAll) {
      CampaignForm cfform = (CampaignForm) form;

      boolean isWasRecurrent = c.getIsRecurrent();

      BeanUtils.copyProperties(req.getAttribute(WebKeys.CAMPAIGN_EDIT), cfform);
      HibernateUtil.saveOrUpdate(c);

      // wipe the old mailing list that was the child
      MailingList ml = (MailingList) InodeFactory.getChildOfClass(c, MailingList.class);
      c.deleteChild(ml);

      //try to get the campaign's new mailing list
      ml = (MailingList) InodeFactory.getInode(String.valueOf(cfform.getMailingList()), MailingList.class);
      if (InodeUtils.isSet(ml.getInode())) {
        c.addChild(ml);
      }

      // wipe the old communication that was the child
      Communication comm = (Communication) InodeFactory.getChildOfClass(c, Communication.class);
      c.deleteChild(comm);

      //try to get the campaign's new communication
      comm = (Communication) InodeFactory.getInode(String.valueOf(cfform.getCommunicationInode()), Communication.class);
      if (InodeUtils.isSet(comm.getInode())) {
        c.addChild(comm);
      }

      // wipe the old user filter that was the child
      UserFilter userfilter = (UserFilter) InodeFactory.getChildOfClass(c, UserFilter.class);
      c.deleteChild(userfilter);

      //try to get the campaign's new communication
      userfilter = (UserFilter) InodeFactory.getInode(String.valueOf(cfform.getUserFilterInode()), UserFilter.class);
      if (InodeUtils.isSet(userfilter.getInode())) {
        c.addChild(userfilter);
      }

      c.setUserId(user.getUserId());

      if (c.getIsRecurrent()) {
        SchedulerForm schedulerForm = new SchedulerForm();
        BeanUtils.copyProperties(schedulerForm, cfform);
        schedulerForm.setJavaClass("com.dotmarketing.quartz.job.DeliverCampaignThread");

        //schedulerForm.setJobName(c.getTitle());
        schedulerForm.setJobName(String.valueOf(c.getInode()));

        HashMap hashMap = new HashMap<String, String>();
        hashMap.put("inode", c.getInode());
        schedulerForm.setMap(hashMap);
        schedulerForm.setJobDescription(c.getTitle());

        //schedulerForm.setJobGroup(String.valueOf(c.getInode()));
        schedulerForm.setJobGroup("Recurrent Campaign");

        // create/edit quartz job
        result = EditSchedulerAction._saveScheduler(req, res, config, schedulerForm, user);
      }
      else if (isWasRecurrent) {
        // ending quartz job
        QuartzUtils.removeJob(c.getInode(), "Recurrent Campaign");
      }
     
      if (result)
        HibernateUtil.saveOrUpdate(c);
View Full Code Here

  }

  public void _copyCampaign(ActionRequest req, ActionResponse res,PortletConfig config,ActionForm form, User user)
  throws Exception {

    Campaign c = (Campaign) req.getAttribute(WebKeys.CAMPAIGN_EDIT);
    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);

    Campaign copy = CampaignFactory.newInstance();

    copy.setTitle( c.getTitle() + " (copy)");
    copy.setFromEmail(c.getFromEmail());
    copy.setFromName(c.getFromName());
    copy.setCStartDate(c.getCStartDate());
    copy.setSubject(c.getSubject());
    copy.setMessage(c.getMessage());
    copy.setOwner(c.getOwner());
    copy.setUserId(c.getUserId());
    copy.setCommunicationInode(c.getCommunicationInode());
    copy.setUserFilterInode(c.getUserFilterInode());

    //no sure if this is needed
    HibernateUtil.saveOrUpdate(copy);

    if(InodeUtils.isSet(ml.getInode())){
      copy.addChild(ml);
    }
    if(InodeUtils.isSet(page.getInode())){
      copy.addChild(page);
    }
    if (InodeUtils.isSet(comm.getInode())) {
      copy.addChild(comm);
    }
    if (InodeUtils.isSet(userfilter.getInode())) {
      copy.addChild(userfilter);
    }
    HibernateUtil.saveOrUpdate(copy);

    //add message
    if (c.isSendEmail())
View Full Code Here

  }

  public void _deleteCampaign(ActionRequest req, ActionResponse res,PortletConfig config,ActionForm form, User user)
  throws Exception {
    PermissionAPI perAPI = APILocator.getPermissionAPI();
    Campaign c = (Campaign) req.getAttribute(WebKeys.CAMPAIGN_EDIT);
    boolean UserHasWriteCampPerms = perAPI.doesUserHavePermission(c,PERMISSION_WRITE,user);
    if(c.getUserId().equalsIgnoreCase(user.getUserId()) || UserHasWriteCampPerms)
    {
      //Ending Quartz Job
      if ((c.getIsRecurrent() && !InodeUtils.isSet(c.getParentCampaign())) && c.getUserId().equalsIgnoreCase(user.getUserId()) || UserHasWriteCampPerms)
      {
        // removing the recurrent campaign occurrences
        List childCampaigns = CampaignFactory.getChildCampaignsByParent(String.valueOf(c.getInode()));
        if (childCampaigns.size() > 0) {
          Iterator childCampIter = childCampaigns.iterator();
         
          //### LOOP THE CHILD CAMPAIGNS ###
          while (childCampIter.hasNext()) {
            //Obtain the campaign
            Campaign childCampaign = (Campaign) childCampIter.next();
            CampaignFactory.deleteCampaign(childCampaign, user.getUserId());
          }
        }

        QuartzUtils.removeJob(String.valueOf(c.getInode()), "Recurrent Campaign");
View Full Code Here

TOP

Related Classes of com.dotmarketing.portlets.campaigns.model.Campaign

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.