Skip to content

Commit

Permalink
New API
Browse files Browse the repository at this point in the history
  • Loading branch information
silentbalanceyh committed Jun 2, 2023
1 parent 0317077 commit 3ac985d
Show file tree
Hide file tree
Showing 8 changed files with 177 additions and 140 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@

<!-- Third Part -->
<jetbrains.version>23.1.0</jetbrains.version>
<scala.version>2.13.11-M2</scala.version>
<scala.version>2.13.11</scala.version>
<feign.version>8.18.0</feign.version>
<joda.version>2.12.5</joda.version>
<ignite.version>2.15.0</ignite.version>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package io.horizon.specification.typed;

import io.vertx.core.Future;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;

/**
* 「六维执行接口」
* 可以在不同模块中使用,参考六个核心维度:
* <pre><code>
* 1. 输入执行维度
* T -> 核心DTO
* JsonObject -> 单记录执行
* JsonArray -> 多记录执行
* 2. 行为维度
* Sync -> 同步执行(默认方式)
* Async -> 异步执行
* 最终转换成 2 x 3 的六维度处理
* </code></pre>
*
* @author lang : 2023-06-03
*/
public interface THex<I, O> extends THexJ<O> {

/**
* (核心DTO)专用检查方法,检查数据结果是否符合预期
*
* @param data 数据
* @param config 配置
*
* @return {@link O}
*/
O execute(I data, JsonObject config);

/**
* 「异步版本」(核心DTO)专用检查方法,检查数据结果是否符合预期
*
* @param data 数据
* @param config 配置
*
* @return {@link Future}
*/
default Future<O> executeAsync(final I data, final JsonObject config) {
return Future.succeededFuture(this.execute(data, config));
}
}

interface THexJ<O> {
/**
* (JsonObject)专用检查方法,检查数据结果是否符合预期
*
* @param data 数据
* @param config 配置
*
* @return {@link O}
*/
O executeJ(final JsonObject data, final JsonObject config);

/**
* 「异步版本」(JsonObject)专用检查方法,检查数据结果是否符合预期
*
* @param data 数据
* @param config 配置
*
* @return {@link Future}
*/
default Future<O> executeJAsync(final JsonObject data, final JsonObject config) {
return Future.succeededFuture(this.executeJ(data, config));
}

/**
* (JsonArray)专用检查方法,检查数据结果是否符合预期
*
* @param data 数据
* @param config 配置
*
* @return {@link O}
*/
O executeJ(final JsonArray data, final JsonObject config);

/**
* 「异步版本」(JsonArray)专用检查方法,检查数据结果是否符合预期
*
* @param data 数据
* @param config 配置
*
* @return {@link O}
*/
default Future<O> executeJAsync(final JsonArray data, final JsonObject config) {
return Future.succeededFuture(this.executeJ(data, config));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package io.horizon.specification.uca;

import io.horizon.specification.typed.THex;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;

/**
* 「检查器」
* 可以在不同的模块中使用,主要用于检查数据本身的合法性,核心使用场景:
* <pre><code>
* 1. 请求拦截器:可配置到 AOP 层直接拦截请求,检查请求的合法性
* 2. 检查结果通常会以异步的方式处理
* - 成功:{@link io.vertx.core.Future#succeededFuture(Object)}
* - 失败:{@link io.vertx.core.Future#failedFuture(Throwable)}
* 3. 不仅如此,检查的最终结果会直接返回输入信息,方便后续的处理
* </code></pre>
*
* @author lang : 2023-05-27
*/
public interface HTrue<T> extends THex<T, Boolean> {

@Override
default Boolean execute(final T data, final JsonObject config) {
return Boolean.TRUE;
}

@Override
default Boolean executeJ(final JsonObject data, final JsonObject config) {
return Boolean.TRUE;
}

@Override
default Boolean executeJ(final JsonArray data, final JsonObject config) {
return Boolean.TRUE;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ E80302: "(500) - (Ambient) The Init implementation class = {0} does not `impleme
E80303: "(500) - (Ambient) The Prerequisite class = {0} does not satisfy specification"
E80304: "(409) - (Atom) The atom (`{0}`) could not generate `Activity` record because trackable is FALSE"
E80305: "(501) - (Atom) The `indent` field of configuration missing, config =`{0}`"
E80306: "(403) - (Refer) Parent record could not be deleted because it''s referenced by children, identifier = {}"
E80306: "(403) - (Refer) Linked records could not be deleted because it''s referenced by other records, identifier = {}"

# Jet
E80400: "(500) - (Jet) The container try to connect App/Source, but `UnityApp` is null and could not start up"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@

import cn.vertxup.ambient.domain.tables.pojos.XCategory;
import io.horizon.eon.em.typed.ChangeFlag;
import io.horizon.specification.uca.HChecker;
import io.horizon.specification.uca.HTrue;
import io.horizon.uca.aop.Before;
import io.vertx.core.Future;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import io.vertx.mod.ambient.error._403TreeDeletionException;
import io.vertx.mod.ambient.uca.validator.TreeChecker;
import io.vertx.up.eon.KName;
import io.vertx.up.util.Ut;
import io.vertx.up.fn.Fn;

import java.util.Set;

/**
* @author lang : 2023-05-27
*/
public class BeforeTreeChecker implements Before {
private final HChecker<XCategory> checker = TreeChecker.create();
private final HTrue<XCategory> checker = TreeChecker.of();

@Override
public Set<ChangeFlag> types() {
Expand All @@ -27,13 +25,17 @@ public Set<ChangeFlag> types() {

@Override
public Future<JsonObject> beforeAsync(final JsonObject data, final JsonObject config) {
final String identifier = data.getString(KName.IDENTIFIER);
return Future.failedFuture(new _403TreeDeletionException(this.getClass(), identifier));
// 全为 false 过
return Fn.passNone(data, TreeChecker.webFailure(this.getClass(), data), Set.of(
(input) -> this.checker.executeJAsync(data, config)
));
}

@Override
public Future<JsonArray> beforeAsync(final JsonArray data, final JsonObject config) {
final Set<String> identifiers = Ut.valueSetString(data, KName.IDENTIFIER);
return Future.failedFuture(new _403TreeDeletionException(this.getClass(), Ut.fromJoin(identifiers)));
// 全为 false 过
return Fn.passNone(data, TreeChecker.webFailure(this.getClass(), data), Set.of(
(input) -> this.checker.executeJAsync(data, config)
));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
/**
* @author lang : 2023-05-27
*/
public class _403TreeDeletionException extends WebException {
public class _403LinkDeletionException extends WebException {

public _403TreeDeletionException(final Class<?> clazz,
public _403LinkDeletionException(final Class<?> clazz,
final String identifier) {
super(clazz, identifier);
}
Expand Down
Loading

0 comments on commit 3ac985d

Please sign in to comment.