Java Code Examples for org.apache.struts.action.DynaActionForm#getStrings()

The following examples show how to use org.apache.struts.action.DynaActionForm#getStrings() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PackageSearchAction.java    From uyuni with GNU General Public License v2.0 4 votes vote down vote up
protected ActionForward doExecute(HttpServletRequest request, ActionMapping mapping,
                DynaActionForm form)
    throws MalformedURLException, XmlRpcFault, SearchServerIndexException {

    RequestContext ctx = new RequestContext(request);
    String searchString = form.getString(SEARCH_STR);
    String viewmode = form.getString(VIEW_MODE);
    Boolean fineGrained = (Boolean) form.get(FINE_GRAINED);
    String searchCriteria = form.getString(WHERE_CRITERIA);
    String[] selectedArches = null;
    Long filterChannelId = null;
    boolean relevantFlag = false;

    // Default to relevant channels if no search criteria was specified
    if (searchCriteria == null || searchCriteria.equals("")) {
        searchCriteria = RELEVANT;
    }

    // Handle the radio button selection for channel filtering
    if (searchCriteria.equals(RELEVANT)) {
        relevantFlag = true;
    }
    else if (searchCriteria.equals(ARCHITECTURE)) {
        /* The search call will function as being scoped to architectures if the arch
           list isn't null. In order to actually get radio-button-like functionality
           we can't rely on the arch list coming in from the form to be null; the
           user may have selected an arch but *not* the radio button for arch. If we
           push off retrieving the arches until we know we want to use them, we can
           get the desired functionality described by the UI.
          */
        selectedArches = form.getStrings(CHANNEL_ARCH);
    }
    else if (searchCriteria.equals(CHANNEL)) {
        String sChannelId = form.getString(CHANNEL_FILTER);
        filterChannelId = Long.parseLong(sChannelId);
    }

    List<Map<String, String>> searchOptions = buildSearchOptions();
    List<Map<String, String>> channelArches = buildChannelArches();

    // Load list of available channels to select as filter
    List<Map<String, Object>> allChannels =
            ChannelManager.allChannelsTree(ctx.getCurrentUser());

    request.setAttribute(SEARCH_STR, searchString);
    request.setAttribute(VIEW_MODE, viewmode);
    request.setAttribute(SEARCH_OPT, searchOptions);
    request.setAttribute(CHANNEL_ARCHES, channelArches);
    request.setAttribute(CHANNEL_ARCH, selectedArches);
    request.setAttribute(ALL_CHANNELS, allChannels);
    request.setAttribute(CHANNEL_FILTER,
                    form.getString(CHANNEL_FILTER));
    request.setAttribute(RELEVANT, relevantFlag ? "yes" : "no");
    request.setAttribute(FINE_GRAINED, fineGrained);

    // Default where to search criteria
    request.setAttribute(WHERE_CRITERIA, searchCriteria);

    if (!StringUtils.isBlank(searchString)) {
        List<PackageOverview> results =
                performSearch(ctx, searchString, viewmode, fineGrained, selectedArches,
                        filterChannelId, relevantFlag, searchCriteria);

        request.setAttribute(RequestContext.PAGE_LIST,
                results != null ? results : Collections.emptyList());
    }
    else {
        request.setAttribute(RequestContext.PAGE_LIST, Collections.emptyList());
    }
    return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
}
 
Example 2
Source File: KickstartSoftwareEditAction.java    From uyuni with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected ValidatorError processFormValues(HttpServletRequest request,
        DynaActionForm form,
        BaseKickstartCommand cmdIn) {

    KickstartData ksdata = cmdIn.getKickstartData();
    boolean wasRhel5OrLess = ksdata.isRHEL5OrLess();
    RequestContext ctx = new RequestContext(request);
    KickstartTreeUpdateType updateType = null;
    KickstartableTree tree = null;
    Long channelId = (Long) form.get(CHANNEL);
    String url = form.getString(URL);
    Org org = ctx.getCurrentUser().getOrg();

    if (form.get(USE_NEWEST_KSTREE_PARAM) != null) {
        updateType = KickstartTreeUpdateType.ALL;
        tree = KickstartFactory.getNewestTree(updateType, channelId, org);
    }
    else if (form.get(USE_NEWEST_RH_KSTREE_PARAM) != null) {
        updateType = KickstartTreeUpdateType.RED_HAT;
        tree = KickstartFactory.getNewestTree(updateType, channelId, org);
    }
    else {
        updateType = KickstartTreeUpdateType.NONE;
        tree = KickstartFactory.lookupKickstartTreeByIdAndOrg(
                (Long) form.get(TREE), org);
    }

    if (tree == null) {
        return new ValidatorError("kickstart.softwaredit.tree.required");
    }

    Distro distro = CobblerProfileCommand.getCobblerDistroForVirtType(tree,
            ksdata.getKickstartDefaults().getVirtualizationType(),
            ctx.getCurrentUser());
    if (distro == null) {
        return new ValidatorError("kickstart.cobbler.profile.invalidtreeforvirt");
    }

    KickstartEditCommand cmd = (KickstartEditCommand) cmdIn;
    ValidatorError ve = cmd.updateKickstartableTree(channelId, org.getId(),
            tree.getId(), url);

    if (ve == null) {
        String [] repos = form.getStrings(SELECTED_REPOS);
        cmd.updateRepos(repos);
    }

    ksdata.setRealUpdateType(updateType);

    // need to reset auth field
    if (wasRhel5OrLess != cmd.getKickstartData().isRHEL5OrLess()) {
        KickstartCommand auth = cmd.getKickstartData().getCommand("auth");
        if (auth != null) {
            auth.setArguments(cmd.getKickstartData().defaultAuthArgs());
        }
    }

    CobblerProfileEditCommand cpec = new CobblerProfileEditCommand(ksdata,
            ctx.getCurrentUser());
    cpec.store();

    // Process the selected child channels
    String[] childchannelIds = request.getParameterValues(CHILD_CHANNELS);
    cmd.updateChildChannels(childchannelIds);

    if (ve != null) {
        return ve;
    }
    return null;
}
 
Example 3
Source File: ExtAuthSgDetailAction.java    From uyuni with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public ActionForward execute(ActionMapping mapping, ActionForm formIn,
        HttpServletRequest request, HttpServletResponse response) {
    RequestContext ctx = new RequestContext(request);
    DynaActionForm form = (DynaActionForm)formIn;

    User user = ctx.getCurrentUser();
    Org org = user.getOrg();

    Long gid = ctx.getParamAsLong("gid");
    OrgUserExtGroup extGroup = null;
    if (gid != null) {
        ctx.copyParamToAttributes("gid");
        extGroup = UserGroupFactory.lookupOrgExtGroupByIdAndOrg(gid, org);
        request.setAttribute("group", extGroup);
    }

    if (ctx.isSubmitted()) {
        ValidatorResult result = RhnValidationHelper.validate(this.getClass(),
                makeValidationMap(form), null,
                VALIDATION_XSD);
        if (!result.isEmpty()) {
            getStrutsDelegate().saveMessages(request, result);
            setupSystemGroups(request, user, extGroup, form);
            return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
        }

        String label = (String) form.get("extGroupLabel");
        String[] selectedSgs = form.getStrings("selected_sgs");

        Set<ServerGroup> sgs = new HashSet<ServerGroup>();
        for (String sg : selectedSgs) {
            sgs.add(ServerGroupFactory.lookupByNameAndOrg(sg, org));
        }

        if (extGroup == null) {
            extGroup = new OrgUserExtGroup(org);
        }

        if (!label.equals(extGroup.getLabel())) {
            if (UserGroupFactory.lookupOrgExtGroupByLabelAndOrg(label, org) != null) {
                createErrorMessage(request, "extgrouplabel.already.exists", label);
                setupSystemGroups(request, user, extGroup, form);
                return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
            }
            extGroup.setLabel(label);
        }
        extGroup.setServerGroups(sgs);
        UserGroupFactory.save(extGroup);


        if (gid == null) {
            createSuccessMessage(request, "message.extgroup.created", label);
        }
        else {
            createSuccessMessage(request, "message.extgroup.updated", label);
        }
        return mapping.findForward("success");
    }

    // not submitted
    setupSystemGroups(request, user, extGroup, form);
    return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
}
 
Example 4
Source File: PackageSearchAction.java    From spacewalk with GNU General Public License v2.0 4 votes vote down vote up
protected ActionForward doExecute(HttpServletRequest request, ActionMapping mapping,
                DynaActionForm form)
    throws MalformedURLException, XmlRpcFault, SearchServerIndexException {

    RequestContext ctx = new RequestContext(request);
    String searchString = form.getString(SEARCH_STR);
    String viewmode = form.getString(VIEW_MODE);
    Boolean fineGrained = (Boolean) form.get(FINE_GRAINED);
    String searchCriteria = form.getString(WHERE_CRITERIA);
    String[] selectedArches = null;
    Long filterChannelId = null;
    boolean relevantFlag = false;

    // Default to relevant channels if no search criteria was specified
    if (searchCriteria == null || searchCriteria.equals("")) {
        searchCriteria = RELEVANT;
    }

    // Handle the radio button selection for channel filtering
    if (searchCriteria.equals(RELEVANT)) {
        relevantFlag = true;
    }
    else if (searchCriteria.equals(ARCHITECTURE)) {
        /* The search call will function as being scoped to architectures if the arch
           list isn't null. In order to actually get radio-button-like functionality
           we can't rely on the arch list coming in from the form to be null; the
           user may have selected an arch but *not* the radio button for arch. If we
           push off retrieving the arches until we know we want to use them, we can
           get the desired functionality described by the UI.
          */
        selectedArches = form.getStrings(CHANNEL_ARCH);
    }
    else if (searchCriteria.equals(CHANNEL)) {
        String sChannelId = form.getString(CHANNEL_FILTER);
        filterChannelId = Long.parseLong(sChannelId);
    }

    List<Map<String, String>> searchOptions = buildSearchOptions();
    List<Map<String, String>> channelArches = buildChannelArches();

    // Load list of available channels to select as filter
    List<Map<String, Object>> allChannels =
            ChannelManager.allChannelsTree(ctx.getCurrentUser());

    request.setAttribute(SEARCH_STR, searchString);
    request.setAttribute(VIEW_MODE, viewmode);
    request.setAttribute(SEARCH_OPT, searchOptions);
    request.setAttribute(CHANNEL_ARCHES, channelArches);
    request.setAttribute(CHANNEL_ARCH, selectedArches);
    request.setAttribute(ALL_CHANNELS, allChannels);
    request.setAttribute(CHANNEL_FILTER,
                    form.getString(CHANNEL_FILTER));
    request.setAttribute(RELEVANT, relevantFlag ? "yes" : "no");
    request.setAttribute(FINE_GRAINED, fineGrained);

    // Default where to search criteria
    request.setAttribute(WHERE_CRITERIA, searchCriteria);

    if (!StringUtils.isBlank(searchString)) {
        List<PackageOverview> results =
                performSearch(ctx, searchString, viewmode, fineGrained, selectedArches,
                        filterChannelId, relevantFlag, searchCriteria);

        request.setAttribute(RequestContext.PAGE_LIST,
                results != null ? results : Collections.emptyList());
    }
    else {
        request.setAttribute(RequestContext.PAGE_LIST, Collections.emptyList());
    }
    return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
}
 
Example 5
Source File: KickstartSoftwareEditAction.java    From spacewalk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
protected ValidatorError processFormValues(HttpServletRequest request,
        DynaActionForm form,
        BaseKickstartCommand cmdIn) {

    KickstartData ksdata = cmdIn.getKickstartData();
    boolean wasRhel5OrLess = ksdata.isRHEL5OrLess();
    RequestContext ctx = new RequestContext(request);
    KickstartTreeUpdateType updateType = null;
    KickstartableTree tree = null;
    Long channelId = (Long) form.get(CHANNEL);
    String url = form.getString(URL);
    Org org = ctx.getCurrentUser().getOrg();

    if (form.get(USE_NEWEST_KSTREE_PARAM) != null) {
        updateType = KickstartTreeUpdateType.ALL;
        tree = KickstartFactory.getNewestTree(updateType, channelId, org);
    }
    else if (form.get(USE_NEWEST_RH_KSTREE_PARAM) != null) {
        updateType = KickstartTreeUpdateType.RED_HAT;
        tree = KickstartFactory.getNewestTree(updateType, channelId, org);
    }
    else {
        updateType = KickstartTreeUpdateType.NONE;
        tree = KickstartFactory.lookupKickstartTreeByIdAndOrg(
                (Long) form.get(TREE), org);
    }

    if (tree == null) {
        return new ValidatorError("kickstart.softwaredit.tree.required");
    }

    Distro distro = CobblerProfileCommand.getCobblerDistroForVirtType(tree,
            ksdata.getKickstartDefaults().getVirtualizationType(),
            ctx.getCurrentUser());
    if (distro == null) {
        return new ValidatorError("kickstart.cobbler.profile.invalidtreeforvirt");
    }

    KickstartEditCommand cmd = (KickstartEditCommand) cmdIn;
    ValidatorError ve = cmd.updateKickstartableTree(channelId, org.getId(),
            tree.getId(), url);

    if (ve == null) {
        String [] repos = form.getStrings(SELECTED_REPOS);
        cmd.updateRepos(repos);
    }

    ksdata.setRealUpdateType(updateType);

    // need to reset auth field
    if (wasRhel5OrLess != cmd.getKickstartData().isRHEL5OrLess()) {
        KickstartCommand auth = cmd.getKickstartData().getCommand("auth");
        if (auth != null) {
            auth.setArguments(cmd.getKickstartData().defaultAuthArgs());
        }
    }

    CobblerProfileEditCommand cpec = new CobblerProfileEditCommand(ksdata,
            ctx.getCurrentUser());
    cpec.store();

    // Process the selected child channels
    String[] childchannelIds = request.getParameterValues(CHILD_CHANNELS);
    cmd.updateChildChannels(childchannelIds);

    if (ve != null) {
        return ve;
    }
    return null;
}
 
Example 6
Source File: ExtAuthSgDetailAction.java    From spacewalk with GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
@Override
public ActionForward execute(ActionMapping mapping, ActionForm formIn,
        HttpServletRequest request, HttpServletResponse response) {
    RequestContext ctx = new RequestContext(request);
    DynaActionForm form = (DynaActionForm)formIn;

    User user = ctx.getCurrentUser();
    Org org = user.getOrg();

    Long gid = ctx.getParamAsLong("gid");
    OrgUserExtGroup extGroup = null;
    if (gid != null) {
        ctx.copyParamToAttributes("gid");
        extGroup = UserGroupFactory.lookupOrgExtGroupByIdAndOrg(gid, org);
        request.setAttribute("group", extGroup);
    }

    if (ctx.isSubmitted()) {
        ValidatorResult result = RhnValidationHelper.validate(this.getClass(),
                makeValidationMap(form), null,
                VALIDATION_XSD);
        if (!result.isEmpty()) {
            getStrutsDelegate().saveMessages(request, result);
            setupSystemGroups(request, user, extGroup, form);
            return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
        }

        String label = (String) form.get("extGroupLabel");
        String[] selectedSgs = form.getStrings("selected_sgs");

        Set <ServerGroup>sgs = new HashSet<ServerGroup>();
        for (String sg : selectedSgs) {
            sgs.add(ServerGroupFactory.lookupByNameAndOrg(sg, org));
        }

        if (extGroup == null) {
            extGroup = new OrgUserExtGroup(org);
        }

        if (!label.equals(extGroup.getLabel())) {
            if (UserGroupFactory.lookupOrgExtGroupByLabelAndOrg(label, org) != null) {
                createErrorMessage(request, "extgrouplabel.already.exists", label);
                setupSystemGroups(request, user, extGroup, form);
                return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
            }
            extGroup.setLabel(label);
        }
        extGroup.setServerGroups(sgs);
        UserGroupFactory.save(extGroup);


        if (gid == null) {
            createSuccessMessage(request, "message.extgroup.created", label);
        }
        else {
            createSuccessMessage(request, "message.extgroup.updated", label);
        }
        return mapping.findForward("success");
    }

    // not submitted
    setupSystemGroups(request, user, extGroup, form);
    return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
}