public static Option<User> findBy(String email, String password) {
    User user =
        Ebean.find(User.class).where().eq("email", email).eq("password", password).findUnique();

    if (user == null) {
      return Option.<User>None();
    }

    return Option.Some(user);
  }
Example #2
0
 /**
  * 保存
  *
  * @param entry
  * @return
  */
 @Override
 public Option<Station> save(Station entry) {
   Option<Station> entryOps = OptionUtil.apply(entry);
   if (entryOps.isDefined()) {
     entry.save();
     if (OptionUtil.apply(entry.id).isDefined()) {
       return OptionUtil.apply(entry);
     }
   }
   return new None<Station>();
 }
Example #3
0
 /**
  * 県で検索
  *
  * @param id
  * @return
  */
 public Option<List<Station>> findByPref(Long id) {
   Option<Long> idOps = OptionUtil.apply(id);
   if (idOps.isDefined()) {
     Model.Finder<Long, Station> find = ModelUtil.getFinder(Station.class);
     return OptionUtil.apply(
         find.fetch("line")
             .fetch("line.company")
             .fetch("prefecture")
             .where()
             .eq("prefecture_id", id)
             .findList());
   }
   return new None<List<Station>>();
 }
Example #4
0
 /**
  * IDで検索
  *
  * @param id
  * @return
  */
 @Override
 public Option<Station> findById(Long id) {
   Option<Long> idOps = OptionUtil.apply(id);
   if (idOps.isDefined()) {
     Model.Finder<Long, Station> find = ModelUtil.getFinder(Station.class);
     // return OptionUtil.apply(find.byId(id));
     return OptionUtil.apply(
         find.fetch("line")
             .fetch("line.company")
             .fetch("prefecture")
             .where()
             .eq("id", id)
             .findUnique());
   }
   return new None<Station>();
 }
Example #5
0
  /**
   * Retrieve a field.
   *
   * @param key field name
   * @return the field (even if the field does not exist you get a field)
   */
  public Field field(String key) {

    // Value
    String fieldValue = null;
    if (data.containsKey(key)) {
      fieldValue = data.get(key);
    } else {
      if (value.isDefined()) {
        BeanWrapper beanWrapper = new BeanWrapperImpl(value.get());
        beanWrapper.setAutoGrowNestedPaths(true);
        String objectKey = key;
        if (rootName != null && key.startsWith(rootName + ".")) {
          objectKey = key.substring(rootName.length() + 1);
        }
        if (beanWrapper.isReadableProperty(objectKey)) {
          Object oValue = beanWrapper.getPropertyValue(objectKey);
          if (oValue != null) {
            fieldValue =
                play.data.format.Formatters.print(
                    beanWrapper.getPropertyTypeDescriptor(objectKey), oValue);
          }
        }
      }
    }

    // Error
    List<ValidationError> fieldErrors = errors.get(key);
    if (fieldErrors == null) {
      fieldErrors = new ArrayList<ValidationError>();
    }

    // Format
    Tuple<String, List<Object>> format = null;
    BeanWrapper beanWrapper = new BeanWrapperImpl(blankInstance());
    beanWrapper.setAutoGrowNestedPaths(true);
    try {
      for (Annotation a : beanWrapper.getPropertyTypeDescriptor(key).getAnnotations()) {
        Class<?> annotationType = a.annotationType();
        if (annotationType.isAnnotationPresent(play.data.Form.Display.class)) {
          play.data.Form.Display d = annotationType.getAnnotation(play.data.Form.Display.class);
          if (d.name().startsWith("format.")) {
            List<Object> attributes = new ArrayList<Object>();
            for (String attr : d.attributes()) {
              Object attrValue = null;
              try {
                attrValue = a.getClass().getDeclaredMethod(attr).invoke(a);
              } catch (Exception e) {
              }
              attributes.add(attrValue);
            }
            format = Tuple(d.name(), attributes);
          }
        }
      }
    } catch (NullPointerException e) {
    }

    // Constraints
    PropertyDescriptor property =
        play.data.validation.Validation.getValidator()
            .getConstraintsForClass(backedType)
            .getConstraintsForProperty(key);
    List<Tuple<String, List<Object>>> constraints = new ArrayList<Tuple<String, List<Object>>>();
    if (property != null) {
      constraints = Constraints.displayableConstraint(property.getConstraintDescriptors());
    }

    return new Field(this, key, constraints, format, fieldErrors, fieldValue);
  }
Example #6
0
 /** Gets the concrete value if the submission was a success. */
 public T get() {
   return value.get();
 }