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.filemanager.elfinder.command.impl.ArchiveCommand.java

License:Open Source License

@Override
public void execute(ElFinderContext efContext, JsonObject json, Handler<AsyncResult<List<ITarget>>> handler) {
    List<String> targets = efContext.getParameterValues(ElFinderConstants.ELFINDER_PARAMETER_TARGETS);
    String type = efContext.getParameter(ElFinderConstants.ELFINDER_PARAMETER_TYPE);
    List<ITarget> targetList = findTargets(efContext, targets);
    handler.handle(Future.failedFuture(new UnsupportedOperationException("Archiving unsupported")));
}

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

License:Open Source License

@Override
public void execute(ElFinderContext efContext, JsonObject json, Handler<AsyncResult<ITarget>> handler) {
    final String targetString = efContext.getParameter(ElFinderConstants.ELFINDER_PARAMETER_TARGET);

    BufferedImage image;/*w  w  w. jav  a  2s.c om*/
    ITarget target = findTarget(efContext, targetString);
    try {
        image = ImageIO.read(target.openInputStream());
        json.put(ElFinderConstants.ELFINDER_JSON_RESPONSE_DIM,
                image.getWidth() + SEPARATOR + image.getHeight());
        handler.handle(createFuture(target));
    } catch (IOException e) {
        handler.handle(Future.failedFuture(e));
    }
}

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

License:Open Source License

@Override
public void execute(ElFinderContext efContext, JsonObject json, Handler<AsyncResult<ITarget>> handler) {
    handler.handle(Future.failedFuture(new UnsupportedOperationException("Extract")));
}

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

License:Open Source License

@Override
public void execute(ElFinderContext efContext, JsonObject json, Handler<AsyncResult<ITarget>> handler) {
    String target = efContext.getParameter("target");
    boolean download = STREAM.equals(efContext.getParameter("download"));
    ITarget fsi = super.findTarget(efContext, target);
    HttpServerResponse response = efContext.getRoutingContext().response();
    if (download) {
        response.sendFile(fsi.getAbsolutePath(), res -> {
            if (res.failed()) {
                handler.handle(Future.failedFuture(res.cause()));
            } else {
                handler.handle(createFuture(fsi));
            }// ww  w  .  j a v a  2s  .  c  om
        });
    } else {
        String mime = fsi.getMimeType();
        response.putHeader("content-type", mime + "; charset=utf-8");
        response.end(fsi.readFile());
        handler.handle(createFuture(fsi));
    }
}

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

License:Open Source License

@Override
public void execute(ElFinderContext efContext, JsonObject json, Handler<AsyncResult<ITarget>> handler) {
    handler.handle(Future.failedFuture(new UnsupportedOperationException()));
}

From source file:de.braintags.netrelay.controller.persistence.AbstractAction.java

License:Open Source License

@SuppressWarnings({ "rawtypes", "unchecked" })
protected void saveObjectInDatastore(Object ob, String entityName, RoutingContext context, IMapper mapper,
        Handler<AsyncResult<Void>> handler) {
    IWrite write = getPersistenceController().getNetRelay().getDatastore().createWrite(mapper.getMapperClass());
    write.add(ob);//from   www .j  a  v a2  s  .  c o  m
    write.save(res -> {
        AsyncResult<IWriteResult> result = (AsyncResult<IWriteResult>) res;
        if (result.failed()) {
            handler.handle(Future.failedFuture(result.cause()));
        } else {
            LOGGER.info("adding new entity to context with key " + entityName);
            addToContext(context, entityName, ob);
            handler.handle(Future.succeededFuture());
        }
    });
}

From source file:de.braintags.netrelay.controller.persistence.DataAuthorizator.java

License:Open Source License

/**
 * Check if an AuthHandler exists in Context and wether current user has the rights for all actions to be processed
 * /* w w w.ja  va2s .  co  m*/
 * @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
 */
public static void checkAuthorization(RoutingContext context, IAuthenticatable member,
        List<CaptureMap> resolvedCaptureCollections, Handler<AsyncResult<Boolean>> handler) {
    AuthHandler auth = context.get(AuthenticationController.AUTH_HANDLER_PROP);
    if (auth != null && auth instanceof RedirectAuthHandlerBt) {
        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.controller.persistence.DeleteAction.java

License:Open Source License

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override// ww w .ja v a2 s  .c o m
void handle(String entityName, RoutingContext context, CaptureMap captureMap,
        Handler<AsyncResult<Void>> handler) {
    IMapper mapper = getMapper(entityName);
    String id = captureMap.get(PersistenceController.ID_CAPTURE_KEY);
    IDataStore datastore = getPersistenceController().getNetRelay().getDatastore();
    IDelete<?> delete = datastore.createDelete(mapper.getMapperClass());
    IQuery query = getPersistenceController().getNetRelay().getDatastore().createQuery(mapper.getMapperClass());
    query.field(mapper.getIdField().getName()).is(id);
    delete.setQuery(query);
    delete.delete(result -> {
        if (result.failed()) {
            handler.handle(Future.failedFuture(result.cause()));
        } else {
            handler.handle(Future.succeededFuture());
        }
    });
}

From source file:de.braintags.netrelay.controller.persistence.DisplayAction.java

License:Open Source License

protected void handleList(String entityName, RoutingContext context, CaptureMap map, IMapper mapper, String id,
        Handler<AsyncResult<Void>> handler) {
    IQuery<?> query = getPersistenceController().getNetRelay().getDatastore()
            .createQuery(mapper.getMapperClass());
    try {/*from   w w  w  . j a v  a  2  s. com*/
        if (map.containsKey(PersistenceController.SELECTION_SIZE_CAPTURE_KEY)) {
            query.setLimit(Integer.parseInt(map.get(PersistenceController.SELECTION_SIZE_CAPTURE_KEY)));
        }
        if (map.containsKey(PersistenceController.SELECTION_START_CAPTURE_KEY)) {
            query.setStart(Integer.parseInt(map.get(PersistenceController.SELECTION_START_CAPTURE_KEY)));
        }
        if (map.containsKey(PersistenceController.ORDERBY_CAPTURE_KEY)) {
            addSortDefintions(query, map);
        }

        query.execute(result -> {
            if (result.failed()) {
                handler.handle(Future.failedFuture(result.cause()));
            } else {
                IQueryResult<?> qr = result.result();
                qr.toArray(arr -> {
                    if (arr.failed()) {
                        handler.handle(Future.failedFuture(arr.cause()));
                    } else {
                        addToContext(context, entityName, Arrays.asList(arr.result()));
                        handler.handle(Future.succeededFuture());
                    }
                });
            }
        });
    } catch (Exception e) {
        handler.handle(Future.failedFuture(e));
    }
}

From source file:de.braintags.netrelay.controller.persistence.DisplayAction.java

License:Open Source License

protected void handleSingleRecord(String entityName, RoutingContext context, IMapper mapper, String id,
        Handler<AsyncResult<Void>> handler) {
    IQuery<?> query = getPersistenceController().getNetRelay().getDatastore()
            .createQuery(mapper.getMapperClass());
    query.field(mapper.getIdField().getName()).is(id);
    query.execute(result -> {/*from  w  w w.j a  va 2s . c  om*/
        if (result.failed()) {
            handler.handle(Future.failedFuture(result.cause()));
        } else {
            IQueryResult<?> qr = result.result();
            if (qr.isEmpty()) {
                handler.handle(Future
                        .failedFuture(new NoSuchRecordException(String.format(ERRORMESSAGE_RECNOTFOUND, id))));
            } else {
                qr.iterator().next(ir -> {
                    if (ir.failed()) {
                        handler.handle(Future.failedFuture(ir.cause()));
                    } else {
                        addToContext(context, entityName, ir.result());
                        handler.handle(Future.succeededFuture());
                    }
                });
            }
        }
    });
}