@Test public void testValidateSubGroupParent2() { try { GeneralCommand cmd = new GeneralCommand(); Errors errors = new BindException(cmd, "GeneralCommand"); cmd.setEditMode(true); cmd.setName("TestName"); cmd.setFromDate(new Date()); cmd.setSubGroupType("Sub-Group"); cmd.setSubGroupSeparator(" > "); cmd.setType("Sub-Group"); cmd.setAction(GeneralCommand.ACTION_ADD_PARENT); testInstance.validate(cmd, errors); assertEquals("Expecting 0 errors", 0, errors.getErrorCount()); } catch (Exception e) { String message = e.getClass().toString() + " - " + e.getMessage(); log.debug(message); fail(message); } }
public void validate(Object comm, Errors errors) { GeneralCommand command = (GeneralCommand) comm; if(command.isEditMode()) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "required", getObjectArrayForLabel(GeneralCommand.PARAM_NAME), "Name is a required field"); if(command.getName() != null) { ValidatorUtil.validateValueNotContained(errors, command.getName(), command.getSubGroupSeparator(), "string.contains", getObjectArrayForLabelAndValue(GeneralCommand.PARAM_NAME, command.getSubGroupSeparator()), "'"+command.getSubGroupSeparator()+"' cannot be a sub-string of Name"); } if(command.getSubGroupType().equals(command.getType()) && !GeneralCommand.ACTION_ADD_PARENT.equals(command.getAction())) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "parentOid", "required", getObjectArrayForLabel(GeneralCommand.PARAM_PARENT_OID), "Parent Group is a required field"); } ValidatorUtil.validateStringMaxLength(errors, command.getName(), GeneralCommand.CNST_MAX_LEN_NAME, "string.maxlength", getObjectArrayForLabelAndInt(GeneralCommand.PARAM_NAME, GeneralCommand.CNST_MAX_LEN_NAME), "Name is too long."); ValidatorUtil.validateStringMaxLength(errors, command.getDescription(), GeneralCommand.CNST_MAX_LEN_DESC, "string.maxlength", getObjectArrayForLabelAndInt(GeneralCommand.PARAM_DESCRIPTION, GeneralCommand.CNST_MAX_LEN_DESC), "Description is too long."); ValidatorUtil.validateStringMaxLength(errors, command.getOwnershipMetaData(), GeneralCommand.CNST_MAX_LEN_OWNER_INFO, "string.maxlength", getObjectArrayForLabelAndInt(GeneralCommand.PARAM_OWNER_INFO, GeneralCommand.CNST_MAX_LEN_OWNER_INFO), "Owner info is too long."); ValidatorUtil.validateStringMaxLength(errors, command.getType(), TargetGroup.MAX_TYPE_LENGTH, "string.maxlength", getObjectArrayForLabelAndInt(GeneralCommand.PARAM_TYPE, TargetGroup.MAX_TYPE_LENGTH), "Group Type is too long."); if (!errors.hasErrors()) { if (command.getFromDate() != null && command.getToDate() != null) { ValidatorUtil.validateStartBeforeEndTime(errors, command.getFromDate(), command.getToDate(), "time.range", new Object[] {"To date", "From date"}, "To date is before from date"); } } } }
GeneralValidator extends AbstractBaseValidator { public void validate(Object comm, Errors errors) { GeneralCommand command = (GeneralCommand) comm; if(command.isEditMode()) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "required", getObjectArrayForLabel(GeneralCommand.PARAM_NAME), "Name is a required field"); if(command.getName() != null) { ValidatorUtil.validateValueNotContained(errors, command.getName(), command.getSubGroupSeparator(), "string.contains", getObjectArrayForLabelAndValue(GeneralCommand.PARAM_NAME, command.getSubGroupSeparator()), "'"+command.getSubGroupSeparator()+"' cannot be a sub-string of Name"); } if(command.getSubGroupType().equals(command.getType()) && !GeneralCommand.ACTION_ADD_PARENT.equals(command.getAction())) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "parentOid", "required", getObjectArrayForLabel(GeneralCommand.PARAM_PARENT_OID), "Parent Group is a required field"); } ValidatorUtil.validateStringMaxLength(errors, command.getName(), GeneralCommand.CNST_MAX_LEN_NAME, "string.maxlength", getObjectArrayForLabelAndInt(GeneralCommand.PARAM_NAME, GeneralCommand.CNST_MAX_LEN_NAME), "Name is too long."); ValidatorUtil.validateStringMaxLength(errors, command.getDescription(), GeneralCommand.CNST_MAX_LEN_DESC, "string.maxlength", getObjectArrayForLabelAndInt(GeneralCommand.PARAM_DESCRIPTION, GeneralCommand.CNST_MAX_LEN_DESC), "Description is too long."); ValidatorUtil.validateStringMaxLength(errors, command.getOwnershipMetaData(), GeneralCommand.CNST_MAX_LEN_OWNER_INFO, "string.maxlength", getObjectArrayForLabelAndInt(GeneralCommand.PARAM_OWNER_INFO, GeneralCommand.CNST_MAX_LEN_OWNER_INFO), "Owner info is too long."); ValidatorUtil.validateStringMaxLength(errors, command.getType(), TargetGroup.MAX_TYPE_LENGTH, "string.maxlength", getObjectArrayForLabelAndInt(GeneralCommand.PARAM_TYPE, TargetGroup.MAX_TYPE_LENGTH), "Group Type is too long."); if (!errors.hasErrors()) { if (command.getFromDate() != null && command.getToDate() != null) { ValidatorUtil.validateStartBeforeEndTime(errors, command.getFromDate(), command.getToDate(), "time.range", new Object[] {"To date", "From date"}, "To date is before from date"); } } } } }
GeneralValidator extends AbstractBaseValidator { public void validate(Object comm, Errors errors) { GeneralCommand command = (GeneralCommand) comm; if(command.isEditMode()) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "required", getObjectArrayForLabel(GeneralCommand.PARAM_NAME), "Name is a required field"); if(command.getName() != null) { ValidatorUtil.validateValueNotContained(errors, command.getName(), command.getSubGroupSeparator(), "string.contains", getObjectArrayForLabelAndValue(GeneralCommand.PARAM_NAME, command.getSubGroupSeparator()), "'"+command.getSubGroupSeparator()+"' cannot be a sub-string of Name"); } if(command.getSubGroupType().equals(command.getType()) && !GeneralCommand.ACTION_ADD_PARENT.equals(command.getAction())) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "parentOid", "required", getObjectArrayForLabel(GeneralCommand.PARAM_PARENT_OID), "Parent Group is a required field"); } ValidatorUtil.validateStringMaxLength(errors, command.getName(), GeneralCommand.CNST_MAX_LEN_NAME, "string.maxlength", getObjectArrayForLabelAndInt(GeneralCommand.PARAM_NAME, GeneralCommand.CNST_MAX_LEN_NAME), "Name is too long."); ValidatorUtil.validateStringMaxLength(errors, command.getDescription(), GeneralCommand.CNST_MAX_LEN_DESC, "string.maxlength", getObjectArrayForLabelAndInt(GeneralCommand.PARAM_DESCRIPTION, GeneralCommand.CNST_MAX_LEN_DESC), "Description is too long."); ValidatorUtil.validateStringMaxLength(errors, command.getOwnershipMetaData(), GeneralCommand.CNST_MAX_LEN_OWNER_INFO, "string.maxlength", getObjectArrayForLabelAndInt(GeneralCommand.PARAM_OWNER_INFO, GeneralCommand.CNST_MAX_LEN_OWNER_INFO), "Owner info is too long."); ValidatorUtil.validateStringMaxLength(errors, command.getType(), TargetGroup.MAX_TYPE_LENGTH, "string.maxlength", getObjectArrayForLabelAndInt(GeneralCommand.PARAM_TYPE, TargetGroup.MAX_TYPE_LENGTH), "Group Type is too long."); if (!errors.hasErrors()) { if (command.getFromDate() != null && command.getToDate() != null) { ValidatorUtil.validateStartBeforeEndTime(errors, command.getFromDate(), command.getToDate(), "time.range", new Object[] {"To date", "From date"}, "To date is before from date"); } } } }  }
GeneralValidator extends AbstractBaseValidator { public void validate(Object comm, Errors errors) { GeneralCommand command = (GeneralCommand) comm; if(command.isEditMode()) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "required", getObjectArrayForLabel(GeneralCommand.PARAM_NAME), "Name is a required field"); if(command.getName() != null) { ValidatorUtil.validateValueNotContained(errors, command.getName(), command.getSubGroupSeparator(), "string.contains", getObjectArrayForLabelAndValue(GeneralCommand.PARAM_NAME, command.getSubGroupSeparator()), "'"+command.getSubGroupSeparator()+"' cannot be a sub-string of Name"); } if(command.getSubGroupType().equals(command.getType()) && !GeneralCommand.ACTION_ADD_PARENT.equals(command.getAction())) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "parentOid", "required", getObjectArrayForLabel(GeneralCommand.PARAM_PARENT_OID), "Parent Group is a required field"); } ValidatorUtil.validateStringMaxLength(errors, command.getName(), GeneralCommand.CNST_MAX_LEN_NAME, "string.maxlength", getObjectArrayForLabelAndInt(GeneralCommand.PARAM_NAME, GeneralCommand.CNST_MAX_LEN_NAME), "Name is too long."); ValidatorUtil.validateStringMaxLength(errors, command.getDescription(), GeneralCommand.CNST_MAX_LEN_DESC, "string.maxlength", getObjectArrayForLabelAndInt(GeneralCommand.PARAM_DESCRIPTION, GeneralCommand.CNST_MAX_LEN_DESC), "Description is too long."); ValidatorUtil.validateStringMaxLength(errors, command.getOwnershipMetaData(), GeneralCommand.CNST_MAX_LEN_OWNER_INFO, "string.maxlength", getObjectArrayForLabelAndInt(GeneralCommand.PARAM_OWNER_INFO, GeneralCommand.CNST_MAX_LEN_OWNER_INFO), "Owner info is too long."); ValidatorUtil.validateStringMaxLength(errors, command.getType(), TargetGroup.MAX_TYPE_LENGTH, "string.maxlength", getObjectArrayForLabelAndInt(GeneralCommand.PARAM_TYPE, TargetGroup.MAX_TYPE_LENGTH), "Group Type is too long."); if (!errors.hasErrors()) { if (command.getFromDate() != null && command.getToDate() != null) { ValidatorUtil.validateStartBeforeEndTime(errors, command.getFromDate(), command.getToDate(), "time.range", new Object[] {"To date", "From date"}, "To date is before from date"); } } } }  boolean supports(Class clazz); void validate(Object comm, Errors errors); }
GeneralValidator extends AbstractBaseValidator { public void validate(Object comm, Errors errors) { GeneralCommand command = (GeneralCommand) comm; if(command.isEditMode()) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "required", getObjectArrayForLabel(GeneralCommand.PARAM_NAME), "Name is a required field"); if(command.getName() != null) { ValidatorUtil.validateValueNotContained(errors, command.getName(), command.getSubGroupSeparator(), "string.contains", getObjectArrayForLabelAndValue(GeneralCommand.PARAM_NAME, command.getSubGroupSeparator()), "'"+command.getSubGroupSeparator()+"' cannot be a sub-string of Name"); } if(command.getSubGroupType().equals(command.getType()) && !GeneralCommand.ACTION_ADD_PARENT.equals(command.getAction())) { ValidationUtils.rejectIfEmptyOrWhitespace(errors, "parentOid", "required", getObjectArrayForLabel(GeneralCommand.PARAM_PARENT_OID), "Parent Group is a required field"); } ValidatorUtil.validateStringMaxLength(errors, command.getName(), GeneralCommand.CNST_MAX_LEN_NAME, "string.maxlength", getObjectArrayForLabelAndInt(GeneralCommand.PARAM_NAME, GeneralCommand.CNST_MAX_LEN_NAME), "Name is too long."); ValidatorUtil.validateStringMaxLength(errors, command.getDescription(), GeneralCommand.CNST_MAX_LEN_DESC, "string.maxlength", getObjectArrayForLabelAndInt(GeneralCommand.PARAM_DESCRIPTION, GeneralCommand.CNST_MAX_LEN_DESC), "Description is too long."); ValidatorUtil.validateStringMaxLength(errors, command.getOwnershipMetaData(), GeneralCommand.CNST_MAX_LEN_OWNER_INFO, "string.maxlength", getObjectArrayForLabelAndInt(GeneralCommand.PARAM_OWNER_INFO, GeneralCommand.CNST_MAX_LEN_OWNER_INFO), "Owner info is too long."); ValidatorUtil.validateStringMaxLength(errors, command.getType(), TargetGroup.MAX_TYPE_LENGTH, "string.maxlength", getObjectArrayForLabelAndInt(GeneralCommand.PARAM_TYPE, TargetGroup.MAX_TYPE_LENGTH), "Group Type is too long."); if (!errors.hasErrors()) { if (command.getFromDate() != null && command.getToDate() != null) { ValidatorUtil.validateStartBeforeEndTime(errors, command.getFromDate(), command.getToDate(), "time.range", new Object[] {"To date", "From date"}, "To date is before from date"); } } } }  boolean supports(Class clazz); void validate(Object comm, Errors errors);  }