Example usage for io.vertx.core Future failedFuture

List of usage examples for io.vertx.core Future failedFuture

Introduction

In this page you can find the example usage for io.vertx.core Future failedFuture.

Prototype

static <T> Future<T> failedFuture(String failureMessage) 

Source Link

Document

Create a failed future with the specified failure message.

Usage

From source file:de.braintags.netrelay.controller.authentication.PasswordLostController.java

License:Open Source License

private void getUser(String email, Handler<AsyncResult<IAuthenticatable>> handler) {
    if (email == null || email.hashCode() == 0) {
        handler.handle(Future.failedFuture(PasswordLostCode.EMAIL_REQUIRED.toString()));
    } else {/*from   www  .  ja  v  a 2  s .c  om*/
        IQuery<? extends IAuthenticatable> query = getNetRelay().getDatastore()
                .createQuery(this.authenticatableCLass);
        query.field("email").is(email);
        QueryHelper.executeToList(query, qr -> {
            if (qr.failed()) {
                LOGGER.error("", qr.cause());
                handler.handle(Future.failedFuture(qr.cause()));
            } else {
                if (qr.result().size() == 0) {
                    handler.handle(Future.failedFuture(PasswordLostCode.NO_ACCOUNT.toString()));
                } else {
                    handler.handle(Future.succeededFuture((IAuthenticatable) qr.result().get(0)));
                }
            }
        });
    }
}

From source file:de.braintags.netrelay.controller.authentication.RegisterController.java

License:Open Source License

private void createRegisterClaim(RoutingContext context, String email, String password,
        Handler<AsyncResult<RegisterClaim>> handler) {
    deactivatePreviousClaims(context, email, previous -> {
        if (previous.failed()) {
            handler.handle(Future.failedFuture(previous.cause()));
        } else {//from w ww  .j  a va  2s  .  com
            RegisterClaim rc = new RegisterClaim(email, password, context.request());
            IWrite<RegisterClaim> write = getNetRelay().getDatastore().createWrite(RegisterClaim.class);
            write.add(rc);
            write.save(sr -> {
                if (sr.failed()) {
                    LOGGER.error("", sr.cause());
                    handler.handle(Future.failedFuture(sr.cause()));
                } else {
                    context.put(RegisterClaim.class.getSimpleName(), rc);
                    context.put(MailController.TO_PARAMETER, email);
                    context.put(VALIDATION_ID_PARAM, rc.id);
                    handler.handle(Future.succeededFuture(rc));
                }
            });
        }
    });
}

From source file:de.braintags.netrelay.controller.authentication.RegisterController.java

License:Open Source License

private void deactivatePreviousClaims(RoutingContext context, String email,
        Handler<AsyncResult<Void>> handler) {
    IQuery<RegisterClaim> query = getNetRelay().getDatastore().createQuery(RegisterClaim.class);
    query.field("email").is(email).field("active").is(true);
    QueryHelper.executeToList(query, qr -> {
        if (qr.failed()) {
            handler.handle(Future.failedFuture(qr.cause()));
        } else {// ww w.  ja  v  a 2  s.c o m
            List<RegisterClaim> cl = (List<RegisterClaim>) qr.result();
            if (!cl.isEmpty()) {
                IWrite<RegisterClaim> write = getNetRelay().getDatastore().createWrite(RegisterClaim.class);
                cl.forEach(rc -> rc.setActive(false));
                write.addAll(cl);
                write.save(wr -> {
                    if (wr.failed()) {
                        handler.handle(Future.failedFuture(wr.cause()));
                    } else {
                        handler.handle(Future.succeededFuture());
                    }
                });
            } else {
                handler.handle(Future.succeededFuture());
            }
        }
    });
}

From source file:de.braintags.netrelay.controller.authentication.RegisterController.java

License:Open Source License

private void checkPassword(String password, Handler<AsyncResult<RegistrationCode>> handler) {
    if (password == null || password.hashCode() == 0) {
        handler.handle(Future.failedFuture(RegistrationCode.PASSWORD_REQUIRED.toString()));
    } else {// ww  w.  j  a  v  a2s .c o m
        handler.handle(Future.succeededFuture(RegistrationCode.OK));
    }
}

From source file:de.braintags.netrelay.controller.authentication.RegisterController.java

License:Open Source License

private void checkEmail(String email, Handler<AsyncResult<RegistrationCode>> handler) {
    if (email == null || email.hashCode() == 0) {
        handler.handle(Future.failedFuture(RegistrationCode.EMAIL_REQUIRED.toString()));
    } else if (!allowDuplicateEmail) {
        IQuery<? extends IAuthenticatable> query = getNetRelay().getDatastore()
                .createQuery(this.authenticatableCLass);
        query.field("email").is(email);
        query.executeCount(qr -> {/*w  w w.  ja va 2 s . co  m*/
            if (qr.failed()) {
                LOGGER.error("", qr.cause());
                handler.handle(Future.failedFuture(qr.cause()));
            } else {
                if (qr.result().getCount() > 0) {
                    handler.handle(Future.failedFuture(RegistrationCode.EMAIL_EXISTS.toString()));
                } else {
                    handler.handle(Future.succeededFuture(RegistrationCode.OK));
                }
            }
        });
    } else {
        handler.handle(Future.succeededFuture(RegistrationCode.OK));
    }
}

From source file:de.braintags.netrelay.controller.authentication.RegisterController.java

License:Open Source License

@SuppressWarnings({ "unchecked" })
private void toAuthenticatable(RoutingContext context, RegisterClaim rc, Handler<AsyncResult<Void>> handler) {
    NetRelayMapperFactory mapperFactory = (NetRelayMapperFactory) getNetRelay().getNetRelayMapperFactory();
    Map<String, String> props = extractPropertiesFromMap(mapper.getMapperClass().getSimpleName(),
            rc.getRequestParameter());//from ww  w .jav  a2 s. com
    IStoreObjectFactory<Map<String, String>> sf = mapperFactory.getStoreObjectFactory();
    sf.createStoreObject(props, mapper, result -> {
        if (result.failed()) {
            handler.handle(Future.failedFuture(result.cause()));
        } else {
            IAuthenticatable user = (IAuthenticatable) result.result().getEntity();
            user.setEmail(rc.getEmail());
            user.setPassword(rc.getPassword());
            IWrite<IAuthenticatable> write = (IWrite<IAuthenticatable>) getNetRelay().getDatastore()
                    .createWrite(authenticatableCLass);
            write.add(user);
            write.save(wr -> {
                if (wr.failed()) {
                    handler.handle(Future.failedFuture(wr.cause()));
                } else {
                    deactivateRegisterClaim(rc);
                    doUserLogin(context, user, handler);
                }
            });
        }
    });
}

From source file:de.braintags.netrelay.controller.authentication.RegisterController.java

License:Open Source License

private void doUserLogin(RoutingContext context, IAuthenticatable user, Handler<AsyncResult<Void>> handler) {
    AuthProvider auth = getAuthProvider();
    if (auth == null) {
        handler.handle(Future.succeededFuture());
    } else if (auth instanceof AuthProviderProxy) {
        try {/*from w w w .  ja  va 2s.c o m*/
            AuthProviderProxy mAuth = (AuthProviderProxy) auth;
            JsonObject authInfo = getAuthObject(user, mAuth);
            mAuth.authenticate(authInfo, res -> {
                if (res.failed()) {
                    LOGGER.warn("Unsuccessfull login", res.cause());
                    handler.handle(Future.failedFuture(res.cause()));
                } else {
                    LOGGER.info("direct login successfull, user: " + res.result());
                    MemberUtil.setContextUser(context, res.result());
                    handler.handle(Future.succeededFuture());
                }
            });
        } catch (Exception e) {
            handler.handle(Future.failedFuture(e));
        }
    } else {
        handler.handle(Future.failedFuture(new UnsupportedOperationException(
                "unsupported AuthProvider for direct login: " + auth.getClass().getName())));
    }
}

From source file:de.braintags.netrelay.controller.filemanager.elfinder.command.impl.AbstractCommand.java

License:Open Source License

@Override
public final void execute(ElFinderContext efContext, Handler<AsyncResult<JsonObject>> handler) {
    listenerBefore(efContext, lb -> {
        if (lb.failed()) {
            handler.handle(Future.failedFuture(lb.cause()));
        } else if (lb.result()) {
            doExecute(efContext, handler);
        } else {/*from w  w w  .  j  a  v a 2 s . c om*/
            // command denied
            handler.handle(Future.failedFuture("action denied by server"));
        }
    });

}

From source file:de.braintags.netrelay.controller.filemanager.elfinder.command.impl.AbstractCommand.java

License:Open Source License

private void doExecute(ElFinderContext efContext, Handler<AsyncResult<JsonObject>> handler) {
    JsonObject json = new JsonObject();
    try {//from   ww  w.  ja va 2  s  .  com
        execute(efContext, json, res -> {
            if (res.failed()) {
                handler.handle(Future.failedFuture(res.cause()));
            } else {
                listenerAfter(efContext, json, res.result(), handler);
            }
        });
    } catch (Exception e) {
        handler.handle(Future.failedFuture(e));
    }
}

From source file:de.braintags.netrelay.controller.filemanager.elfinder.command.impl.AbstractCommand.java

License:Open Source License

private void listenerAfter(ElFinderContext efContext, JsonObject json, T result,
        Handler<AsyncResult<JsonObject>> handler) {
    if (listener != null) {
        listener.after(this, efContext, result, json, lr -> {
            if (lr.failed()) {
                handler.handle(Future.failedFuture(lr.cause()));
            } else {
                handler.handle(Future.succeededFuture(json));
            }// ww w.  j av  a  2s .c om
        });
    } else {
        handler.handle(Future.succeededFuture(json));
    }
}