PredicatedAction.java 641 B

12345678910111213141516171819202122
  1. package utils;
  2. /**
  3. * A predicated action is one where a condition must be satisfied in order to proceed with the request. If the
  4. * condition is not satisfied then a supplied status result is yielded.
  5. */
  6. import play.mvc.Action;
  7. import play.mvc.Http;
  8. import play.mvc.Result;
  9. public class PredicatedAction extends Action<Predicated> {
  10. @Override
  11. public Result call(final Http.Context ctx) throws Throwable {
  12. final Predicate p = configuration.predicate().newInstance();
  13. if (p.condition()) {
  14. return delegate.call(ctx);
  15. } else {
  16. return status(configuration.failed());
  17. }
  18. }
  19. }