Exemplo n.º 1
0
  private Long create(DynaActionForm form, ActionErrors errors, RequestContext ctx) {

    User loggedInUser = ctx.getCurrentUser();
    Long cid = null;

    // handle submission
    // why can't I just pass in a dictionary? sigh, there are
    // times where python would make this SOOOO much easier.
    CreateChannelCommand ccc = new CreateChannelCommand();
    ccc.setArchLabel((String) form.get("arch"));
    ccc.setChecksumLabel((String) form.get("checksum"));
    ccc.setLabel((String) form.get("label"));
    ccc.setName((String) form.get("name"));
    ccc.setSummary((String) form.get("summary"));
    ccc.setDescription(StringUtil.nullIfEmpty((String) form.get("description")));
    ccc.setParentLabel(null);
    ccc.setUser(loggedInUser);
    ccc.setGpgKeyId(StringUtil.nullIfEmpty((String) form.get("gpg_key_id")));
    ccc.setGpgKeyUrl(StringUtil.nullIfEmpty((String) form.get("gpg_key_url")));
    ccc.setGpgKeyFp(StringUtil.nullIfEmpty((String) form.get("gpg_key_fingerprint")));
    ccc.setMaintainerName(StringUtil.nullIfEmpty((String) form.get("maintainer_name")));
    ccc.setMaintainerEmail(StringUtil.nullIfEmpty((String) form.get("maintainer_email")));
    ccc.setMaintainerPhone(StringUtil.nullIfEmpty((String) form.get("maintainer_phone")));
    ccc.setSupportPolicy(StringUtil.nullIfEmpty((String) form.get("support_policy")));
    ccc.setAccess((String) form.get("org_sharing"));

    String parent = (String) form.get("parent");
    if (parent == null || parent.equals("")) {
      ccc.setParentId(null);
    } else {
      ccc.setParentId(Long.valueOf(parent));
    }

    try {
      Channel c = ccc.create();
      String sharing = (String) form.get("per_user_subscriptions");
      c.setGloballySubscribable(
          (sharing != null) && ("all".equals(sharing)), loggedInUser.getOrg());
      c = (Channel) ChannelFactory.reload(c);
      cid = c.getId();
    } catch (InvalidGPGFingerprintException borg) {
      errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("edit.channel.invalidgpgfp"));
    } catch (InvalidGPGKeyException dukat) {
      errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("edit.channel.invalidgpgkey"));
    } catch (InvalidGPGUrlException khan) {
      errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("edit.channel.invalidgpgurl"));
    } catch (InvalidChannelNameException ferengi) {
      handleChannelNameException(errors, ferengi);
    } catch (InvalidChannelLabelException q) {
      handleChannelLabelException(errors, q);
    } catch (IllegalArgumentException iae) {
      errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(iae.getMessage()));
    }

    return cid;
  }
Exemplo n.º 2
0
  /**
   * Will the system hardware clock use UTC
   *
   * @return Boolean Are we using UTC?
   */
  public Boolean isUsingUtc() {
    KickstartCommand tzCommand = this.getCommand("timezone");

    if (tzCommand == null || tzCommand.getArguments() == null) {
      return Boolean.FALSE;
    }

    List<String> tokens = StringUtil.stringToList(tzCommand.getArguments());

    Iterator<String> iter = tokens.iterator();

    while (iter.hasNext()) {
      String token = iter.next();

      if (token.equals("--utc")) {
        return Boolean.TRUE;
      }
    }

    return Boolean.FALSE;
  }
Exemplo n.º 3
0
  /**
   * Get the timezone - just the timezone, not the --utc or other args
   *
   * @return String: The timezone (like "Asia/Qatar")
   */
  public String getTimezone() {
    KickstartCommand tzCommand = this.getCommand("timezone");

    // my @args = grep { not /--/ } split / /, $tzCommand;
    // return @args ? $args[0] : "";

    if (tzCommand == null || tzCommand.getArguments() == null) {
      return "";
    }

    List<String> tokens = StringUtil.stringToList(tzCommand.getArguments());

    Iterator<String> iter = tokens.iterator();

    while (iter.hasNext()) {
      String token = iter.next();

      if (!token.startsWith("--")) {
        return token;
      }
    }

    return null;
  }
  /**
   * Executes the appropriate PackageAction
   *
   * @param mapping ActionMapping
   * @param formIn ActionForm
   * @param request ServletRequest
   * @param response ServletResponse
   * @return The ActionForward to go to next.
   */
  public ActionForward executePackageAction(
      ActionMapping mapping,
      ActionForm formIn,
      HttpServletRequest request,
      HttpServletResponse response) {

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

    Long sid = requestContext.getRequiredParam("sid");
    User user = requestContext.getCurrentUser();
    // updateList(newactions, user.getId());

    List<Map<String, Long>> data = PackageListItem.toKeyMaps(getDataResult(request));
    int numPackages = data.size();

    // Archive the actions
    Server server = SystemManager.lookupByIdAndUser(sid, user);

    // The earliest time to perform the action.
    DynaActionForm dynaActionForm = (DynaActionForm) formIn;
    Date earliest =
        getStrutsDelegate().readDatePicker(dynaActionForm, "date", DatePicker.YEAR_RANGE_POSITIVE);

    // The action chain to append this action to, if any
    ActionChain actionChain = ActionChainHelper.readActionChain(dynaActionForm, user);

    PackageAction pa = schedulePackageAction(formIn, requestContext, data, earliest, actionChain);

    // Remove the actions from the users set
    SessionSetHelper.obliterate(request, getDecl(sid));

    ActionMessages msgs = new ActionMessages();

    if (actionChain == null) {
      /**
       * If there was only one action archived, display the "action" archived message, else display
       * the "actions" archived message.
       */
      if (numPackages == 1) {
        msgs.add(
            ActionMessages.GLOBAL_MESSAGE,
            new ActionMessage(
                getMessageKeyForOne(),
                LocalizationService.getInstance().formatNumber(numPackages),
                pa.getId().toString(),
                sid.toString(),
                StringUtil.htmlifyText(server.getName())));
      } else {
        msgs.add(
            ActionMessages.GLOBAL_MESSAGE,
            new ActionMessage(
                getMessageKeyForMany(),
                LocalizationService.getInstance().formatNumber(numPackages),
                pa.getId().toString(),
                sid.toString(),
                StringUtil.htmlifyText(server.getName())));
      }
    } else {
      msgs.add(
          ActionMessages.GLOBAL_MESSAGE,
          new ActionMessage(
              "message.addedtoactionchain",
              actionChain.getId(),
              StringUtil.htmlifyText(actionChain.getLabel())));
    }

    strutsDelegate.saveMessages(request, msgs);
    Map params = new HashMap();
    processParamMap(formIn, request, params);
    return strutsDelegate.forwardParams(mapping.findForward(RhnHelper.CONFIRM_FORWARD), params);
  }
Exemplo n.º 5
0
 private void prepareAttributeUpdate(String attrName, UpdateUserCommand cmd, String value) {
   String methodName = StringUtil.beanify("set_" + attrName);
   Object[] params = {value};
   MethodUtil.callMethod(cmd, methodName, params);
 }