Exemplo n.º 1
0
 @SkipValidation
 public String reset() throws Exception {
   setHeaderResources();
   cForm.reset();
   clearErrorsAndMessages();
   AppdefEntityID appdefId = RequestUtils.getEntityId(request);
   if (appdefId != null) {
     internalEid = appdefId.getId() + ":" + appdefId.getType();
     ;
   }
   internalRid = appdefId.getId().toString();
   internalType = String.valueOf(appdefId.getType());
   return "reset";
 }
Exemplo n.º 2
0
  protected ScheduleValue covertToScheduleValue() {
    if (!(cForm.getEndTime().equals("1"))) {
      cForm.setEndTime(ScheduleFormNG.END_ON_DATE);
      cForm.setEndMin(cForm.getStartMin());
      cForm.setEndHour(cForm.getStartHour());
      cForm.setEndAmPm(cForm.getStartAmPm());
    } else {
      cForm.setEndTime(ScheduleFormNG.END_NEVER);
    }
    if (!(cForm.getRecurInterval().equals(ScheduleFormNG.RECUR_NEVER))) {
      if (cForm.getRecurInterval().equals(ScheduleFormNG.RECUR_DAILY)) {
        if (cForm.getRecurrenceFrequencyDaily().equals("1")) {
          cForm.setRecurrenceFrequencyDaily(ScheduleFormNG.EVERY_DAY);

        } else {
          cForm.setRecurrenceFrequencyDaily(ScheduleFormNG.EVERY_WEEKDAY);
        }
      }
      if (cForm.getRecurInterval().equals(ScheduleFormNG.RECUR_MONTHLY)) {
        if (cForm.getRecurrenceFrequencyMonthly().equals("1")) {
          cForm.setRecurrenceFrequencyMonthly(ScheduleFormNG.ON_EACH);

        } else {
          cForm.setRecurrenceFrequencyMonthly(ScheduleFormNG.ON_DAY);
        }
      }
    }
    ScheduleValue sv = cForm.createSchedule();
    sv.setDescription(cForm.getDescription());
    return sv;
  }
Exemplo n.º 3
0
  // @SkipValidation
  // public String start() throws Exception {
  //
  // // log.trace("preparing new server control action");
  // // request=getServletRequest();
  // // int sessionId = RequestUtils.getSessionId(request).intValue();
  // //
  // // AppdefEntityID appdefId = RequestUtils.getEntityId(request);
  // //
  // // List<String> actions = controlBoss.getActions(sessionId, appdefId);
  // //
  // // Map options= new LinkedHashMap<String, String>();
  // // for (String action : actions) {
  // // String value = action;
  // // String label = StringUtil.capitalize(value);
  // // options.put(value,label);
  // // }
  // // cForm.setControlActions(options);
  // // cForm.setNumControlActions(new Integer(options.size()));
  // // if (cForm.getStartHour() == null) {
  // // Date date = new Date();
  // // Calendar calendar = GregorianCalendar.getInstance();
  // // calendar.setTime(date);
  // // int hours=calendar.get(Calendar.HOUR);
  // // cForm.setStartHour(hours+"");
  // // }
  // // if (cForm.getStartMin()==null) {
  // // DateTime dt = new DateTime();
  // // int minutes = dt.getMinuteOfHour();
  // // cForm.setStartMin(minutes+"");
  // // }
  // // if (cForm.getStartAmPm()==null) {
  // // Date date = new Date();
  // // Calendar calendar = GregorianCalendar.getInstance();
  // // calendar.setTime(date);
  // // int ampm=calendar.get(Calendar.AM_PM);
  // // if (ampm==0) {
  // // cForm.setStartAmPm("AM");
  // // } else {
  // // cForm.setStartAmPm("PM");
  // // }
  // // }
  // return "formNewActionLoad";
  // }
  public String save() throws Exception {

    log.trace("creating new action");
    try {
      request = getServletRequest();
      int sessionId = RequestUtils.getSessionId(request).intValue();
      AppdefEntityID appdefId = RequestUtils.getEntityId(request);
      request.setAttribute(Constants.RESOURCE_PARAM, appdefId.getId());
      request.setAttribute(Constants.RESOURCE_TYPE_ID_PARAM, new Integer(appdefId.getType()));
      boolean validationFailed = false;
      String des = this.cForm.getDescription();
      if (des != null && des.length() > 100) {
        this.addFieldError("description", getText("ng.errors.maxlength", new String[] {"100"}));

        validationFailed = true;
      }
      if (!(cForm.getStartTime().equals("1"))) {
        try {
          int tmph = Integer.parseInt(cForm.getStartHour());
          if (tmph < 0 || tmph > 12) {
            this.addFieldError(
                "startHour", getText("errors.range", new String[] {tmph + "", "1", "12"}));
            validationFailed = true;
          }
        } catch (NumberFormatException nfe) {
          this.addFieldError(
              "startHour",
              getText("errors.invalid.StartHour", new String[] {cForm.getStartHour() + ""}));
          validationFailed = true;
        }

        try {
          int tmpmin = Integer.parseInt(cForm.getStartMin());
          if (tmpmin > 59 || tmpmin < 0) {
            this.addFieldError(
                "startMin", getText("errors.range", new String[] {tmpmin + "", "0", "59"}));
            validationFailed = true;
          }
        } catch (NumberFormatException nfe) {
          this.addFieldError(
              "startMin",
              getText("errors.invalid.StartMin", new String[] {cForm.getStartMin() + ""}));
          validationFailed = true;
        }
      }

      String cAction = this.cForm.getControlAction();
      if (cAction != null && cAction.equals("")) {
        this.addFieldError(
            "controlAction",
            getText(
                "errors.required", new String[] {getText("dash.home.TableHeader.ControlAction")}));
        validationFailed = true;
      }
      // make sure that the ControlAction is valid.
      String action = cForm.getControlAction();
      List<String> validActions = controlBoss.getActions(sessionId, appdefId);
      if (!validActions.contains(action)) {
        this.addActionError(getText("resource.common.control.error.ControlActionNotValid"));
        validationFailed = true;
      }
      if (!(cForm.getStartTime().equals("1"))) {
        cForm.setStartTime(ScheduleFormNG.START_ON_DATE);

        if (cForm.getStartTime().equals(ScheduleFormNG.START_ON_DATE)
            && cForm.getRecurInterval().equals(ScheduleFormNG.RECUR_WEEKLY)) {
          Integer tmpNumWeeks = null;
          try {
            tmpNumWeeks = new Integer(Integer.parseInt(cForm.getNumWeeks()));
          } catch (NumberFormatException nfe) {
            this.addFieldError(
                "numWeeks",
                getText(
                    "resource.autodiscovery.ScheduleTab.error.numWeeks",
                    new String[] {cForm.getNumWeeks()}));
            validationFailed = true;
          }
          if (null == cForm.getRecurrenceDay() || cForm.getRecurrenceDay().length == 0) {
            this.addFieldError(
                "recurrenceDay", getText("resource.autodiscovery.ScheduleTab.error.recurrenceDay"));
            validationFailed = true;
          }
        }
        if (cForm.getStartTime().equals(ScheduleFormNG.START_ON_DATE)
            && cForm.getRecurInterval().equals(ScheduleFormNG.RECUR_DAILY)) {
          Integer tmpNumDays = null;
          try {
            tmpNumDays = new Integer(Integer.parseInt(cForm.getNumDays()));
          } catch (NumberFormatException nfe) {
            this.addFieldError(
                "numDays",
                getText(
                    "resource.autodiscovery.ScheduleTab.error.numDays",
                    new String[] {cForm.getNumDays()}));
            validationFailed = true;
          }
        }
        if (cForm.getStartTime().equals(ScheduleFormNG.START_ON_DATE)
            && cForm.getRecurInterval().equals(ScheduleFormNG.RECUR_MONTHLY)) {
          Integer tmpNumMonths = null;
          try {
            tmpNumMonths = new Integer(Integer.parseInt(cForm.getNumMonths()));
          } catch (NumberFormatException nfe) {
            this.addFieldError(
                "numMonths",
                getText(
                    "resource.autodiscovery.ScheduleTab.error.numDays",
                    new String[] {cForm.getNumMonths()}));
            validationFailed = true;
          }
        }

        LocalDate localDate =
            new LocalDate(cForm.getEndYear(), cForm.getEndMonth() + 1, cForm.getEndDay());
        Date endDate = new Date();
        if (cForm.getRecurInterval().equals("recurNever")
            && (cForm.getEndTime().equals("1") || cForm.getEndTime().equals(null))) {
          endDate = null;
        } else {
          endDate = java.sql.Date.valueOf(localDate + "");
        }
        if ((!(cForm.getRecurInterval().equals(ScheduleFormNG.RECUR_NEVER))
            && (cForm.getStartDate() != null && !(cForm.getEndTime().equals("1"))))) {
          Date tmpStartDate = cForm.getStartDate();
          Date tmpEndDate = endDate;
          if (tmpStartDate.after(tmpEndDate)) {
            this.addFieldError(
                "startMonth", getText("resource.common.monitor.error.FromEarlierThanTo"));
            validationFailed = true;
          }
        }
        Date d = new Date();
        GregorianCalendar cal = new GregorianCalendar();
        cal.set(Calendar.YEAR, Calendar.getInstance().get(Calendar.YEAR));
        cal.set(Calendar.MONTH, Calendar.getInstance().get(Calendar.MONTH));
        cal.set(Calendar.DAY_OF_MONTH, Calendar.getInstance().get(Calendar.DAY_OF_MONTH));
        cal.set(Calendar.HOUR_OF_DAY, Calendar.getInstance().get(Calendar.HOUR_OF_DAY));
        cal.set(Calendar.MINUTE, Calendar.getInstance().get(Calendar.MINUTE));
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        d = cal.getTime();
        Date startDate = cForm.getStartDate();
        if ((startDate != null) && (d.after(startDate))) {
          this.addFieldError("startYear", getText("resource.common.control.error.ScheduleInvalid"));
          validationFailed = true;
        }
      } else {
        cForm.setStartTime(ScheduleFormNG.START_NOW);
      }
      request.setAttribute("recurrenceDay", cForm.getRecurrenceDay());
      if (validationFailed) {
        return INPUT;
      }
      if (cForm.getStartTime().equals(ScheduleFormNG.START_NOW)) {
        if (runBackendSave) {
          controlBoss.doAction(sessionId, appdefId, action, (String) null);
        }
      } else {

        // create the new action to schedule

        if (runBackendSave) {
          controlBoss.doAction(sessionId, appdefId, action, covertToScheduleValue());
        }
      }

      // set confirmation message
      if (runBackendSave) {
        addActionMessage(getText("resource.common.scheduled.Confirmation"));
      }
      internalRid = appdefId.getId().toString();
      internalType = String.valueOf(appdefId.getType());
      internalEid = internalType + ":" + internalRid;
      return SUCCESS;
    } catch (PluginNotFoundException pnfe) {
      log.trace("no plugin available", pnfe);
      this.addActionError(getText("resource.common.control.PluginNotFound"));
      return INPUT;
    } catch (PluginException cpe) {
      log.trace("control not enabled", cpe);
      this.addActionError(getText("resource.common.error.ControlNotEnabled"));
      return INPUT;
    } catch (PermissionException pe) {
      this.addActionError(getText("resource.common.control.error.NewPermission"));
      return INPUT;
    } catch (SchedulerException se) {
      this.addActionError(getText("resource.common.control.error.ScheduleInvalid"));
      return INPUT;
    }
  }