All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.vertx.up.unity.Ux Maven / Gradle / Ivy

There is a newer version: 0.9.0
Show newest version
package io.vertx.up.unity;

import io.github.jklingsporn.vertx.jooq.future.VertxDAO;
import io.vertx.core.AsyncResult;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.eventbus.Message;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.ext.auth.jwt.JWTAuthOptions;
import io.vertx.ext.jwt.JWT;
import io.vertx.ext.jwt.JWTOptions;
import io.vertx.ext.mongo.FindOptions;
import io.vertx.up.atom.query.Criteria;
import io.vertx.up.atom.query.Inquiry;
import io.vertx.up.commune.Envelop;
import io.vertx.up.eon.Strings;
import io.vertx.up.exception.WebException;
import io.vertx.up.fn.Actuator;
import io.vertx.up.fn.Fn;
import io.vertx.up.fn.wait.Log;
import io.vertx.up.uca.container.Refer;
import io.vertx.up.util.Ut;
import org.jooq.Condition;

import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.function.*;

/**
 * Here Ux is a util interface of uniform to call different tools.
 * It just like helper for business usage.
 */
@SuppressWarnings("all")
public final class Ux {

    // ---------------------- Fast Logging ----------------------------
    public static Log log(final Class clazz) {
        return Log.create(null == clazz ? Ux.class : clazz);
    }

    // ---------------------- Debug/Timer --------------------------
    public static void debug(final Object... objects) {
        Debug.monitor(objects);
    }

    public static  Future debug(final T item) {
        Fn.safeNull(() -> Debug.monitor(item), item);
        return Future.succeededFuture(item);
    }

    public static  T debug(final Throwable error, final Supplier supplier) {
        if (Objects.nonNull(error)) {
            // TODO: Debug for JVM;
            error.printStackTrace();
        }
        return supplier.get();
    }

    public static void timer(final Class clazz, final Actuator actuator) {
        Debug.timer(clazz, actuator);
    }

    public static  T timer(final Class clazz, final Supplier supplier) {
        return Debug.timer(clazz, supplier);
    }

    // ---------------------- JsonObject Returned --------------------------
    // T -> JsonObject
    public static  JsonObject toJson(final T entity) {
        return To.toJson(entity, "");
    }

    // T -> JsonObject ( with Pojo )
    public static  JsonObject toJson(final T entity, final String pojo) {
        return To.toJson(entity, pojo);
    }

    public static JsonObject toFilters(final String[] columns, final Supplier... supplier) {
        return To.toFilters(columns, supplier);
    }

    // Toggle switch from interface style to worker here, the key should be "0", "1", "2", "3", ....
    public static JsonObject toToggle(final Object... args) {
        return To.toToggle(args);
    }

    public static  T fromJson(final JsonObject data, final Class clazz) {
        return From.fromJson(data, clazz, "");
    }

    public static  T fromJson(final JsonObject data, final Class clazz, final String pojo) {
        return From.fromJson(data, clazz, pojo);
    }

    public static JsonObject fromJson(final JsonObject data, final String pojo) {
        return From.fromJson(data, pojo);
    }

    // JsonArray -> JsonObject ( with field grouped )
    public static JsonObject toGroup(final JsonArray array, final String field) {
        return Calculator.groupBy(array, field);
    }

    // JsonArray -> Future
    public static Future thenGroup(final JsonArray array, final String field) {
        return Future.succeededFuture(Calculator.groupBy(array, field));
    }

    // Special Merge
    public static void appendJson(final JsonObject target, final JsonObject source) {
        Calculator.appendJson(target, source);
    }

    // ---------------------- Web Error Returned --------------------------
    // -> WebException direct
    public static WebException toError(final Class clazz, final Object... args) {
        return To.toError(clazz, args);
    }

    // ---------------------- JsonArray Returned --------------------------
    // -> List -> JsonArray
    public static  JsonArray toArray(final List list) {
        return To.toArray(list, "");
    }

    // -> List -> JsonArray ( with Pojo )
    public static  JsonArray toArray(final List list, final String pojo) {
        return To.toArray(list, pojo);
    }

    // ---------------------- Envelop Returned --------------------------
    public static  Future toFuture(final T entity) {
        return To.toFuture(entity);
    }

    public static  Future toFuture(final T entity, final Supplier defaultFun, final Function actualFun) {
        return null == entity ? Future.succeededFuture(defaultFun.get()) : Future.succeededFuture(actualFun.apply(entity));
    }

    // ---------------------- If/Else Future ----------------------------
    public static  Future toFuture(final Supplier> caseLine) {
        return Fn.future(caseLine);
    }

    public static  Future toFuture(final Actuator executor, final Supplier> caseLine) {
        return Fn.future(executor, caseLine);
    }

    // ---------------------- Envelop Returned --------------------------
    // -> List -> Envelop
    public static  Envelop to(final List list) {
        return Envelop.success(Ux.toArray(list));
    }

    // -> Class -> Envelop ( With failure )
    public static Envelop to(final Class clazz, final Object... args) {
        return To.toEnvelop(clazz, args);
    }

    // -> T -> Envelop
    public static  Envelop to(final T entity) {
        return To.toEnvelop(entity);
    }

    // -> T -> Envelop ( If entity is null, return Envelop.failure(error) )
    public static  Envelop to(final T entity, final WebException error) {
        return To.toEnvelop(entity, error);
    }

    // -> JsonArray -> Envelop ( To JsonObject, Result length must be 1 )
    public static Envelop toOne(final JsonArray array) {
        return Envelop.success(To.toUnique(array, ""));
    }

    // -> List -> JsonObject ( Result length must be 1 )
    public static  JsonObject toUnique(final List list) {
        return To.toUnique(Ux.toArray(list), "");
    }

    public static  JsonObject toUnique(final List list, final String pojo) {
        return To.toUnique(Ux.toArray(list), pojo);
    }

    // -> JsonArray -> JsonObject ( Result length must be 1 )
    public static  JsonObject toUnique(final JsonArray array) {
        return To.toUnique(array, "");
    }

    // ---------------------- User Data -------------------------------------

    // -> Message -> String ( Security )
    @Deprecated
    public static String getUserID(final Envelop envelop, final String field) {
        return In.requestUser(envelop, field);
    }
    /*
    public static String getUserID(final Message message, final String field) {
        return In.requestUser(message, field);
    }


    // -> Message -> UUID ( Security )
    public static UUID getUserUUID(final Message message, final String field) {
        return UUID.fromString(getUserID(message, field));
    }

    public static UUID getUserUUID(final Envelop envelop, final String field) {
        return UUID.fromString(getUserID(envelop, field));
    }*/

    // -> Message -> Session ( Key )
    /*
    public static Object getSession(final Message message, final String field) {
        return In.requestSession(message, field);
    }

    public static Object getSession(final Envelop envelop, final String field) {
        return In.requestSession(envelop, field);
    }*/

    // -> JsonArray ( JsonObject ) + JsonArray ( String ) -> add 'serial'
    public static JsonArray serial(final JsonArray items, final JsonArray serials) {
        return In.assignValue(items, serials, "serial", true);
    }

    public static JsonArray field(final JsonArray items, final JsonArray targets, final String field) {
        return In.assignValue(items, targets, field, true);
    }

    // ---------------------- Function Generator --------------------------------------
    public static Future fnRpc(final JsonArray array) {
        return UxRpc.fnRpc(array);
    }

    public static Future fnRpc(final JsonObject data) {
        return UxRpc.fnRpc(data);
    }

    public static  Future fnJObject(final T item) {
        return thenJsonOne(item, "");
    }

    public static  Future fnJArray(final List item) {
        return thenJsonMore(item, "");
    }

    public static  Function> fnJObject(final String pojo) {
        return item -> thenJsonOne(item, pojo);
    }

    public static  Function, Future> fnJArray(final String pojo) {
        return list -> Ux.thenJsonMore(list, pojo);
    }

    // ---------------------- Web Flow --------------------------------------
    public static  Handler> handler(final Message message) {
        return Web.toHandler(message);
    }

    // ---------------------- Future --------------------------
    public static  Future thenRpc(final String name, final String address, final JsonObject params) {
        return UxRpc.thenRpc(name, address, params);
    }

    public static  Future thenRpc(final String name, final String address, final String field, final Object value) {
        return UxRpc.thenRpc(name, address, new JsonObject().put(field, value));
    }

    // ---------------------- New future ----------------------
    public static  Future then(final T entity) {
        return Future.succeededFuture(to(entity));
    }

    public static Future thenBool(final Boolean result) {
        return Future.succeededFuture(new JsonObject().put(Strings.J_RESULT, result));
    }

    public static  Future thenJsonMore(final List list) {
        return Future.succeededFuture(To.toArray(list, ""));
    }

    public static  Future thenJsonMore(final List list, final String pojo) {
        return Future.succeededFuture(To.toArray(list, pojo));
    }

    public static  Future thenJsonOne(final List list, final String pojo) {
        return Future.succeededFuture(To.toUnique(new JsonArray(list), pojo));
    }

    public static  Future thenJsonOne(final T entity, final String pojo) {
        return Future.succeededFuture(To.toJson(entity, pojo));
    }

    public static  Future thenUpsert(final T entity,
                                                    final Supplier> supplier) {
        return Async.toUpsertFuture(entity, "", supplier, null);
    }

    public static  Future thenUpsert(final T entity,
                                                    final Supplier> supplier,
                                                    final Function updateFun) {
        return Async.toUpsertFuture(entity, "", supplier, updateFun);
    }

    public static  Future thenUpsert(final T entity, final String pojo,
                                                    final Supplier> supplier) {
        return Async.toUpsertFuture(entity, pojo, supplier, null);
    }

    public static  Future thenUpsert(final T entity, final String pojo,
                                                    final Supplier> supplier,
                                                    final Function updateFun) {
        return Async.toUpsertFuture(entity, pojo, supplier, updateFun);
    }

    public static  Future thenMore(final List list, final String pojo) {
        return Future.succeededFuture(Envelop.success(To.toArray(list, pojo)));
    }

    public static  Future thenOne(final T entity, final String pojo) {
        return Future.succeededFuture(Envelop.success(To.toJson(entity, pojo)));
    }

    // -> Consumer> -> Future
    public static  Future thenGeneric(final Consumer> consumer) {
        return Fn.thenGeneric(consumer);
    }

    public static  Future thenGeneric(final Object result, final Future future, final Throwable ex) {
        return Fn.thenGeneric(result, future, ex);
    }

    // ---------------------- Future --------------------------

    /**
     * Parallel generate
     * Source ->
     * source1 -> Future<1>
     * source2 -> Future<2>
     * For each element merge 1,2 -> 3
     *
     * @param source      List
     * @param generateFun F -> Future
     * @param mergeFun    Each element: (F,S) -> T
     * @param          first
     * @param          second
     * @param          third
     * @return List
     */
    public static  Future> thenParallel(final Future> source, final Function> generateFun, final BiFunction mergeFun) {
        return Fluctuate.thenParallel(source, generateFun, mergeFun);
    }

    public static Future thenParallelArray(final Future source, final Function> generateFun, final BinaryOperator operatorFun) {
        return Fluctuate.thenParallelArray(source, generateFun, operatorFun);
    }

    public static Future thenParallelArray(final Future... sources) {
        return Fluctuate.thenParallelArray(sources);
    }

    public static Future thenParallelJson(final Future... sources) {
        return Fluctuate.thenParallelJson(sources);
    }

    public static Future thenParallelJson(final Future source, final Function> generateFun, final BiConsumer... operatorFun) {
        return Fluctuate.thenParallelJson(source, generateFun, operatorFun);
    }

    public static Future thenParallelJson(final JsonObject source, final Function> generateFun, final BiConsumer... operatorFun) {
        return Fluctuate.thenParallelJson(Future.succeededFuture(source), generateFun, operatorFun);
    }

    /**
     * Scatter generate
     * Source ->
     * source1 -> Future>
     * source2 -> Future>
     * Fore each element mergage 1, List<2> -> 3
     *
     * @param source      JsonArray
     * @param generateFun JsonObject -> Future
     * @param mergeFun    Each element: JsonObject + JsonArray -> JsonObject
     * @return JsonArray
     */
    public static Future thenScatterJson(final Future source, final Function> generateFun, final BiFunction mergeFun) {
        return Fluctuate.thenScatterJson(source, generateFun, mergeFun);
    }

    /**
     * Merge multi Future<> to single one, one for all module.
     * source ->
     * supplier1
     * supplier2
     * supplier3
     * .....
     * All suppliers will be executed after source, then return the final Future.
     *
     * @param mergeFun  How to merge source result and all supplier's results into final result:
     * @param source    Single Future --> F
     * @param suppliers Multi Futures --> List
     * @param        Type of source element
     * @param        Type of supplier's list element
     * @param        Type of return
     * @return Future for final result.
     */
    public static  Future thenComposite(final Future source, final BiFunction, T> mergeFun, final Supplier>... suppliers) {
        return Fluctuate.thenComposite(source, mergeFun, suppliers);
    }

    public static Future thenComposite(final List> futures) {
        return Fluctuate.thenComposite(futures);
    }

    public static  Future> thenSet(final List data, final Function> fun) {
        return Fluctuate.thenSet(data, fun);
    }

    // -> Merge multi Future<> to single one, one for all module.
    public static  Future thenComposite(final Future source, final BiFunction, T> mergeFun, final Function>... functions) {
        return Fluctuate.thenComposite(source, mergeFun, functions);
    }

    // -> IfElse true -> Future, false -> Future
    public static  Future thenOtherwise(final Future condition, final Supplier> trueFuture, final Function trueFun, final Supplier> falseFuture, final Function falseFun) {
        return Fluctuate.thenOtherwise(condition, trueFuture, trueFun, falseFuture, falseFun);
    }

    // -> IfOr true -> Future, false -> Future
    public static  Future thenError(final Future condition, final Supplier> trueFuture, final Function trueFun, final Class clazz, final Object... args) {
        return Fluctuate.thenOtherwise(condition, trueFuture, trueFun, clazz, args);
    }

    // -> IfOr true -> Future, false -> Future
    public static Future thenError(final Future condition, final Supplier> trueFuture, final Class clazz, final Object... args) {
        return Fluctuate.thenOtherwise(condition, trueFuture, item -> item, clazz, args);
    }

    // -> To error directly
    public static  Future thenError(final Class clazz, final Object... args) {
        return Fluctuate.thenError(clazz, args);
    }

    // -> If only true -> Future
    public static  Future thenTrue(final Future condition, final Supplier> trueFuture, final Function trueFun) {
        return Fluctuate.thenOtherwise(condition, trueFuture, trueFun, null);
    }

    // ---------------------- Request Data Extract --------------------------
    // -> Message -> T ( Interface mode )

    public static JsonArray getArray(final Envelop envelop, final int index) {
        return In.request(envelop, index, JsonArray.class);
    }

    // -> Message -> T ( Interface mode )
    public static JsonArray getArray(final Envelop envelop) {
        return In.request(envelop, 0, JsonArray.class);
    }

    // -> Message -> T ( Interface mode )

    public static JsonArray getArray1(final Envelop envelop) {
        return In.request(envelop, 1, JsonArray.class);
    }

    // -> Message -> T ( Interface mode )

    public static JsonArray getArray2(final Envelop envelop) {
        return In.request(envelop, 2, JsonArray.class);
    }

    // -> Message -> T ( Interface mode )

    public static JsonArray getArray3(final Envelop envelop) {
        return In.request(envelop, 3, JsonArray.class);
    }

    // -> Message -> String ( Interface mode )

    public static String getString(final Envelop envelop, final int index) {
        return In.request(envelop, index, String.class);
    }

    // -> Message -> String ( Interface mode )
    public static String getString(final Envelop envelop) {
        return In.request(envelop, 0, String.class);
    }

    // -> Message -> String ( Interface mode )
    public static String getString1(final Envelop envelop) {
        return In.request(envelop, 1, String.class);
    }

    // -> Message -> String ( Interface mode )
    public static String getString2(final Envelop envelop) {
        return In.request(envelop, 2, String.class);
    }

    // -> Message -> String ( Interface mode )
    public static String getString3(final Envelop envelop) {
        return In.request(envelop, 3, String.class);
    }

    // -> Message -> JsonObject ( Interface mode )

    public static JsonObject getJson(final Envelop envelop, final int index) {
        return In.request(envelop, index, JsonObject.class);
    }

    // -> Message -> JsonObject ( Interface mode )

    public static  T fromEnvelop(final Envelop envelop, final Class clazz, final String pojo) {
        return From.fromJson(getJson(envelop), clazz, pojo);
    }

    public static JsonObject fromEnvelop(final Envelop envelop, final String pojo) {
        return From.fromJson(Ux.getJson(envelop), pojo);
    }

    public static JsonObject getJson(final Envelop envelop) {
        return In.request(envelop, 0, JsonObject.class);
    }

    public static Inquiry getInquiry(final JsonObject envelop) {
        return Query.getInquiry(envelop, "");
    }

    public static Inquiry getInquiry(final JsonObject envelop, final String pojo) {
        return Query.getInquiry(envelop, pojo);
    }

    // -> Message -> JsonObject ( Interface mode )

    public static  T fromEnvelop1(final Envelop envelop, final Class clazz, final String pojo) {
        return From.fromJson(getJson1(envelop), clazz, pojo);
    }

    public static JsonObject fromEnvelop1(final Envelop envelop, final String pojo) {
        return From.fromJson(Ux.getJson1(envelop), pojo);
    }

    public static JsonObject getJson1(final Envelop envelop) {
        return In.request(envelop, 1, JsonObject.class);
    }

    // -> Message -> JsonObject ( Interface mode )

    public static JsonObject getJson2(final Envelop envelop) {
        return In.request(envelop, 2, JsonObject.class);
    }

    public static JsonObject fromEnvelop2(final Envelop envelop, final String pojo) {
        return From.fromJson(Ux.getJson2(envelop), pojo);
    }

    public static  T fromEnvelop2(final Envelop envelop, final Class clazz, final String pojo) {
        return From.fromJson(getJson2(envelop), clazz, pojo);
    }

    // -> Message -> JsonObject ( Interface mode )

    public static JsonObject getJson3(final Envelop envelop) {
        return In.request(envelop, 3, JsonObject.class);
    }

    public static JsonObject fromEnvelop3(final Envelop envelop, final String pojo) {
        return From.fromJson(Ux.getJson3(envelop), pojo);
    }

    public static  T fromEnvelop3(final Envelop envelop, final Class clazz, final String pojo) {
        return From.fromJson(getJson3(envelop), clazz, pojo);
    }

    // -> Message -> Integer ( Interface mode )

    public static Integer getInteger(final Envelop envelop, final int index) {
        return In.request(envelop, index, Integer.class);
    }

    public static Integer getInteger(final Envelop envelop) {
        return In.request(envelop, 0, Integer.class);
    }

    // -> Message -> Integer ( Interface mode )
    public static Integer getInteger1(final Envelop envelop) {
        return In.request(envelop, 1, Integer.class);
    }

    // -> Message -> Integer ( Interface mode )
    public static Integer getInteger2(final Envelop envelop) {
        return In.request(envelop, 2, Integer.class);
    }

    // -> Message -> Integer ( Interface mode )
    public static Integer getInteger3(final Envelop envelop) {
        return In.request(envelop, 3, Integer.class);
    }

    // -> Message -> Long ( Interface mode )

    public static Long getLong(final Envelop envelop, final int index) {
        return In.request(envelop, index, Long.class);
    }

    // -> Message -> Long ( Interface mode )
    public static Long getLong(final Envelop envelop) {
        return In.request(envelop, 0, Long.class);
    }

    // -> Message -> Long ( Interface mode )
    public static Long getLong1(final Envelop envelop) {
        return In.request(envelop, 1, Long.class);
    }

    // -> Message -> Long ( Interface mode )
    public static Long getLong2(final Envelop envelop) {
        return In.request(envelop, 2, Long.class);
    }

    // -> Message -> Long ( Interface mode )
    public static Long getLong3(final Envelop envelop) {
        return In.request(envelop, 3, Long.class);
    }

    // -> Message -> T ( Interface mode )

    public static  T getT(final Envelop envelop, final int index, final Class clazz) {
        return In.request(envelop, index, clazz);
    }

    // -> Message -> T ( Interface mode )

    public static  T getT(final Envelop envelop, final Class clazz) {
        return In.request(envelop, 0, clazz);
    }

    // -> Message -> T ( Interface mode )

    public static  T getT1(final Envelop envelop, final Class clazz) {
        return In.request(envelop, 1, clazz);
    }

    // -> Message -> T ( Interface mode )

    public static  T getT2(final Envelop envelop, final Class clazz) {
        return In.request(envelop, 2, clazz);
    }

    // -> Message -> T ( Interface mode )

    public static  T getT3(final Envelop envelop, final Class clazz) {
        return In.request(envelop, 3, clazz);
    }

    // ---------------------- Agent mode usage --------------------------
    // -> Message -> JsonObject ( Agent mode )
    // -> Envelop -> JsonObject ( Agent mode )
    public static JsonObject getBody(final Envelop envelop) {
        return In.request(envelop, JsonObject.class);
    }

    // -> Message -> T ( Agent mode )

    // -> Envelop -> T ( Agent mode )
    public static  T getBodyT(final Envelop envelop, final Class clazz) {
        return In.request(envelop, clazz);
    }

    // ---------------------- Request Data Ending --------------------------
    public static  Future rxContainer(final Refer container, final E entity) {
        return Functions.fnSupplier(container, entity, null);
    }

    public static  Future rxContainer(final Refer container, final E entity, final Supplier supplier) {
        return Functions.fnSupplier(container, entity, supplier);
    }

    public static  Future rxContainer(final Refer container, final E entity, final Consumer consumer) {
        return Functions.fnConsumer(container, entity, consumer);
    }

    public static  Future rxContainer(final Refer container, final E entity, final Function function) {
        return Functions.fnConsumer(container, entity, item -> function.apply((T) item));
    }

    public static  Future rxContainer(final Refer container, final E entity, final T target) {
        return Functions.fnSupplier(container, entity, () -> target);
    }

    // -- Atom
    public static Function> atomJoin(final String field, final JsonObject to) {
        return Atomic.joinTo(to, field);
    }

    public static Function> atomJoin(final JsonObject from, final String field) {
        return Atomic.joinFrom(from, field);
    }

    // -> Jooq Condition
    public static Condition condition(final JsonObject filters) {
        return UxJooq.transform(filters);
    }

    public static Condition condition(final Criteria criteria) {
        return UxJooq.transform(criteria.toJson());
    }

    public static void initComponent(final JsonObject init) {
        Atomic.initComponent(init);
    }

    // -> Jooq
    public static class Jooq {

        public static UxJooq on(final Class clazz) {
            return Fn.pool(io.vertx.up.unity.Pool.JOOQ, clazz, () -> new UxJooq(clazz));
        }

        public static UxJooq on(final Class clazz, final VertxDAO vertxDAO) {
            return Fn.pool(io.vertx.up.unity.Pool.JOOQ, clazz, () -> new UxJooq(clazz, vertxDAO));
        }
    }

    public static class Pool {

        public static UxPool on(final String name) {
            return Fn.pool(io.vertx.up.unity.Pool.POOL, name, () -> new UxPool(name));
        }

        public static UxPool on() {
            return new UxPool();
        }
    }

    public static class Job {
        public static UxJob on() {
            return new UxJob();
        }
    }

    // -> Jwt
    public static class Jwt {

        public static String token(final JsonObject claims) {
            return UxJwt.generate(claims, new JWTOptions());
        }

        public static String token(final JsonObject claims, final Function funcBuffer) {
            return UxJwt.generate(claims, new JWTOptions(), funcBuffer);
        }

        public static JsonObject extract(final JsonObject vertxToken) {
            return UxJwt.extract(vertxToken.getString("jwt"));
        }

        public static JsonObject extract(final String token) {
            return UxJwt.extract(token);
        }

        public static JsonObject extract(final String token, final JsonObject config) {
            return UxJwt.extract(token, config);
        }

        public static JWT create(final JWTAuthOptions config) {
            return UxJwt.create(new JWTAuthOptions(config), Ut::ioBuffer);
        }

        public static JWT create(final JsonObject config) {
            return UxJwt.create(new JWTAuthOptions(config), Ut::ioBuffer);
        }

        public static JWT create(final JWTAuthOptions config, final Function funcBuffer) {
            return UxJwt.create(config, funcBuffer);
        }

        public static JWT create(final JsonObject config, final Function funcBuffer) {
            return UxJwt.create(new JWTAuthOptions(config), funcBuffer);
        }
    }

    // -> Mongo
    public static class Mongo {

        public static JsonObject termIn(final JsonObject filter, final String field, final JsonArray values) {
            return UxMongo.termIn(filter, field, values);
        }

        public static JsonObject termLike(final JsonObject filter, final String field, final String value) {
            return UxMongo.termLike(filter, field, value);
        }

        public static Future missing(final String collection, final JsonObject filter) {
            return UxMongo.missing(collection, filter);
        }

        public static Future existing(final String collection, final JsonObject filter) {
            return UxMongo.existing(collection, filter);
        }

        public static Future insert(final String collection, final JsonObject data) {
            return UxMongo.insert(collection, data);
        }

        public static Future findOne(final String collection, final JsonObject filter) {
            return UxMongo.findOne(collection, filter);
        }

        public static Future findOne(final String collection, final JsonObject filter,
                                                 final String joinedCollection, final String joinedKey, final JsonObject additional,
                                                 final BinaryOperator operatorFun) {
            return UxMongo.findOne(collection, filter, joinedCollection, joinedKey, additional, operatorFun);
        }

        public static Future findOneAndReplace(final String collection, final JsonObject filter,
                                                           final String field, final Object value) {
            return UxMongo.findOneAndReplace(collection, filter, new JsonObject().put(field, value));
        }

        public static Future findOneAndReplace(final String collection, final JsonObject filter,
                                                           final JsonObject data) {
            return UxMongo.findOneAndReplace(collection, filter, data);
        }

        public static Future removeDocument(final String collection, final JsonObject filter) {
            return UxMongo.removeDocument(collection, filter);
        }

        public static Future findWithOptions(final String collection, final JsonObject filter,
                                                        final FindOptions options) {
            return UxMongo.findWithOptions(collection, filter, options);
        }

        public static Future findWithOptions(final String collection, final JsonObject filter, final FindOptions options,
                                                        // Secondary Query
                                                        final String joinedCollection, final String joinedKey, final JsonObject additional,
                                                        final BinaryOperator operatorFun) {
            return UxMongo.findWithOptions(collection, filter, options,
                    joinedCollection, joinedKey, additional, operatorFun);
        }

        public static Future find(final String collection, final JsonObject filter) {
            return UxMongo.findWithOptions(collection, filter, new FindOptions());
        }
    }
}