Package hirondelle.web4j.model

Examples of hirondelle.web4j.model.ModelCtorException


 
  private static final Pattern LOGIN_NAME = Pattern.compile("(?:\\S){6,50}");
  private static final Pattern SCREEN_NAME_REGEX = Pattern.compile("(?:.){6,50}");

  private void validateState() throws ModelCtorException {
    ModelCtorException ex = new ModelCtorException();
    if ( FAILS == Check.required(fUserId) ) {
      ex.add("User id is required (programmer error).");
    }
    if ( FAILS == Check.required(fLoginName,  Check.pattern(LOGIN_NAME)) ) {
      ex.add("Login Name is required, 6..50 chars, no spaces.");
    }
    if ( FAILS == Check.optional(fScreenName,  Check.pattern(SCREEN_NAME_REGEX)) ) {
      ex.add("Screen Name is optional, 6..50 chars.");
    }
    if ( ! ex.isEmpty() ) throw ex;
  }
View Full Code Here


  private int fHashCode;
 
  private enum CheckDate{YES, NO};

  private void validateState(CheckDate aCheckDate) throws ModelCtorException {
    ModelCtorException ex = new ModelCtorException();
   
    if ( FAILS == Check.required(fTitle, Check.max(50)) ) {
      ex.add("Please provide a title (up to 50 characters)");
    }
    if ( FAILS == Check.required(fUser) ){
      ex.add("User id is missing (programmer error)");
    }
    if( CheckDate.YES == aCheckDate ){
      if ( FAILS == Check.required(fCreationDate) ) {
        ex.add("Creation date missing is missing (programmer error).");
      }
    }

    if ( ! ex.isEmpty() ) throw ex;
  }
View Full Code Here

  /**
   Does NOT throw ModelCtorException, since errors here represent bugs.
  */
  private void validateState(){
    ModelCtorException ex = new ModelCtorException();
    Pattern simpleId = Pattern.compile(FORMAT);
    if ( ! Check.required(fStatementName, Check.pattern(simpleId)) ) {
      ex.add("Statement Name is required, and must match SqlId.FORMAT.");
    }
    if ( ! Check.optional(fDatabaseName, Check.pattern(simpleId)) ) {
      ex.add("Database Name is optional, and must match SqlId.FORMAT.");
    }
    if ( ! ex.isEmpty() ) {
      throw new IllegalArgumentException(Util.logOnePerLine(ex.getMessages()));
    }
  }
View Full Code Here

  private Object[] getSignificantFields(){
    return new Object[] {fId, fText, fShortText, fLongText, fOrderIdx};
  }
 
  private void validateState() throws ModelCtorException {
    ModelCtorException ex = new ModelCtorException();
    if ( ! Check.optional(fId, Check.min(1), Check.max(50))) {
      ex.add("Code Id is optional, 1..50 chars.");
    }
    if ( ! Check.required(fText, Check.range(1,50))) {
      ex.add("Text is required, 1..50 chars.");
    }
    if ( ! Check.optional(fShortText, Check.range(1,10))) {
      ex.add("Short Text is optional, 1..10 chars.");
    }
    if ( ! Check.optional(fLongText, Check.range(1,200))) {
      ex.add("Long Text is optional, 1..200 chars.");
    }
    if ( ! Check.optional(fOrderIdx, Check.range(1,1000))) {
      ex.add("Order Idx is optional, 1..1000.");
    }
    if ( ! ex.isEmpty() ) throw ex;
  }
View Full Code Here

    private final BigDecimal fDesiredSalary;
    private final Long fBirthDate;
    private static final Integer ZERO = new Integer(0);
   
    private void validateState() throws ModelCtorException {
      ModelCtorException ex = new ModelCtorException();
      if ( ! isValidLoginName(fLoginName) ) {
        ex.add("Login name must have 3..30 characters");
      }
      if ( ! isValidLoginPassword(fLoginPassword) ) {
        ex.add("Password must have 3..20 characters, with no spaces");
      }
      if ( ! isValidEmailAddress(fEmailAddress) ){
        ex.add("Email address has an invalid form");
      }
      if ( ! isValidStarRating(fStarRating) ){
        ex.add("Star Rating (optional) must be in range 1..4");
      }
      //no validation needed for favoriteTheory, sendCard
      if ( ! isValidAge(fAge) ) {
        ex.add("Age must be in range 0..150");
      }
      if ( ! isValidDesiredSalary(fDesiredSalary) ) {
        ex.add("Desired Salary must be 0 or more.");
      }
      if ( ! isValidBirthDate(fBirthDate) ){
        ex.add("Birth Date must be in the past.");
      }
      if ( ! ex.isEmpty() ) throw ex;
    }
View Full Code Here

    if( Util.textHasContent(filteredValue) ){
      try {
        result  = fConvertUserInput.convert(filteredValue, aSupportedTargetClass, fLocale, fTimeZone);
      }
      catch (ModelCtorException ex){
        ModelCtorException conversionEx = fConversionError.get(aSupportedTargetClass, filteredValue, aReqParam);
        throw conversionEx;
      }
    }
    return result;
  }
View Full Code Here

   @param aReqParam underlying request parameter
   @param aSupportedTargetClass must be supported - see {@link ConvertParam#isSupported(Class)}
  */
  public <T> List<T> toSupportedObjects(RequestParameter aReqParam, Class<T> aSupportedTargetClass) throws ModelCtorException {
    List<T> result = new ArrayList<T>();
    ModelCtorException conversionExceptions = new ModelCtorException();
    if( ! fConvertUserInput.isSupported(aSupportedTargetClass) ){
      throw new AssertionError("This class is not supported by ConvertParam: " + Util.quote(aSupportedTargetClass));
    }
    String[] rawValues = getRawParamValues(aReqParam);
    if(rawValues != null){
      for(String rawValue: rawValues){
        String filteredValue = fConvertUserInput.filter(rawValue); //possibly null
        //is it possible to have a multi-valued boolean param???       
        if ( Util.textHasContent(filteredValue) || Boolean.class == aSupportedTargetClass){
          try {
            T convertedItem  = fConvertUserInput.convert(filteredValue, aSupportedTargetClass, fLocale, fTimeZone);
            result.add(convertedItem);
          }
          catch (ModelCtorException ex){
            AppException conversionEx = fConversionError.get(aSupportedTargetClass, filteredValue, aReqParam);
            conversionExceptions.add(conversionEx);
          }
        }
        else {
          result.add(null);
        }
      }
      if (conversionExceptions.isNotEmpty()) throw conversionExceptions;
    }
    return Collections.unmodifiableList(result);
  }
View Full Code Here

  }
  private void validateState(){
    //use the model ctor exception only to gather errors together
    //it is never actually thrown.
    ModelCtorException ex = new ModelCtorException();
    if ( ! Util.textHasContent(fName) ){
      ex.add("Name must have content.");
    }
    if ( fIsRegularParameter && (fRegex == null || ! Util.textHasContent(fRegex.pattern()) ) ){
      ex.add("For regular request parameters, regex pattern must be present.");
    }
    if ( ! fIsRegularParameter && fRegex != null  ){
      ex.add("For file upload parameters, regex pattern must be null.");
    }
    if ( ex.isNotEmpty() ) {
      throw new IllegalArgumentException(ex.getMessages().toString());
    }
  }
View Full Code Here

   @param aRequestParser translates parameter values into <tt>Integer</tt>,
   <tt>Date</tt>, and so on, using the implementation of {@link ConvertParam}.
  */
  public ModelFromRequest(RequestParser aRequestParser){
    fRequestParser = aRequestParser;
    fModelCtorException = new ModelCtorException();
  }
View Full Code Here

  private Id fLocaleId;
  private Id fBaseTextId;
  private int fHashCode;
 
  private void validateState() throws ModelCtorException {
    ModelCtorException ex = new ModelCtorException();
    if( ! Check.required(fBaseText) ) {
      ex.add("Base Text must have content.");     
    }
    if( ! Check.required(fLocale) ) {
      ex.add("Locale must have content.");     
    }
    if( ! Check.required(fTranslation) ) {
      ex.add("Translation must have content.");
    }
    if( ! Check.optional(fLocaleId, Check.min(1), Check.max(50)) ){
      ex.add("LocaleId optional, 1..50 characters.");
    }
    if( ! Check.optional(fBaseTextId, Check.min(1), Check.max(50)) ){
      ex.add("BaseTextId optional, 1..50 characters.");
    }
    if( ex.isNotEmpty() )  throw ex;
  }
View Full Code Here

TOP

Related Classes of hirondelle.web4j.model.ModelCtorException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.