private F.Option<ModelMetadata> getModel(final String name) {
    ModelMetadata modelInfo = null;
    try {
      modelInfo =
          (ModelMetadata)
              Cache.getOrElse(
                  getClass().getName() + "_ModelMetadata_" + name,
                  new Callable<Object>() {

                    @Override
                    public Object call() throws Exception {
                      return Iterables.find(
                          modelRegistry.getModels(),
                          new Predicate<ModelMetadata>() {
                            @Override
                            public boolean apply(ModelMetadata model) {
                              String modelName = model.getName();
                              return modelName.equals(name);
                            }
                          },
                          null);
                    }
                  },
                  0);
    } catch (Exception e) {
      e.printStackTrace();
    }
    return modelInfo == null ? F.Option.<ModelMetadata>None() : F.Option.Some(modelInfo);
  }
Esempio n. 2
0
 @Override
 public F.Option<Pager> bind(String key, Map<String, String[]> data) {
   if (data.containsKey(key + ".index") && data.containsKey(key + ".size")) {
     try {
       index = Integer.parseInt(data.get(key + ".index")[0]);
       size = Integer.parseInt(data.get(key + ".size")[0]);
       return F.Option.Some(this);
     } catch (NumberFormatException e) {
       return F.Option.None();
     }
   } else {
     return F.Option.None();
   }
 }
  private F.Either<ControllerProxy, ? extends Result> controllerOrNotFound(final String name) {
    F.Option<ModelMetadata> modelInfo = getModel(name);
    if (!modelInfo.isDefined())
      return F.Either.Right(notFound("Model with name " + name + " not found!"));

    ModelMetadata model = modelInfo.get();

    F.Option<? extends ControllerProxy<?, ?>> crud;
    try {
      crud = getController(model);
    } catch (IncompatibleControllerException e) {
      crud = null;
    }

    if (crud == null || !crud.isDefined())
      return F.Either.Right(notFound("Controller for model " + model.getType() + " not found"));

    ControllerProxy controller = crud.get();
    return F.Either.Left(controller);
  }
Esempio n. 4
0
 @Override
 public F.Option<Product> bind(String key, Map<String, String[]> data) {
   return F.Option.Some(findByEan(data.get("ean")[0]));
 }
 private F.Option<? extends ControllerProxy<?, ?>> getController(ModelMetadata model)
     throws IncompatibleControllerException {
   ControllerProxy<?, ?> crud =
       controllerRegistry.getController(model.getKeyField().getType(), model.getType());
   return crud == null ? F.Option.<ControllerProxy<?, ?>>None() : F.Option.Some(crud);
 }