org.apache.struts.action.ActionErrors Java Examples

The following examples show how to use org.apache.struts.action.ActionErrors. 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: RecipientForm.java    From openemm with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
    * Validate the properties that have been set from this HTTP request,
    * and return an <code>ActionErrors</code> object that encapsulates any
    * validation errors that have been found.  If no errors are found, return
    * <code>null</code> or an <code>ActionErrors</code> object with no
    * recorded error messages.
    *
    * @param mapping The mapping used to select this instance
    * @param request The servlet request we are processing
    * @return errors
    */
   @Override
public ActionErrors formSpecificValidate(ActionMapping mapping, HttpServletRequest request) {
       errors = new ActionErrors();

       if (request.getParameter("trgt_clear") != null) {
           setRecipientID(0);
           clearRules();

           if (action != RecipientAction.ACTION_LIST ){ // reset filter fields only if there is no future running
           	setUser_status(0);
           	setUser_type("");
           	setTargetID(0);
              	setListID(0);
           }
       }

       return errors;
   }
 
Example #2
Source File: MissingPackageAction.java    From uyuni with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Callback for the Subscribe to channels button, it attempts to subscribe
 * to the channels containing the Packages.
 * @param mapping ActionMapping
 * @param formIn ActionForm
 * @param request HttpServletRequest
 * @param response HttpServletResponse
 * @return ActionForward
 */
public ActionForward subscribeToChannels(ActionMapping mapping,
        ActionForm formIn,
        HttpServletRequest request,
        HttpServletResponse response) {
    RequestContext requestContext = new RequestContext(request);
    Long sid = requestContext.getRequiredParam("sid");
    Set<String> pkgIdCombos = SessionSetHelper.lookupAndBind(request,
            getDecl(requestContext, sid));
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("sid", sid);

    try {
        syncToVictim(requestContext, sid, pkgIdCombos,
                ProfileManager.OPTION_SUBSCRIBE);
    }
    catch (TaskomaticApiException e) {
        log.error("Could not schedule package synchronization:");
        log.error(e);
        ActionErrors errors = new ActionErrors();
        getStrutsDelegate().addError(errors, "taskscheduler.down");
        getStrutsDelegate().saveMessages(request, errors);
    }
    return getStrutsDelegate().forwardParams(
            mapping.findForward("showprofile"), params);
}
 
Example #3
Source File: ManageLessonDA.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
public ActionForward prepareCreate(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    DynaActionForm manageLessonForm = (DynaActionForm) form;

    InfoShift infoShift = (InfoShift) request.getAttribute(PresentationConstants.SHIFT);
    Shift shift = FenixFramework.getDomainObject(infoShift.getExternalId());
    GenericPair<YearMonthDay, YearMonthDay> maxLessonsPeriod = shift.getExecutionCourse().getMaxLessonsPeriod();

    if (maxLessonsPeriod != null) {
        request.setAttribute("executionDegreeLessonsStartDate", maxLessonsPeriod.getLeft().toString("dd/MM/yyyy"));
        request.setAttribute("executionDegreeLessonsEndDate", maxLessonsPeriod.getRight().toString("dd/MM/yyyy"));
        manageLessonForm.set("newBeginDate", maxLessonsPeriod.getLeft().toString("dd/MM/yyyy"));
        manageLessonForm.set("newEndDate", maxLessonsPeriod.getRight().toString("dd/MM/yyyy"));
        manageLessonForm.set("createLessonInstances", Boolean.TRUE);

    } else {
        ActionErrors actionErrors = new ActionErrors();
        actionErrors.add("error.executionDegree.empty.lessonsPeriod", new ActionError(
                "error.executionDegree.empty.lessonsPeriod"));
        saveErrors(request, actionErrors);
        return mapping.findForward("EditShift");
    }

    return mapping.findForward("ShowLessonForm");
}
 
Example #4
Source File: SsmScheduleXccdfConfirmAction.java    From uyuni with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public ActionForward execute(ActionMapping mapping,
        ActionForm formIn,
        HttpServletRequest request,
        HttpServletResponse response) {
    StrutsDelegate strutsDelegate = getStrutsDelegate();
    DynaActionForm form = (DynaActionForm) formIn;

    if (isSubmitted(form)) {
        ActionErrors errors = RhnValidationHelper.validateDynaActionForm(this, form);
        if (errors.isEmpty()) {
            return processForm(mapping, request, form);
        }
    }

    return strutsDelegate.forwardParams(
            mapping.findForward(ERROR),
            request.getParameterMap());
}
 
Example #5
Source File: EditGroupAction.java    From spacewalk with GNU General Public License v2.0 6 votes vote down vote up
private Long create(DynaActionForm form, ActionErrors errors,
        RequestContext ctx) {

    validate(form, errors, ctx);

    if (errors.isEmpty()) {
        ServerGroupManager manager = ServerGroupManager.getInstance();
        ManagedServerGroup sg = manager.create(ctx.getCurrentUser(),
                form.getString("name"), form.getString("description"));

        if (form.get("is_ssm") != null && (Boolean)form.get("is_ssm")) {
            List<SystemOverview> systems = SystemManager.inSet(ctx.getCurrentUser(),
                    RhnSetDecl.SYSTEMS.getLabel());
            List<Server> hibernateServers = new ArrayList<Server>();
            for (SystemOverview system : systems) {
                hibernateServers.add(ServerFactory.lookupById(system.getId()));
            }
            manager.addServers(sg, hibernateServers, ctx.getCurrentUser());
        }

        return sg.getId();
    }

    return null;
}
 
Example #6
Source File: ExamSolverForm.java    From unitime with Apache License 2.0 6 votes vote down vote up
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
       ActionErrors errors = new ActionErrors();

       if(iSetting==null || iSetting.intValue()<0)
           errors.add("setting", new ActionMessage("errors.lookup.config.required", ""));
       
       for (Iterator i=iParamValues.entrySet().iterator();i.hasNext();) {
       	Map.Entry entry = (Map.Entry)i.next();
        	Long parm = (Long)entry.getKey();
       	String val = (String)entry.getValue();
       	if (val==null || val.trim().length()==0)
       		errors.add("parameterValue["+parm+"]", new ActionMessage("errors.required", ""));
       }
       
       return errors;
}
 
Example #7
Source File: EnableSubmitAction.java    From spacewalk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Enables the selected set of systems for configuration management
 * @param mapping struts ActionMapping
 * @param formIn struts ActionForm
 * @param request HttpServletRequest
 * @param response HttpServletResponse
 * @return forward to the summary page.
 */
public ActionForward enable(ActionMapping mapping,
        ActionForm formIn,
        HttpServletRequest request,
        HttpServletResponse response) {
    User user = new RequestContext(request).getCurrentUser();
    RhnSetDecl set = RhnSetDecl.SYSTEMS;

    //get the earliest schedule for package install actions.
    DynaActionForm form = (DynaActionForm) formIn;
    Date earliest = getStrutsDelegate().readDatePicker(form, "date",
            DatePicker.YEAR_RANGE_POSITIVE);
    try {
        ConfigurationManager.getInstance().enableSystems(set, user, earliest);
    }
    catch (MultipleChannelsWithPackageException e) {
        ValidatorError verrors = new ValidatorError("config.multiple.channels");
        ActionErrors errors = RhnValidationHelper.validatorErrorToActionErrors(verrors);
        getStrutsDelegate().saveMessages(request, errors);
        return mapping.findForward("default");
    }

    return mapping.findForward("summary");
}
 
Example #8
Source File: SsmScheduleXccdfAction.java    From spacewalk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public ActionForward execute(ActionMapping mapping,
        ActionForm formIn,
        HttpServletRequest request,
        HttpServletResponse response) {
    DynaActionForm form = (DynaActionForm) formIn;

    if (isSubmitted(form)) {
        ActionErrors errors = RhnValidationHelper.validateDynaActionForm(this, form);
        if (errors.isEmpty()) {
            return getStrutsDelegate().forwardParams(mapping.findForward("submit"),
                    request.getParameterMap());
        }
        getStrutsDelegate().saveMessages(request, errors);
    }
    setupDatePicker(request, form);
    setupListHelper(request);
    return getStrutsDelegate().forwardParams(
        mapping.findForward(RhnHelper.DEFAULT_FORWARD),
        request.getParameterMap());
}
 
Example #9
Source File: ExecutionDegreesManagementDispatchAction.java    From fenixedu-academic with GNU Lesser General Public License v3.0 6 votes vote down vote up
public ActionForward deleteExecutionDegrees(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws FenixActionException {
    DynaActionForm deleteForm = (DynaActionForm) form;
    List<String> executionDegreesIds = Arrays.asList((String[]) deleteForm.get("internalIds"));

    try {

        List<String> undeletedExecutionDegreesYears = DeleteExecutionDegreesOfDegreeCurricularPlan.run(executionDegreesIds);

        if (!undeletedExecutionDegreesYears.isEmpty()) {
            ActionErrors actionErrors = new ActionErrors();
            for (String undeletedExecutionDegreesYear : undeletedExecutionDegreesYears) {
                // Create an ACTION_ERROR for each EXECUTION_DEGREE
                ActionError error =
                        new ActionError("errors.invalid.delete.not.empty.execution.degree", undeletedExecutionDegreesYear);
                actionErrors.add("errors.invalid.delete.not.empty.execution.degree", error);
            }
            saveErrors(request, actionErrors);
        }

        return readExecutionDegrees(mapping, form, request, response);

    } catch (FenixServiceException fenixServiceException) {
        throw new FenixActionException(fenixServiceException.getMessage());
    }
}
 
Example #10
Source File: SettingsForm.java    From unitime with Apache License 2.0 6 votes vote down vote up
/** 
 * Method validate
 * @param mapping
 * @param request
 * @return ActionErrors
 */
public ActionErrors validate(
    ActionMapping mapping,
    HttpServletRequest request) {

    ActionErrors errors = new ActionErrors();
    
    if(key==null || key.trim().length()==0)
        errors.add("key", new ActionMessage("errors.required", ""));
    else {
        Settings setting = Settings.getSetting(key);
        if(op.equals("Save") && setting!=null && setting.getDefaultValue().toString().trim().length()>0)
            errors.add("key", new ActionMessage("errors.exists", key));
    }
    
    if(defaultValue==null || defaultValue.trim().length()==0)
        errors.add("defaultValue", new ActionMessage("errors.required", ""));
    
    if(allowedValues==null || allowedValues.trim().length()==0)
        errors.add("allowedValues", new ActionMessage("errors.required", ""));
    
    if(description==null || description.trim().length()==0)
        errors.add("description", new ActionMessage("errors.required", ""));
    
    return errors;
}
 
Example #11
Source File: SystemsController.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
protected void createErrorMessage(HttpServletRequest req, String beanKey,
                                  String param) {
    ActionErrors errs = new ActionErrors();
    String escParam = StringEscapeUtils.escapeHtml4(param);
    errs.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(beanKey, escParam));
    StrutsDelegate.getInstance().saveMessages(req, errs);
}
 
Example #12
Source File: RoomFeatureListForm.java    From unitime with Apache License 2.0 5 votes vote down vote up
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
    ActionErrors errors = new ActionErrors();
    
    if(deptCode==null || deptCode.equalsIgnoreCase("")) {
    	errors.add("deptCode", 
                new ActionMessage("errors.required", "Department") );
    }
   
    return errors;
}
 
Example #13
Source File: EditGroupAction.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
private void edit(DynaActionForm form, ActionErrors errors,
        RequestContext ctx) {

    validate(form, errors, ctx);

    if (errors.isEmpty()) {
        ManagedServerGroup sg = ctx.lookupAndBindServerGroup();
        sg.setName(form.getString("name"));
        sg.setDescription(form.getString("description"));
        ServerGroupFactory.save(sg);
    }
}
 
Example #14
Source File: RhnValidationHelper.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Converts an array of Strings into a set of ActionError messages
 *
 * @param errors Array of ValidatorErrors you want to convert
 * @return ActionErrors object with set of messages
 */
public static ActionErrors validatorErrorToActionErrors(
        ValidatorError... errors) {
    ActionErrors messages = new ActionErrors();

    for (int i = 0; i < errors.length; i++) {
        messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
                errors[i].getKey(), errors[i].getValues()));
    }
    return messages;
}
 
Example #15
Source File: CreateCustomKeyAction.java    From spacewalk with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
public ActionForward execute(ActionMapping mapping,
        ActionForm formIn,
        HttpServletRequest request,
        HttpServletResponse response) {

    RequestContext requestContext = new RequestContext(request);
    User user =  requestContext.getCurrentUser();

    if (requestContext.isSubmitted()) {
        String label = request.getParameter(LABEL_PARAM);
        String description = request.getParameter(DESC_PARAM);

        ActionErrors errors = validateLabelAndDescription(label, description, user);
        if (!errors.isEmpty()) {
            request.setAttribute("old_label", label);
            request.setAttribute("old_description", description);
            addErrors(request, errors);
            return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
        }

        CustomDataKey key = new CustomDataKey();
        key.setLabel(label);
        key.setDescription(description);
        key.setCreator(user);
        key.setOrg(user.getOrg());
        key.setLastModifier(user);
        ServerFactory.saveCustomKey(key);
        bindMessage(requestContext, "system.customkey.addsuccess");
        return mapping.findForward("created");
    }

    return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
}
 
Example #16
Source File: ChameleonForm.java    From unitime with Apache License 2.0 5 votes vote down vote up
/** 
 * Method validate
 * @param mapping
 * @param request
 * @return ActionErrors
 */
public ActionErrors validate(
    ActionMapping mapping,
    HttpServletRequest request) {

    ActionErrors errors = new ActionErrors();        
    return errors;        
    
}
 
Example #17
Source File: RhnValidationHelper.java    From spacewalk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Converts an array of Strings into a set of ActionError messages
 *
 * @param errors Array of ValidatorErrors you want to convert
 * @return ActionErrors object with set of messages
 */
public static ActionErrors validatorErrorToActionErrors(
        ValidatorError... errors) {
    ActionErrors messages = new ActionErrors();

    for (int i = 0; i < errors.length; i++) {
        messages.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
                errors[i].getKey(), errors[i].getValues()));
    }
    return messages;
}
 
Example #18
Source File: ManagerSettingsForm.java    From unitime with Apache License 2.0 5 votes vote down vote up
/** 
 * Method validate
 * @param mapping
 * @param request
 * @return ActionErrors
 */
public ActionErrors validate(
    ActionMapping mapping,
    HttpServletRequest request) {

    ActionErrors errors = new ActionErrors();
    
    if(value==null || value.trim().length()==0)
        errors.add("value", new ActionMessage("errors.required", ""));
    
    return errors;
}
 
Example #19
Source File: EditChannelAction.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
private Channel makePrivate(DynaActionForm form,
                            ActionErrors errors,
                            RequestContext ctx) {

    User user = ctx.getCurrentUser();
    Long cid = ctx.getParamAsLong("cid");
    Channel channel = ChannelFactory.lookupById(cid);
    unsubscribeOrgsFromChannel(user, channel, Channel.PRIVATE);
    return edit(form, errors, ctx);
}
 
Example #20
Source File: StrutsDelegate.java    From spacewalk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add a message to an existing set of ActionErrors. Useful to add stuff to
 * an already populated ActionErrors instance
 * @param errors to add too
 * @param msgKey to add
 * @param params key params
 */
// TODO Write unit tests for addError(String, ActionErrors)
public void addError(ActionErrors errors, String msgKey, Object...params) {
    ActionMessages msg = new ActionMessages();
    msg.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(msgKey,
            params));
    errors.add(msg);
}
 
Example #21
Source File: EditChannelAction.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
private Long clone(DynaActionForm form, ActionErrors errors, RequestContext ctx) {
    User user = ctx.getCurrentUser();
    Channel original = ChannelManager.lookupByIdAndUser((Long) form.get(ORIGINAL_ID),
            user);

    boolean originalState = true;
    if (form.getString(CLONE_TYPE).equals("current")) {
        originalState = false;
    }

    CloneChannelCommand command = new CloneChannelCommand(originalState ? ORIGINAL_STATE : CURRENT_STATE, original);
    return createChannelHelper(command, form, errors, ctx);
}
 
Example #22
Source File: ScheduleXccdfAction.java    From spacewalk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public ActionForward execute(ActionMapping mapping, ActionForm formIn,
        HttpServletRequest request,
        HttpServletResponse response) {
    RequestContext context = new RequestContext(request);
    ActionForward forward = null;
    DynaActionForm form = (DynaActionForm) formIn;
    StrutsDelegate strutsDelegate = getStrutsDelegate();

    if (isSubmitted(form)) {
        Long sid = context.getRequiredParam("sid");
        User user = context.getCurrentUser();
        Server server = SystemManager.lookupByIdAndUser(sid, user);
        ActionErrors errors = RhnValidationHelper.validateDynaActionForm(this, form);

        if (errors.isEmpty()) {
            ActionMessages msgs = processForm(user, server, form);
            strutsDelegate.saveMessages(request, msgs);
            Map params = makeParamMap(request);
            params.put("sid", sid);
            forward = strutsDelegate.forwardParams(mapping.findForward("submit"),
                    params);
        }
        else {
            strutsDelegate.saveMessages(request, errors);
            forwardValuesOnError(form, strutsDelegate, request);
            forward = mapping.findForward("error");
        }
    }
    else {
        setupDefaultValues(request, form);
        forward = strutsDelegate.forwardParams(
                mapping.findForward(RhnHelper.DEFAULT_FORWARD),
                request.getParameterMap());
    }
    setupScapEnablementInfo(context);
    return forward;
}
 
Example #23
Source File: FileListConfirmSubmitAction.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
private ActionForward createErrorMessage(HttpServletRequest request,
        ActionMapping mapping, ActionForm formIn, Long sid, String message) {
    ActionErrors errors = new ActionErrors();
    errors.add(ActionMessages.GLOBAL_MESSAGE,
            new ActionMessage(message));
    addErrors(request, errors);
    return getStrutsDelegate().forwardParam(
            mapping.findForward(RhnHelper.DEFAULT_FORWARD),
            "sid", sid.toString());
}
 
Example #24
Source File: ActivationKeyCloneAction.java    From spacewalk with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public final ActionForward execute(ActionMapping mapping,
        ActionForm formIn, HttpServletRequest request,
        HttpServletResponse response) {

    DynaActionForm form = (DynaActionForm) formIn;
    RequestContext ctx = new RequestContext(request);
    StrutsDelegate strutsDelegate = getStrutsDelegate();

    if (isSubmitted(form)) {
        ActionErrors errors = RhnValidationHelper.validateDynaActionForm(
                this, form);
        if (!errors.isEmpty()) {
            strutsDelegate.saveMessages(request, errors);
        }
        else {
            String cloneDescription = form.getString("label");
            String sdesc = (String) request.getSession().getAttribute(
                    "sdesc");
            if (StringUtils.isBlank(cloneDescription)) {
                cloneDescription = "clone-" + sdesc;
            }
            String sak = (String) request.getSession().getAttribute("sak");
            ActivationKeyCloneCommand cak = new ActivationKeyCloneCommand(
                    ctx.getCurrentUser(), sak, cloneDescription);

            createSuccessMessage(request, "activation-key.java.cloned",
                    sdesc);
            return mapping.findForward("success");
        }
    }

    ActivationKey key = ctx.lookupAndBindActivationKey();
    request.setAttribute("stoken", key.getToken());
    request.getSession().setAttribute("sak", key.getKey());
    request.getSession().setAttribute("sdesc", key.getNote());
    return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
}
 
Example #25
Source File: JavaSecurityManagementForm.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * This method is used to check for completeness of the form as well as verification of the desired password
 */
public ActionErrors validateGenerateClientKeystore(ActionMapping mapping, HttpServletRequest request) {
    ActionErrors errors = new ActionErrors();
    // check that all data is filled in
    if (StringUtils.isBlank(getAlias())) {
        errors.add("property", new ActionMessage("Alias must have a valid value.",false));
    }
    if (StringUtils.isBlank(getPassword()) || StringUtils.isBlank(getPasswordVerify()) ) {
        errors.add("property", new ActionMessage("Password must have a valid value in both fields.",false));
    }
    if (errors.isEmpty()) {
        // if password and passwordVerify are not equal error out
        if (!StringUtils.equals(getPassword(), getPasswordVerify())) {
            errors.add("property", new ActionMessage("Passwords do not match.",false));
        }
    }
    if (errors.isEmpty()) {
        try {
            if (KSBServiceLocator.getJavaSecurityManagementService().isAliasInKeystore(getAlias())) {
                errors.add("property", new ActionMessage("Alias '" + getAlias() + "' already exists in keystore.",false));
            }
        } catch (KeyStoreException e) {
            errors.add("property", new ActionMessage("Could not check keystore file for alias '" + getAlias(),false));
        }
    }
    return errors;
}
 
Example #26
Source File: HibernateQueryTestForm.java    From unitime with Apache License 2.0 5 votes vote down vote up
/** 
 * Method validate
 * @param mapping
 * @param request
 * @return ActionErrors
 */
public ActionErrors validate(
    ActionMapping mapping,
    HttpServletRequest request) {

    ActionErrors errors = new ActionErrors();
    if(query==null || query.trim().length()==0)
        errors.add("query", new ActionMessage("errors.generic", "Invalid value for query" ));
    
    return errors;
}
 
Example #27
Source File: EditRoomGroupForm.java    From unitime with Apache License 2.0 5 votes vote down vote up
/** 
 * Method validate
 * @param mapping
 * @param request
 * @return ActionErrors
 */
public ActionErrors validate(
	ActionMapping mapping,
	HttpServletRequest request) {
	
       ActionErrors errors = new ActionErrors();
       
       return errors;
}
 
Example #28
Source File: CobblerAction.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
/** {@inheritDoc}
 * @param mapping the ActionMapping
 * @param formIn the ActionForm
 * @param request the HttpServletRequest
 * @param response the HttpServletResponse
 * @return the ActionForward
 */
@Override
public ActionForward execute(ActionMapping mapping,
                             ActionForm formIn,
                             HttpServletRequest request,
                             HttpServletResponse response) {
    RequestContext ctx = new RequestContext(request);
    ActionErrors errors = new ActionErrors();

    if (ctx.isSubmitted()) {
        ValidatorError ve;
        try {
            ve = new CobblerSyncCommand(ctx.getCurrentUser()).store();
        }
        catch (Exception ex) {
            this.getStrutsDelegate().addError(errors,
                                              "cobbler.jsp.xmlrpc.fail",
                                              ex.getLocalizedMessage());
            this.getStrutsDelegate().saveMessages(request, errors);
            return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
        }

        if (ve == null) {
            addMessage(request, "cobbler.jsp.synced");
        }
        else {
            getStrutsDelegate().addError(errors, ve.getKey(), ve.getValues());
            getStrutsDelegate().saveMessages(request, errors);
        }
    }

    return mapping.findForward(RhnHelper.DEFAULT_FORWARD);
}
 
Example #29
Source File: GeneralConfigAction.java    From uyuni with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This function checks if the user entered a valid e-mail, hostname,
 * and if the password and password confirmation fields match. Any
 * errors found are returned.
 * @param GeneralConfingForm to validate
 * @return errors that were found in the submitted form
 */
private ActionErrors validateForm(DynaActionForm form) {
    ActionErrors errors = new ActionErrors();

    // Check if proxy is given as host:port
    String proxy = (String) form.get(
            translateFormPropertyName("server.satellite.http_proxy"));
    HostPortValidator validator = HostPortValidator.getInstance();
    if (!(proxy.equals("") || validator.isValid(proxy))) {
        errors.add(ActionMessages.GLOBAL_MESSAGE,
                new ActionMessage("error.proxy_invalid"));
    }

    String password = (String) form.get(
               translateFormPropertyName("server.satellite.http_proxy_password"));
    String confirmationPassword = (String) form.get(
       translateFormPropertyName("server.satellite.http_proxy_password_confirm"));

    if (!password.equals(confirmationPassword)) {
        form.set(
                translateFormPropertyName("server.satellite.http_proxy_password"),
                "");

        form.set(
                translateFormPropertyName
                ("server.satellite.http_proxy_password_confirm"),
                "");
        errors.add(ActionMessages.GLOBAL_MESSAGE,
                new ActionMessage("error.password_mismatch"));
    }

    return errors;
}
 
Example #30
Source File: EditGroupAction.java    From spacewalk with GNU General Public License v2.0 5 votes vote down vote up
private void validate(DynaActionForm form, ActionErrors errors,
        RequestContext ctx) {

    String name = form.getString("name");
    String desc = form.getString("description");
    Long sgid = ctx.getParamAsLong("sgid");

    // Check if both values are entered
    if (StringUtils.isEmpty(name) || StringUtils.isEmpty(desc)) {
        errors.add(ActionMessages.GLOBAL_MESSAGE,
                new ActionMessage("systemgroup.create.requirements"));
    }

    // Check if sg already exists
    ManagedServerGroup newGroup = ServerGroupFactory.lookupByNameAndOrg(name,
            ctx.getCurrentUser().getOrg());

    // Ugly condition for two error cases:
    //     creating page + group name exists
    //     editing page + group name exists except our group
    if (((sgid == null) && (newGroup != null)) ||
            (sgid != null) && (newGroup != null) && (!sgid.equals(newGroup.getId()))) {
        errors.add(ActionMessages.GLOBAL_MESSAGE,
                new ActionMessage("systemgroup.create.alreadyexists"));
    }

}