List of usage examples for io.vertx.core Future failedFuture
static <T> Future<T> failedFuture(String failureMessage)
From source file:de.braintags.netrelay.controller.persistence.InsertAction.java
License:Open Source License
@Override final void handle(String entityName, RoutingContext context, CaptureMap captureMap, Handler<AsyncResult<Void>> handler) { IMapper mapper = getMapper(entityName); Map<String, String> params = extractProperties(entityName, captureMap, context, mapper); handleFileUploads(entityName, context, params); getPersistenceController().getMapperFactory().getStoreObjectFactory().createStoreObject(params, mapper, result -> {/* w ww . j a va 2 s .c om*/ if (result.failed()) { handler.handle(Future.failedFuture(result.cause())); } else { Object ob = result.result().getEntity(); saveObjectInDatastore(ob, entityName, context, mapper, handler); } }); }
From source file:de.braintags.netrelay.controller.persistence.PersistenceController.java
License:Open Source License
@Override protected void handle(RoutingContext context, List<CaptureMap> resolvedCaptureCollections, Handler<AsyncResult<Void>> handler) { checkAuthorization(context, resolvedCaptureCollections, res -> { if (res.failed()) { handler.handle(Future.failedFuture(res.cause())); } else if (!res.result()) { context.fail(403);// www . j av a 2 s .co m } else { handlePersistence(context, resolvedCaptureCollections, handler); } }); }
From source file:de.braintags.netrelay.controller.persistence.PersistenceController.java
License:Open Source License
/** * Check wether current user has the rights for all actions to be processed * //from w w w .j ava 2 s . com * @param context * @param resolvedCaptureCollections * @param handler * is getting true, if rights to all actions are granted or if no Authentication handler is active; * false, if right for only one action is not granted */ private void checkAuthorization(RoutingContext context, List<CaptureMap> resolvedCaptureCollections, Handler<AsyncResult<Boolean>> handler) { AuthHandler auth = context.get(AuthenticationController.AUTH_HANDLER_PROP); if (auth != null && auth instanceof RedirectAuthHandlerBt) { MemberUtil.getCurrentUser(context, getNetRelay(), result -> { if (result.failed()) { handler.handle(Future.failedFuture(result.cause())); } else { IAuthenticatable member = result.result(); if (member == null) { // this is an error handler.handle(Future.failedFuture(new IllegalArgumentException( "This should not happen, we need an instance of IAuthenticatable here"))); } else { checkAuthorization(resolvedCaptureCollections, auth, member, handler); } } }); } else { handler.handle(Future.succeededFuture(true)); } }
From source file:de.braintags.netrelay.mapping.NetRelayStoreObject.java
License:Open Source License
/** * Initialize the internal entity from the information previously read from the datastore. * /* www .j a v a 2s. c o m*/ * @param handler */ public final void initToEntity(Handler<AsyncResult<Void>> handler) { createEntity(result -> { if (result.failed()) { handler.handle(Future.failedFuture(result.cause())); } else { T tmpObject = result.result(); LOGGER.debug("start initToEntity"); iterateFields(tmpObject, fieldResult -> { if (fieldResult.failed()) { handler.handle(fieldResult); return; } iterateObjectReferences(tmpObject, orResult -> { if (orResult.failed()) { handler.handle(orResult); return; } finishToEntity(tmpObject, handler); LOGGER.debug("finished initToEntity"); }); }); } }); }
From source file:de.braintags.netrelay.mapping.NetRelayStoreObject.java
License:Open Source License
private void createEntity(Handler<AsyncResult<T>> handler) { if (entity != null) { handler.handle(Future.succeededFuture(entity)); } else if (hasProperty(getMapper().getIdField())) { Object id = get(getMapper().getIdField()); IQuery<T> query = netRelay.getDatastore().createQuery(getMapper().getMapperClass()); query.field(query.getMapper().getIdField().getName()).is(id); query.execute(qrr -> {/*from w w w .j a v a 2s .c o m*/ if (qrr.failed()) { handler.handle(Future.failedFuture(qrr.cause())); } else { IQueryResult<T> qr = qrr.result(); if (!qr.iterator().hasNext()) { handler.handle(Future .failedFuture(new NoSuchRecordException("Could not find record with ID " + id))); } else { qr.iterator().next(ir -> { if (ir.failed()) { handler.handle(Future.failedFuture(ir.cause())); } else { handler.handle(Future.succeededFuture(ir.result())); } }); } } }); } else { T returnObject = getMapper().getObjectFactory().createInstance(getMapper().getMapperClass()); handler.handle(Future.succeededFuture(returnObject)); } }
From source file:de.braintags.netrelay.mapping.NetRelayStoreObject.java
License:Open Source License
protected void finishToEntity(T tmpObject, Handler<AsyncResult<Void>> handler) { this.entity = tmpObject; try {//from w ww . j av a2s . c o m handler.handle(Future.succeededFuture()); } catch (Exception e) { handler.handle(Future.failedFuture(e)); } }
From source file:de.braintags.netrelay.mapping.NetRelayStoreObjectFactory.java
License:Open Source License
@Override public <T> void createStoreObject(IMapper<T> mapper, T entity, Handler<AsyncResult<IStoreObject<T, ?>>> handler) { NetRelayStoreObject<T> storeObject = new NetRelayStoreObject<>(mapper, entity); storeObject.initFromEntity(initResult -> { if (initResult.failed()) { handler.handle(Future.failedFuture(initResult.cause())); } else {/*from www. ja va 2s . c o m*/ handler.handle(Future.succeededFuture(storeObject)); } }); }
From source file:de.braintags.netrelay.mapping.NetRelayStoreObjectFactory.java
License:Open Source License
/** * This method is called in cases, where a subobject needs to be updated, which can't be loaded from the datastore * /*from w w w . j ava 2s . c o m*/ * @param storedObject * @param entity * @param mapper * @param handler */ public <T> void createStoreObject(Map<String, String> storedObject, T entity, IMapper<T> mapper, Handler<AsyncResult<IStoreObject<T, ?>>> handler) { NetRelayStoreObject<T> storeObject = new NetRelayStoreObject<>(storedObject, entity, mapper, netRelay); storeObject.initToEntity(result -> { if (result.failed()) { handler.handle(Future.failedFuture(result.cause())); } else { handler.handle(Future.succeededFuture(storeObject)); } }); }
From source file:de.braintags.netrelay.MemberUtil.java
License:Open Source License
/** * Fetch the instance of IAuthenticatable from the datastore and store it into the context * //from w w w . ja v a 2 s. c o m * @param context * @param netRelay * @param user * @param resultHandler */ private static void readUser(RoutingContext context, NetRelay netRelay, User user, Handler<AsyncResult<IAuthenticatable>> resultHandler) { Class<? extends IAuthenticatable> mapperClass = getMapperClass(context, netRelay); if (user instanceof MongoUser) { readMongoUser(context, netRelay, (MongoUser) user, resultHandler, mapperClass); } else if (user instanceof DatastoreUser) { resultHandler.handle(Future.succeededFuture(((DatastoreUser) user).getAuthenticatable())); } else { Future<IAuthenticatable> future = Future.failedFuture( new UnsupportedOperationException("user type not supported: " + user.getClass().getName())); resultHandler.handle(future); } }
From source file:de.braintags.netrelay.MemberUtil.java
License:Open Source License
/** * @param context/* ww w .ja va2 s .c o m*/ * @param netRelay * @param user * @param resultHandler * @param mapperClass */ private static void readMongoUser(RoutingContext context, NetRelay netRelay, MongoUser user, Handler<AsyncResult<IAuthenticatable>> resultHandler, Class<? extends IAuthenticatable> mapperClass) { String id = user.principal().getString("_id"); IQuery<? extends IAuthenticatable> query = netRelay.getDatastore().createQuery(mapperClass); query.field(query.getMapper().getIdField().getName()).is(id); query.execute(qr -> { if (qr.failed()) { resultHandler.handle(Future.failedFuture(qr.cause())); } else { if (qr.result().size() <= 0) { resultHandler.handle( Future.failedFuture(new NoSuchRecordException("no record found for principal with id " + id + " in mapper " + mapperClass.getName()))); } qr.result().iterator().next(ir -> { if (ir.failed()) { resultHandler.handle(Future.failedFuture(ir.cause())); } else { IAuthenticatable auth = ir.result(); setCurrentUser(auth, context); resultHandler.handle(Future.succeededFuture(auth)); } }); } }); }