예제 #1
0
  public void processAction(
      ActionMapping mapping,
      ActionForm form,
      PortletConfig config,
      ActionRequest req,
      ActionResponse res)
      throws Exception {

    String cmd = req.getParameter(Constants.CMD);
    String referer = req.getParameter("referer");

    if ((referer != null) && (referer.length() != 0)) {
      referer = URLDecoder.decode(referer, "UTF-8");
    }

    // Load the structure in the request
    try {
      Logger.debug(this, "Calling Retrieve method");
      _loadStructure(form, req, res);
    } catch (Exception ae) {
      _handleException(ae, req);
      return;
    }

    HibernateUtil.startTransaction();
    boolean returnToList = false;
    /*
     * If we are updating the workflow message, copy the information from
     * the struts bean to the hbm inode and run the update action and return
     * to the list
     */
    if ((cmd != null) && cmd.equals(Constants.ADD)) {
      try {
        Logger.debug(this, "Calling Add/Edit Method");
        if (Validator.validate(req, form, mapping)) {

          if (UtilMethods.isSet(((StructureForm) form).getInode())) {
            returnToList = true;
          }

          _saveStructure(form, req, res);
        }

      } catch (Exception ae) {
        _handleException(ae, req);
        return;
      }

    }
    /*
     * If we are deleteing the structure, run the delete action and return
     * to the list
     *
     */
    else if ((cmd != null) && cmd.equals(Constants.DELETE)) {
      try {
        Logger.debug(this, "Calling Delete Method");
        _deleteStructure(form, req, res);
      } catch (Exception ae) {
        _handleException(ae, req);
        return;
      }
      _sendToReferral(req, res, referer);
      return;
    } else if ((cmd != null) && cmd.equals(WebKeys.Structure.SET_DEFAULT)) {
      try {
        _defaultStructure(form, req, res);
      } catch (Exception ae) {
        _handleException(ae, req);
        return;
      }
      _sendToReferral(req, res, referer);
      return;
    } else if ((cmd != null) && cmd.equals(com.dotmarketing.util.Constants.RESET)) {
      try {
        _resetIntervals(form, req, res);
      } catch (Exception ae) {
        _handleException(ae, req);
        return;
      }
      _sendToReferral(req, res, referer);
      return;
    }

    HibernateUtil.commitTransaction();
    _loadForm(form, req, res);
    if (returnToList) {
      if (!UtilMethods.isSet(referer)) {
        java.util.Map<String, String[]> params = new java.util.HashMap<String, String[]>();

        if (((StructureForm) form).getStructureType() == Structure.STRUCTURE_TYPE_FORM) {
          params.put("struts_action", new String[] {"/ext/formhandler/view_form"});
        } else {
          params.put("struts_action", new String[] {"/ext/structure/view_structure"});
        }

        referer =
            com.dotmarketing.util.PortletURLUtil.getActionURL(
                req, WindowState.MAXIMIZED.toString(), params);
      }
      _sendToReferral(req, res, referer);
    } else {
      setForward(req, "portlet.ext.structure.edit_structure");
    }
  }
  public void processAction(
      ActionMapping mapping,
      ActionForm form,
      PortletConfig config,
      ActionRequest req,
      ActionResponse res)
      throws Exception {

    String cmd = req.getParameter(Constants.CMD);
    Logger.debug(this, "Inside EditContentImporterJobAction cmd=" + cmd);

    // get the user
    User user = _getUser(req);

    CronScheduledTask scheduler = null;

    try {
      Logger.debug(this, "I'm retrieving the schedule");
      scheduler = _retrieveScheduler(req, res, config, form);
    } catch (Exception ae) {
      _handleException(ae, req);
    }

    /*
     *  if we are saving,
     *
     */
    if ((cmd != null) && cmd.equals(Constants.ADD)) {
      try {

        ContentImporterForm contentImporterForm = (ContentImporterForm) form;
        boolean hasErrors = false;

        if (!UtilMethods.isSet(contentImporterForm.getJobName())) {
          SessionMessages.add(req, "error", "message.Scheduler.invalidJobName");
          hasErrors = true;
        } else if (!contentImporterForm.isEditMode() && (scheduler != null)) {
          SessionMessages.add(req, "error", "message.Scheduler.jobAlreadyExists");
          hasErrors = true;
        }

        SimpleDateFormat sdf = new SimpleDateFormat(WebKeys.DateFormats.DOTSCHEDULER_DATE2);

        if (contentImporterForm.isHaveCronExpression()) {
          if (!UtilMethods.isSet(contentImporterForm.getCronExpression())) {
            SessionMessages.add(req, "error", "message.Scheduler.cronexpressionNeeded");
            hasErrors = true;
          }
        }
        Date endDate = null;
        if (contentImporterForm.isHaveEndDate()) {
          try {
            endDate = sdf.parse(contentImporterForm.getEndDate());
          } catch (Exception e) {
          }
        }

        if ((endDate != null) && !hasErrors) {
          Date startDate = null;
          if (contentImporterForm.isHaveStartDate()) {
            try {
              startDate = sdf.parse(contentImporterForm.getStartDate());
            } catch (Exception e) {
            }
          }

          if (startDate == null) {
            SessionMessages.add(req, "error", "message.Scheduler.startDateNeeded");
            hasErrors = true;
          } else if (endDate.before(startDate)) {
            SessionMessages.add(req, "error", "message.Scheduler.endDateBeforeStartDate");
            hasErrors = true;
          } else if (endDate.before(new Date())) {
            SessionMessages.add(req, "error", "message.Scheduler.endDateBeforeActualDate");
            hasErrors = true;
          }
        }

        if (!UtilMethods.isSet(contentImporterForm.getStructure())) {
          SessionMessages.add(req, "error", "message.content.importer.structure.required");
          hasErrors = true;
        }

        if (!UtilMethods.isSet(contentImporterForm.getFilePath())) {
          SessionMessages.add(req, "error", "message.content.importer.file.path.required");
          hasErrors = true;
        }

        if ((contentImporterForm.getFields() != null)
            && (0 < contentImporterForm.getFields().length)) {
          boolean containsIdentifier = false;
          for (String key : contentImporterForm.getFields()) {
            if (key.equals("0")) {
              containsIdentifier = true;
              break;
            }
          }
        }

        if (Validator.validate(req, form, mapping) && !hasErrors) {
          Logger.debug(this, "I'm Saving the scheduler");
          if (_saveScheduler(req, res, config, form, user)) {
            scheduler = _retrieveScheduler(req, res, config, form);

            if (scheduler != null) {
              _populateForm(form, scheduler);
              contentImporterForm.setMap(scheduler.getProperties());
            }

            String redirect = req.getParameter("referrer");
            if (UtilMethods.isSet(redirect)) {
              redirect = URLDecoder.decode(redirect, "UTF-8") + "&group=" + scheduler.getJobGroup();
              _sendToReferral(req, res, redirect);
              return;
            }
          } else {
            SessionMessages.clear(req);
            SessionMessages.add(req, "error", "message.Scheduler.invalidJobSettings");
            contentImporterForm.setMap(getSchedulerProperties(req, contentImporterForm));
            loadEveryDayForm(form, req);
          }
        } else {
          contentImporterForm.setMap(getSchedulerProperties(req, contentImporterForm));
          loadEveryDayForm(form, req);
        }
      } catch (Exception ae) {
        if (!ae.getMessage().equals(WebKeys.UNIQUE_SCHEDULER_EXCEPTION)) {
          _handleException(ae, req);
        }
      }
    }

    /*
     * deleting the list, return to listing page
     *
     */
    else if ((cmd != null) && cmd.equals(Constants.DELETE)) {
      try {
        Logger.debug(this, "I'm deleting the scheduler");
        _deleteScheduler(req, res, config, form, user);

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

      String redirect = req.getParameter("referrer");
      if (UtilMethods.isSet(redirect)) {
        redirect = URLDecoder.decode(redirect, "UTF-8");
        _sendToReferral(req, res, redirect);
        return;
      }
    }

    /*
     * Copy copy props from the db to the form bean
     *
     */
    if ((cmd != null) && cmd.equals(Constants.EDIT)) {
      if (scheduler != null) {
        _populateForm(form, scheduler);
        ContentImporterForm contentImporterForm = (ContentImporterForm) form;

        contentImporterForm.setEditMode(true);
        if (!UtilMethods.isSet(scheduler.getCronExpression())) {
          SessionMessages.add(req, "message", "message.Scheduler.jobExpired");
        }
      }
    }

    /*
     * return to edit page
     *
     */
    setForward(req, "portlet.ext.plugins.content.importer.struts.edit_job");
  }