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:org.etourdot.vertx.marklogic.impl.MarkLogicDocumentImpl.java

License:Open Source License

void saveAndTransform(JsonObject documents, TransformOptions transformOptions,
        Handler<AsyncResult<JsonArray>> resultHandler) {
    requireNonNull(documents, "documents cannot be null");
    requireNonNull(resultHandler, "resultHandler cannot be null");

    try {//from   w ww.ja  v a  2 s. c  o m
        if (documents.containsKey(DOCUMENTS)) {
            Documents docs = new DocumentsImpl(documents);
            saveDocuments(docs, transformOptions, resultHandler);
        } else {
            final Document doc = Document.create(documents);
            save(doc, transformOptions, resultHandler);
        }
        //Future.succeededFuture();
    } catch (Exception ex) {
        Future.failedFuture(ex);
    }
}

From source file:org.etourdot.vertx.marklogic.impl.MarkLogicDocumentImpl.java

License:Open Source License

void readDocument(String docId, List<String> categories, Handler<AsyncResult<JsonObject>> resultHandler) {
    JsonArray docIds = new JsonArray(Collections.singletonList(docId));
    readDocuments(docIds, categories, (result) -> {
        if (result.failed()) {
            resultHandler.handle(Future.failedFuture(result.cause()));
        } else {//from   w  w w  .  j  a v a2s. c  o  m
            resultHandler.handle(Future.succeededFuture(result.result().getJsonObject(0)));
        }
    });
}

From source file:org.etourdot.vertx.marklogic.impl.MarkLogicDocumentImpl.java

License:Open Source License

void readDocuments(JsonArray docIds, List<String> categories, Handler<AsyncResult<JsonArray>> resultHandler) {
    MultiPartRequest marklogicRequest = restService.newMultipartRequest();
    marklogicRequest.get(DOCUMENTS_URL).addParam(FORMAT, "json").addParams(CATEGORY, categories);
    docIds.stream().forEach(docId -> marklogicRequest.addParam(MarkLogicConstants.URI, (String) docId));
    marklogicRequest.execute(response -> {
        SearchResponse searchResponse = new SearchResponse(response);
        searchResponse.endHandler(marklogicResponse -> {
            if (HttpResponseStatus.OK.code() == marklogicResponse.statusCode()) {
                JsonArray documents = new JsonArray();
                for (Document document : ((SearchResponse) marklogicResponse).getDocuments()) {
                    documents.add(document.toJson());
                }/*w  w  w  .j  av a2s  . c  o  m*/
                resultHandler.handle(Future.succeededFuture(documents));
            }
            if (HttpResponseStatus.NOT_FOUND.code() == marklogicResponse.statusCode()) {
                resultHandler.handle(
                        Future.failedFuture(new ResourceNotFoundException(marklogicResponse.statusMessage())));
            }
            resultHandler.handle(Future.succeededFuture());
        });
        searchResponse.process();
    });
}

From source file:org.etourdot.vertx.marklogic.impl.MarkLogicManagementImpl.java

License:Open Source License

void createForest(ForestsOptions forestsOption, Handler<AsyncResult<Void>> resultHandler) {
    requireNonNull(forestsOption, "forestsOption cannot be null");
    requireNonNull(resultHandler, "resultHandler cannot be null");

    MarkLogicRequest marklogicRequest = restService.newMarklogicRequest();
    marklogicRequest.post(MANAGE_FORESTS).withBody(forestsOption.toJson()).execute(response -> {
        if (HttpResponseStatus.CREATED.code() == response.statusCode()) {
            resultHandler.handle(Future.succeededFuture());
        } else {//from  www .  j  a  va2 s .c  o  m
            response.contentHandler(
                    buffer -> resultHandler.handle(Future.failedFuture(buffer.toJsonObject().encode())));
        }
    });
}

From source file:org.etourdot.vertx.marklogic.impl.MarkLogicManagementImpl.java

License:Open Source License

void deleteForest(ForestsOptions forestsOption, Handler<AsyncResult<Void>> resultHandler) {
    requireNonNull(forestsOption, "config cannot be null");
    requireNonNull(resultHandler, "resultHandler cannot be null");
    requireNonNull(forestsOption.getName(), "name cannot be null");

    MarkLogicRequest marklogicRequest = restService.newMarklogicRequest();
    String serverHttpString = getUrlWithInstance(MANAGE_FORESTS, forestsOption);
    marklogicRequest.delete(serverHttpString);
    if (forestsOption.hasLevel()) {
        marklogicRequest.addParam(LEVEL, forestsOption.getLevel());
    }//from   w  w  w .  ja  v  a2 s .co  m
    if (forestsOption.hasReplicas()) {
        marklogicRequest.addParam(REPLICAS, forestsOption.getReplicas());
    }

    marklogicRequest.execute(response -> {
        if (HttpResponseStatus.NO_CONTENT.code() == response.statusCode()) {
            response.contentHandler(buffer -> resultHandler.handle(Future.succeededFuture()));
        } else {
            resultHandler.handle(Future.failedFuture(response.statusMessage()));
        }
    });
}

From source file:org.etourdot.vertx.marklogic.impl.MarkLogicManagementImpl.java

License:Open Source License

void setForestProps(ForestsOptions forestsOption, Handler<AsyncResult<Void>> resultHandler) {
    requireNonNull(forestsOption, "forestsOption cannot be null");
    requireNonNull(resultHandler, "resultHandler cannot be null");
    requireNonNull(forestsOption.getName(), "forest-name cannot be null");

    MarkLogicRequest marklogicRequest = restService.newMarklogicRequest();
    String serverHttpString = getUrlWithInstance(MANAGE_FORESTS, forestsOption) + "/properties";
    marklogicRequest.put(serverHttpString).execute(response -> {
        if (HttpResponseStatus.NO_CONTENT.code() == response.statusCode()) {
            response.contentHandler(buffer -> resultHandler.handle(Future.succeededFuture()));
        } else {/*  w w  w .j  a  v  a  2s  .  com*/
            resultHandler.handle(Future.failedFuture(response.statusMessage()));
        }
    });
}

From source file:org.etourdot.vertx.marklogic.impl.MarkLogicManagementImpl.java

License:Open Source License

void databaseOperation(DatabasesOptions databasesOptions, Handler<AsyncResult<String>> resultHandler) {
    requireNonNull(databasesOptions, "databaseOption cannot be null");
    requireNonNull(resultHandler, "resultHandler cannot be null");

    MarkLogicRequest marklogicRequest = restService.newMarklogicRequest();
    String serverHttpString = getUrlWithInstance(MANAGE_DATABASES, databasesOptions);
    marklogicRequest.post(serverHttpString).withBody(databasesOptions.getOperation()).execute(response -> {
        if (HttpResponseStatus.ACCEPTED.code() == response.statusCode()) {
            resultHandler.handle(Future.succeededFuture(response.statusMessage()));
        } else {/*  w w  w . j av  a 2 s .co m*/
            resultHandler.handle(Future.failedFuture(response.statusMessage()));
        }
    });
}

From source file:org.etourdot.vertx.marklogic.impl.MarkLogicManagementImpl.java

License:Open Source License

void setDatabaseProps(DatabasesOptions databasesOptions, Handler<AsyncResult<String>> resultHandler) {
    requireNonNull(databasesOptions, "databaseOption cannot be null");
    requireNonNull(resultHandler, "resultHandler cannot be null");

    MarkLogicRequest marklogicRequest = restService.newMarklogicRequest();
    String serverHttpString = getUrlWithInstance(MANAGE_DATABASES, databasesOptions) + "/properties";
    marklogicRequest.put(serverHttpString).withBody(databasesOptions.getOperation()).execute(response -> {
        if (HttpResponseStatus.NO_CONTENT.code() == response.statusCode()) {
            response.contentHandler(buffer -> resultHandler.handle(Future.succeededFuture()));
        } else {/*from w w  w  .  ja  v a  2  s  .  c  om*/
            resultHandler.handle(Future.failedFuture(response.statusMessage()));
        }
    });
}

From source file:org.etourdot.vertx.marklogic.impl.MarkLogicManagementImpl.java

License:Open Source License

private void deleteNameObject(NameViewOptions nameOptions, Handler<AsyncResult<Void>> resultHandler,
        String baseUrl) {//  www  . ja v a2s  .c om
    MarkLogicRequest marklogicRequest = restService.newMarklogicRequest();
    String serverHttpString = getUrlWithInstance(baseUrl, nameOptions);
    marklogicRequest.delete(serverHttpString);
    marklogicRequest.execute(response -> {
        if (HttpResponseStatus.NO_CONTENT.code() == response.statusCode()) {
            response.contentHandler(buffer -> resultHandler.handle(Future.succeededFuture()));
        } else {
            resultHandler.handle(Future.failedFuture(response.statusMessage()));
        }
    });
}

From source file:org.etourdot.vertx.marklogic.impl.MarkLogicManagementImpl.java

License:Open Source License

private void createNameObject(IdNameDesc idName, Handler<AsyncResult<Void>> resultHandler, String baseUrl) {
    MarkLogicRequest marklogicRequest = restService.newMarklogicRequest();
    marklogicRequest.post(baseUrl).withBody(idName.toJson()).execute(response -> {
        if (HttpResponseStatus.CREATED.code() == response.statusCode()) {
            resultHandler.handle(Future.succeededFuture());
        } else {/*from  w  ww.j  a  va2s.co m*/
            response.contentHandler(
                    buffer -> resultHandler.handle(Future.failedFuture(buffer.toJsonObject().encode())));
        }
    });
}