Package hirondelle.web4j.model

Examples of hirondelle.web4j.model.ModelCtorException


  private final SafeText fMemberName;
  private Boolean fResponse;
  private int fHashCode;
 
  private void validateState() throws ModelCtorException {
    ModelCtorException ex = new ModelCtorException();
    if ( FAILS ==  Check.required(fVisitId, Check.range(1, 50)) ) {
      ex.add("Visit Id is required, 1..50 chars.");
    }
    if ( FAILS ==  Check.required(fMemberId, Check.range(1, 50)) ) {
      ex.add("Member Id is required, 1..50 chars.");
    }
    if ( FAILS == Check.optional(fMemberName, Check.range(2, 50)) ) {
      ex.add("Member Name is optional, 2..50 chars.");
    }
    //no check on response - can be null, or true/false
    if ( ! ex.isEmpty() ) throw ex;
  }
View Full Code Here


  private int fHashCode;
 
  private static final Decimal HUNDRED = Decimal.from("100");

  private void validateState() throws ModelCtorException {
    ModelCtorException ex = new ModelCtorException();
    if ( FAILS == Check.optional(fId, Check.range(1,50)) ) {
      ex.add("Id is optional, 1..50 chars.");
    }
    if ( FAILS == Check.required(fName, Check.range(2,50)) ) {
      ex.add("Restaurant Name is required, 2..50 chars.");
    }
    if ( FAILS == Check.optional(fLocation, Check.range(2,50)) ) {
      ex.add("Location is optional, 2..50 chars.");
    }
    Validator[] priceChecks = {Check.range(ZERO, HUNDRED), Check.numDecimalsAlways(2)};
    if ( FAILS == Check.optional(fPrice, priceChecks)) {
      ex.add("Price is optional, 0.00 to 100.00.");
    }
    if ( FAILS == Check.optional(fComment, Check.range(2,50))) {
      ex.add("Comment is optional, 2..50 chars.");
    }
    if ( ! ex.isEmpty() ) throw ex;
  }
View Full Code Here

  private final Integer fBeerRating;
  private final BigDecimal fOverallRating;
  private int fHashCode;

  private void validateState() throws ModelCtorException {
    ModelCtorException ex = new ModelCtorException();
    Validator[] ratingsChecks = {Check.min(0), Check.max(10)};
    if ( FAILS == Check.required(fId, Check.range(1,50)) ) {
      ex.add("Id is required, 1..50 chars.");
    }
    if ( FAILS ==  Check.optional(fName, Check.range(2,50)) ) {
      ex.add("Name is optional, 2..50 chars.");
    }
    if ( FAILS == Check.required(fFishRating, ratingsChecks) ) {
      ex.add("Fish Rating is required, 0..10.");
    }
    if ( FAILS == Check.required(fChipsRating, ratingsChecks) ) {
      ex.add("Chips Rating is required, 0..10.");
    }
    if ( FAILS == Check.required(fPriceRating, ratingsChecks) ) {
      ex.add("Price Rating is required, 0..10.");
    }
    if ( FAILS == Check.required(fLocationRating, ratingsChecks) ) {
      ex.add("Location Rating is required, 0..10.");
    }
    if ( FAILS == Check.required(fServiceRating, ratingsChecks) ) {
      ex.add("Service Rating is required, 0..10.");
    }
    if ( FAILS == Check.required(fBeerRating, ratingsChecks) ) {
      ex.add("Beer Rating is required, 0..10.");
    }
    BigDecimal ZERO = new BigDecimal("0.00");
    BigDecimal TEN =  new BigDecimal("10.00");
    if ( FAILS == Check.optional(fOverallRating, Check.range(ZERO, TEN))  ) {
      ex.add("Overall Rating is optional, 0.00..10.00.");
    }
    if ( ! ex.isEmpty() ) throw ex;
  }
View Full Code Here

  private static Validator CHECK_EXTENSION = new ValidateExtension();
  private static Validator CHECK_CONTENT_TYPE = new ValidateContentType();
  private static final Logger fLogger = Util.getLogger(Image.class);

  private void validateState() throws ModelCtorException {
    ModelCtorException ex = new ModelCtorException();

    if (FAILS == Check.required(fDescription, Check.range(1, 100))) {
      ex.add("Image Description is required.");
    }
    if (FAILS == Check.required(fFileName, Check.range(1, 100), CHECK_EXTENSION)) {
      ex.add("File Name is required. Must end in .jpeg, .jpg, .gif, or .png");
    }
    else {
      if (FAILS == Check.required(fFileContentType, Check.range(1, 100), CHECK_CONTENT_TYPE)) {
        ex.add("File Content-Type is required. Must be image/jpeg, image/gif, or image/png");
      }
      if (FAILS == Check.required(fFileSize, Check.range(1024, 1024 * 50))) {
        ex.add("File size is required, in range 1K to 50K.");
      }
    }

    if (!ex.isEmpty()) {
      fLogger.fine(ex.getMessage());
      throw ex;
    }
  }
View Full Code Here

  private final SafeText fShortForm;
  private final SafeText fDescription;
  private int fHashCode;
 
  private void validateState() throws ModelCtorException {
    ModelCtorException ex = new ModelCtorException();
    if ( FAILS == Check.optional(fId, Check.range(1, 50)) ) {
      ex.add("Id is optional, 1..50 chars.");
    }
    if ( FAILS == Check.required(fShortForm, Check.range(2,50)) ) {
      ex.add("Short Form is required, 2..50 chars.");
    }
    if ( FAILS == Check.required(fDescription, Check.range(2,50)) ) {
      ex.add("Description is required, 2..50 chars.");
    }
    if ( ! ex.isEmpty() ) throw ex;
  }
View Full Code Here

  private final Boolean fIsActive;
  private final Code fDisposition;
  private int fHashCode;
 
  private void validateState() throws ModelCtorException {
    ModelCtorException ex = new ModelCtorException();
   
    if ( FAILS == Check.optional(fId, Check.range(1,50)) ) {
      ex.add("Id is optional, 1..50 chars.");
    }
    if ( FAILS == Check.required(fName, Check.range(2,50))) {
      ex.add("Name is required, 2..50 chars.");
    }
    if ( FAILS == Check.required(fIsActive) ) {
      ex.add("Is Active is required. Inactive Members will not appear in the RSVP list.");
    }
    if ( FAILS == Check.required(fDisposition) ) {
      ex.add("Disposition is required.");
    }
    if ( ! ex.isEmpty() ) throw ex;
  }
View Full Code Here

 
  private static final Decimal HUNDRED = Decimal.from("100.00");
  private static final Pattern NO_WILDCARD = Pattern.compile(".*[^" + WILDCARD + "]$");
 
  private void validateState() throws ModelCtorException {
    ModelCtorException ex = new ModelCtorException();
   
    if( FAILS == Check.optional(fStartsWith, Check.max(MAX_LENGTH)) ) {
      ex.add("Please enter a shorter Restaurant Name.");
    }
    if( FAILS ==  Check.optional(fStartsWith, Check.pattern(NO_WILDCARD)) ){
      ex.add("Restaurant name (_1_) cannot have this character at the end : _2_", fStartsWith, Util.quote(WILDCARD));
    }
    if( FAILS == Check.optional(fMinPrice, Check.range(ZERO,HUNDRED), Check.numDecimalsAlways(2)) ){
      ex.add("Minimum Price (_1_) must be in the range 0.00 to 100.00, 2 decimals", fMinPrice.toString());
    }
    if( FAILS == Check.optional(fMaxPrice, Check.range(ZERO,HUNDRED), Check.numDecimalsAlways(2)) ){
      ex.add("Maximum Price (_1_) must be in the range 0.00 to 100.00, 2 decimals", fMaxPrice.toString() );
    }
    if ( fMaxPrice != null || fMinPrice != null ){
      if( fMaxPrice == null || fMinPrice == null ){
        ex.add("When specifying price, please specify both minimum and maximum.");
      }
    }
    if( fMaxPrice != null && fMinPrice != null ){
      if ( fMinPrice.gt(fMaxPrice) ){
        ex.add("Minimum price cannot be greater than maximum price.");
      }
    }
    if ( ! Util.textHasContent(fStartsWith) && fMinPrice == null && fMaxPrice == null ) {
      ex.add("Please enter criteria on name and/or price.");
    }
   
    if ( ex.isNotEmpty() ) throw ex;
  }
View Full Code Here

  private final Date fLunchDate;
  private final SafeText fMessage;
  private int fHashCode;
 
  private void validateState() throws ModelCtorException {
    ModelCtorException ex = new ModelCtorException();
    if ( FAILS ==  Check.optional(fId, Check.range(1, 50)) ) {
      ex.add("Visit Id is optional, 1..50 chars.");
    }
    if ( FAILS == Check.required(fRestaurantCode) ) {
      ex.add("Restaurant is required.");
    }
    if ( FAILS == Check.required(fLunchDate, Check.range(MIN_DATE.getTimeInMillis(), MAX_DATE.getTimeInMillis())) ) {
      ex.add("Lunch Date is required, year in range 2006..2100.");
    }
    if ( FAILS == Check.optional(fMessage, Check.range(2, 50)) ) {
      ex.add("Message is optional, 2..50 characters.");
    }
    if ( ! ex.isEmpty() ) throw ex;
  }
View Full Code Here

  private Object[] getSignificantFields(){
    return new Object[] {fUserName, fBody, new Date(fDate)};
  }
 
  private void validateState() throws ModelCtorException {
    ModelCtorException ex = new ModelCtorException();
    if( FAILS ==  Check.required(fUserName) ) {
      ex.add("User name must have content.");
    }
    if ( FAILS == Check.required(fBody) ) {
      ex.add("Comment body must have content.");
    }
    if ( ! ex.isEmpty() ) throw ex;
  }
View Full Code Here

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

  private void validateState() throws ModelCtorException {
    ModelCtorException ex = new ModelCtorException();
    if ( FAILS == Check.required(fUserName,  Check.pattern(ACCEPTED_PATTERN)) ) {
      ex.add("Name is required, 6..50 chars, no spaces.");
    }
    if ( FAILS == Check.required(fLocale) ) {
      ex.add("Language is required.");
    }
    if ( ! ex.isEmpty() ) 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.