RuleVO ruleVO = new RuleVO();
// name - required field
String ruleName = (String)ruleForm.get("name");
if (ruleName == null || ruleName.length() <= 0) {
allErrors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.general.requiredField", "Name"));
}else{
ruleVO.setRuleName(ruleName);
}
// description - required field
String description = (String)ruleForm.get("description");
if (description == null || description.length() <= 0) {
allErrors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.general.requiredField", "Description"));
}else{
ruleVO.setDescription(description);
}
// enabled - required field, but default to true if it's not given (shouldn't ever happen)
Boolean enabled = (Boolean)ruleForm.get("enabled");
if (enabled == null) {
enabled = new Boolean(true);
}else{
ruleVO.setEnabled(enabled.booleanValue());
}
// accountID - required field. But user can't fix the error if it's not supplied :-(
accountID = (Integer)ruleForm.get("accountID");
if (accountID == null || accountID.intValue() <= 0) {
allErrors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.general.requiredField", "Account ID"));
}else{
ruleVO.setAccountID(accountID.intValue());
}
// moveMessage - if true, then folderID is required. Default to false.
Boolean moveMessage = (Boolean)ruleForm.get("moveMessage");
if (moveMessage == null) {
moveMessage = new Boolean(false);
}else{
ruleVO.setMoveMessage(moveMessage.booleanValue());
}
// folderID = required only if moveMessage == true
Integer folderID = (Integer)ruleForm.get("folderID");
if (moveMessage.booleanValue() == true) {
if (folderID == null || folderID.intValue() <= 0) {
allErrors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.freeForm", "You must choose a destination when moving a message."));
}else{
ruleVO.setFolderID(folderID.intValue());
}
}
// markMessageRead - Default to false.
Boolean markMessageRead = (Boolean)ruleForm.get("markMessageRead");
if (markMessageRead == null) {
markMessageRead = new Boolean(false);
}else{
ruleVO.setMarkMessageRead(markMessageRead.booleanValue());
}
// deleteMessage - Default to false.
Boolean deleteMessage = (Boolean)ruleForm.get("deleteMessage");
if (deleteMessage == null) {
deleteMessage = new Boolean(false);
}else{
ruleVO.setDeleteMessage(deleteMessage.booleanValue());
}
// At least one of moveMessage OR deleteMessage OR markMessageRead MUST be selected
if (deleteMessage.booleanValue() == false && moveMessage.booleanValue() == false && markMessageRead.booleanValue() == false) {
allErrors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.freeForm", "You must select at least one Action."));
}
// search criteria - get the List of SearchCriteriaVO's from the form
// and check to see if there is at least ONE valid criteria. If not,
// throw an error.
List searchCriteria = Arrays.asList((SearchCriteriaVO[])ruleForm.get("searchCriteria"));
if (searchCriteria == null || searchCriteria.isEmpty()) {
allErrors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.freeForm", "You must supply at least one Criteria,"));
}else{
Iterator iter = searchCriteria.iterator();
int count = 1;
while (iter.hasNext()) {
SearchCriteriaVO criteria = (SearchCriteriaVO)iter.next();
if (criteria == null || criteria.getValue() == null || (criteria.getValue()).length() <= 0) {
allErrors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("error.freeForm", "The Criteria field cannot be blank. (line " + count + ")"));
}else{
RuleCriteriaVO ruleCriteriaVO = new RuleCriteriaVO();
ruleCriteriaVO.setOrderID(count);
ruleCriteriaVO.setExpressionType(criteria.getExpressionType());