/** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext requestContext = new RequestContext(request);
    StrutsDelegate strutsDelegate = getStrutsDelegate();

    User user = requestContext.getCurrentUser();

    Errata errata = requestContext.lookupErratum();
    DataResult dr = ErrataManager.systemsAffected(user, errata.getId(), null);

    RhnSet set = RhnSetDecl.SYSTEMS_AFFECTED.get(user);
    RhnListSetHelper helper = new RhnListSetHelper(request);

    // if its not submitted
    // ==> this is the first visit to this page
    // clear the 'dirty set'
    if (!requestContext.isSubmitted()) {
      set.clear();
      RhnSetManager.store(set);
    }

    if (request.getParameter(DISPATCH) != null) {
      helper.updateSet(set, LIST_NAME);
      if (!set.isEmpty()) {
        // Send to AffectedSystemsAction to handle submit
        return strutsDelegate.forwardParams(
            mapping.findForward("confirm"), request.getParameterMap());
      }
      RhnHelper.handleEmptySelection(request);
    }

    if (ListTagHelper.getListAction(LIST_NAME, request) != null) {
      helper.execute(set, LIST_NAME, dr);
    }

    // if I have a previous set selections populate data using it
    if (!set.isEmpty()) {
      helper.syncSelections(set, dr);
      ListTagHelper.setSelectedAmount(LIST_NAME, set.size(), request);
    }

    TagHelper.bindElaboratorTo("systemAffectedList", dr.getElaborator(), request);
    ListTagHelper.bindSetDeclTo(LIST_NAME, RhnSetDecl.SYSTEMS_AFFECTED, request);

    request.setAttribute(RequestContext.PAGE_LIST, dr);
    request.setAttribute("set", set);
    request.setAttribute("errata", errata);
    request.setAttribute(
        ListTagHelper.PARENT_URL,
        request.getRequestURI() + "?" + RequestContext.ERRATA_ID + "=" + errata.getId());

    return strutsDelegate.forwardParams(
        mapping.findForward(RhnHelper.DEFAULT_FORWARD), request.getParameterMap());
  }
  protected boolean validateFirstSelections(DynaActionForm form, RequestContext ctx) {
    String cobblerId = ListTagHelper.getRadioSelection(ListHelper.LIST, ctx.getRequest());
    if (StringUtils.isBlank(cobblerId)) {
      cobblerId = ctx.getParam(RequestContext.COBBLER_ID, true);
    }

    boolean retval = false;
    form.set(RequestContext.COBBLER_ID, cobblerId);
    ctx.getRequest().setAttribute(RequestContext.COBBLER_ID, cobblerId);
    if (form.get("scheduleAsap") != null) {
      retval = true;
    } else if (form.get(RequestContext.COBBLER_ID) != null) {
      return true;
    }
    return retval;
  }
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext requestContext = new RequestContext(request);
    User user = requestContext.getCurrentUser();
    Long cid = Long.parseLong(request.getParameter(CID));
    Channel currentChan = ChannelFactory.lookupByIdAndUser(cid, user);
    Channel selectedChannel = null;

    PublishErrataHelper.checkPermissions(user, cid);

    request.setAttribute(CID, cid);
    request.setAttribute("user", user);
    request.setAttribute("channel_name", currentChan.getName());
    request.setAttribute(ListTagHelper.PARENT_URL, request.getRequestURI());

    List<SelectableChannelVersion> versionList =
        SelectableChannelVersion.getCurrentChannelVersionList();
    List<SelectableChannel> channelList = null;
    request.setAttribute(VERSION_LIST, versionList);

    String selectedVersionStr = null;
    String selectedChannelStr = null;
    Boolean checked = true;

    // Set initail strings
    selectedChannelStr = request.getParameter(SELECTED_CHANNEL_OLD);
    selectedVersionStr = request.getParameter(SELECTED_VERSION_OLD);
    if (selectedVersionStr == null) {
      selectedVersionStr = versionList.get(0).getVersion();
    }

    // If the channel submit button was clicked
    if (requestContext.wasDispatched(CHANNEL_SUBMIT)) {
      selectedChannelStr = request.getParameter(SELECTED_CHANNEL);
      // selectedChannelStr might be null
    }
    // if the version submit button was clicked
    else if (requestContext.wasDispatched(VERSION_SUBMIT)) {
      selectedVersionStr = request.getParameter(SELECTED_VERSION);
      // selectedChannelStr might be null
      selectedChannelStr = null;
    }

    if (!requestContext.isSubmitted()) {
      // If this is a clone, go ahead and pre-select the original Channel
      Channel original = ChannelFactory.lookupOriginalChannel(currentChan);

      while (original != null) {

        selectedChannel = original;
        selectedChannelStr = selectedChannel.getId().toString();
        String tmp = findVersionFromChannel(selectedChannel);
        if (tmp == null) {
          // if we haven't found channel version, let's try to check its parent
          if (!selectedChannel.isBaseChannel()) {
            tmp = findVersionFromChannel(selectedChannel.getParentChannel());
          }
        }
        if (tmp != null) {
          selectedVersionStr = tmp;
          break;
        }
        original = ChannelFactory.lookupOriginalChannel(original);
      }
    }

    if (selectedVersionStr != null) {
      // set selected version based off version selected
      for (SelectableChannelVersion chanVer : versionList) {
        if (chanVer.getVersion().equals(selectedVersionStr)) {
          chanVer.setSelected(true);
          request.setAttribute(SELECTED_VERSION_NAME, chanVer.getName());
          break;
        }
      }

      List<Channel> channelSet = findChannelsByVersion(user, selectedVersionStr);
      channelList = new ArrayList();
      if (channelSet != null) {
        sortChannelsAndChildify(channelSet, channelList, user, selectedChannelStr);
        request.setAttribute(CHANNEL_LIST, channelList);
      }
    }

    if (requestContext.isSubmitted() && request.getParameter(CHECKED) == null) {
      checked = false;
    }

    request.setAttribute(CHECKED, checked);
    request.setAttribute(SELECTED_CHANNEL, selectedChannelStr);
    request.setAttribute(SELECTED_VERSION, selectedVersionStr);

    if (requestContext.wasDispatched(SUBMITTED)) {
      Map params = new HashMap();
      params.put(CID, request.getParameter(CID));
      params.put(SELECTED_CHANNEL, selectedChannelStr);
      params.put(CHECKED, request.getParameter(CHECKED));
      return getStrutsDelegate().forwardParams(mapping.findForward("submit"), params);
    }

    // If we clicked on the channel selection, clear the set
    if (requestContext.wasDispatched(CHANNEL_SUBMIT)
        || requestContext.wasDispatched(VERSION_SUBMIT)
        || !requestContext.isSubmitted()) {
      RhnSet eset = getSetDecl(currentChan).get(user);
      eset.clear();
      RhnSetManager.store(eset);
    }

    if (selectedChannelStr != null) {
      selectedChannel = ChannelFactory.lookupByIdAndUser(Long.parseLong(selectedChannelStr), user);
    }

    RhnListSetHelper helper = new RhnListSetHelper(request);
    RhnSet set = getSetDecl(currentChan).get(user);

    DataResult dr = getData(request, selectedChannel, currentChan, channelList, checked, user);

    request.setAttribute(RequestContext.PAGE_LIST, dr);

    if (ListTagHelper.getListAction("errata", request) != null) {
      helper.execute(set, "errata", dr);
    }
    if (!set.isEmpty()) {
      helper.syncSelections(set, dr);
      ListTagHelper.setSelectedAmount("errata", set.size(), request);
    }

    TagHelper.bindElaboratorTo("errata", dr.getElaborator(), request);
    ListTagHelper.bindSetDeclTo("errata", getSetDecl(currentChan), request);

    return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
  }
  /**
   * The first step in the wizard
   *
   * @param mapping ActionMapping for struts
   * @param form DynaActionForm representing the form
   * @param ctx RequestContext request context
   * @param response HttpServletResponse response object
   * @param step WizardStep what step are we on?
   * @return ActionForward struts action forward
   * @throws Exception if something goes amiss
   */
  public ActionForward runFirst(
      ActionMapping mapping,
      DynaActionForm form,
      RequestContext ctx,
      HttpServletResponse response,
      WizardStep step)
      throws Exception {
    log.debug("runFirst");
    Long sid = (Long) form.get(RequestContext.SID);
    User user = ctx.getCurrentUser();

    KickstartScheduleCommand cmd = getKickstartScheduleCommand(sid, user);

    Server system = SystemManager.lookupByIdAndUser(sid, user);
    if (system.isVirtualGuest()
        && VirtualInstanceFactory.getInstance()
            .getParaVirtType()
            .equals(system.getVirtualInstance().getType())) {
      ctx.getRequest().setAttribute(IS_VIRTUAL_GUEST, Boolean.TRUE.toString());

      ctx.getRequest().setAttribute(VIRT_HOST_IS_REGISTERED, Boolean.FALSE.toString());
      if (system.getVirtualInstance().getHostSystem() != null) {
        Long hostSid = system.getVirtualInstance().getHostSystem().getId();
        ctx.getRequest().setAttribute(VIRT_HOST_IS_REGISTERED, Boolean.TRUE.toString());
        ctx.getRequest().setAttribute(HOST_SID, hostSid);
      }
    } else {
      ctx.getRequest().setAttribute(IS_VIRTUAL_GUEST, Boolean.FALSE.toString());
    }

    addRequestAttributes(ctx, cmd, form);
    checkForKickstart(form, cmd, ctx);
    setupProxyInfo(ctx);
    if (StringUtils.isBlank(form.getString(PROXY_HOST))) {
      form.set(PROXY_HOST, "");
    }
    // create and prepopulate the date picker.
    getStrutsDelegate()
        .prepopulateDatePicker(ctx.getRequest(), form, "date", DatePicker.YEAR_RANGE_POSITIVE);

    SdcHelper.ssmCheck(ctx.getRequest(), system.getId(), user);
    Map params = new HashMap<String, String>();
    params.put(RequestContext.SID, sid);
    ListHelper helper = new ListHelper(new Profiles(), ctx.getRequest(), params);
    helper.execute();
    if (!StringUtils.isBlank(form.getString(RequestContext.COBBLER_ID))) {
      ListTagHelper.selectRadioValue(
          ListHelper.LIST, form.getString(RequestContext.COBBLER_ID), ctx.getRequest());
    } else if (system.getCobblerId() != null) {
      // if nothing is selected by the user yet, use the cobbler
      //  system record to pre-select something.
      SystemRecord rec =
          SystemRecord.lookupById(
              CobblerXMLRPCHelper.getConnection(ConfigDefaults.get().getCobblerAutomatedUser()),
              system.getCobblerId());
      if (rec != null) {
        ListTagHelper.selectRadioValue(ListHelper.LIST, rec.getProfile().getId(), ctx.getRequest());
      }
    }

    ActionForward retval = mapping.findForward("first");
    return retval;
  }
Exemplo n.º 5
0
  /** {@inheritDoc} */
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

    RequestContext context = new RequestContext(request);
    User user = context.getCurrentUser();
    Long cid = Long.parseLong(request.getParameter(CID));
    Channel channel = ChannelFactory.lookupByIdAndUser(cid, user);

    PublishErrataHelper.checkPermissions(user, cid);

    request.setAttribute(CID, cid);
    request.setAttribute("user", user);
    request.setAttribute("channel_name", channel.getName());
    request.setAttribute(ListTagHelper.PARENT_URL, request.getRequestURI());
    request.setAttribute("emptyKey", EMPTY_KEY);

    List<SelectableChannel> channelList = null;

    RhnSet set = getDecl(channel).get(user);
    // if its not submitted
    // ==> this is the first visit to this page
    // clear the 'dirty set'
    if (!context.isSubmitted()) {
      set.clear();
      RhnSetManager.store(set);
    }

    Channel original = ChannelFactory.lookupOriginalChannel(channel);

    RhnListSetHelper helper = new RhnListSetHelper(request);
    if (request.getParameter(DISPATCH) != null) {
      // if its one of the Dispatch actions handle it..
      helper.updateSet(set, LIST_NAME);
      if (!set.isEmpty()) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put(CID, request.getParameter(CID));
        params.put(ConfirmErrataAction.SELECTED_CHANNEL, original.getId());
        return getStrutsDelegate().forwardParams(mapping.findForward("submit"), params);
      } else {
        RhnHelper.handleEmptySelection(request);
      }
    }

    // get the errata list
    DataResult<ErrataOverview> dataSet =
        ErrataFactory.relevantToOneChannelButNotAnother(original.getId(), channel.getId());

    if (ListTagHelper.getListAction(LIST_NAME, request) != null) {
      helper.execute(set, LIST_NAME, dataSet);
    }

    if (!set.isEmpty()) {
      helper.syncSelections(set, dataSet);
      ListTagHelper.setSelectedAmount(LIST_NAME, set.size(), request);
    }

    request.setAttribute(RequestContext.PAGE_LIST, dataSet);
    ListTagHelper.bindSetDeclTo(LIST_NAME, getDecl(channel), request);
    TagHelper.bindElaboratorTo(LIST_NAME, dataSet.getElaborator(), request);

    return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
  }