Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
io.vertx.up.unity.Ux Maven / Gradle / Ivy
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 extends WebException> 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 extends WebException> 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 extends WebException> 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 extends WebException> clazz, final Object... args) {
return Fluctuate.thenOtherwise(condition, trueFuture, item -> item, clazz, args);
}
// -> To error directly
public static Future thenError(final Class extends WebException> 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