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.vertx.core.*;
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.User;
import io.vertx.ext.web.FileUpload;
import io.vertx.tp.plugin.database.DataPool;
import io.vertx.tp.plugin.jooq.JooqDsl;
import io.vertx.tp.plugin.jooq.JooqInfix;
import io.vertx.up.atom.Kv;
import io.vertx.up.atom.query.Pagination;
import io.vertx.up.atom.record.Apt;
import io.vertx.up.atom.secure.AegisItem;
import io.vertx.up.atom.secure.Vis;
import io.vertx.up.commune.Envelop;
import io.vertx.up.commune.Record;
import io.vertx.up.commune.exchange.DiConsumer;
import io.vertx.up.commune.exchange.DiFabric;
import io.vertx.up.commune.exchange.DiSetting;
import io.vertx.up.commune.rule.RuleTerm;
import io.vertx.up.eon.Constants;
import io.vertx.up.eon.KName;
import io.vertx.up.eon.Strings;
import io.vertx.up.eon.em.AuthWall;
import io.vertx.up.eon.em.ChangeFlag;
import io.vertx.up.exception.WebException;
import io.vertx.up.fn.Fn;
import io.vertx.up.fn.wait.Log;
import io.vertx.up.secure.Lee;
import io.vertx.up.secure.LeeBuiltIn;
import io.vertx.up.uca.jooq.UxJoin;
import io.vertx.up.uca.jooq.UxJooq;
import io.vertx.up.util.Ut;
import org.jooq.Table;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.ConcurrentMap;
import java.util.function.*;
/**
* #「Kt」Utility X Component in zero
*
* 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 {
/*
* output part converting
*/
public static JsonObject outBool(final boolean checked) {
return Async.bool(KName.RESULT, checked);
}
public static JsonObject outBool(final String key, final boolean checked) {
return Async.bool(key, checked);
}
/**
* Create new log instance for store `Annal` mapping
*
* Debug method for help us to do development
* 1) log: for branch log creation
* 2) debug:
* 3) otherwise:
* ( Business Part: Debugging )
*/
public static Log log(final Class> clazz) {
return Log.create(null == clazz ? Ux.class : clazz);
}
public static void debug(final Object... objects) {
Debug.monitor(objects);
}
public static Future debug(final T item) {
return Debug.debug(item);
}
public static T debug(final Throwable error, final Supplier supplier) {
return Debug.debug(error, supplier);
}
public static Function otherwise() {
return Debug.otherwise();
}
public static Function otherwise(Supplier supplier) {
return Debug.otherwise(supplier);
}
public static Function otherwise(T input) {
return otherwise(() -> input);
}
public static T updateT(final T query, final JsonObject params) {
return Compare.updateT(query, params);
}
public static List updateT(final List query, final JsonArray params) {
return Compare.updateT(query, params, KName.KEY);
}
public static List updateT(final List query, final JsonArray params, final String field) {
return Compare.updateT(query, params, field);
}
public static Record updateR(final Record record, final JsonObject params) {
return Compare.updateR(record, params, () -> UUID.randomUUID().toString());
}
public static Record[] updateR(final Record[] record, final JsonArray array) {
return updateR(record, array, KName.KEY);
}
public static Record[] updateR(final Record[] record, final JsonArray array, final String field) {
final List recordList = Arrays.asList(record);
return Compare.updateR(recordList, array, field).toArray(new Record[]{});
}
/*
* Rule Match
* 1. single checking
* 2. double checking
* 3. array checking
*/
public static JsonObject ruleAll(final Collection rules, final JsonObject input) {
return Unique.ruleAll(rules, input);
}
public static ConcurrentMap ruleAll(final Collection rules, final JsonArray input) {
return Unique.ruleAll(rules, input);
}
public static JsonObject ruleAll(final Collection rules, final JsonObject recordO, final JsonObject recordN) {
return Unique.ruleAll(rules, recordO, recordN);
}
public static JsonObject ruleAll(final Collection rules, final JsonArray source, final JsonObject record) {
return Unique.ruleAll(rules, source, record);
}
public static JsonObject ruleAny(final Collection rules, final JsonObject input) {
return Unique.ruleAny(rules, input);
}
public static JsonObject ruleAny(final Collection rules, final JsonObject record0, final JsonObject recordN) {
return Unique.ruleAny(rules, record0, recordN);
}
public static JsonObject ruleAny(final Collection rules, final JsonArray source, final JsonObject record) {
return Unique.ruleAny(rules, source, record);
}
public static ConcurrentMap ruleAny(final Collection rules, final JsonArray input) {
return Unique.ruleAny(rules, input);
}
public static JsonObject ruleTwins(final JsonObject recordO, final JsonObject recordN) {
return Unique.ruleTwins(recordO, recordN);
}
public static JsonObject ruleNil(final JsonObject twins, final ChangeFlag flag) {
return Unique.ruleNil(twins, flag);
}
public static JsonObject ruleNil(final JsonObject recordN, final JsonObject recordO) {
return Objects.isNull(recordN) ? recordO : recordN;
}
public static Apt ruleApt(final JsonArray twins, final boolean isReplaced) {
return Unique.ruleApt(twins, isReplaced);
}
// ------------------------- Compare Json ------------------------
/*
* 1) ruleJOk
* 2) ruleJReduce
* 3) ruleJEqual
* 4) ruleJFind
*/
public static boolean ruleJOk(final JsonObject record, final Set fields) {
return CompareJ.ruleJOk(record, fields);
}
public static boolean ruleJOk(final JsonObject record, final JsonArray matrix) {
return CompareJ.ruleJOk(record, matrix);
}
public static JsonArray ruleJReduce(final JsonArray records, final Set fields) {
return CompareJ.ruleJReduce(records, fields);
}
public static JsonArray ruleJReduce(final JsonArray records, final JsonArray matrix) {
return CompareJ.ruleJReduce(records, matrix);
}
public static boolean ruleJEqual(final JsonObject record, final JsonObject latest, final Set fields) {
return CompareJ.ruleJEqual(record, latest, fields);
}
public static boolean ruleJEqual(final JsonObject record, final JsonObject latest, final JsonArray matrix) {
return CompareJ.ruleJEqual(record, latest, matrix);
}
public static JsonObject ruleJFind(final JsonArray source, final JsonObject expected, final Set fields) {
return CompareJ.ruleJFind(source, expected, fields);
}
public static JsonObject ruleJFind(final JsonArray source, final JsonObject expected, final JsonArray matrix) {
return CompareJ.ruleJFind(source, expected, matrix);
}
/*
* Entity ( Pojo ) to JsonObject, support pojo file here
* 1) toJson / fromJson
* 2) toZip: Toggle switch from interface style to worker here, the key should be "0", "1", "2", "3", ....
* 3) toJArray
* ( Business Part, support `pojoFile` conversation )
* 4) toFile
*/
public static JsonObject toJson(final T entity) {
return To.toJObject(entity, "");
}
public static JsonObject toJson(final T entity, final String pojo) {
return To.toJObject(entity, pojo);
}
public static JsonArray toJson(final List list) {
return To.toJArray(list, "");
}
public static JsonArray toJson(final List list, final String pojo) {
return To.toJArray(list, pojo);
}
public static JsonObject toZip(final Object... args) {
return To.toToggle(args);
}
public static T fromJson(final JsonObject data, final Class clazz) {
return From.fromJson(data, clazz, "");
}
public static List fromJson(final JsonArray array, final Class clazz) {
return From.fromJson(array, clazz, "");
}
public static List fromPage(final JsonObject data, final Class clazz) {
return fromJson(pageData(data), clazz);
}
public static T fromJson(final JsonObject data, final Class clazz, final String pojo) {
return From.fromJson(data, clazz, pojo);
}
public static List fromJson(final JsonArray array, final Class clazz, final String pojo) {
return From.fromJson(array, clazz, pojo);
}
public static JsonObject criteria(final JsonObject data, final String pojo) {
return From.fromJson(data, pojo);
}
/**
* File upload tool to convert data
*
* @param fileUploads Set of file uploads
* @param expected The method declared type
* @param consumer File consumer to read `filename` to Buffer
* @param Returned type for declared
*
* @return T reference that converted
*/
public static T toFile(final Set fileUploads, final Class> expected, final Function consumer) {
return Upload.toFile(fileUploads, expected, consumer);
}
/**
* Single file upload converting
*
* @param fileUpload The `FileUpload` reference
* @param expected The method declared type
* @param consumer File consumer to read `filename` to Buffer
* @param Returned type of declared
*
* @return T reference that converted
*/
public static T toFile(final FileUpload fileUpload, final Class> expected, final Function consumer) {
return Upload.toFile(fileUpload, expected, consumer);
}
/**
* Split `Set` by fieldname
*
* @param fileUploads FileUpload Set
*
* @return Map of `field = Set`
*/
public static ConcurrentMap> toFile(final Set fileUploads) {
return Upload.toFile(fileUploads);
}
/*
* Envelop building here
* 1) envelop: ( Get different Envelop )
* 2) future: ( Wrapper Future.successedFuture / Future.failureFuture ) at same time
* 3) handler: ( Handler> )
* 4) compare: ( Compare two object )
* 5) complex:
* - JsonObject -> condition -> executor
* - JsonArray -> condition -> grouper -> executor
*/
public static Envelop fromEnvelop(final Class extends WebException> clazz, final Object... args) {
return To.toEnvelop(clazz, args);
}
public static Envelop fromEnvelop(final T entity) {
return To.toEnvelop(entity);
}
public static Envelop fromEnvelop(final T entity, final WebException error) {
return To.toEnvelop(entity, error);
}
public static Future fromAsync(final CompletionStage state) {
return Async.fromAsync(state);
}
public static Future future(final T entity) {
return To.future(entity);
}
public static Future future(final T input, final List>> functions) {
return Async.future(input, functions);
}
public static Future future(final T input, final Set>> functions) {
return Async.future(input, functions);
}
public static Future future() {
return To.future(null);
}
public static Future complex(final JsonObject input, final Predicate predicate, final Supplier> executor) {
return Complex.complex(input, predicate, executor);
}
public static Future complex(final Pagination first, final Function> total, final Function> page, final Function> result) {
return Complex.complex(first, total, page, result, JsonArray::addAll);
}
public static Function> complex(final Function> total, final Function> page, final Function> result) {
return Complex.complex(total, page, result);
}
public static Function> complex(final Function> page) {
return complex(data -> To.future(data.getInteger("count")), page, response -> To.future(response.getJsonArray("list")));
}
public static Handler> handler(final Message message) {
return Web.toHandler(message);
}
public static Future handler(final Consumer>> handler) {
return Web.toFuture(handler);
}
/*
* 1) compare
* 2) compareJ
* 3) compareRun
*/
public static ConcurrentMap> compare(final List original, final List current, final Function fnValue, final String pojoFile) {
return Compare.compare(original, current, fnValue, pojoFile);
}
public static ConcurrentMap> compare(final List original, final List current, final Function fnValue) {
return Compare.compare(original, current, fnValue, Strings.EMPTY);
}
public static ConcurrentMap> compare(final List original, final List current, final Set uniqueSet, final String pojoFile) {
return Compare.compare(original, current, uniqueSet, pojoFile);
}
public static ConcurrentMap> compare(final List original, final List current, final Set uniqueSet) {
return Compare.compare(original, current, uniqueSet, Strings.EMPTY);
}
public static ConcurrentMap compareJ(
final JsonArray original, final JsonArray current, final Set fields) {
return CompareJ.compareJ(original, current, fields);
}
public static Future> compareJAsync(
final JsonArray original, final JsonArray current, final Set fields) {
return To.future(CompareJ.compareJ(original, current, fields));
}
public static ConcurrentMap compareJ(
final JsonArray original, final JsonArray current, final JsonArray matrix) {
return CompareJ.compareJ(original, current, matrix);
}
public static Future> compareJAsync(
final JsonArray original, final JsonArray current, final JsonArray matrix) {
return To.future(CompareJ.compareJ(original, current, matrix));
}
public static Future compareRun(final ConcurrentMap> compared, final Function, Future>> insertAsyncFn, final Function, Future>> updateAsyncFn) {
return Compare.run(compared, insertAsyncFn, updateAsyncFn);
}
/*
* future prefix processing here
*
* JsonArray
* 1) futureA
* -- futureA()
* -- futureA(List)
* -- futureA(List, pojo)
* -- futureA(String)
* -- futureA(Record[])
*
* JsonObject
* 2) futureJ
* -- futureJ()
* -- futureJ(T)
* -- futureJ(T, pojo)
* -- futureJ(String)
* -- futureJ(Record)
* -- futureJM(T, String)
*
* List
* 3) futureL
* -- futureL()
* -- futureL(List)
* -- futureL(List, pojo)
* -- futureL(String)
*
* Grouped
* 4) futureG
* -- futureG(List, String)
* -- futureG(T, String)
* -- futureG(List)
* -- futureG(T)
*
* Error Future
* 5) futureE
* -- futureE(T)
* -- futureE(Supplier)
*
* Spec Data
* 6)
* -- futureJA(JsonArray)
* -- futureB(JsonObject)
* -- futureB(boolean)
*/
public static Future futureT() {
return To.future(Boolean.TRUE);
}
public static Future futureF() {
return To.future(Boolean.FALSE);
}
public static Future> futureL() {
return future(new ArrayList<>());
}
public static Future futureB(final boolean checked) {
return To.future(outBool(checked));
}
public static Future futureB(final JsonObject checked) {
return To.future(Async.bool(checked));
}
public static Future futureJA(final JsonArray array) {
return To.future(Async.array(array));
}
public static Function> futureE(final T input) {
return Async.toErrorFuture(() -> input);
}
public static Function> futureE(final Supplier supplier) {
return Async.toErrorFuture(supplier);
}
public static Future futureA(final List list, final String pojo) {
return Future.succeededFuture(To.toJArray(list, pojo));
}
public static Future futureA() {
return futureA(new ArrayList<>(), Strings.EMPTY);
}
public static Future futureA(Throwable ex) {
return Async.toErrorFuture(JsonArray::new).apply(ex);
}
public static Future futureA(final List list) {
return futureA(list, Strings.EMPTY);
}
public static Function, Future> futureA(final String pojo) {
return list -> futureA(list, pojo);
}
// --------------- T of entity processing -----------------
public static Future futureJ(final T entity, final String pojo) {
return Future.succeededFuture(To.toJObject(entity, pojo));
}
public static Function, Future> futureJM(final T entity, final String field) {
return list -> Future.succeededFuture(To.toMerge(entity, field, list));
}
public static Future futureJ() {
return futureJ(new JsonObject(), Strings.EMPTY);
}
public static Future futureJ(Throwable ex) {
return Async.toErrorFuture(JsonObject::new).apply(ex);
}
public static Future futureJ(final T entity) {
return futureJ(entity, Strings.EMPTY);
}
public static Function> futureJ(final String pojo) {
return entity -> futureJ(entity, pojo);
}
// --------------- List of future processing -----------------
public static Future> futureL(final List list, final String pojo) {
return Future.succeededFuture(To.toJList(list, pojo));
}
public static Future> futureLJ() {
return futureL(new ArrayList<>(), Strings.EMPTY);
}
public static Future> futureL(final List list) {
return futureL(list, Strings.EMPTY);
}
public static Function, Future>> futureL(final String pojo) {
return list -> futureL(list, pojo);
}
// --------------- Record processing -----------------
public static Future futureJ(final Record record) {
return Fn.getNull(futureJ(), () -> To.future(record.toJson()), record);
}
public static Future futureA(final Record[] records) {
return Fn.getNull(futureA(), () -> To.future(Ut.toJArray(records)), records);
}
// --------------- Future of Map -----------------
public static Future> futureG(final List item, final String field) {
return futureG(To.toJArray(item, ""), field);
}
public static Future> futureG(final JsonArray item, final String field) {
return Future.succeededFuture(Ut.elementGroup(item, field));
}
public static Future> futureG(final List item) {
return futureG(To.toJArray(item, ""), "type");
}
public static Future> futureG(final JsonArray item) {
return futureG(item, "type");
}
/*
* Flatting method for function executing
* 1) attach -> JsonObject ( field )
* 2) attachJ -> Advanced JsonObject ( field )
*/
public static Function> attach(final String field, final Function> function) {
return Web.toAttach(field, function);
}
public static Function> attachJ(final String field, final Function> function) {
return Web.toAttachJ(field, function);
}
public static Function> attachJ(final String field, final JsonObject data) {
return Web.toAttachJ(field, data);
}
/*
* Normalize pageData in framework
* {
* "list": [],
* "count": xx
* }
*/
public static JsonObject pageData() {
return Web.pageData(new JsonArray(), 0L);
}
public static JsonObject pageData(final JsonArray data, final long size) {
return Web.pageData(data, size);
}
public static JsonArray pageData(final JsonObject data) {
return Ut.valueJArray(data.getJsonArray(KName.LIST));
}
public static JsonObject pageData(final JsonObject pageData, final Function function) {
return Web.pageData(pageData, function);
}
/*
* Complex calculation
* 1) thenCombine
* 2) thenCombineArray
* 3) thenCompress
* 4) thenError
* 5) thenErrorSigma
*
* Additional methods for generic T here
* 1) thenCombineT
* 2) thenCombineArrayT
*/
/**
* Future async specific workflow for combine future here.
*
* For example:
*
* ```shell
* //
* --------> generateFun ( Supplier ) operatorFun ( BiConsumer )
* --------> json1 -> ? future -> operatorFun[0] -> (json1, out1) -> merged1
* jarray -> json2 -> ? future -> operatorFun[1] -> (json2, out2) -> merged2 -> merged ( Future )
* --------> json3 -> ? future -> operatorFun[2] -> (json3, out3) -> merged3
* //
* ```
*
* @param source The first query result of list
* @param generateFun (json) -> future(out) ( each record )
* @param operatorFun (json, out) -> merged
*
* @return It often used in secondary select in database here
*/
public static Future thenCombine(final Future source, final Function> generateFun, final BinaryOperator operatorFun) {
return Combine.thenCombine(source, generateFun, operatorFun);
}
/**
* The workflow
* ------> generateFun ( Supplier ) operatorFun ( BiConsumer )
* ------> future1 ( json -> ? future ) -> operatorFun[0] -> (json, out1) -> merged1 ->
* json -> future2 ( json -> ? future ) -> operatorFun[1] -> (json, out2) -> merged2 -> merged
* ------> future3 ( json -> ? future ) -> operatorFun[2] -> (json, out3) -> merged3 ->
*
* @param source The input json object
* @param generateFun The json object should generate list, each future should be json object
* @param operatorFun merged the result to json object instead of other
*
* @return The final result of future
*/
public static Future thenCombine(final JsonObject source, final Function> generateFun, final BiConsumer... operatorFun) {
return Combine.thenCombine(Future.succeededFuture(source), generateFun, operatorFun);
}
/**
* input:
* - List: [future1, future2, future3]
* output:
* - Future: JsonArray ( future1 -> json, future2 -> json, future3 -> json )
* The workflow
* future1 -> (in1 -> out1)
* future2 -> (in2 -> out2) --> future ( [out1, out2, out3] )
* future3 -> (in3 -> out3)
*
* @param futures The list of futures
*
* @return The final result of futures
*/
public static Future thenCombine(final List> futures) {
return Combine.thenCombine(futures);
}
public static Future thenCombine(final Supplier> futureF, final Supplier> futureS,
final BiFunction> consumer) {
return Combine.thenCombine(futureF, futureS, consumer);
}
public static Future thenCombine(final Future futureF, final Future futureS,
final BiFunction> consumer) {
return Combine.thenCombine(() -> futureF, () -> futureS, consumer);
}
public static Future thenCombine(final JsonArray input, final Function> function) {
final List> futures = new ArrayList<>();
Ut.itJArray(input).map(function).forEach(futures::add);
return Combine.thenCombine(futures);
}
public static Future> thenCombineT(final List> futures) {
return Combine.thenCombineT(futures);
}
public static Future> thenCombineT(final List source, final Function> consumer) {
final List> futures = new ArrayList<>();
Ut.itList(source).map(consumer).forEach(futures::add);
return Combine.thenCombineT(futures);
}
public static Future> thenCombine(final ConcurrentMap> futureMap) {
return Combine.thenCombine(futureMap);
}
/*
* Specific combine method here.
*/
public static Future thenCombineArray(final List> futures) {
return Combine.thenCombineArray(futures);
}
public static Future thenCombineArray(final JsonArray source, final Function> consumer) {
return thenCombineArray(source, JsonObject.class, consumer);
}
public static Future thenCombineArray(final JsonArray source, final Class clazz, final Function> consumer) {
final List> futures = new ArrayList<>();
Ut.itJArray(source, clazz, (item, index) -> futures.add(consumer.apply(item)));
return Combine.thenCombineArray(futures);
}
public static Future> thenCombineArrayT(final List>> futures) {
return Combine.thenCombineArrayT(futures);
}
public static Future> thenCompress(final List>> futures) {
return Combine.thenCompress(futures, (original, latest) -> original.addAll(latest));
}
/**
* Common usage: To error directly
*
* @param clazz The type of WebException, class type, it will be created by reflection.
* @param args The rule
* - arg0: this.getClass(), Because all the first arg of WebException must be clazz here.
* - argX: the arguments of WebException constructor here, instead of fixed arguments.
*/
public static Future thenError(final Class extends WebException> clazz, final Object... args) {
return Combine.thenError(clazz, args);
}
public static