Package com.dotmarketing.portlets.campaigns.struts

Examples of com.dotmarketing.portlets.campaigns.struts.CampaignForm


    else if ((cmd != null) && cmd.equals(Constants.ADD)) {
      try {
        String updateCampaignPermissionsOnly = req.getParameter(com.dotmarketing.util.Constants.UPDATE_CAMPAIGN_PERMISSIONS_ONLY);
        boolean updateAll = false;
       
        CampaignForm schedulerForm = (CampaignForm) form;
        boolean hasErrors = false;
        boolean displayRecurrence = false;
       
        if (schedulerForm.getTitle().trim().equals("")) {
          SessionMessages.add(req, "error", "message.campaign.error.titleRequired");
          hasErrors = true;
        }
       
        SimpleDateFormat sdf = new SimpleDateFormat(WebKeys.DateFormats.DOTSCHEDULER_DATE2);
       
        Date endDate = null;
        if (schedulerForm.isHaveEndDate()) {
          try {
            endDate = sdf.parse(schedulerForm.getEndDate());
          } catch (Exception e) {
          }
        }
       
        if ((endDate != null) && !hasErrors) {
          Date startDate = null;
          if (schedulerForm.isHaveStartDate()) {
            try {
              startDate = sdf.parse(schedulerForm.getStartDate());
            } catch (Exception e) {
            }
          }
         
          if (startDate == null) {
            SessionMessages.add(req, "error", "message.Scheduler.startDateNeeded");
            hasErrors = true;
            displayRecurrence = true;
          } else if (endDate.before(startDate)) {
            SessionMessages.add(req, "error", "message.Scheduler.endDateBeforeStartDate");
            hasErrors = true;
            displayRecurrence = false;
          } else if (endDate.before(new Date())) {
            SessionMessages.add(req, "error", "message.Scheduler.endDateBeforeActualDate");
            hasErrors = true;
            displayRecurrence = true;
          }
        }

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

        if ((updateCampaignPermissionsOnly != null) && (!updateAll) && !hasErrors) {
          try {
            int temp = Integer.parseInt(updateCampaignPermissionsOnly);
            if (temp < 1)
              updateAll = true;
          } catch (Exception e) {
          }
        }
       
        if (!hasErrors) {
          if (updateAll) {
            if (Validator.validate(req,form,mapping)) {
              hasErrors = !_saveCampaign(req, res, config, form, user);
            }
            else {
              setForward(req,"portlet.ext.campaigns.edit_campaign");
              return;
            }
          } else {
            hasErrors = !_saveCampaign(req, res, config, form, user);
          }
        }
       
        if (hasErrors) {
//          _editCampaign(req, res, config, form, user);
          loadEveryDayForm(form, req);
          schedulerForm = (CampaignForm) form;
          schedulerForm.setDisplayRecurrence(displayRecurrence);
          setForward(req,"portlet.ext.campaigns.edit_campaign");
          return;
        }
      } catch (ActionException ae) {
        _handleException(ae, req);
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");
    cfform.setWebStartDate(DATE_TO_PRETTY_HTML_DATE.format(now));

    cfform.setExpirationDate(null);
    cfform.setWebExpirationDate("");

    cfform.setCompletedDate(null);
    cfform.setWebCompletedDate("");
   
    cfform.setInode(null);

    BeanUtils.copyProperties(cToResend, cfform);

    req.setAttribute("CampaignForm", cfform);
    req.setAttribute(WebKeys.CAMPAIGN_EDIT, cToResend);
View Full Code Here

  }

  private void loadEveryDayForm(ActionForm form, ActionRequest req) {
    String[] everyDay = req.getParameterValues("everyDay");
   
    CampaignForm schedulerForm = (CampaignForm) form;
    if (UtilMethods.isSet(everyDay) && schedulerForm.isEveryInfo()) {
      for (String dayOfWeek: everyDay) {
        if (dayOfWeek.equals("MON"))
          schedulerForm.setMonday(true);
        else if (dayOfWeek.equals("TUE"))
          schedulerForm.setTuesday(true);
        else if (dayOfWeek.equals("WED"))
          schedulerForm.setWednesday(true);
        else if (dayOfWeek.equals("THU"))
          schedulerForm.setThusday(true);
        else if (dayOfWeek.equals("FRI"))
          schedulerForm.setFriday(true);
        else if (dayOfWeek.equals("SAT"))
          schedulerForm.setSaturday(true);
        else if (dayOfWeek.equals("SUN"))
          schedulerForm.setSunday(true);
      }
     
      schedulerForm.setEveryInfo(true);
      schedulerForm.setEvery("isDays");
    } else {
      schedulerForm.setEvery("");
      schedulerForm.setMonday(false);
      schedulerForm.setTuesday(false);
      schedulerForm.setWednesday(false);
      schedulerForm.setThusday(false);
      schedulerForm.setFriday(false);
      schedulerForm.setSaturday(false);
      schedulerForm.setSunday(false);
    }
  }
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);

        CronScheduledTask job = (CronScheduledTask) jobs.get(0);
       
        String startDateStr = sdf.format(job.getStartDate());
        if (UtilMethods.isSet(startDateStr)) {
          cfform.setHaveStartDate(true);
          cfform.setStartDate(startDateStr);
        }
        else {
          cfform.setHaveStartDate(false);
          cfform.setStartDate(null);
        }

        String endDateStr = sdf.format(job.getEndDate());
        if (UtilMethods.isSet(endDateStr)) {
          cfform.setHaveEndDate(true);
          cfform.setEndDate(endDateStr);
        }
        else {
          cfform.setHaveEndDate(false);
          cfform.setEndDate(null);
        }

        String cronExpression = job.getCronExpression();
       
        if (UtilMethods.isSet(cronExpression)) {
View Full Code Here

      } 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());
View Full Code Here

  }
 
  private void _populateForm(ActionForm form, CronScheduledTask scheduler) {
    try {
      BeanUtils.copyProperties(form, scheduler);
      CampaignForm schedulerForm = ((CampaignForm) form);
     
      if (scheduler.getStartDate() != null) {
        schedulerForm.setHaveStartDate(true);
      } else {
        schedulerForm.setHaveStartDate(false);
      }
     
      if (scheduler.getEndDate() != null) {
        schedulerForm.setHaveEndDate(true);
      } else {
        schedulerForm.setHaveEndDate(false);
      }
     
      if (UtilMethods.isSet(scheduler.getCronExpression())) {
        StringTokenizer cronExpressionTokens = new StringTokenizer(scheduler.getCronExpression());
        String token;
        String[] intervalTokens;
        String[] rangeTokens;
       
        // Seconds Cron Expression
        if (cronExpressionTokens.hasMoreTokens()) {
          token = cronExpressionTokens.nextToken();
         
          if (token.equals("*")) {
            schedulerForm.setAtInfo(false);
            schedulerForm.setAt(null);
            schedulerForm.setAtTimeSecond(0);
          } else {
            intervalTokens = token.split("/");
            rangeTokens = intervalTokens[0].split("-");
           
            if (rangeTokens.length == 2) {
              schedulerForm.setAtInfo(true);
              schedulerForm.setAt("isBetween");
              try {
                schedulerForm.setBetweenFromSecond(Integer.parseInt(rangeTokens[0]));
                schedulerForm.setBetweenToSecond(Integer.parseInt(rangeTokens[1]));
              } catch (Exception e) {
                schedulerForm.setBetweenFromSecond(0);
                schedulerForm.setBetweenToSecond(0);
              }
            } else {
              schedulerForm.setAtInfo(true);
              schedulerForm.setAt("isTime");
              try {
                schedulerForm.setAtTimeSecond(Integer.parseInt(intervalTokens[0]));
              } catch (Exception e) {
                schedulerForm.setAtTimeSecond(0);
              }
            }
           
  //          if (intervalTokens.length == 2) {
  //            ;
  //          }
          }
        }
       
        schedulerForm.setEachInfo(false);
       
        // Minutes Cron Expression
        if (cronExpressionTokens.hasMoreTokens()) {
          token = cronExpressionTokens.nextToken();
         
          if (token.equals("*")) {
            schedulerForm.setAtInfo(false);
            schedulerForm.setAt(null);
            schedulerForm.setAtTimeMinute(0);
          } else {
            intervalTokens = token.split("/");
            rangeTokens = intervalTokens[0].split("-");
           
            if (rangeTokens.length == 2) {
              schedulerForm.setAtInfo(true);
              schedulerForm.setAt("isBetween");
              try {
                schedulerForm.setBetweenFromMinute(Integer.parseInt(rangeTokens[0]));
                schedulerForm.setBetweenToMinute(Integer.parseInt(rangeTokens[1]));
              } catch (Exception e) {
                schedulerForm.setBetweenFromMinute(0);
                schedulerForm.setBetweenToMinute(0);
              }
            } else {
              schedulerForm.setAtInfo(true);
              schedulerForm.setAt("isTime");
              try {
                schedulerForm.setAtTimeMinute(Integer.parseInt(intervalTokens[0]));
              } catch (Exception e) {
                schedulerForm.setAtTimeMinute(0);
              }
            }
           
            if (intervalTokens.length == 2) {
              try {
                schedulerForm.setEachMinutes(Integer.parseInt(intervalTokens[1]));
                schedulerForm.setEachInfo(true);
              } catch (Exception e) {
                schedulerForm.setEachMinutes(0);
              }
            }
          }
        }
       
        // Hours Cron Expression
        if (cronExpressionTokens.hasMoreTokens()) {
          token = cronExpressionTokens.nextToken();
         
          if (token.equals("*")) {
            schedulerForm.setAtInfo(false);
            schedulerForm.setAt(null);
            schedulerForm.setAtTimeHour(0);
          } else {
            intervalTokens = token.split("/");
            rangeTokens = intervalTokens[0].split("-");
           
            if (rangeTokens.length == 2) {
              schedulerForm.setAtInfo(true);
              schedulerForm.setAt("isBetween");
              try {
                schedulerForm.setBetweenFromHour(Integer.parseInt(rangeTokens[0]));
                schedulerForm.setBetweenToHour(Integer.parseInt(rangeTokens[1]));
              } catch (Exception e) {
                schedulerForm.setBetweenFromHour(0);
                schedulerForm.setBetweenToHour(0);
              }
            } else {
              schedulerForm.setAtInfo(true);
              schedulerForm.setAt("isTime");
              try {
                schedulerForm.setAtTimeHour(Integer.parseInt(intervalTokens[0]));
              } catch (Exception e) {
                schedulerForm.setAtTimeHour(0);
              }
            }
           
            if (intervalTokens.length == 2) {
              try {
                schedulerForm.setEachHours(Integer.parseInt(intervalTokens[1]));
                schedulerForm.setEachInfo(true);
              } catch (Exception e) {
                schedulerForm.setEachHours(0);
              }
            }
          }
        }
       
        schedulerForm.setEveryInfo(false);
        schedulerForm.setEvery(null);
       
        // Days of Month Cron Expression
        if (cronExpressionTokens.hasMoreTokens()) {
          token = cronExpressionTokens.nextToken();
         
          if (token.equals("*") || token.equals("?")) {
            schedulerForm.setEveryDateDay(-1);
          } else {
            try {
              schedulerForm.setEveryDateDay(Integer.parseInt(token));
              schedulerForm.setEveryInfo(true);
              schedulerForm.setEvery("isDate");
            } catch (Exception e) {
              schedulerForm.setEveryDateDay(-1);
            }
          }
        }
       
        // Months Cron Expression
        if (cronExpressionTokens.hasMoreTokens()) {
          token = cronExpressionTokens.nextToken();
         
          if (token.equals("*")) {
            schedulerForm.setEveryDateMonth(-1);
          } else {
            try {
              schedulerForm.setEveryDateMonth(Integer.parseInt(token));
              schedulerForm.setEveryInfo(true);
              schedulerForm.setEvery("isDate");
            } catch (Exception e) {
              schedulerForm.setEveryDateMonth(-1);
            }
          }
        }
       
        // Days of Week Cron Expression
        if (cronExpressionTokens.hasMoreTokens()) {
          token = cronExpressionTokens.nextToken();
         
          if ((!token.equals("*")) && (!token.equals("?"))) {
            StringTokenizer daysOfWeek = new StringTokenizer(token, ",");
            String dayOfWeek;
           
            for (; daysOfWeek.hasMoreTokens();) {
              dayOfWeek = daysOfWeek.nextToken();
             
              if (dayOfWeek.equals("MON"))
                schedulerForm.setMonday(true);
              else if (dayOfWeek.equals("TUE"))
                schedulerForm.setTuesday(true);
              else if (dayOfWeek.equals("WED"))
                schedulerForm.setWednesday(true);
              else if (dayOfWeek.equals("THU"))
                schedulerForm.setThusday(true);
              else if (dayOfWeek.equals("FRI"))
                schedulerForm.setFriday(true);
              else if (dayOfWeek.equals("SAT"))
                schedulerForm.setSaturday(true);
              else if (dayOfWeek.equals("SUN"))
                schedulerForm.setSunday(true);
            }
           
            schedulerForm.setEveryInfo(true);
            schedulerForm.setEvery("isDays");
          }
        }
       
        // Years Cron Expression
        if (cronExpressionTokens.hasMoreTokens()) {
          token = cronExpressionTokens.nextToken();
         
          if (token.equals("*")) {
            schedulerForm.setEveryDateYear(-1);
          } else {
            try {
              schedulerForm.setEveryDateYear(Integer.parseInt(token));
              schedulerForm.setEveryInfo(true);
              schedulerForm.setEvery("isDate");
            } catch (Exception e) {
              schedulerForm.setEveryDateYear(-1);
            }
          }
        }
        if (scheduler.getCronExpression().endsWith("0 0 * * * ? *")) {
          schedulerForm.setEveryInfo(true);
          schedulerForm.setEvery("isDate");
        }
      }
    } catch (Exception e) {
      Logger.warn(this, e.getMessage());
    }
View Full Code Here

TOP

Related Classes of com.dotmarketing.portlets.campaigns.struts.CampaignForm

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.